MinGfx Toolkit
1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
|
This implements a user interface for controlling the camera with the mouse.
This interface is appropriate for "first person" camera control, as in games like Minecraft.
Use the arrow keys or A,S,W,Z keys to move around in the virtual world. UP/DOWN and W/Z move forward and back. LEFT/RIGHT or A/S rotate your body to face left or right. You can rotate and tilt your head to look left/right/up/down by moving the mouse. In Minecraft, that movement happens whenever you move the mouse, regardless of whether you are holding down a mouse button, but in some games you want to hold the camera still while you use the mouse to draw on the screen or do something else. It's possible to use this interface both ways by calling the MouseMove() function either every time the mouse moves, or only when the mouse is in a dragging mode.
Example usage:
Definition at line 79 of file craft_cam.h.
#include <craft_cam.h>
Public Member Functions | |
CraftCam () | |
Creates a CraftCam object with an initial view matrix = identity. More... | |
CraftCam (const Matrix4 &initial_view_matrix) | |
Creates a CraftCam object with the supplied initial view matrix. More... | |
virtual | ~CraftCam () |
void | UpdateSimulation (double dt, GLFWwindow *window_ptr) |
Call this from your app's UpdateSimulation() method. This tells the camera to simulate walking based on the keyboard keys currently pressed. You need to pass a pointer to the underlying GLFW window created by GraphicsApp. Example: More... | |
void | OnMouseMove (const Vector2 &normalized_mouse_delta) |
Call this from your app's OnMouseMove() or On*MouseDrag() method. Use OnMouseMove() if you want to always rotate the view with the mouse. Remember to convert the mouse coordinates (usually reported by window managers in pixels) into normalized device coordinates: More... | |
Matrix4 | view_matrix () |
Access the camera view matrix created by the CraftCam interactions via this method and use it to draw the geometry in your scence. For example, within GraphicsApp::DrawUsingOpenGL(), you might have: More... | |
Point3 | eye () |
Returns the "eye" point (i.e., focal point) of the camera in world space coordinates. More... | |
Vector3 | look () |
Returns the look direction (i.e., -Z axis of the camera matrix) in world space coordinates. More... | |
void | UpdateHeight (float new_y_value) |
Sets the y value of the camera (i.e., the height). If you want to set the entire view matrix, then use set_view_matrix(), but if you just want to update the height, e.g., while walking around a bumpy terrain, then use this. More... | |
void | set_view_matrix (Matrix4 view_matrix) |
This is not required, but you may use this if you wish to set an initial view matrix or reset the view matrix. More... | |
float | translation_scale () |
This is the scale factor used to speed up / slow down forward/backward translation when walking for the UP / DOWN keys. It defaults to 1.0, smaller values will make the camera walk slower, larger values will speed it up. More... | |
void | set_translation_scale (float s) |
This is the scale factor used to speed up / slow down forward/backward translation when walking for the UP / DOWN keys. It defaults to 1.0, smaller values will make the camera walk slower, larger values will speed it up. More... | |
float | rotation_scale () |
This is the scale factor used to speed up / slow down left/right rotation when walking for the LEFT / RIGHT keys. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up. More... | |
void | set_rotation_scale (float s) |
This is the scale factor used to speed up / slow down left/right rotation when walking for the LEFT / RIGHT keys. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up. More... | |
float | look_scale () |
This is the scale factor used to speed up / slow down looking around when moving the head with the mouse. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up. More... | |
void | set_look_scale (float s) |
This is the scale factor used to speed up / slow down looking around when moving the head with the mouse. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up. More... | |
mingfx::CraftCam::CraftCam | ( | ) |
Creates a CraftCam object with an initial view matrix = identity.
mingfx::CraftCam::CraftCam | ( | const Matrix4 & | initial_view_matrix | ) |
Creates a CraftCam object with the supplied initial view matrix.
|
virtual |
Point3 mingfx::CraftCam::eye | ( | ) |
Returns the "eye" point (i.e., focal point) of the camera in world space coordinates.
Vector3 mingfx::CraftCam::look | ( | ) |
Returns the look direction (i.e., -Z axis of the camera matrix) in world space coordinates.
float mingfx::CraftCam::look_scale | ( | ) |
This is the scale factor used to speed up / slow down looking around when moving the head with the mouse. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up.
void mingfx::CraftCam::OnMouseMove | ( | const Vector2 & | normalized_mouse_delta | ) |
Call this from your app's OnMouseMove() or On*MouseDrag() method. Use OnMouseMove() if you want to always rotate the view with the mouse. Remember to convert the mouse coordinates (usually reported by window managers in pixels) into normalized device coordinates:
Alternatively, if you want to only rotate the view when the mouse button is held down, use On*MouseDrag() instead:
float mingfx::CraftCam::rotation_scale | ( | ) |
This is the scale factor used to speed up / slow down left/right rotation when walking for the LEFT / RIGHT keys. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up.
void mingfx::CraftCam::set_look_scale | ( | float | s | ) |
This is the scale factor used to speed up / slow down looking around when moving the head with the mouse. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up.
void mingfx::CraftCam::set_rotation_scale | ( | float | s | ) |
This is the scale factor used to speed up / slow down left/right rotation when walking for the LEFT / RIGHT keys. It defaults to 1.0, smaller values will make the camera turn slower, larger values will speed it up.
void mingfx::CraftCam::set_translation_scale | ( | float | s | ) |
This is the scale factor used to speed up / slow down forward/backward translation when walking for the UP / DOWN keys. It defaults to 1.0, smaller values will make the camera walk slower, larger values will speed it up.
void mingfx::CraftCam::set_view_matrix | ( | Matrix4 | view_matrix | ) |
This is not required, but you may use this if you wish to set an initial view matrix or reset the view matrix.
float mingfx::CraftCam::translation_scale | ( | ) |
This is the scale factor used to speed up / slow down forward/backward translation when walking for the UP / DOWN keys. It defaults to 1.0, smaller values will make the camera walk slower, larger values will speed it up.
void mingfx::CraftCam::UpdateHeight | ( | float | new_y_value | ) |
Sets the y value of the camera (i.e., the height). If you want to set the entire view matrix, then use set_view_matrix(), but if you just want to update the height, e.g., while walking around a bumpy terrain, then use this.
void mingfx::CraftCam::UpdateSimulation | ( | double | dt, |
GLFWwindow * | window_ptr | ||
) |
Call this from your app's UpdateSimulation() method. This tells the camera to simulate walking based on the keyboard keys currently pressed. You need to pass a pointer to the underlying GLFW window created by GraphicsApp. Example:
Matrix4 mingfx::CraftCam::view_matrix | ( | ) |
Access the camera view matrix created by the CraftCam interactions via this method and use it to draw the geometry in your scence. For example, within GraphicsApp::DrawUsingOpenGL(), you might have: