2D view setup and navigation. More...
Public Member Functions | |
Camera2D (GraphicsContextAlpha gl, DrawHelpers draw_helpers) | |
void | SetViewX (Vector2 support, Vector2 center) |
Define 2D view by specifying a view center and the X support vector that determines scale and rotation. | |
void | SetViewY (Vector2 support, Vector2 center) |
Define 2D view by specifying a view center and the Y support vector that determines scale and rotation. | |
void | SetViewFromWidthAndCenter (float width, Vector2 center) |
Define 2D view by specifying a view center (the world coordinate of the point that is a the center of the screen), and the amount of world we can see along the screen width. | |
void | SetViewFromHeightAndCenter (float height, Vector2 center) |
Define 2D view by specifying a view center (the world coordinate of the point that is a the center of the screen), and the amount of world we can see along the screen height. | |
void | SetViewFromHeightAndBottomLeft (float height, Vector2 bottom_left) |
Define a 2D view by specifying the world coordinate of the bottom left of the screen, and the amount of world we can see along the screen height. | |
void | SetViewFromWidthAndBottomLeft (float width, Vector2 bottom_left) |
Define a 2D view by specifying the world coordinate of the bottom left of the screen, and the amount of world we can see along the screen width. | |
void | SetViewFromViewport () |
Define a 2D view that matches the viewport, if you want to work in pixel coordinates. | |
void | SetAspectFromViewport () |
Read current viewport to update aspect ratio. | |
Vector2 | X () |
The world vector that maps to (screen center, middle of right screen edge) Aspect ratio is taken into account. | |
Vector2 | Y () |
The world vector that maps to (screen center, middle of top screen edge) Aspect ratio is taken into account. | |
Bounds2 | CalcBounds () |
Calculate the bounds (in world coordinates) of the portion of world visible on screen. | |
Matrix4 | GetTransform () |
Calculate the camera transform matrix (orthonormal positioning matrix), as a Matrix4. | |
Matrix3 | NormalizedToWorldMatrix () |
Return the NormalizedToWorld matrix, as a Matrix3. | |
Vector2 | NormalizedToWorld (Vector2 bottom_left_minus_1_minus_1_top_left_1_1_normalized_screen_pos) |
Given a point in normalized screen coordinates (-1->1), return its corresponding world position. | |
Vector2 | GetTouchPos (int nth=0, bool prev=false) |
Return the 'nth' touch position in world coordinates. | |
void | Navigate (int control) |
Debug navigation: drag/zoom using touch interface. | |
void | Push () |
Push all necessary matrices on the matrix stack. | |
void | Pop () |
Pop all camera matrices from the matrix stack. | |
void | DebugDraw (float step) |
Draw default grid, rulers spacing 1, grey grid + black axis, with coordinate system arrows on top. | |
float | GetPixelSize () |
Based on current viewport size, get the size of a "screen pixel" in world coordinates. | |
void | SetTouchPlaneMatrix (Matrix4 mat) |
The the orientation of the 3D plane that should be used by GetTouchPos(). | |
Properties | |
Vector2 | Center [get, set] |
The world position that maps to screen center. | |
float | Aspect [get, set] |
Aspect ratio width/height. | |
float | Znear [get, set] |
Projection's near z value. | |
float | Zfar [get, set] |
Projection's far z value. |
2D view setup and navigation.
Uses GraphicsContextAlpha + DrawHelpers for the matrix stack and rulers/axis drawing.
Camera2D | ( | GraphicsContextAlpha | gl, |
DrawHelpers | draw_helpers | ||
) |
gl | Needed for the matrix stack |
draw_helpers | Needed only for debug draw |
Bounds2 CalcBounds | ( | ) |
Calculate the bounds (in world coordinates) of the portion of world visible on screen.
This can be used for screen culling (it is used by DrawRulers for instance). If there is no rotation, the bounds matches the screen exactly.
Implements ICamera.
void DebugDraw | ( | float | step | ) |
Draw default grid, rulers spacing 1, grey grid + black axis, with coordinate system arrows on top.
Note that DebugDraw() doesn't call Push()/Pop() internally. It is your responsability to call it between this Camera's Push()/Pop().
Implements ICamera.
float GetPixelSize | ( | ) |
Based on current viewport size, get the size of a "screen pixel" in world coordinates.
Can be used to determine scale factor needed to draw sprites or fonts 1:1 for example.
Implements ICamera.
Vector2 GetTouchPos | ( | int | nth = 0 , |
bool | prev = false |
||
) |
Return the 'nth' touch position in world coordinates.
The 'prev' flag is for internal use only.
Implements ICamera.
Matrix4 GetTransform | ( | ) |
Calculate the camera transform matrix (orthonormal positioning matrix), as a Matrix4.
GetTransform().InverseOrthonormal() is what you push on the view matrix stack.
Implements ICamera.
void SetTouchPlaneMatrix | ( | Matrix4 | mat | ) |
The the orientation of the 3D plane that should be used by GetTouchPos().
3D only.
Implements ICamera.
void SetViewFromHeightAndCenter | ( | float | height, |
Vector2 | center | ||
) |
Define 2D view by specifying a view center (the world coordinate of the point that is a the center of the screen), and the amount of world we can see along the screen height.
This is the same as doing SetViewY( new Vector2(0.0f,height*0.5f), center ).
Note that this call alone is enough to define your camera. SetViewFromWidthAndCenter is not needed (the width is deduced from aspect ratio automatically).
void SetViewFromViewport | ( | ) |
Define a 2D view that matches the viewport, if you want to work in pixel coordinates.
Bottom left is 0,0, top right is the size of the screen.
Implements ICamera.
void SetViewFromWidthAndCenter | ( | float | width, |
Vector2 | center | ||
) |
Define 2D view by specifying a view center (the world coordinate of the point that is a the center of the screen), and the amount of world we can see along the screen width.
This is the same as doing SetViewX( new Vector2(width*0.5f,0.0f), center ).
Note that this call alone is enough to define your camera. SetViewFromHeightAndCenter is not needed (the width is deduced from aspect ratio automatically).
Define 2D view by specifying a view center and the X support vector that determines scale and rotation.
The X support vector is the vector going from the center of the screen to the middle of the right edge of the screen, expressed in the viewed world coordinates.
Define 2D view by specifying a view center and the Y support vector that determines scale and rotation.
The Y support vector is the vector going from the center of the screen to the middle of the top edge of the screen, expressed in the viewed world coordinates.
Vector2 Y | ( | ) |
The world vector that maps to (screen center, middle of top screen edge) Aspect ratio is taken into account.
This is also the direction of the up vector if you were going to use a 3d LookAt.