I have a scene built with THREE.js in which a camera (attached "flashlight") serves as a moving POV in a darkened space (users will have to avoid small cacti as obstacles)
I want the camera to rotate freely around its y axis and in a limited way around its x axis. code snippet illustrating controls is below; a version with an added ambient light is linked, here:
http://card.gda.itesm.mx/mark/baldridge/cameraquestion.html
Works as expected in original camera orientation, but a few units around the y axis and the x rotation begins to exhibit apparent z rotation: at certain y rotation values, the desired x rot is apparently ALL z rot.
What gives? I realize I've misunderstood something fundamental and would welcome a new approach. Also, an issue I have yet to address is a "camera move in lookAt direction" which I want to add once I understand the issues. I would welcome answers that include this functionality.
// code example for limiting tilt and righting the camera as y rot occurs
function update()
{
if ( keyboard.pressed("up") )
{
camera.rotation.x += .01;
if (camera.rotation.x > .3 )
{
camera.rotation.x = .3;
}
}
if ( keyboard.pressed("left") )
{
camera.rotation.y += .01;
if (camera.rotation.x > 0)
{
camera.rotation.x -= .01;
}
if (camera.rotation.x < 0)
{
camera.rotation.x += .01;
...
}
}