Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions jme3-core/src/main/java/com/jme3/cinematic/events/MotionEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import java.io.IOException;

/**
* A MotionEvent is a control over the spatial that manages the position and direction of the spatial while following a motion Path.
*
* A MotionEvent is a control over the spatial that manages
* the position and direction of the spatial while following a motion Path.
* You must first create a MotionPath and then create a MotionEvent to associate a spatial and the path.
*
* @author Nehon
Expand All @@ -70,6 +70,7 @@ public class MotionEvent extends AbstractCinematicEvent implements Control, JmeC
protected Direction directionType = Direction.None;
protected MotionPath path;
private boolean isControl = true;
private final Quaternion tempRotation = new Quaternion();
/**
* the distance traveled by the spatial on the path
*/
Expand All @@ -79,7 +80,6 @@ public class MotionEvent extends AbstractCinematicEvent implements Control, JmeC
* Enum for the different type of target direction behavior.
*/
public enum Direction {

/**
* The target stays in the starting direction.
*/
Expand Down Expand Up @@ -229,13 +229,13 @@ public void write(JmeExporter ex) throws IOException {
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule in = im.getCapsule(this);
lookAt = (Vector3f) in.readSavable("lookAt", null);
upVector = (Vector3f) in.readSavable("upVector", Vector3f.UNIT_Y);
rotation = (Quaternion) in.readSavable("rotation", null);
directionType = in.readEnum("directionType", Direction.class, Direction.None);
path = (MotionPath) in.readSavable("path", null);
spatial = (Spatial) in.readSavable("spatial", null);
InputCapsule ic = im.getCapsule(this);
lookAt = (Vector3f) ic.readSavable("lookAt", null);
upVector = (Vector3f) ic.readSavable("upVector", Vector3f.UNIT_Y);
rotation = (Quaternion) ic.readSavable("rotation", null);
directionType = ic.readEnum("directionType", Direction.class, Direction.None);
path = (MotionPath) ic.readSavable("path", null);
spatial = (Spatial) ic.readSavable("spatial", null);
}

/**
Expand All @@ -249,9 +249,8 @@ public boolean needsDirection() {
private void computeTargetDirection() {
switch (directionType) {
case Path:
Quaternion q = new Quaternion();
q.lookAt(direction, upVector);
spatial.setLocalRotation(q);
tempRotation.lookAt(direction, upVector);
spatial.setLocalRotation(tempRotation);
break;
case LookAt:
if (lookAt != null) {
Expand All @@ -260,10 +259,9 @@ private void computeTargetDirection() {
break;
case PathAndRotation:
if (rotation != null) {
Quaternion q2 = new Quaternion();
q2.lookAt(direction, upVector);
q2.multLocal(rotation);
spatial.setLocalRotation(q2);
tempRotation.lookAt(direction, upVector);
tempRotation.multLocal(rotation);
spatial.setLocalRotation(tempRotation);
}
break;
case Rotation:
Expand All @@ -272,6 +270,7 @@ private void computeTargetDirection() {
}
break;
case None:
// no-op
break;
default:
break;
Expand Down Expand Up @@ -376,8 +375,7 @@ public Vector3f getDirection() {

/**
* Sets the direction of the spatial, using the Y axis as the up vector.
* Use MotionEvent#setDirection((Vector3f direction,Vector3f upVector) if
* you want a custom up vector.
* If a custom up vector is desired, use {@link #setDirection(Vector3f, Vector3f)}.
* This method is used by the motion path.
*
* @param direction the desired forward direction (not null, unaffected)
Expand Down