Skip to content

3D Math: A Practical Starting Point

Positions, directions and rotations are the foundation of a 3D scene. This guide introduces the operations you will use most often in jMonkeyEngine.

Vectors

A Vector3f stores three coordinates. Subtract positions to obtain a direction; normalize it when you need a unit vector. Keep the original positions unchanged when they are still needed:

Vector3f direction = target.subtract(source);
if (direction.lengthSquared() > 0f) {
    direction.normalizeLocal();
}

The dot product compares directions: unit vectors pointing the same way have a dot product near 1, perpendicular vectors near 0, and opposite vectors near -1. The cross product produces a vector perpendicular to both inputs; its direction depends on their order.

Rotation and rays

Use a Quaternion for spatial rotation. Spatial.lookAt(target, up) points a spatial toward a world-space target; choose an up vector that is not parallel to the look direction. A Ray combines an origin and direction and can be tested against scene geometry for picking or line-of-sight checks.

Continue with Math for Dummies, rotations, quaternions, and mouse picking.