//calculate angle to rotate float deltaRotation = rotationVelocity * deltaTime; //calcuate percent of rotation float percent = Math.min(deltaRotation / angle, 1.0f); //create interpolated vector representing the new forward direction Vector3f inter = new Vector3f(heading.x + percent * (direction.x - heading.x), heading.y + percent * (direction.y - heading.y), heading.z + percent * (direction.z - heading.z)); inter.normalize();
//ship heading (already calculated) Vector3f heading /* = ... */; heading.normalize(); //direction of enemy ship relative to ours Vector3d direction = new Vector3f(enemy.x - ship.x, enemy.y - ship.y, enemy.z - ship.z); direction.normalize(); //angle between vectors float angle = heading.angle(direction);
float findAngularOffset() { Vector3f unitToEar = new Vector3f(); Vector3f unitDirection = new Vector3f(); Point3f xformPosition = positions[currentIndex]; Point3f xformCenterEar = centerEars[currentIndex]; float dotProduct; float angle; /* * TODO: (Question) is assumption that xformed values available O.K. * TODO: (Performance) save this angular offset and only recalculate * if centerEar or sound position have changed. */ unitToEar.x = xformCenterEar.x - xformPosition.x; unitToEar.y = xformCenterEar.y - xformPosition.y; unitToEar.z = xformCenterEar.z - xformPosition.z; unitToEar.normalize(); unitDirection.normalize(this.direction); dotProduct = unitToEar.dot(unitDirection); angle = (float)(Math.acos((double)dotProduct)); if (debugFlag) debugPrint(" angle from cone direction = " + angle); return(angle); }
@Override void updateTransformChange() { super.updateTransformChange(); getLastLocalToVworld().transform(direction, xformDirection); xformDirection.normalize(); }
@Override public void simpleUpdate(float tpf) { red.rotate(0, 0.001f, 0); // For the red (moves in a circle) Quaternion rotation = red.getLocalRotation(); Vector3f front = new Vector3f(0, 0, 0.01f); Vector3f heading = rotation.mult(front); red.move(heading); /// For the blue (follows the red) blue.lookAt(red.getWorldTranslation(), Vector3f.UNIT_Y); float velocity = 0.01f; Vector3f trajectory = red.getWorldTranslation().subtract(blue.getWorldTranslation()); trajectory = trajectory.normalize(); Vector3f offset = trajectory.mult(velocity); blue.move(offset); System.out.print(offset); }
@Override void updateTransformChange() { Transform3D lastLocalToVworld = getLastLocalToVworld(); super.updateTransformChange(); lastLocalToVworld.transform(direction, xformDirection); xformDirection.normalize(); // set flag looked at by Scheduler to denote Transform change // this flag will force resneding transformed direction to AudioDevice if (debugFlag) debugPrint("ConeSound xformDirection is (" + xformDirection.x + ", " + xformDirection.y + ", "+ xformDirection.z + ")"); }
@Override void updateTransformChange() { super.updateTransformChange(); getLastLocalToVworld().transform(direction, xformDirection); xformDirection.normalize(); }
/** * This updates the Direction fields of cone sound. * * Neither Angular gain Attenuation and Filtering fields, nor * back distance gain not maintained in mirror object */ @Override void updateMirrorObject(Object[] objs) { if (debugFlag) debugPrint("PointSoundRetained:updateMirrorObj()"); int component = ((Integer)objs[1]).intValue(); int numSnds = ((Integer)objs[2]).intValue(); SoundRetained[] mSnds = (SoundRetained[]) objs[3]; if (component == -1) { // update every field initMirrorObject(((ConeSoundRetained)objs[2])); return; } if ((component & DIRECTION_DIRTY_BIT) != 0) { for (int i = 0; i < numSnds; i++) { ConeSoundRetained cone = (ConeSoundRetained)mSnds[i]; cone.direction = (Vector3f)objs[4]; cone.getLastLocalToVworld().transform(cone.direction, cone.xformDirection); cone.xformDirection.normalize(); } } // call the parent's mirror object update routine super.updateMirrorObject(objs); }
public void getVertexNormal(final Vertex v, final Vector3f ret) { ret.set(0, 0, 0); final Vector3f tn = new Vector3f(); for (final int fIdx : v.triangles) { getFaceNormal(fIdx, tn); ret.add(tn); } ret.normalize(); }
void updateLightState(LightRetained light) { if (light instanceof DirectionalLightRetained) { DirectionalLightRetained dl = (DirectionalLightRetained) light; Transform3D xform = getNormalTransform(); xform.transform(dl.direction, dl.xformDirection); dl.xformDirection.normalize(); } else if (light instanceof SpotLightRetained) { SpotLightRetained sl = (SpotLightRetained) light; Transform3D xform = getNormalTransform(); xform.transform(sl.direction, sl.xformDirection); sl.xformDirection.normalize(); this.modelTransform.transform(sl.position, sl.xformPosition); } else if (light instanceof PointLightRetained) { PointLightRetained pl = (PointLightRetained) light; this.modelTransform.transform(pl.position,pl.xformPosition); pl.localToVworldScale = modelTransform.getDistanceScale(); } }
//the object's default forward size without any transformations Vector3f forward = new Vector3f(0.0f, 0.0f, 1.0f); //rotation axis Vector3f axis = new Vector3f(); axis.cross(forward, inter); axis.normalize(); //New rotation matrix to be applied Matrix4f rotationMatrix = new Matrix4f(); rotationMatrix.setIdentity(); rotationMatrix.setRotation(new AxisAngle4f(axis, forward.angle(inter)));
void updateSoundState(SoundRetained sound) { View view = null; if (canvas3d != null) view = canvas3d.view; // Make sure that: // . Current view is not null // . The sound scheduler running (reference to it is not null) if (view != null) { SoundScheduler soundScheduler = getSoundScheduler(); if (soundScheduler == null) { // XXXX: Re-implement // start up SoundScheduler since it hasn't already been started } } // Update sound fields related to transforms if (sound instanceof ConeSoundRetained) { ConeSoundRetained cs = (ConeSoundRetained) sound; this.modelTransform.transform(cs.direction, cs.xformDirection); cs.xformDirection.normalize(); this.modelTransform.transform(cs.position, cs.xformPosition); // XXXX (Question) Is drawTranform equivalent to Vworld-to-Local? cs.trans.setWithLock(drawTransform); } else if (sound instanceof PointSoundRetained) { PointSoundRetained ps = (PointSoundRetained) sound; this.modelTransform.transform(ps.position, ps.xformPosition); // XXXX (Question) Is drawTranform equivalent to Vworld-to-Local? ps.trans.setWithLock(drawTransform); } }
public Vector3f[] getNormals() { final Vector3f[] normals = new Vector3f[nVertices]; for (int i = 0; i < nVertices; i++) normals[i] = new Vector3f(); final Vector3f v1 = new Vector3f(), v2 = new Vector3f(); for (int i = 0; i < nFaces; i += 3) { final int f1 = faces[i]; final int f2 = faces[i + 1]; final int f3 = faces[i + 2]; v1.sub(vertices[f2], vertices[f1]); v2.sub(vertices[f3], vertices[f1]); v1.cross(v1, v2); normals[f1].add(v1); normals[f2].add(v1); normals[f3].add(v1); } for (int i = 0; i < nVertices; i++) normals[i].normalize(); return normals; }
final Vector3f dir = new Vector3f(); dir.sub(end, start); dir.normalize(); final float fx = first * dir.x; final float fy = first * dir.y;
axis.normalize(); float interval = univ.getRotationInterval();