Scene3D

class Scene3D

Turns points in space into points on the canvas.

This is the whole of the depth effect. A perspective projection divides a point's position by how far away it is, so distant things land closer to the middle of the screen and closer things spread towards the edges. Move the camera forward every frame and the geometry appears to rush past. That is all a flight down a tunnel ever was.

The maths comes from Kite3D's Camera, which builds the view and projection matrices and projects without allocating, so this can run for every vertex of every frame.

Points behind the camera cannot be projected meaningfully: dividing by a negative depth turns the picture inside out. project answers false for those, and for anything past the far plane. Drawings here also wrap their geometry before it reaches the eye, so the case is rare.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

How far away the last point was, 0 at the near plane and 1 at the far one.

Link copied to clipboard

Where the last project landed, in canvas pixels.

Link copied to clipboard

Functions

Link copied to clipboard
fun camera(eyeX: Float, eyeY: Float, eyeZ: Float, targetX: Float = eyeX, targetY: Float = eyeY, targetZ: Float = eyeZ - 1f, roll: Float = 0.0f)

Points the camera. roll banks it around its own forward axis, in radians, which is the cheapest way to make a flight feel like flying rather than like sliding.

Link copied to clipboard
fun fog(distance: Float): Float

How solid something at distance world units away should look, 1 up close and 0 at the far plane. Fog is what stops a tunnel looking like a flat spiral drawn on glass.

Link copied to clipboard
fun lens(size: Size, fovDegrees: Float = 68.0f, near: Float = 0.6f, far: Float = 55.0f)

Sets the lens for this frame. Call once, before any project.

Link copied to clipboard
fun project(x: Float, y: Float, z: Float): Boolean

Projects one point. Returns false when it is behind the camera or beyond the far plane, in which case screenX, screenY and depth are left alone and nothing should be drawn.