@ -82,6 +82,7 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
protected boolean zooming = false ;
protected boolean zooming = false ;
protected boolean trailing = false ;
protected boolean trailing = false ;
protected boolean chasing = false ;
protected boolean chasing = false ;
protected boolean veryCloseRotation = true ;
protected boolean canRotate ;
protected boolean canRotate ;
protected float offsetDistance = 0 . 002f ;
protected float offsetDistance = 0 . 002f ;
protected Vector3f prevPos ;
protected Vector3f prevPos ;
@ -297,8 +298,10 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
if ( targetDistance < minDistance ) {
if ( targetDistance < minDistance ) {
targetDistance = minDistance ;
targetDistance = minDistance ;
}
}
if ( ( targetVRotation < minVerticalRotation ) & & ( targetDistance > ( minDistance + 1 . 0f ) ) ) {
if ( veryCloseRotation ) {
targetVRotation = minVerticalRotation ;
if ( ( targetVRotation < minVerticalRotation ) & & ( targetDistance > ( minDistance + 1 . 0f ) ) ) {
targetVRotation = minVerticalRotation ;
}
}
}
}
}
@ -308,12 +311,21 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
return ;
return ;
}
}
vRotating = true ;
vRotating = true ;
float lastGoodRot = targetVRotation ;
targetVRotation + = value * rotationSpeed ;
targetVRotation + = value * rotationSpeed ;
if ( targetVRotation > maxVerticalRotation ) {
if ( targetVRotation > maxVerticalRotation ) {
targetVRotation = maxVerticalRotation ;
targetVRotation = lastGoodRot ;
}
}
if ( ( targetVRotation < minVerticalRotation ) & & ( targetDistance > ( minDistance + 1 . 0f ) ) ) {
if ( veryCloseRotation ) {
targetVRotation = minVerticalRotation ;
if ( ( targetVRotation < minVerticalRotation ) & & ( targetDistance > ( minDistance + 1 . 0f ) ) ) {
targetVRotation = minVerticalRotation ;
} else if ( targetVRotation < - FastMath . DEG_TO_RAD * 90 ) {
targetVRotation = lastGoodRot ;
}
} else {
if ( ( targetVRotation < minVerticalRotation ) ) {
targetVRotation = lastGoodRot ;
}
}
}
}
}
@ -576,15 +588,14 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
}
/ * *
/ * *
* returns the maximal vertical rotation angle of the camera around the target
* @return The maximal vertical rotation angle in radian of the camera around the target
* @return
* /
* /
public float getMaxVerticalRotation ( ) {
public float getMaxVerticalRotation ( ) {
return maxVerticalRotation ;
return maxVerticalRotation ;
}
}
/ * *
/ * *
* s ets the maximal vertical rotation angle of the camera around the target d efault is Pi / 2 ;
* S ets the maximal vertical rotation angle in radian of the camera around the target . D efault is Pi / 2 ;
* @param maxVerticalRotation
* @param maxVerticalRotation
* /
* /
public void setMaxVerticalRotation ( float maxVerticalRotation ) {
public void setMaxVerticalRotation ( float maxVerticalRotation ) {
@ -592,15 +603,15 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
}
/ * *
/ * *
* returns the minimal vertical rotation angle of the camera around the target
*
* @return
* @return The minimal vertical rotation angle in radian of the camera around the target
* /
* /
public float getMinVerticalRotation ( ) {
public float getMinVerticalRotation ( ) {
return minVerticalRotation ;
return minVerticalRotation ;
}
}
/ * *
/ * *
* s ets the minimal vertical rotation angle of the camera around the target default is 0 ;
* S ets the minimal vertical rotation angle in radian of the camera around the target default is 0 ;
* @param minHeight
* @param minHeight
* /
* /
public void setMinVerticalRotation ( float minHeight ) {
public void setMinVerticalRotation ( float minHeight ) {
@ -608,8 +619,7 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
}
/ * *
/ * *
* returns true is smmoth motion is enabled for this chase camera
* @return True is smooth motion is enabled for this chase camera
* @return
* /
* /
public boolean isSmoothMotion ( ) {
public boolean isSmoothMotion ( ) {
return smoothMotion ;
return smoothMotion ;
@ -742,21 +752,21 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
}
/ * *
/ * *
* sets the default horizontal rotation of the camera at start of the application
* sets the default horizontal rotation in radian of the camera at start of the application
* @param angle
* @param angleInRad
* /
* /
public void setDefaultHorizontalRotation ( float angle ) {
public void setDefaultHorizontalRotation ( float angleInRad ) {
rotation = angle ;
rotation = angleInRad ;
targetRotation = angle ;
targetRotation = angleInRad ;
}
}
/ * *
/ * *
* sets the default vertical rotation of the camera at start of the application
* sets the default vertical rotation in radian of the camera at start of the application
* @param angle
* @param angleInRad
* /
* /
public void setDefaultVerticalRotation ( float angle ) {
public void setDefaultVerticalRotation ( float angleInRad ) {
vRotation = angle ;
vRotation = angleInRad ;
targetVRotation = angle ;
targetVRotation = angleInRad ;
}
}
/ * *
/ * *
@ -781,6 +791,26 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
inputManager . setCursorVisible ( dragToRotate ) ;
inputManager . setCursorVisible ( dragToRotate ) ;
}
}
/ * *
* @param rotateOnlyWhenClose When this flag is set to false the chase
* camera will always rotate around its spatial independently of their
* distance to one another . If set to true , the chase camera will only
* be allowed to rotated below the "horizon" when the distance is smaller
* than minDistance + 1 . 0f ( when fully zoomed - in ) .
* /
public void setDownRotateOnCloseViewOnly ( boolean rotateOnlyWhenClose ) {
veryCloseRotation = rotateOnlyWhenClose ;
}
/ * *
* @return True if rotation below the vertical plane of the spatial tied
* to the camera is allowed only when zoomed in at minDistance + 1 . 0f .
* False if vertical rotation is always allowed .
* /
public boolean getDownRotateOnCloseViewOnly ( ) {
return veryCloseRotation ;
}
/ * *
/ * *
* return the current distance from the camera to the target
* return the current distance from the camera to the target
* @return
* @return