I am using p5.js library and using the functionality of WebGL to make a 3d game. I want to record the z position of the camera and use it to obtain a certain output. Firstly, I wanted to know if there is a way to print the current x, y and z position of the camera.
I created a variable first and created the camera
var cam = createCamera()
Then I used cam.move(x, y, z) to move the camera.
Now, I want to get the position of the camera and print it. Further, I want to know the camera position to implement certain functions in the game.
Is there a way to do this?
Please do help me out in the same... Thank you in advance
The p5.Camera class has a bunch of properties that describe its position and orientation:
| Property | Description |
|---|---|
| eyeX | camera position value on x axis |
| eyeY | camera position value on y axis |
| eyeZ | camera position value on z axis |
| centerX | x coordinate representing center of the sketch |
| centerY | y coordinate representing center of the sketch |
| centerZ | z coordinate representing center of the sketch |
| upX | x component of direction 'up' from camera |
| upY | y component of direction 'up' from camera |
| upZ | z component of direction 'up' from camera |
In this context, "the center of the sketch" is the position the camera is facing. See the reference for more info.