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.
It is a special interface inspired by the "Unicam" technique developed by Zeleznik et al.
The key feature is that this interface makes it possible to control camera pan, dolly, and rotation with only a single mouse button. That is quite useful because it leaves the other mouse buttons free for pointing, sketching, or other interaction techniques.
The only downside of this technique is that it can take some time to learn. In order to enjoy it, you will need to read these brief instructions on how to Pan, Dolly, Rotate, and Spin:
Example usage:
#include <unicam.h>
Public Member Functions | |
UniCam () | |
Creates a UniCam object with an initial view matrix = identity. More... | |
UniCam (const Matrix4 &initialViewMatrix) | |
Creates a UniCam object with the supplied initial view matrix. More... | |
virtual | ~UniCam () |
void | OnButtonDown (const Point2 &normalizedMousePos, float mouseZ) |
Attach this to whatever mouse button you wish, for example, call this from within GraphicsApp::OnRightMouseDown(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. The depth buffer value for the pixel under the mouse is also needed. If you are using GraphicsApp, you can access both of these as follows: More... | |
void | OnDrag (const Point2 &normalizedMousePos) |
Attach this to the corresponding mouse move event, for example, call this from within GraphicsApp::OnRightMouseDrag(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. Within GraphicsApp, use: More... | |
void | OnButtonUp (const Point2 &normalizedMousePos) |
Attach this to the corresponding button up event, for example, call this from within GraphicsApp::OnRightMouseUp(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. Within GraphicsApp, use: More... | |
void | AdvanceAnimation (double dt) |
Attach this to a callback that can be used to control animation. Within GraphicsApp::UpdateSimulation(), use: More... | |
void | Draw (const Matrix4 &projectionMatrix) |
Finally, attach this to your draw callback routine. Within GraphicsApp::DrawUsingOpenGL(), use: More... | |
Matrix4 | view_matrix () |
Access the camera view matrix created by the UniCam 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 | set_view_matrix (Matrix4 viewMatrix) |
This is not required, but you may use this if you wish to set an initial view matrix or reset the view matrix. More... | |
void | set_default_depth (float d) |
This sets the depth of the center of rotation for the case when the user's click does not intersect any geometry. It defaults to 4 units, but the right value to use depends very much on the current scene. For example, you could set a very good value by calculating the current centroid of your scene and the finding the depth of this point (the distance along the look vector) relative to the camera. More... | |
mingfx::UniCam::UniCam | ( | ) |
Creates a UniCam object with an initial view matrix = identity.
mingfx::UniCam::UniCam | ( | const Matrix4 & | initialViewMatrix | ) |
Creates a UniCam object with the supplied initial view matrix.
|
virtual |
void mingfx::UniCam::AdvanceAnimation | ( | double | dt | ) |
Attach this to a callback that can be used to control animation. Within GraphicsApp::UpdateSimulation(), use:
void mingfx::UniCam::Draw | ( | const Matrix4 & | projectionMatrix | ) |
Finally, attach this to your draw callback routine. Within GraphicsApp::DrawUsingOpenGL(), use:
Point3 mingfx::UniCam::eye | ( | ) |
Returns the "eye" point (i.e., focal point) of the camera in world space coordinates.
Vector3 mingfx::UniCam::look | ( | ) |
Returns the look direction (i.e., -Z axis of the camera matrix) in world space coordinates.
void mingfx::UniCam::OnButtonDown | ( | const Point2 & | normalizedMousePos, |
float | mouseZ | ||
) |
Attach this to whatever mouse button you wish, for example, call this from within GraphicsApp::OnRightMouseDown(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. The depth buffer value for the pixel under the mouse is also needed. If you are using GraphicsApp, you can access both of these as follows:
void mingfx::UniCam::OnButtonUp | ( | const Point2 & | normalizedMousePos | ) |
Attach this to the corresponding button up event, for example, call this from within GraphicsApp::OnRightMouseUp(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. Within GraphicsApp, use:
void mingfx::UniCam::OnDrag | ( | const Point2 & | normalizedMousePos | ) |
Attach this to the corresponding mouse move event, for example, call this from within GraphicsApp::OnRightMouseDrag(). If your mousePos is reported in pixels, you will need to convert it to normalized device coordinates before passing it on to this routine. Within GraphicsApp, use:
void mingfx::UniCam::set_default_depth | ( | float | d | ) |
This sets the depth of the center of rotation for the case when the user's click does not intersect any geometry. It defaults to 4 units, but the right value to use depends very much on the current scene. For example, you could set a very good value by calculating the current centroid of your scene and the finding the depth of this point (the distance along the look vector) relative to the camera.
void mingfx::UniCam::set_view_matrix | ( | Matrix4 | viewMatrix | ) |
This is not required, but you may use this if you wish to set an initial view matrix or reset the view matrix.
Matrix4 mingfx::UniCam::view_matrix | ( | ) |
Access the camera view matrix created by the UniCam interactions via this method and use it to draw the geometry in your scence. For example, within GraphicsApp::DrawUsingOpenGL(), you might have: