java.lang.Object
com.marginallyclever.ro3.node.Node
com.marginallyclever.ro3.node.nodes.pose.Pose
com.marginallyclever.ro3.node.nodes.Camera
The Camera class is a subclass of the Pose class and is used by a Viewport to viewport the scene in a 3D graphics or game engine. This class provides several functionalities:
- It can be set to viewport in orthographic projection.
- It has a vertical field of view, a near and far clipping plane for perspective rendering.
- It can translate and rotate relative to its current orientation.
- It can look at a specific point in the scene.
- It can orbit around a point at a certain radius.
- It can get the point it is orbiting around.
- It can change the distance from itself to the orbit point.
- It can get the distance from itself to the orbit point.
- It can get the perspective frustum and orthographic matrix.
- It can get the chosen projection matrix based on whether it is set to draw in orthographic or not.
- It can get the view matrix.
- It can build a Swing Component that represents itself.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dolly
(double delta) Translate relative to camera's current orientation if canTranslate is true.void
fromJSON
(org.json.JSONObject json) Deserialize this node and its children from a JSON object and its children.boolean
boolean
javax.vecmath.Matrix4d
getChosenProjectionMatrix
(int width, int height) void
getComponents
(List<JPanel> list) Build a Swing Component that represents this Node.boolean
double
getFarZ()
double
getFovY()
double
getNearZ()
javax.vecmath.Vector3d
double
javax.vecmath.Matrix4d
getOrthographicMatrix
(int width, int height) Render the scene in orthographic projection.javax.vecmath.Matrix4d
getPerspectiveFrustum
(int width, int height) javax.vecmath.Matrix4d
void
lookAt
(javax.vecmath.Vector3d target) Set the pan and tilt values such that the camera is looking at the target.void
orbit
(double dx, double dy) Orbit the camera around a point orbitRadius ahead of the camera.void
orbitDolly
(double scale) Move towards or away from the orbit point if canTranslate is true.void
pan
(double delta) Rotate relative to camera's current orientation if canRotate is true.void
panTilt
(double panDegrees, double tiltDegrees) Combination pan and tilt.void
pedestal
(double delta) Translate relative to camera's current orientation if canTranslate is true.void
roll
(double delta) Rotate relative to camera's current orientation if canRotate is true.void
setCanRotate
(boolean canRotate) void
setCanTranslate
(boolean canTranslate) void
setDrawOrthographic
(boolean selected) void
setFarZ
(double farZ) void
setFovY
(double fovY) void
setNearZ
(double nearZ) void
setOrbitRadius
(double newRadius) Change the distance from the camera to the orbit point.void
tilt
(double delta) Rotate relative to camera's current orientation if canRotate is true.org.json.JSONObject
toJSON()
Serialize this node and its children to a JSON object and its children.void
truck
(double delta) Translate relative to camera's current orientation if canTranslate is true.Methods inherited from class com.marginallyclever.ro3.node.nodes.pose.Pose
getLocal, getPosition, getRotationEuler, getRotationIndex, getWorld, setLocal, setPosition, setRotationEuler, setRotationIndex, setWorld
Methods inherited from class com.marginallyclever.ro3.node.Node
addAttachListener, addChild, addChild, addDetachListener, addReadyListener, addRenameListener, findByPath, findChild, findChild, findFirstChild, findFirstSibling, findNodeByID, findParent, findParent, getAbsolutePath, getChildren, getName, getParent, getRootNode, getUniqueID, hasParent, isNameUsedBySibling, removeAttachListener, removeChild, removeDetachListener, removeReadyListener, removeRenameListener, setName, update, witnessProtection
-
Constructor Details
-
Camera
public Camera() -
Camera
-
-
Method Details
-
getComponents
Build a Swing Component that represents this Node.- Overrides:
getComponents
in classPose
- Parameters:
list
- the list to add components to.
-
getDrawOrthographic
public boolean getDrawOrthographic() -
setDrawOrthographic
public void setDrawOrthographic(boolean selected) -
getFovY
public double getFovY() -
setFovY
public void setFovY(double fovY) -
getNearZ
public double getNearZ() -
setNearZ
public void setNearZ(double nearZ) -
getFarZ
public double getFarZ() -
setFarZ
public void setFarZ(double farZ) -
pedestal
public void pedestal(double delta) Translate relative to camera's current orientation if canTranslate is true.- Parameters:
delta
- distance to travel. Positive is up.
-
truck
public void truck(double delta) Translate relative to camera's current orientation if canTranslate is true.- Parameters:
delta
- distance to travel. Positive is right.
-
dolly
public void dolly(double delta) Translate relative to camera's current orientation if canTranslate is true.- Parameters:
delta
- distance to travel. Positive is forward.
-
pan
public void pan(double delta) Rotate relative to camera's current orientation if canRotate is true.- Parameters:
delta
- degrees to rotate. Positive is left.
-
tilt
public void tilt(double delta) Rotate relative to camera's current orientation if canRotate is true.- Parameters:
delta
- degrees to rotate. Positive is up.
-
roll
public void roll(double delta) Rotate relative to camera's current orientation if canRotate is true.- Parameters:
delta
- degrees to rotate. Positive is counter-clockwise.
-
lookAt
public void lookAt(javax.vecmath.Vector3d target) Set the pan and tilt values such that the camera is looking at the target. Set the orbit distance to the distance between the camera and the target.- Parameters:
target
- the point to look at.
-
getPerspectiveFrustum
public javax.vecmath.Matrix4d getPerspectiveFrustum(int width, int height) -
getOrthographicMatrix
public javax.vecmath.Matrix4d getOrthographicMatrix(int width, int height) Render the scene in orthographic projection. -
getChosenProjectionMatrix
public javax.vecmath.Matrix4d getChosenProjectionMatrix(int width, int height) -
getViewMatrix
public javax.vecmath.Matrix4d getViewMatrix() -
getOrbitPoint
public javax.vecmath.Vector3d getOrbitPoint()- Returns:
- the point that the camera is orbiting around.
-
setOrbitRadius
public void setOrbitRadius(double newRadius) Change the distance from the camera to the orbit point. The orbit point does not move. In effect the camera is performing a dolly in/out.- Parameters:
newRadius
- new radius. Must be >=1.
-
getOrbitRadius
public double getOrbitRadius() -
orbit
public void orbit(double dx, double dy) Orbit the camera around a point orbitRadius ahead of the camera.- Parameters:
dx
- change in xdy
- change in y
-
panTilt
public void panTilt(double panDegrees, double tiltDegrees) Combination pan and tilt.- Parameters:
panDegrees
- pan angle in degreestiltDegrees
- tilt angle in degrees
-
getCanTranslate
public boolean getCanTranslate() -
setCanTranslate
public void setCanTranslate(boolean canTranslate) -
getCanRotate
public boolean getCanRotate() -
setCanRotate
public void setCanRotate(boolean canRotate) -
orbitDolly
public void orbitDolly(double scale) Move towards or away from the orbit point if canTranslate is true.- Parameters:
scale
- relative to the current orbit distance.
-
toJSON
public org.json.JSONObject toJSON()Description copied from class:Node
Serialize this node and its children to a JSON object and its children. Classes that override this method should call super.toJSON() first, then add to the object returned. -
fromJSON
public void fromJSON(org.json.JSONObject json) Description copied from class:Node
Deserialize this node and its children from a JSON object and its children. Classes that override this method should call super.fromJSON(). When they do it will trigger the creation of child nodes. The child nodes will then call their own fromJSON() methods.
-