Page 1 of 1

Rotate ICameraSceneNode with setRotation()?

Posted: Fri May 05, 2006 10:51 am
by AussieMike
Hi Guys,

Is there anyway I can rotate my ICameraSceneNode (not fps) using setRotation() ??

Currently it doesn't work because it always points to the "target" which doesn't seem to move with setRotation(). I have looked through the APIs but cant find anything to help.

I think I need to tell the camera to always face 'straight ahead' (on the rotation angle) or ignore the 'target' position.

Thanks,

Posted: Fri May 05, 2006 11:38 am
by $L!M
HI
You just need to move your target.
U need to use distance to target, cos and sin.
But this method is not so simple like setRotation.

Posted: Sat May 06, 2006 1:59 am
by AussieMike
Ok,

I dont know much trig w/ cos and sin but this is what I came up with...

Code: Select all

     ICameraSceneNode* node = (ICameraSceneNode*)
     NewtonBodyGetUserData(body);

     if(node)
     {
          node->setPosition(mat.getTranslation());	// set position
          node->setRotation(mat.getRotationDegrees());	// and rotation

          vector3df target;
          target.X = cos(node->getRotation().X) * 10;
          node->setTarget(target);
     }
Is this correct?
Atm - my camera jolts around when I try and move the mouse (vibrates in a 'nonsense-able' way). I am not sure if it is this snippet that is causing that or if its somewhere else in my code?

Either way - I would like comments please!

Thanks,

Posted: Sat May 06, 2006 11:30 am
by $L!M
You need first of all to convert your "node->getRotation().X" angle from degrees to radians in this way: node->getRotation().X/(180/3.1416);

Code: Select all

target.X=cos(node->getRotation().Y/(180/3.1416))*10;
target.Z=sin(node->getRotation().Y/(180/3.1416))*10;
target.Y=0;
node->setTarget(target+node->getPosition());
It seems to me to be workable :). But I'm not sure.

Posted: Tue May 09, 2006 8:22 am
by AussieMike
Thanks LM,

I have re-learnt some trigonometry, tried a few things, I think this works for left-right rotation, still not very smooth but I think that is due to another area of my code.

Code: Select all

vector3df target;
target.Z=cos(node->getRotation().X/(180/3.1416))*10;
target.X=sin(node->getRotation().X/(180/3.1416))*10;
I would like to add up and down rotation now...
I am thinking this should work...

Code: Select all

target.Y=sin(node->getRotation().Y/(180/3.1416))*10;
Except, I dont know how to modify the Z (depth) so as the target rises and falls, it also comes towards me and away from me... without screwing up what I have already done (left -right rotation).

Thanks for any advice!

Posted: Tue May 09, 2006 10:57 am
by stef_
Everytime someone asks of rotating the camera, there is a new complicated way.
Instead is so easy:

Code: Select all

ICameraSceneNode *camera;
camera = smgr->addCameraSceneNodeFPS (0, 100, 500);
camera->setInputReceiverEnabled (false);

then:
camera->setPosition (irr::core::vector3df (posx, posy, posz));
camera->setRotation (irr::core::vector3df (rotx, roty,rotz)); 
I already posted it (http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=12961)

Bye

Posted: Thu May 11, 2006 3:41 am
by AussieMike
Thanks stef_,

Although, I haven't got your code working yet...

As far as I 'knew' smgr->addCameraSceneNodeFPS() will still create a camera that 'looks at' the target. So an FPS camera with input disabled would be the same as a non-FPS camera? ... and setRotation won't work... am I mistaken?, you claim 'it works really well' in your other post... Please explain!

Thanks,

Posted: Thu May 11, 2006 1:03 pm
by stef_
an FPS camera with input disabled is NOT the same as a non-FPS camera

smgr->addCameraSceneNodeFPS()
+
camera->setInputReceiverEnabled (false);

creates a camera with setTarget() behavior completely disabled and setRotation() working.

setRotation doesn't work only with addCameraSceneNode().

Bye