The 3D camera here is quite primitive, as the library is mainly 2D. More...
Public Member Functions | |
Camera3D (GraphicsContextAlpha gl, DrawHelpers draw_helpers) | |
constructor. | |
void | SetFromCamera2D (Camera2D cam2d) |
Position the camera and set the persective so that it matches exactly the 2D ortho view (when all sprites are drawn on the Z=0 plane anyway, which is the default). | |
void | SetAspectFromViewport () |
Update the aspect ratio based on current viewport. | |
Matrix4 | GetTransform () |
Calculate the camera transform marix (positioning matrix), as a Matrix4. | |
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 a canonical debug grid. | |
Vector2 | NormalizedToWorld (Vector2 bottom_left_minus_1_minus_1_top_left_1_1_normalized_screen_pos) |
Note that unlike Camera2D.NormalizedToWorld, Camera3D.NormalizedToWorld might not return a valid position, since it's a ray/plane intersection. | |
Vector2 | GetTouchPos (int nth=0, bool prev=false) |
Return the 'nth' touch position in world coordinates. | |
Bounds2 | CalcBounds () |
Return the most recent bounds set by SetFromCamera2D. | |
void | SetViewFromViewport () |
Creates a 3D view that max the screen bounds in pixel size (in plane z=0). | |
float | GetPixelSize () |
Based on current viewport size, get the size of a "screen pixel" in world coordinates. | |
void | Navigate (int control) |
Debug camera navigation. | |
void | SetTouchPlaneMatrix (Matrix4 mat) |
Set the model plane matrix used in GetTouchPos and NormalizedToWorld. | |
Public Attributes | |
Vector3 | Eye |
Eye positions. | |
Vector3 | Center |
View center/target position. | |
Vector3 | Up |
Up vector. | |
Frustum | Frustum |
The perspective. | |
Matrix4 | TouchPlaneMatrix = Matrix4.Identity |
This model matrix is used by NormalizedToWorld/GetTouchPos so we can define a 2d plane to raytrace touch direction against. |
The 3D camera here is quite primitive, as the library is mainly 2D.
Camera3D | ( | GraphicsContextAlpha | gl, |
DrawHelpers | draw_helpers | ||
) |
constructor.
gl | Needed for its matrix stack. |
draw_helpers | Needed only for debug draw (DebugDraw). |
void DebugDraw | ( | float | step | ) |
Draw a canonical debug grid.
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 | ( | ) |
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 marix (positioning matrix), as a Matrix4.
GetTransform().InverseOrthonormal() is what you push on the view matrix stack. Return an orthonormal matrix.
Implements ICamera.
Note that unlike Camera2D.NormalizedToWorld, Camera3D.NormalizedToWorld might not return a valid position, since it's a ray/plane intersection.
The return point is in 2d, in touch plane local coordinates. This function uses the TouchPlaneMatrix property to know which plane to intersect, so TouchPlaneMatrix must have been set beforehand (use Node.NormalizedToWorld does it for you).
Implements ICamera.
void SetViewFromViewport | ( | ) |
Creates a 3D view that max the screen bounds in pixel size (in plane z=0).
Exactly match the 3D frustum. Eye distance to z=0 plane is calculated based on current Frustum.FovY value.
Implements ICamera.