本文整理汇总了Java中com.bulletphysics.linearmath.QuaternionUtil.shortestArcQuat方法的典型用法代码示例。如果您正苦于以下问题:Java QuaternionUtil.shortestArcQuat方法的具体用法?Java QuaternionUtil.shortestArcQuat怎么用?Java QuaternionUtil.shortestArcQuat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bulletphysics.linearmath.QuaternionUtil
的用法示例。
在下文中一共展示了QuaternionUtil.shortestArcQuat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: spawnPrefab
import com.bulletphysics.linearmath.QuaternionUtil; //导入方法依赖的package包/类
@Command(shortDescription = "Spawns an instance of a prefab in the world")
public void spawnPrefab(@CommandParam(name = "prefabId") String prefabName) {
Camera camera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
Vector3f spawnPos = camera.getPosition();
Vector3f offset = new Vector3f(camera.getViewingDirection());
offset.scale(2);
spawnPos.add(offset);
Vector3f dir = new Vector3f(camera.getViewingDirection());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(0, 0, 1);
}
Quat4f rotation = QuaternionUtil.shortestArcQuat(new Vector3f(0, 0, 1), dir, new Quat4f());
Prefab prefab = CoreRegistry.get(PrefabManager.class).getPrefab(prefabName);
if (prefab != null && prefab.getComponent(LocationComponent.class) != null) {
CoreRegistry.get(EntityManager.class).create(prefab, spawnPos, rotation);
}
}
示例2: HingeConstraint
import com.bulletphysics.linearmath.QuaternionUtil; //导入方法依赖的package包/类
public HingeConstraint (RigidBody rbA, RigidBody rbB, Vector3 pivotInA, Vector3 pivotInB, Vector3 axisInA, Vector3 axisInB) {
super(TypedConstraintType.HINGE_CONSTRAINT_TYPE, rbA, rbB);
Stack stack = Stack.enter();
angularOnly = false;
enableAngularMotor = false;
rbAFrame.origin.set(pivotInA);
// since no frame is given, assume this to be zero angle and just pick rb transform axis
Vector3 rbAxisA1 = stack.allocVector3();
Vector3 rbAxisA2 = stack.allocVector3();
Transform centerOfMassA = rbA.getCenterOfMassTransform(stack.allocTransform());
MatrixUtil.getColumn(centerOfMassA.basis, 0, rbAxisA1);
float projection = axisInA.dot(rbAxisA1);
if (projection >= 1.0f - BulletGlobals.SIMD_EPSILON) {
MatrixUtil.getColumn(centerOfMassA.basis, 2, rbAxisA1);
rbAxisA1.scl(-1);
MatrixUtil.getColumn(centerOfMassA.basis, 1, rbAxisA2);
} else if (projection <= -1.0f + BulletGlobals.SIMD_EPSILON) {
MatrixUtil.getColumn(centerOfMassA.basis, 2, rbAxisA1);
MatrixUtil.getColumn(centerOfMassA.basis, 1, rbAxisA2);
} else {
rbAxisA2.set(axisInA).crs(rbAxisA1);
rbAxisA1.set(rbAxisA2).crs(axisInA);
}
MatrixUtil.setRow(rbAFrame.basis, 0, rbAxisA1.x, rbAxisA2.x, axisInA.x);
MatrixUtil.setRow(rbAFrame.basis, 1, rbAxisA1.y, rbAxisA2.y, axisInA.y);
MatrixUtil.setRow(rbAFrame.basis, 2, rbAxisA1.z, rbAxisA2.z, axisInA.z);
Quaternion rotationArc = QuaternionUtil.shortestArcQuat(axisInA, axisInB, stack.allocQuaternion());
Vector3 rbAxisB1 = QuaternionUtil.quatRotate(rotationArc, rbAxisA1, stack.allocVector3());
Vector3 rbAxisB2 = stack.allocVector3();
rbAxisB2.set(axisInB).crs(rbAxisB1);
rbBFrame.origin.set(pivotInB);
MatrixUtil.setRow(rbBFrame.basis, 0, rbAxisB1.x, rbAxisB2.x, -axisInB.x);
MatrixUtil.setRow(rbBFrame.basis, 1, rbAxisB1.y, rbAxisB2.y, -axisInB.y);
MatrixUtil.setRow(rbBFrame.basis, 2, rbAxisB1.z, rbAxisB2.z, -axisInB.z);
// start with free
lowerLimit = 1e30f;
upperLimit = -1e30f;
biasFactor = 0.3f;
relaxationFactor = 1.0f;
limitSoftness = 0.9f;
solveLimit = false;
stack.leave();
}
示例3: HingeConstraint
import com.bulletphysics.linearmath.QuaternionUtil; //导入方法依赖的package包/类
public HingeConstraint(RigidBody rbA, RigidBody rbB, Vector3f pivotInA, Vector3f pivotInB, Vector3f axisInA, Vector3f axisInB) {
super(TypedConstraintType.HINGE_CONSTRAINT_TYPE, rbA, rbB);
angularOnly = false;
enableAngularMotor = false;
rbAFrame.origin.set(pivotInA);
// since no frame is given, assume this to be zero angle and just pick rb transform axis
Vector3f rbAxisA1 = Stack.alloc(Vector3f.class);
Vector3f rbAxisA2 = Stack.alloc(Vector3f.class);
Transform centerOfMassA = rbA.getCenterOfMassTransform(Stack.alloc(Transform.class));
centerOfMassA.basis.getColumn(0, rbAxisA1);
float projection = axisInA.dot(rbAxisA1);
if (projection >= 1.0f - BulletGlobals.SIMD_EPSILON) {
centerOfMassA.basis.getColumn(2, rbAxisA1);
rbAxisA1.negate();
centerOfMassA.basis.getColumn(1, rbAxisA2);
} else if (projection <= -1.0f + BulletGlobals.SIMD_EPSILON) {
centerOfMassA.basis.getColumn(2, rbAxisA1);
centerOfMassA.basis.getColumn(1, rbAxisA2);
} else {
rbAxisA2.cross(axisInA, rbAxisA1);
rbAxisA1.cross(rbAxisA2, axisInA);
}
rbAFrame.basis.setRow(0, rbAxisA1.x, rbAxisA2.x, axisInA.x);
rbAFrame.basis.setRow(1, rbAxisA1.y, rbAxisA2.y, axisInA.y);
rbAFrame.basis.setRow(2, rbAxisA1.z, rbAxisA2.z, axisInA.z);
Quat4f rotationArc = QuaternionUtil.shortestArcQuat(axisInA, axisInB, Stack.alloc(Quat4f.class));
Vector3f rbAxisB1 = QuaternionUtil.quatRotate(rotationArc, rbAxisA1, Stack.alloc(Vector3f.class));
Vector3f rbAxisB2 = Stack.alloc(Vector3f.class);
rbAxisB2.cross(axisInB, rbAxisB1);
rbBFrame.origin.set(pivotInB);
rbBFrame.basis.setRow(0, rbAxisB1.x, rbAxisB2.x, -axisInB.x);
rbBFrame.basis.setRow(1, rbAxisB1.y, rbAxisB2.y, -axisInB.y);
rbBFrame.basis.setRow(2, rbAxisB1.z, rbAxisB2.z, -axisInB.z);
// start with free
lowerLimit = 1e30f;
upperLimit = -1e30f;
biasFactor = 0.3f;
relaxationFactor = 1.0f;
limitSoftness = 0.9f;
solveLimit = false;
}