Skip to content

@fibbojs / 3d / FGameCamera

Class: FGameCamera

A camera that can be attached to a FComponent and orbits around it in a more game-like way.

Example

ts
import { FCuboid, FGameCamera, FScene } from '@fibbojs/3d'

const scene = new FScene()

const cube = new FCuboid(scene)
scene.addComponent(cube)

scene.camera = new FGameCamera(cube)

Extends

Accessors

zoom

get zoom(): number

set zoom(zoom): void

Parameters

zoom: number

Returns

number

Inherited from

FOrbitCamera.zoom

Defined in

3d/src/cameras/FCamera.ts:114

Constructors

new FGameCamera()

new FGameCamera(scene, options): FGameCamera

Parameters

scene: FScene

options: FAttachedCameraOptions

Returns

FGameCamera

Overrides

FOrbitCamera.constructor

Defined in

3d/src/cameras/FGameCamera.ts:29

Methods

__UPDATE_POSITION__()

__UPDATE_POSITION__(): void

Update the position of the camera according to the transform. This method should be called after updating the transform properties.

Returns

void

Inherited from

FOrbitCamera.__UPDATE_POSITION__

Defined in

3d/src/cameras/FCamera.ts:68


__UPDATE_ROTATION__()

__UPDATE_ROTATION__(): void

Update the rotation of the camera according to the transform. This method should be called after updating the transform properties.

Returns

void

Inherited from

FOrbitCamera.__UPDATE_ROTATION__

Defined in

3d/src/cameras/FCamera.ts:76


__UPDATE_SCALE__()

__UPDATE_SCALE__(): void

Update the scale of the camera according to the transform. This method should be called after updating the transform properties. This method does not make sense for cameras, but it is implemented for consistency.

Returns

void

Inherited from

FOrbitCamera.__UPDATE_SCALE__

Defined in

3d/src/cameras/FCamera.ts:85


emitCollisionWith()

emitCollisionWith(options): void

Emit a collision event with a given class or object.

Parameters

options

The options for the collision event.

options.class?: any

The class to emit the collision event with.

options.component?: FComponent

The component to emit the collision event with.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  class: Enemy
})
typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  object: enemy
})

Inherited from

FOrbitCamera.emitCollisionWith

Defined in

core/dist/index.d.ts:293


emitOnLoaded()

emitOnLoaded(): void

Emit the onLoaded callbacks.

Returns

void

Inherited from

FOrbitCamera.emitOnLoaded

Defined in

core/dist/index.d.ts:247


frame()

frame(delta): void

Update the component. Should be called every frame. The purpose of this method is to render the component, its mesh/sprite, and its properties.

Parameters

delta: number

Returns

void

Overrides

FOrbitCamera.frame

Defined in

3d/src/cameras/FGameCamera.ts:56


getCameraDirection()

getCameraDirection(): Vector3

Get the direction of the camera. This method is useful to get the direction of the camera to apply forces in the direction of the camera.

Returns

Vector3

The direction of the camera. It is a normalized vector.

Inherited from

FOrbitCamera.getCameraDirection

Defined in

3d/src/cameras/FCamera.ts:105


lookAt()

lookAt(target): void

Make the camera look at a target.

Parameters

target: FVector3

The target to look at.

Returns

void

Inherited from

FOrbitCamera.lookAt

Defined in

3d/src/cameras/FCamera.ts:96


onCollisionWith()

onCollisionWith(classOrObject, callback): () => void

Add a callback to be called when a collision occurs.

Parameters

classOrObject: any

The class or object to add the callback to.

callback

The callback to add.

Returns

Function

A function to remove the callback.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(Enemy, () => {
  console.log('Player collided with an Enemy!')
})
typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(enemy, () => {
  console.log('Player collided with the enemy!')
})

Inherited from

FOrbitCamera.onCollisionWith

Defined in

core/dist/index.d.ts:270


onFrame()

onFrame(callback): void

Add a callback to be called every frame.

Parameters

callback

The callback function.

Returns

void

Inherited from

FOrbitCamera.onFrame

Defined in

core/dist/index.d.ts:238


onLoaded()

onLoaded(callback): void

Add a callback to be called when the component is loaded (could be a texture, a 3D model, etc).

Parameters

callback

The callback function.

Returns

void

Inherited from

FOrbitCamera.onLoaded

Defined in

core/dist/index.d.ts:243


setPosition()

setPosition(position): void

Parameters

position: FVector3

Returns

void

Inherited from

FOrbitCamera.setPosition

Defined in

3d/src/cameras/FOrbitCamera.ts:47


setZoom()

setZoom(zoom): void

Parameters

zoom: number

Returns

void

Inherited from

FOrbitCamera.setZoom

Defined in

3d/src/cameras/FOrbitCamera.ts:57

Properties

__CALLBACKS_ON_COLLISION__

__CALLBACKS_ON_COLLISION__: object

Callbacks for when a collision occurs with a given class or object. It is a dictionary where the key is the class name or object id and the value is an array of callbacks.

Index Signature

[key: string]: (data) => void[]

Inherited from

FOrbitCamera.__CALLBACKS_ON_COLLISION__

Defined in

core/dist/index.d.ts:216


__CALLBACKS_ON_FRAME__

__CALLBACKS_ON_FRAME__: () => void[]

Callbacks for when a frame is rendered.

Inherited from

FOrbitCamera.__CALLBACKS_ON_FRAME__

Defined in

core/dist/index.d.ts:207


__CALLBACKS_ON_LOADED__

__CALLBACKS_ON_LOADED__: () => void[]

Callbacks for when the component is loaded (could be a texture, a 3D model, etc).

Inherited from

FOrbitCamera.__CALLBACKS_ON_LOADED__

Defined in

core/dist/index.d.ts:211


__CAMERA__

__CAMERA__: PerspectiveCamera

Three.js camera object.

Inherited from

FOrbitCamera.__CAMERA__

Defined in

3d/src/cameras/FCamera.ts:24


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from

FOrbitCamera.__ID__

Defined in

core/dist/index.d.ts:203


__IS_2D__

__IS_2D__: boolean = false

Inherited from

FOrbitCamera.__IS_2D__

Defined in

3d/src/cameras/FCamera.ts:19


__IS_3D__

__IS_3D__: boolean = true

Internal flags

Inherited from

FOrbitCamera.__IS_3D__

Defined in

3d/src/cameras/FCamera.ts:18


attachedComponent

attachedComponent: FComponent

Inherited from

FOrbitCamera.attachedComponent

Defined in

3d/src/cameras/FOrbitCamera.ts:26


controller?

optional controller: FController

The controller attached to the component.

Inherited from

FOrbitCamera.controller

Defined in

core/dist/index.d.ts:226


controls

controls: OrbitControls

Inherited from

FOrbitCamera.controls

Defined in

3d/src/cameras/FOrbitCamera.ts:28


isPointerLocked

isPointerLocked: boolean = false

Defined in

3d/src/cameras/FGameCamera.ts:25


lastMouseMoveEvent

lastMouseMoveEvent: undefined | MouseEvent

Defined in

3d/src/cameras/FGameCamera.ts:27


scene

scene: FScene

The scene the component is attached to.

Inherited from

FOrbitCamera.scene

Defined in

core/dist/index.d.ts:222


transform

transform: FTransform

Transform of the camera.

Inherited from

FOrbitCamera.transform

Defined in

3d/src/cameras/FCamera.ts:29