Camera::LookAt vs SceneNode::LookAt Topic is solved

Problems building or running the engine, queries about how to use features etc.
farrer
Halfling
Posts: 69
Joined: Mon Sep 12, 2011 7:35 pm
x 13

Camera::LookAt vs SceneNode::LookAt

Post by farrer »

Ogre Version: :14.4.1:
Operating System: : Linux:
Render System: :GL3Plus:

I'm updating some old code here from Ogre 1.12 to Ogre 14.4.1, but I'm struggling with getting the camera back to work.

The camera is defined with a position, a zoom factor and two rotation angles, theta for rotation around X axis and phi for rotation around Y axis, as bellow:

Code: Select all

   Ogre::Radian thetaR = Ogre::Radian(Ogre::Degree(state.theta));
   Ogre::Radian phiR = Ogre::Radian(Ogre::Degree(state.phi));

   Ogre::Real cosTheta = Ogre::Math::Cos(thetaR);
   Ogre::Real sinTheta = Ogre::Math::Sin(thetaR);

   Ogre::Real cosPhi = Ogre::Math::Cos(phiR);
   Ogre::Real sinPhi = Ogre::Math::Sin(phiR);

   eye.x = state.center.x + state.zoom * cosTheta * sinPhi;
   eye.y = state.center.y + state.zoom * sinTheta;
   eye.z = state.center.z + state.zoom * cosTheta * cosPhi;

   ogreCamera->setPosition(eye);
   ogreCamera->lookAt(state.center);

Converting it to use a SceneNode, I've got wrong rotations within my phi variable (expected to be around Y axis). There is any difference in the usage of SceneNode::lookAt from the behavior of Camera::lookAt that I'm missing out?

My SceneNode creation:

Code: Select all

   ogreSceneNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
   ogreSceneNode->attachObject(ogreCamera);

and the change in the camera code:

Code: Select all

   ogreSceneNode->setPosition(eye);
   ogreSceneNode->lookAt(state.center, Ogre::Node::TS_WORLD);
paroj
OGRE Team Member
OGRE Team Member
Posts: 2274
Joined: Sun Mar 30, 2014 2:51 pm
x 1239

Re: Camera::LookAt vs SceneNode::LookAt

Post by paroj »

you need Node::TS_PARENT AFAIR

farrer
Halfling
Posts: 69
Joined: Mon Sep 12, 2011 7:35 pm
x 13

Re: Camera::LookAt vs SceneNode::LookAt

Post by farrer »

paroj wrote: Wed Dec 17, 2025 11:30 am

you need Node::TS_PARENT AFAIR

Same behavior as TS_WORLD (expected as the camera's SceneNode is a child of rootSceneNode).

I couldn't mimic the behavior of Camera::lookAt with SceneNode::lookAt with neither variations in transform spaces (world/parent/local) and/or direction vectors (-z/z/-x/x/-y/y).

paroj
OGRE Team Member
OGRE Team Member
Posts: 2274
Joined: Sun Mar 30, 2014 2:51 pm
x 1239

Re: Camera::LookAt vs SceneNode::LookAt

Post by paroj »

ogreSceneNode->setFixedYawAxis(true); ?

feel free to check the code marked with OGRE_NODELESS_POSITIONING or just disable that setting.

farrer
Halfling
Posts: 69
Joined: Mon Sep 12, 2011 7:35 pm
x 13

Re: Camera::LookAt vs SceneNode::LookAt

Post by farrer »

paroj wrote: Wed Dec 17, 2025 6:30 pm

ogreSceneNode->setFixedYawAxis(true); ?

That done the trick! Thanks!