]>
git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/camera_rotator.js
1 import { mat4
, vec3
} from 'gl-matrix';
2 import { System
} from '@serpentity/serpentity';
3 import Cameras
from '../nodes/cameras';
6 * Rotates the camera around a "sphere"
8 export default class CameraRotator
extends System
{
17 this.cameras
= engine
.getNodes(Cameras
);
27 for (const camera
of this.cameras
) {
29 let rotationMatrix
= mat4
.create();
30 mat4
.rotateY(rotationMatrix
, rotationMatrix
, camera
.angle
.yaw
);
31 mat4
.rotateX(rotationMatrix
, rotationMatrix
, camera
.angle
.pitch
);
32 mat4
.rotateZ(rotationMatrix
, rotationMatrix
, camera
.angle
.roll
);
34 let eye
= vec3
.fromValues(0, 0, camera
.radius
.radius
);
35 vec3
.transformMat4(eye
, eye
, rotationMatrix
);
37 camera
.position
.x
= eye
[0];
38 camera
.position
.y
= eye
[1];
39 camera
.position
.z
= eye
[2];
41 let up
= vec3
.fromValues(0, 1, 0);
42 vec3
.transformMat4(up
, up
, rotationMatrix
);
47 camera
.angle
.pitch
= (camera
.angle
.pitch
+ camera
.velocity
.x
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);
48 camera
.angle
.yaw
= (camera
.angle
.yaw
+ camera
.velocity
.y
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);
49 camera
.angle
.roll
= (camera
.angle
.roll
+ camera
.velocity
.z
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);