Render3D. CameraControl3D

CameraControl3D - Drag to turn the camera around a point, roll the wheel to zoom

  • An EngineObject3D, so move its pos3D to follow something, or parent it to an object
  • Destroy it to hand the camera back, and it stops driving the camera
  • Set persistent to keep it when engineObjectsDestroy clears out a level
  • Every part of it is a field, so a game can change the buttons, speeds and limits

Constructor

new CameraControl3D(targetopt, distanceopt, pitchopt, idleSpinopt)

Create a camera control, it drives render3D.camera every frame

Parameters:
NameTypeAttributesDefaultDescription
targetVector3<optional>

The point to look at, its pos3D

distancenumber<optional>
10

How far the camera sits from the target

pitchnumber<optional>
0.4

Angle above the horizon, PI/2 looks straight down

idleSpinnumber<optional>
0

Turned each frame while not dragging, 0 holds still

Example
new CameraControl3D(vec3(0, 1, 0), 15); // look at a point from 15 units away

Extends

  • EngineObject3D

Members

distance

Properties
TypeDescription
number

How far the camera sits from the target

dragButton

Properties
TypeDescription
number

Mouse button that turns the camera, 0 is left and 2 is right

dragSpeed

Properties
TypeDescription
number

How far dragging a pixel turns the camera

idleSpin

Properties
TypeDescription
number

Turned each frame while not dragging

pitch

Properties
TypeDescription
number

Angle above the horizon

pitchRange

Properties
TypeDescription
Vector2

Lowest and highest pitch, so it cannot tip over the top

yaw

Properties
TypeDescription
number

Angle around the target, dragging changes it

zoomRange

Properties
TypeDescription
Vector2

Closest and furthest the wheel can zoom to

zoomSpeed

Properties
TypeDescription
number

How much one wheel notch zooms, 0 turns zooming off

Methods

render3D()

Camera controls draw nothing

update()

Read the mouse and put the camera on its orbit, called automatically each frame