本文整理汇总了Java中javax.vecmath.Quat4f.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Quat4f.normalize方法的具体用法?Java Quat4f.normalize怎么用?Java Quat4f.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.vecmath.Quat4f
的用法示例。
在下文中一共展示了Quat4f.normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSkeleton
import javax.vecmath.Quat4f; //导入方法依赖的package包/类
private void updateSkeleton(SkeletalMeshComponent skeletalMeshComp, MeshAnimationFrame frameA, MeshAnimationFrame frameB, float interpolationVal) {
Vector3f newPos = new Vector3f();
Quat4f newRot = new Quat4f();
for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) {
EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i));
if (boneEntity == null) {
continue;
}
LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class);
if (boneLoc != null) {
newPos.interpolate(frameA.getPosition(i), frameB.getPosition(i), interpolationVal);
boneLoc.setLocalPosition(newPos);
newRot.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal);
newRot.normalize();
boneLoc.setLocalRotation(newRot);
boneEntity.saveComponent(boneLoc);
}
}
}
示例2: integrateTransform
import javax.vecmath.Quat4f; //导入方法依赖的package包/类
@StaticAlloc
public static void integrateTransform(Transform curTrans, Vector3f linvel, Vector3f angvel, float timeStep, Transform predictedTransform) {
predictedTransform.origin.scaleAdd(timeStep, linvel, curTrans.origin);
// //#define QUATERNION_DERIVATIVE
// #ifdef QUATERNION_DERIVATIVE
// btQuaternion predictedOrn = curTrans.getRotation();
// predictedOrn += (angvel * predictedOrn) * (timeStep * btScalar(0.5));
// predictedOrn.normalize();
// #else
// Exponential map
// google for "Practical Parameterization of Rotations Using the Exponential Map", F. Sebastian Grassia
Vector3f axis = Stack.alloc(Vector3f.class);
float fAngle = angvel.length();
// limit the angular motion
if (fAngle * timeStep > ANGULAR_MOTION_THRESHOLD) {
fAngle = ANGULAR_MOTION_THRESHOLD / timeStep;
}
if (fAngle < 0.001f) {
// use Taylor's expansions of sync function
axis.scale(0.5f * timeStep - (timeStep * timeStep * timeStep) * (0.020833333333f) * fAngle * fAngle, angvel);
}
else {
// sync(fAngle) = sin(c*fAngle)/t
axis.scale((float) Math.sin(0.5f * fAngle * timeStep) / fAngle, angvel);
}
Quat4f dorn = Stack.alloc(Quat4f.class);
dorn.set(axis.x, axis.y, axis.z, (float) Math.cos(fAngle * timeStep * 0.5f));
Quat4f orn0 = curTrans.getRotation(Stack.alloc(Quat4f.class));
Quat4f predictedOrn = Stack.alloc(Quat4f.class);
predictedOrn.mul(dorn, orn0);
predictedOrn.normalize();
// #endif
predictedTransform.setRotation(predictedOrn);
}
示例3: calculateDiffAxisAngle
import javax.vecmath.Quat4f; //导入方法依赖的package包/类
public static void calculateDiffAxisAngle(Transform transform0, Transform transform1, Vector3f axis, float[] angle) {
// #ifdef USE_QUATERNION_DIFF
// btQuaternion orn0 = transform0.getRotation();
// btQuaternion orn1a = transform1.getRotation();
// btQuaternion orn1 = orn0.farthest(orn1a);
// btQuaternion dorn = orn1 * orn0.inverse();
// #else
Matrix3f tmp = Stack.alloc(Matrix3f.class);
tmp.set(transform0.basis);
MatrixUtil.invert(tmp);
Matrix3f dmat = Stack.alloc(Matrix3f.class);
dmat.mul(transform1.basis, tmp);
Quat4f dorn = Stack.alloc(Quat4f.class);
MatrixUtil.getRotation(dmat, dorn);
// #endif
// floating point inaccuracy can lead to w component > 1..., which breaks
dorn.normalize();
angle[0] = QuaternionUtil.getAngle(dorn);
axis.set(dorn.x, dorn.y, dorn.z);
// TODO: probably not needed
//axis[3] = btScalar(0.);
// check for axis length
float len = axis.lengthSquared();
if (len < BulletGlobals.FLT_EPSILON * BulletGlobals.FLT_EPSILON) {
axis.set(1f, 0f, 0f);
}
else {
axis.scale(1f / (float) Math.sqrt(len));
}
}
示例4: storeTransformAt
import javax.vecmath.Quat4f; //导入方法依赖的package包/类
/**
* Stores the transformation of the bone at a specific point in the animation. This method interpolates between the
* nearest two key-frames using the correct interpolation mode.
*
* @param frame
* @param transform
* @param subFrame
* @return
*/
public void storeTransformAt(float frame, BoneTransformation transform) {
Vector3f t = translationBuffer.get();
t.set(loc_x.getValueAt(frame), loc_y.getValueAt(frame), loc_z.getValueAt(frame));
Quat4f r = rotationBuffer.get();
r.set(quat_x.getValueAt(frame), quat_y.getValueAt(frame), quat_z.getValueAt(frame), quat_w.getValueAt(frame));
r.normalize();
Vector3f s = scaleBuffer.get();
s.set(scale_x.getValueAt(frame), scale_y.getValueAt(frame), scale_z.getValueAt(frame));
Utils.fromRTS(r, t, s, transform.matrix);
}
示例5: completeQuat4f
import javax.vecmath.Quat4f; //导入方法依赖的package包/类
public static Quat4f completeQuat4f(float x, float y, float z) {
float t = 1.0f - (x * x) - (y * y) - (z * z);
float w = 0;
if (t > 0.0f) {
w = (float) -Math.sqrt(t);
}
Quat4f result = new Quat4f(x, y, z, w);
result.normalize();
return result;
}