]>
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';
5 export default class CameraRotator
extends System
{
14 this.cameras
= engine
.getNodes(Cameras
);
24 for (const camera
of this.cameras
) {
26 let rotationMatrix
= mat4
.create();
27 mat4
.rotateY(rotationMatrix
, rotationMatrix
, camera
.angle
.yaw
);
28 mat4
.rotateX(rotationMatrix
, rotationMatrix
, camera
.angle
.pitch
);
29 mat4
.rotateZ(rotationMatrix
, rotationMatrix
, camera
.angle
.roll
);
31 let eye
= vec3
.fromValues(0, 0, camera
.radius
.radius
);
32 vec3
.transformMat4(eye
, eye
, rotationMatrix
);
34 camera
.position
.x
= eye
[0];
35 camera
.position
.y
= eye
[1];
36 camera
.position
.z
= eye
[2];
38 let up
= vec3
.fromValues(0, 1, 0);
39 vec3
.transformMat4(up
, up
, rotationMatrix
);
44 camera
.angle
.pitch
= (camera
.angle
.pitch
+ camera
.velocity
.x
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);
45 camera
.angle
.yaw
= (camera
.angle
.yaw
+ camera
.velocity
.y
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);
46 camera
.angle
.roll
= (camera
.angle
.roll
+ camera
.velocity
.z
* dt
/ 500 + 2 * Math
.PI
) % (2 * Math
.PI
);