// Create vectors Vector3f directionVector = new Vector3f(dx, dy, dz); Vector3f axisVector = new Vector3f(ax, ay, az); Vector3f constantBaseVector = new Vector3f(1, 0, 0); //Calculate angle float angle = constantBaseVector.angle(directionVector); //create AxisAngle4f AxisAngle4f axisAngle = new AxisAngle4f(axisVector, angle);
//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);
final float angleX = yAxis.angle(direction); final float a = axis.x * (float) Math.sin(angleX / 2f); final float b = axis.y * (float) Math.sin(angleX / 2f);
//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)));
cross.cross(vpc, vplane); aa.set(cross.x, cross.y, cross.z, -vplane.angle(vpc));