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/*fromwww.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.armature;
import java.util.Iterator;
import android.util.SparseArray;
import com.supermercerbros.gameengine.math.Curve;
import com.supermercerbros.gameengine.motion.Movement;
publicclass Action {
privatefinal SparseArray<Curve> boneCurves;
publicfinal Movement movement;
public Action(Movement movement, SparseArray<Curve> curves) {
this.boneCurves = curves;
this.movement = movement;
}
publicvoid update(ActionData data, Skeleton skeleton, long time) {
if (time < data.startTime) {
// Interpolating to the action
finalfloat framePoint = (time - data.callTime) / (data.startTime - data.callTime);
final Iterator<Bone> iter = skeleton.bones.iterator();
for (int i = 0; iter.hasNext(); i++) {
finalint offset = i*4;
final Bone bone = iter.next();
finalfloat sw = data.callState.boneStates[offset ];
finalfloat sx = data.callState.boneStates[offset + 1];
finalfloat sy = data.callState.boneStates[offset + 2];
finalfloat sz = data.callState.boneStates[offset + 3];
finalfloat fw, fx, fy, fz;
Curve wCurve = boneCurves.get(offset );
if (wCurve != null) {
Curve xCurve = boneCurves.get(offset + 1);
Curve yCurve = boneCurves.get(offset + 2);
Curve zCurve = boneCurves.get(offset + 3);
fw = wCurve.getStartValue();
fx = xCurve.getStartValue();
fy = yCurve.getStartValue();
fz = zCurve.getStartValue();
} else {
fw = 1.0f;
fx = 0.0f;
fy = 0.0f;
fz = 0.0f;
}
finalfloat w = sw + (fw - sw) * framePoint;
finalfloat x = sx + (fx - sx) * framePoint;
finalfloat y = sy + (fy - sy) * framePoint;
finalfloat z = sz + (fz - sz) * framePoint;
bone.setRotation(w, x, y, z);
}
} else {
// Interpolating in the action
finalfloat framePoint = ((float) (time - data.startTime)) / data.duration;
//TODO: do this more better-er. See MeshAnimation, line 74-ish
if (framePoint > 1.0f) {
return; // Don't animate.
}
final Iterator<Bone> iter = skeleton.bones.iterator();
for (int i = 0; iter.hasNext(); i++) {
finalint offset = i*4;
final Bone bone = iter.next();
Curve wCurve = boneCurves.get(offset );
if (wCurve != null) {
Curve xCurve = boneCurves.get(offset + 1);
Curve yCurve = boneCurves.get(offset + 2);
Curve zCurve = boneCurves.get(offset + 3);
finalfloat w = wCurve.getInterpolation(framePoint);
finalfloat x = xCurve.getInterpolation(framePoint);
finalfloat y = yCurve.getInterpolation(framePoint);
finalfloat z = zCurve.getInterpolation(framePoint);
bone.setRotation(w, x, y, z);
}
}
}
}
}