本文整理了Java中com.jme3.math.Quaternion
类的一些代码示例,展示了Quaternion
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Quaternion
类的具体详情如下:
包路径:com.jme3.math.Quaternion
类名称:Quaternion
[英]Quaternion
defines a single example of a more general class of hypercomplex numbers. Quaternions extends a rotation in three dimensions to a rotation in four dimensions. This avoids "gimbal lock" and allows for smooth continuous rotation. Quaternion
is defined by four floating point numbers: {x y z w}.
[中]Quaternion
定义了一个更一般的超复数类的例子。四元数将三维旋转扩展为四维旋转。这避免了“万向锁”,并允许平稳连续旋转。Quaternion
由四个浮点数定义:{x y z w}。
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Converts the euler angles from {@link #getVector3Value(long)} to
* a quaternion rotation.
* @param time Time at which to get the euler angles.
* @return The rotation at time
*/
public Quaternion getQuaternionValue(long time) {
Vector3f eulerAngles = getVector3Value(time);
System.out.println("\tT: " + time + ". Rotation: " +
eulerAngles.x + ", " +
eulerAngles.y + ", " + eulerAngles.z);
Quaternion q = new Quaternion();
q.fromAngles(eulerAngles.x * FastMath.DEG_TO_RAD,
eulerAngles.y * FastMath.DEG_TO_RAD,
eulerAngles.z * FastMath.DEG_TO_RAD);
return q;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public void simpleUpdate(float tpf){
// Rotate around X axis
Quaternion rotate = new Quaternion();
rotate.fromAngleAxis(tpf, Vector3f.UNIT_X);
// Combine rotation with previous
rotation.multLocal(rotate);
// Set new rotation into bone
bone.setUserTransforms(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ);
// After changing skeleton transforms, must update world data
skeleton.updateWorldVectors();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static Quaternion spline(Quaternion qnm1, Quaternion qn, Quaternion qnp1, Quaternion store, Quaternion tmp) {
Quaternion invQn = new Quaternion(-qn.x, -qn.y, -qn.z, qn.w);
log(invQn.mult(qnp1), tmp);
log(invQn.mult(qnm1), store);
store.addLocal(tmp).multLocal(-1f / 4f);
exp(store, tmp);
store.set(qn).multLocal(tmp);
return store.normalizeLocal();
//return qn * (((qni * qnm1).log() + (qni * qnp1).log()) / -4).exp();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static void convertMatrix4toQuat(Matrix4f in, Quaternion out) {
// convert rotation matrix to quat
out.fromRotationMatrix(in.m00, in.m01, in.m02, in.m10, in.m11, in.m12, in.m20, in.m21, in.m22);
// flip the pitch
out.set(-out.getX(), out.getY(), -out.getZ(), out.getW());
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static Quaternion toQuat(float ax1v, Vector3f ax1, float ax2v, Vector3f ax2, float ax3v, Vector3f ax3) {
// TODO It has some potential in optimization
Quaternion q1 = new Quaternion().fromAngleNormalAxis(ax1v, ax1);
Quaternion q2 = new Quaternion().fromAngleNormalAxis(ax2v, ax2);
Quaternion q3 = new Quaternion().fromAngleNormalAxis(ax3v, ax3);
return q1.multLocal(q2).multLocal(q3);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Stores this rotation value into the given Quaternion. If quat is null, a new Quaternion is created to
* hold the value. The value, once stored, is returned.
* @param quat The store location for this matrix's rotation.
* @return The value of this matrix's rotation.
*/
public Quaternion getRotation(Quaternion quat) {
if (quat==null) quat=new Quaternion();
quat.set(rot);
return quat;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Creates a quad with the water material applied to it.
* @param width
* @param height
* @return
*/
public Geometry createWaterGeometry(float width, float height) {
Quad quad = new Quad(width, height);
Geometry geom = new Geometry("WaterGeometry", quad);
geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
geom.setMaterial(material);
return geom;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* <code>subtract</code> subtracts the values of the parameter quaternion
* from those of this quaternion. The result is returned as a new
* quaternion.
*
* @param q
* the quaternion to subtract from this.
* @return the new quaternion.
*/
public Quaternion subtract(Quaternion q) {
return new Quaternion(x - q.x, y - q.y, z - q.z, w - q.w);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
Quaternion rotateL = new Quaternion().fromAngleAxis(FastMath.PI * tpf, Vector3f.UNIT_Y);
rotateL.multLocal(viewDirection);
} else if (rightRotate) {
Quaternion rotateR = new Quaternion().fromAngleAxis(-FastMath.PI * tpf, Vector3f.UNIT_Y);
rotateR.multLocal(viewDirection);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Alter the transforms of a rigidBody to match the transforms of a bone.
* This is used to make the ragdoll follow animated motion in Kinematic mode
*
* @param link the bone link connecting the bone and the rigidBody
* @param position temporary storage used in calculations (not null)
* @param tmpRot1 temporary storage used in calculations (not null)
*/
protected void matchPhysicObjectToBone(PhysicsBoneLink link, Vector3f position, Quaternion tmpRot1) {
//computing position from rotation and scale
targetModel.getWorldTransform().transformVector(link.bone.getModelSpacePosition(), position);
//computing rotation
tmpRot1.set(link.bone.getModelSpaceRotation()).multLocal(link.bone.getModelBindInverseRotation());
targetModel.getWorldRotation().mult(tmpRot1, tmpRot1);
tmpRot1.normalizeLocal();
//updating physics location/rotation of the physics bone
link.rigidBody.setPhysicsLocation(position);
link.rigidBody.setPhysicsRotation(tmpRot1);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
float z = parseFloat(attribs.getValue("z"));
float w = parseFloat(attribs.getValue("w"));
return new Quaternion(x, y, z, w);
} else if (attribs.getValue("qx") != null) {
float z = parseFloat(attribs.getValue("qz"));
float w = parseFloat(attribs.getValue("qw"));
return new Quaternion(x, y, z, w);
} else if (attribs.getValue("angle") != null) {
float axisY = parseFloat(attribs.getValue("axisY"));
float axisZ = parseFloat(attribs.getValue("axisZ"));
Quaternion q = new Quaternion();
q.fromAngleAxis(angle, new Vector3f(axisX, axisY, axisZ));
return q;
} else {
float angleY = parseFloat(attribs.getValue("angleY"));
float angleZ = parseFloat(attribs.getValue("angleZ"));
Quaternion q = new Quaternion();
q.fromAngles(angleX, angleY, angleZ);
return q;
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public Quaternion getFinalObserverRotation(int index) {
// Copied from OpenVRInput
VREnvironment env = hardware.getEnvironment();
OculusViewManager vrvm = (OculusViewManager) hardware.getEnvironment().getVRViewManager();
Object obs = env.getObserver();
Quaternion tempq = new Quaternion(); // TODO move to class scope?
if (obs instanceof Camera) {
tempq.set(((Camera) obs).getRotation());
} else {
tempq.set(((Spatial) obs).getWorldRotation());
}
return tempq.multLocal(getOrientation(index));
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
Quaternion localRotation = new Quaternion();
Vector3f localScale = new Vector3f(Vector3f.UNIT_XYZ);
Quaternion preRotation = new Quaternion();
double y = (Double) e2.properties.get(5);
double z = (Double) e2.properties.get(6);
localRotation.fromAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD);
} else if (propName.equals("Lcl Scaling")) {
double x = (Double) e2.properties.get(4);
double y = (Double) e2.properties.get(5);
double z = (Double) e2.properties.get(6);
preRotation.set(FbxNodeUtil.quatFromBoneAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD));
} else if (propName.equals("InheritType")) {
int inheritType = (Integer) e2.properties.get(4);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* FIXME: This seems to have singularity type issues with angle == 0, possibly others such as PI.
* @param store
* A Quaternion to store our result in. If null, a new one is
* created.
* @return The store quaternion (or a new Quaternion, if store is null) that
* describes a rotation that would point you in the exact opposite
* direction of this Quaternion.
*/
public Quaternion opposite(Quaternion store) {
if (store == null) {
store = new Quaternion();
}
Vector3f axis = new Vector3f();
float angle = toAngleAxis(axis);
store.fromAngleAxis(FastMath.PI + angle, axis);
return store;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Forcefully takes over Camera adding functionality and placing it behind the character
* @param tpf Tickes Per Frame
*/
private void camTakeOver(float tpf) {
cam.setLocation(player.getLocalTranslation().add(-8, 2, 0));
cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y);
Quaternion rot = new Quaternion();
rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z);
cam.setRotation(cam.getRotation().mult(rot));
camAngle *= FastMath.pow(.99f, fpsRate * tpf);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Rotate the physics object to the specified orientation.
* <p>
* We don't set the actual physics rotation but the view rotation here. It
* might actually be altered by the calculateNewForward method.
*
* @param quat desired orientation (not null, unaffected)
*/
@Override
protected void setPhysicsRotation(Quaternion quat) {
rotation.set(quat);
rotation.multLocal(rotatedViewDirection.set(viewDirection));
updateLocalViewDirection();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void applyWheelTransform() {
if (wheelSpatial == null) {
return;
}
Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
Vector3f localLocation = wheelSpatial.getLocalTranslation();
if (!applyLocal && wheelSpatial.getParent() != null) {
localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
localRotationQuat.set(wheelWorldRotation);
tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
wheelSpatial.setLocalTranslation(localLocation);
wheelSpatial.setLocalRotation(localRotationQuat);
} else {
wheelSpatial.setLocalTranslation(wheelWorldLocation);
wheelSpatial.setLocalRotation(wheelWorldRotation);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
ownerAngles = ownerRotation.toAngles(ownerAngles);
targetAngles = targetTransform.getRotation().toAngles(targetAngles);
Quaternion startRotation = ownerRotation.clone();
Quaternion offset = Quaternion.IDENTITY;
if ((flag & ROTLIKE_OFFSET) != 0) {// we add the original rotation to
ownerRotation.fromAngles(ownerAngles).multLocal(offset);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* <code>mult</code> multiplies this quaternion by a parameter quaternion.
* The result is returned as a new quaternion. It should be noted that
* quaternion multiplication is not commutative so q * p != p * q.
*
* @param q
* the quaternion to multiply this quaternion by.
* @return the new quaternion.
*/
public Quaternion mult(Quaternion q) {
return mult(q, null);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
tmpRot1.fromAngleAxis(rot, vectorAxis);
tmpRot2[posOrNeg] = link.bone.getLocalRotation().mult(tmpRot1);
tmpRot2[posOrNeg].normalizeLocal();
link.bone.getLocalRotation().normalizeLocal();
内容来源于网络,如有侵权,请联系作者删除!