📄 abstractcamera.java
字号:
onFrustumChange();
}
/**
* <code>getLocation</code> retrieves the location vector of the camera.
*
* @return the position of the camera.
* @see Camera#getLocation()
*/
public Vector3f getLocation() {
return location;
}
/**
* <code>getDirection</code> retrieves the direction vector the camera is
* facing.
*
* @return the direction the camera is facing.
* @see Camera#getDirection()
*/
public Vector3f getDirection() {
return direction;
}
/**
* <code>getLeft</code> retrieves the left axis of the camera.
*
* @return the left axis of the camera.
* @see Camera#getLeft()
*/
public Vector3f getLeft() {
return left;
}
/**
* <code>getUp</code> retrieves the up axis of the camera.
*
* @return the up axis of the camera.
* @see Camera#getUp()
*/
public Vector3f getUp() {
return up;
}
/**
* <code>setLocation</code> sets the position of the camera.
*
* @param location the position of the camera.
* @see Camera#setLocation(com.jme.math.Vector3f)
*/
public void setLocation( Vector3f location ) {
this.location = location;
onFrameChange();
}
/**
* <code>setDirection</code> sets the direction this camera is facing. In
* most cases, this changes the up and left vectors of the camera. If your
* left or up vectors change, you must updates those as well for correct
* culling.
*
* @param direction the direction this camera is facing.
* @see Camera#setDirection(com.jme.math.Vector3f)
*/
public void setDirection( Vector3f direction ) {
this.direction = direction;
onFrameChange();
}
/**
* <code>setLeft</code> sets the left axis of this camera. In most cases,
* this changes the up and direction vectors of the camera. If your
* direction or up vectors change, you must updates those as well for
* correct culling.
*
* @param left the left axis of this camera.
* @see Camera#setLeft(com.jme.math.Vector3f)
*/
public void setLeft( Vector3f left ) {
this.left = left;
onFrameChange();
}
/**
* <code>setUp</code> sets the up axis of this camera. In most cases, this
* changes the direction and left vectors of the camera. If your left or up
* vectors change, you must updates those as well for correct culling.
*
* @param up the up axis of this camera.
* @see Camera#setUp(com.jme.math.Vector3f)
*/
public void setUp( Vector3f up ) {
this.up = up;
onFrameChange();
}
/**
* <code>setAxes</code> sets the axes (left, up and direction) for this
* camera.
*
* @param left the left axis of the camera.
* @param up the up axis of the camera.
* @param direction the direction the camera is facing.
* @see Camera#setAxes(com.jme.math.Vector3f,com.jme.math.Vector3f,com.jme.math.Vector3f)
*/
public void setAxes( Vector3f left, Vector3f up, Vector3f direction ) {
this.left = left;
this.up = up;
this.direction = direction;
onFrameChange();
}
/**
* <code>setAxes</code> uses a rotational matrix to set the axes of the
* camera.
*
* @param axes the matrix that defines the orientation of the camera.
*/
public void setAxes( Quaternion axes ) {
left = axes.getRotationColumn( 0, left );
up = axes.getRotationColumn( 1, up );
direction = axes.getRotationColumn( 2, direction );
onFrameChange();
}
/**
* normalize normalizes the camera vectors.
*/
public void normalize() {
left.normalizeLocal();
up.normalizeLocal();
direction.normalizeLocal();
}
/**
* <code>setFrustum</code> sets the frustum of this camera object.
*
* @param near the near plane.
* @param far the far plane.
* @param left the left plane.
* @param right the right plane.
* @param top the top plane.
* @param bottom the bottom plane.
* @see Camera#setFrustum(float, float, float, float,
* float, float)
*/
public void setFrustum( float near, float far, float left, float right,
float top, float bottom ) {
frustumNear = near;
frustumFar = far;
frustumLeft = left;
frustumRight = right;
frustumTop = top;
frustumBottom = bottom;
onFrustumChange();
}
public void setFrustumPerspective( float fovY, float aspect, float near,
float far ) {
if (Float.isNaN(aspect) || Float.isInfinite(aspect)) {
// ignore.
logger.warning("Invalid aspect given to setFrustumPerspective: "
+ aspect);
return;
}
float h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near;
float w = h * aspect;
frustumLeft = -w;
frustumRight = w;
frustumBottom = -h;
frustumTop = h;
frustumNear = near;
frustumFar = far;
onFrustumChange();
}
/**
* <code>setFrame</code> sets the orientation and location of the camera.
*
* @param location the point position of the camera.
* @param left the left axis of the camera.
* @param up the up axis of the camera.
* @param direction the facing of the camera.
* @see Camera#setFrame(com.jme.math.Vector3f,
* com.jme.math.Vector3f, com.jme.math.Vector3f, com.jme.math.Vector3f)
*/
public void setFrame( Vector3f location, Vector3f left, Vector3f up,
Vector3f direction ) {
this.location = location;
this.left = left;
this.up = up;
this.direction = direction;
onFrameChange();
}
/**
* <code>lookAt</code> is a convienence method for auto-setting the frame
* based on a world position the user desires the camera to look at. It
* repoints the camera towards the given position using the difference
* between the position and the current camera location as a direction
* vector and the worldUpVector to compute up and left camera vectors.
*
* @param pos where to look at in terms of world coordinates
* @param worldUpVector a normalized vector indicating the up direction of the world.
* (typically {0, 1, 0} in jME.)
*/
public void lookAt( Vector3f pos, Vector3f worldUpVector ) {
newDirection.set( pos ).subtractLocal( location ).normalizeLocal();
// check to see if we haven't really updated camera -- no need to call
// sets.
if ( newDirection.equals( direction ) ) {
return;
}
direction.set( newDirection );
up.set(worldUpVector).normalizeLocal();
if (up.equals(Vector3f.ZERO))
up.set(Vector3f.UNIT_Y);
left.set(up).crossLocal(direction).normalizeLocal();
if (left.equals(Vector3f.ZERO)) {
if (direction.x != 0) {
left.set(direction.y, -direction.x, 0f);
} else {
left.set(0f, direction.z, -direction.y);
}
}
up.set(direction).crossLocal(left).normalizeLocal();
onFrameChange();
}
/**
* <code>setFrame</code> sets the orientation and location of the camera.
*
* @param location
* the point position of the camera.
* @param axes
* the orientation of the camera.
*/
public void setFrame( Vector3f location, Quaternion axes ) {
this.location = location;
left = axes.getRotationColumn( 0, left );
up = axes.getRotationColumn( 1, up );
direction = axes.getRotationColumn( 2, direction );
onFrameChange();
}
/**
* <code>update</code> updates the camera parameters by calling
* <code>onFrustumChange</code>,<code>onViewPortChange</code> and
* <code>onFrameChange</code>.
*
* @see Camera#update()
*/
public void update() {
onFrustumChange();
onViewPortChange();
onFrameChange();
}
/**
* <code>getPlaneState</code> returns the state of the frustum planes. So
* checks can be made as to which frustum plane has been examined for
* culling thus far.
*
* @return the current plane state int.
*/
public int getPlaneState() {
return planeState;
}
/**
* <code>setPlaneState</code> sets the state to keep track of tested
* planes for culling.
*
* @param planeState the updated state.
*/
public void setPlaneState( int planeState ) {
this.planeState = planeState;
}
/**
* <code>getViewPortLeft</code> gets the left boundary of the viewport
*
* @return the left boundary of the viewport
*/
public float getViewPortLeft() {
return viewPortLeft;
}
/**
* <code>setViewPortLeft</code> sets the left boundary of the viewport
*
* @param left the left boundary of the viewport
*/
public void setViewPortLeft( float left ) {
viewPortLeft = left;
}
/**
* <code>getViewPortRight</code> gets the right boundary of the viewport
*
* @return the right boundary of the viewport
*/
public float getViewPortRight() {
return viewPortRight;
}
/**
* <code>setViewPortRight</code> sets the right boundary of the viewport
*
* @param right the right boundary of the viewport
*/
public void setViewPortRight( float right ) {
viewPortRight = right;
}
/**
* <code>getViewPortTop</code> gets the top boundary of the viewport
*
* @return the top boundary of the viewport
*/
public float getViewPortTop() {
return viewPortTop;
}
/**
* <code>setViewPortTop</code> sets the top boundary of the viewport
*
* @param top the top boundary of the viewport
*/
public void setViewPortTop( float top ) {
viewPortTop = top;
}
/**
* <code>getViewPortBottom</code> gets the bottom boundary of the viewport
*
* @return the bottom boundary of the viewport
*/
public float getViewPortBottom() {
return viewPortBottom;
}
/**
* <code>setViewPortBottom</code> sets the bottom boundary of the viewport
*
* @param bottom the bottom boundary of the viewport
*/
public void setViewPortBottom( float bottom ) {
viewPortBottom = bottom;
}
/**
* <code>setViewPort</code> sets the boundaries of the viewport
*
* @param left the left boundary of the viewport
* @param right the right boundary of the viewport
* @param bottom the bottom boundary of the viewport
* @param top the top boundary of the viewport
*/
public void setViewPort( float left, float right, float bottom, float top ) {
setViewPortLeft( left );
setViewPortRight( right );
setViewPortBottom( bottom );
setViewPortTop( top );
}
/**
* <code>culled</code> tests a bounding volume against the planes of the
* camera's frustum. The frustums planes are set such that the normals all
* face in towards the viewable scene. Therefore, if the bounding volume is
* on the negative side of the plane is can be culled out. If the object
* should be culled (i.e. not rendered) true is returned, otherwise, false
* is returned. If bound is null, false is returned and the object will not
* be culled.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -