If you think the Android project Schooner-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012 Dan Mercer//www.java2s.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.supermercerbros.gameengine.motion;
import com.supermercerbros.gameengine.math.Curve;
import com.supermercerbros.gameengine.math.MatrixUtils;
import com.supermercerbros.gameengine.objects.GameObject;
publicclass CurveMovement implements Movement {
privatefinal Curve xPos, yPos, zPos, wRot, xRot, yRot, zRot,
xScl, yScl, zScl;
/**
* @param flags
* @param curves
*
* @throws ArrayIndexOutOfBoundsException if not enough Curves are supplied for the given flags
*/public CurveMovement(int flags, Curve... curves) {
short index = 0;
if ((flags & POSITION) != 0 && curves[index] != null) {
xPos = curves[index++];
yPos = curves[index++];
zPos = curves[index++];
} else {
xPos = null;
yPos = null;
zPos = null;
}
if ((flags & ROTATION) != 0 && curves[index] != null) {
wRot = curves[index++];
xRot = curves[index++];
yRot = curves[index++];
zRot = curves[index++];
} else {
wRot = null;
xRot = null;
yRot = null;
zRot = null;
}
if ((flags & SCALE) != 0 && curves[index] != null) {
xScl = curves[index++];
yScl = null;
zScl = null;
} elseif ((flags & SCALE_AXIS) != 0 && curves[index] != null) {
xScl = curves[index++];
yScl = curves[index++];
zScl = curves[index++];
} else {
xScl = null;
yScl = null;
zScl = null;
}
}
@Override
publicvoid getFrame(GameObject target, MovementData data, long time) {
finalfloat framePoint = ((float) (time - data.startTime))
/ (float) data.duration;
if (framePoint >= 1) {
target.endMovement();
}
// Translate
if (xPos != null) {
finalfloat posX = xPos.getInterpolation(framePoint);
finalfloat posY = yPos.getInterpolation(framePoint);
finalfloat posZ = zPos.getInterpolation(framePoint);
MatrixUtils.translateM(target.modelMatrix, 0, data.matrix, 0, posX, posY, posZ);
}
// Rotate
if (wRot != null) {
finalfloat rotW = wRot.getInterpolation(framePoint);
finalfloat rotX = xRot.getInterpolation(framePoint);
finalfloat rotY = yRot.getInterpolation(framePoint);
finalfloat rotZ = zRot.getInterpolation(framePoint);
MatrixUtils.rotateQuaternionM(target.modelMatrix, 0, rotW, rotX, rotY, rotZ);
}
// Scale
if (xScl != null) {
if (yScl != null) {
// Nonuniform Scale
finalfloat sclX = xScl.getInterpolation(framePoint);
finalfloat sclY = yScl.getInterpolation(framePoint);
finalfloat sclZ = zScl.getInterpolation(framePoint);
MatrixUtils.scaleM(target.modelMatrix, 0, sclX, sclY, sclZ);
} else {
// Uniform Scale
finalfloat scl = xScl.getInterpolation(framePoint);
MatrixUtils.scaleM(target.modelMatrix, 0, scl, scl, scl);
}
}
}
}