Render3D. FirstPersonCamera3D

FirstPersonCamera3D - Look around with the mouse and move with the keys, with the camera at its position

  • Click to capture the mouse so looking needs no button held, Esc lets it go; holding the button looks too, for touch
  • WASD or the arrow keys walk level, or move the way it looks when fly is set
  • An EngineObject3D that moves by velocity3D, so give it a size3D and call setCollision to walk into solid objects instead of through them; walking keeps velocity3D.y, so render3D.gravity can pull it down
  • Starts from wherever render3D.camera is, so it can take over from another camera without a jump
  • Destroy it to hand the camera back

Constructor

new FirstPersonCamera3D(pos3Dopt, yawopt, pitchopt)

Create a first person camera, it drives render3D.camera every frame

Parameters:
NameTypeAttributesDescription
pos3DVector3<optional>

Where the eye is, defaults to where the camera is now

yawnumber<optional>

Radians around Y, defaults to the camera's

pitchnumber<optional>

Radians up from level, defaults to the camera's

Example
const player = new FirstPersonCamera3D(vec3(0, 1.5, 5));
player.size3D = vec3(1); // bump into solid objects
player.collideAsSphere3D = true;
player.setCollision();

Extends

  • EngineObject3D

Members

fly

Properties
TypeDescription
boolean

Move the way it looks, up and down included, instead of walking level

lockPointer

Properties
TypeDescription
boolean

Capture the mouse on a click, so looking needs no button held

lookSpeed

Properties
TypeDescription
number

How far a pixel of mouse movement turns the view

moveSpeed

Properties
TypeDescription
number

World units per frame at full speed

pitch

Properties
TypeDescription
number

Angle up from level, the mouse tilts it

pitchRange

Properties
TypeDescription
Vector2

Lowest and highest pitch

yaw

Properties
TypeDescription
number

Angle around Y, the mouse turns it

Methods

destroy(immediateopt)

Let go of the mouse and stop driving the camera

Parameters:
NameTypeAttributesDescription
immediateboolean<optional>

render3D()

Camera controls draw nothing

update()

Read the mouse and keys and put the camera at the eye, called automatically each frame