Daniel Gray

Thoughts, Notes, Ideas, Projects

← Back to home

Camera System and Interactive Controls

The camera follows a sophisticated flight path that creates an immersive flying experience through the procedurally generated terrain.

Flight Path System

The camera implements several key behaviors:

1. Terrain Following

Samples terrain height at current position and ahead, maintaining a steady altitude above the terrain (typically 12 units). This ensures the camera never clips through the ground and follows the landscape naturally.

2. Canyon Flying

Tends to steer away from peaks and toward valleys, creating a path through the landscape. The steering is minimal and mostly forward, creating a sense of exploration without being too aggressive.

3. Banking

When turning, the camera tilts like an aircraft banking into a turn. The banking angle is limited to ±0.25 radians for subtlety, creating a natural flying sensation.

4. Smooth Interpolation

All movements use linear interpolation (lerp) with carefully tuned factors (0.03-0.05) for fluid motion without jitter.

User Controls

The camera responds to:

  • Mouse Movement: Controls pitch and yaw slightly (0.08 sensitivity), allowing gentle camera control

  • Scroll: Moves forward/backward through the terrain at a rate of 0.01 units per pixel scrolled

  • Link Hover: Smoothly pans upward toward stars near the space station, dimming the background to 70% darkness to draw attention to links. The camera saves its position on hover and returns to it on mouse-out.

Implementation

The camera system uses Three.js camera controls with custom interpolation logic to achieve smooth, natural movement.

Terrain Height Sampling


// Sample terrain height at current position

const terrainHeight = sampleTerrainHeight(camera.position.x, camera.position.z);

  

// Maintain altitude above terrain

const targetY = terrainHeight + targetAltitude;

camera.position.y = lerp(camera.position.y, targetY, 0.05);

Smooth Interpolation

All camera movements use linear interpolation for smooth transitions:


function lerp(start: number, end: number, factor: number): number {

return start + (end - start) * factor;

}

  

// Apply to all camera movements

camera.position.x = lerp(camera.position.x, targetX, 0.03);

camera.position.y = lerp(camera.position.y, targetY, 0.05);

camera.position.z = lerp(camera.position.z, targetZ, 0.03);

Link Hover Effects

When hovering over blog post links, the camera:

  1. Saves its current position and orientation

  2. Smoothly pans upward toward a unique star in the sky

  3. Dims the background to 70% darkness

  4. On mouse-out, smoothly returns to the saved position

This creates a subtle interaction that draws attention to links while maintaining the immersive experience.

References

For more information on camera systems in 3D graphics:

Related Articles

Related Content

The 3D Background

The 3D Background The animated 3D background is a procedurally generated landscape that creates an infinite, dynamically rendered terrain with fractal trees, atmospheric effects, and interactive camer...