/** * 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; }
@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(); }
float axisZ = parseFloat(attribs.getValue("axisZ")); Quaternion q = new Quaternion(); q.fromAngleAxis(angle, new Vector3f(axisX, axisY, axisZ)); return q; } else {
/** * 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; }
if (name.equals("left")) { tmp.set(cam.getDirection()); s.rotate(tmpQuat.fromAngleAxis(value, tmp)); s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
if (name.equals("left")) { tmp.set(cam.getDirection()); s.rotate(tmpQuat.fromAngleAxis(value, tmp)); s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
@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)); } }
@Override public void simpleUpdate(float tpf) { if (!done) { done = true; batch.attachChild(cube2); batch.batch(); } updateBoindPoints(points); frustum.update(points); time += tpf; dl.setDirection(cam.getDirection()); cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0); cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f)); // batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z)); } //
pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1); pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1); pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1); pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1); pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z)); pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1); pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
public void setupFloor() { mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"); Node floorGeom = new Node("floorGeom"); Quad q = new Quad(100, 100); q.scaleTextureCoordinates(new Vector2f(10, 10)); Geometry g = new Geometry("geom", q); g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); floorGeom.attachChild(g); TangentBinormalGenerator.generate(floorGeom); floorGeom.setLocalTranslation(-50, 22, 60); //floorGeom.setLocalScale(100); floorGeom.setMaterial(mat); rootNode.attachChild(floorGeom); }
public void setupFloor() { mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWallPBR.j3m"); //mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWallPBR2.j3m"); Node floorGeom = new Node("floorGeom"); Quad q = new Quad(100, 100); q.scaleTextureCoordinates(new Vector2f(10, 10)); Geometry g = new Geometry("geom", q); g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); floorGeom.attachChild(g); TangentBinormalGenerator.generate(floorGeom); floorGeom.setLocalTranslation(-50, 22, 60); //floorGeom.setLocalScale(100); floorGeom.setMaterial(mat); rootNode.attachChild(floorGeom); }
/** * This method transforms the first line of the bevel points positioning it * on the first point of the curve. * * @param startingLinePoints * the vbevel shape points * @param firstCurvePoint * the first curve's point * @param secondCurvePoint * the second curve's point * @return points of transformed bevel */ protected Vector3f[] transformToFirstLineOfBevelPoints(Vector3f[] startingLinePoints, Vector3f firstCurvePoint, Vector3f secondCurvePoint) { Vector3f planeNormal = secondCurvePoint.subtract(firstCurvePoint).normalizeLocal(); float angle = FastMath.acos(planeNormal.dot(Vector3f.UNIT_X)); Vector3f rotationVector = Vector3f.UNIT_X.cross(planeNormal).normalizeLocal(); Matrix4f m = new Matrix4f(); m.setRotationQuaternion(new Quaternion().fromAngleAxis(angle, rotationVector)); m.setTranslation(firstCurvePoint); Vector3f temp = new Vector3f(); Vector3f[] verts = new Vector3f[startingLinePoints.length]; for (int i = 0; i < verts.length; ++i) { verts[i] = m.mult(startingLinePoints[i], temp).clone(); } return verts; } }
float[] angles = new float[3]; model.getLocalRotation().toAngles(angles); q.fromAngleAxis(angles[1], Vector3f.UNIT_Y); model.setLocalRotation(q); if (angles[0] < 0) {
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);
tmpRot1.fromAngleAxis(rot, vectorAxis);
tmpRot1.fromAngleAxis(rot, vectorAxis);
mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat_ground);
mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat_ground);
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry ground = new Geometry("ground", new Quad(50, 50)); ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); ground.setLocalTranslation(-25, -1, 25); ground.setMaterial(mat);
animationFactory.addTimeRotation(0.5f,new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Z));