Rotate ICameraSceneNode with setRotation()?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
AussieMike
Posts: 10
Joined: Fri May 05, 2006 10:38 am
Location: Australia

Rotate ICameraSceneNode with setRotation()?

Post 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,
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Post 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.
AussieMike
Posts: 10
Joined: Fri May 05, 2006 10:38 am
Location: Australia

Post 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,
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Post 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.
AussieMike
Posts: 10
Joined: Fri May 05, 2006 10:38 am
Location: Australia

Post 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!
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post 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
AussieMike
Posts: 10
Joined: Fri May 05, 2006 10:38 am
Location: Australia

Post 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,
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post 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
Post Reply