use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestBetterCharacter method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
// Apply planet gravity to character if close enough (see below)
checkPlanetGravity();
// Get current forward and left vectors of model by using its rotation
// to rotate the unit vectors
Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
// WalkDirection is global!
// You *can* make your character fly with this.
walkDirection.set(0, 0, 0);
if (leftStrafe) {
walkDirection.addLocal(modelLeftDir.mult(3));
} else if (rightStrafe) {
walkDirection.addLocal(modelLeftDir.negate().multLocal(3));
}
if (forward) {
walkDirection.addLocal(modelForwardDir.mult(3));
} else if (backward) {
walkDirection.addLocal(modelForwardDir.negate().multLocal(3));
}
physicsCharacter.setWalkDirection(walkDirection);
// setApplyPhysicsLocal()
if (leftRotate) {
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);
}
physicsCharacter.setViewDirection(viewDirection);
fpsText.setText("Touch da ground = " + physicsCharacter.isOnGround());
if (!lockView) {
cam.lookAt(characterNode.getWorldTranslation().add(new Vector3f(0, 2, 0)), Vector3f.UNIT_Y);
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestCollisionShapeFactory method attachRandomGeometry.
private void attachRandomGeometry(Node node, Material mat) {
Box box = new Box(0.25f, 0.25f, 0.25f);
Torus torus = new Torus(16, 16, 0.2f, 0.8f);
Geometry[] boxes = new Geometry[] { new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) };
for (int i = 0; i < boxes.length; i++) {
Geometry geometry = boxes[i];
geometry.setLocalTranslation((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI));
geometry.setLocalScale((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
geometry.setMaterial(mat);
node.attachChild(geometry);
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNodeCluster method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
time += tpf;
int random = rand.nextInt(2000);
float mult1 = 1.0f;
float mult2 = 1.0f;
if (random < 500) {
mult1 = 1.0f;
mult2 = 1.0f;
} else if (random < 1000) {
mult1 = -1.0f;
mult2 = 1.0f;
} else if (random < 1500) {
mult1 = 1.0f;
mult2 = -1.0f;
} else if (random <= 2000) {
mult1 = -1.0f;
mult2 = -1.0f;
}
box = batchNode.getChild("Box" + random);
if (box != null) {
Vector3f v = box.getLocalTranslation();
box.setLocalTranslation(v.x + FastMath.sin(time * mult1) * 20, v.y + (FastMath.sin(time * mult1) * FastMath.cos(time * mult1) * 20), v.z + FastMath.cos(time * mult2) * 20);
}
terrain.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Y));
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestHoveringTank method makeMissile.
public void makeMissile() {
Vector3f pos = spaceCraft.getWorldTranslation().clone();
Quaternion rot = spaceCraft.getWorldRotation();
Vector3f dir = rot.getRotationColumn(2);
Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
missile.scale(0.5f);
missile.rotate(0, FastMath.PI, 0);
missile.updateGeometricState();
BoundingBox box = (BoundingBox) missile.getWorldBound();
final Vector3f extent = box.getExtent(null);
BoxCollisionShape boxShape = new BoxCollisionShape(extent);
missile.setName("Missile");
missile.rotate(rot);
missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
missile.setLocalRotation(hoverControl.getPhysicsRotation());
missile.setShadowMode(ShadowMode.Cast);
RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
control.setLinearVelocity(dir.mult(100));
control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
missile.addControl(control);
rootNode.attachChild(missile);
getPhysicsSpace().add(missile);
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class PhysicsGhostObject method getPhysicsRotation.
/**
* @return the physicsLocation
*/
public Quaternion getPhysicsRotation(Quaternion rot) {
if (rot == null) {
rot = new Quaternion();
}
gObject.getWorldTransform(tempTrans);
Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation());
return rot.set(physicsLocation.getRotation());
}
Aggregations