Package arc.graphics.g3d
Class Camera3D
java.lang.Object
arc.graphics.g3d.Camera3D
-
Field Summary
Modifier and TypeFieldDescriptionfinal Mat3D
the combined projection and view matrixfinal Vec3
the unit length direction vector of the camerafloat
the far clipping plane distance, has to be positivefloat
field of view.final Frustum
the frustum, for clipping operationsfloat
the viewport width and heightfinal Mat3D
the inverse combined projection and view matrixfloat
the near clipping plane distance, has to be positiveboolean
if set to true, a perspective projection is used.final Vec3
the position of the camerafinal Mat3D
the projection matrixfinal Vec3
the unit length up vector of the camerafinal Mat3D
the view matrixfloat
the viewport width and height -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetPickRay
(float screenX, float screenY) Creates a pickingRay
from the coordinates given in screen coordinates.getPickRay
(float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Creates a pickingRay
from the coordinates given in screen coordinates.void
lookAt
(float x, float y, float z) void
Recalculates the direction of the camera to look at the point (x, y, z).void
Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then recalculating the up vector via a cross product between right and direction.Projects theVec3
given in world space to screen coordinates.project
(Vec3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Projects theVec3
given in world space to screen coordinates.void
resize
(float width, float height) Function to translate a point given in screen coordinates to world space.unproject
(Vec3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Function to translate a point given in screen coordinates to world space.void
update()
-
Field Details
-
fov
public float fovfield of view. -
near
public float nearthe near clipping plane distance, has to be positive -
far
public float farthe far clipping plane distance, has to be positive -
perspective
public boolean perspectiveif set to true, a perspective projection is used. -
width
public float widththe viewport width and height -
height
public float heightthe viewport width and height -
position
the position of the camera -
direction
the unit length direction vector of the camera -
up
the unit length up vector of the camera -
combined
the combined projection and view matrix -
projection
the projection matrix -
view
the view matrix -
invProjectionView
the inverse combined projection and view matrix -
frustum
the frustum, for clipping operations
-
-
Constructor Details
-
Camera3D
public Camera3D()
-
-
Method Details
-
update
public void update() -
resize
public void resize(float width, float height) -
lookAt
public void lookAt(float x, float y, float z) -
lookAt
Recalculates the direction of the camera to look at the point (x, y, z).- Parameters:
target
- the point to look at
-
normalizeUp
public void normalizeUp()Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then recalculating the up vector via a cross product between right and direction. -
unproject
public Vec3 unproject(Vec3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not rely on OpenGL. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left corner, y pointing down, x pointing to the right) as reported by the touch methods inInput
. A z-coordinate of 0 will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane. This method allows you to specify the viewport position and dimensions in the coordinate system expected by glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.- Parameters:
screenCoords
- the point in screen coordinates (origin top left)viewportX
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportY
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportWidth
- the width of the viewport in pixelsviewportHeight
- the height of the viewport in pixels- Returns:
- the mutated and unprojected screenCoords
Vec3
-
unproject
Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject but does not rely on OpenGL. The viewport is assumed to span the whole screen and is fetched fromGraphics.getWidth()
andGraphics.getHeight()
. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left corner, y pointing down, x pointing to the right) as reported by the touch methods inInput
. A z-coordinate of 0 will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane.- Parameters:
screenCoords
- the point in screen coordinates- Returns:
- the mutated and unprojected screenCoords
Vec3
-
project
Projects theVec3
given in world space to screen coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The screen coordinate system has its origin in the bottom left, with the y-axis pointing upwards and the x-axis pointing to the right. This makes it easily useable in conjunction with Batch and similar classes.- Returns:
- the mutated and projected worldCoords
Vec3
-
project
public Vec3 project(Vec3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Projects theVec3
given in world space to screen coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The screen coordinate system has its origin in the bottom left, with the y-axis pointing upwards and the x-axis pointing to the right. This makes it easily useable in conjunction with Batch and similar classes. This method allows you to specify the viewport position and dimensions in the coordinate system expected by glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.- Parameters:
viewportX
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportY
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportWidth
- the width of the viewport in pixelsviewportHeight
- the height of the viewport in pixels- Returns:
- the mutated and projected worldCoords
Vec3
-
getMouseRay
-
getPickRay
public Ray getPickRay(float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight) Creates a pickingRay
from the coordinates given in screen coordinates. It is assumed that the viewport spans the whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function.- Parameters:
viewportX
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportY
- the coordinate of the bottom left corner of the viewport in glViewport coordinates.viewportWidth
- the width of the viewport in pixelsviewportHeight
- the height of the viewport in pixels- Returns:
- the picking Ray.
-
getPickRay
Creates a pickingRay
from the coordinates given in screen coordinates. It is assumed that the viewport spans the whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function.- Returns:
- the picking Ray.
-