1

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;
...
}   
}
marqso
  • 61
  • 9
  • 1
    see http://stackoverflow.com/questions/13261270/first-person-simulation-with-three-js-using-keyboard-arrows/13262612#13262612 – WestLangley Feb 05 '14 at 18:18
  • also see http://stackoverflow.com/questions/17517937/three-js-camera-tilt-up-or-down-and-keep-horizon-level/17518092#17518092 – WestLangley Feb 05 '14 at 18:24
  • @WestLangley: Gracias! (as we say here in Mexico) and I see I owe this answer to you in the first place, so gracias de nuevo! – marqso Feb 05 '14 at 20:55

0 Answers0