Rotating Camera

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Rotating Camera

Post by Jedive »

I have created a camera scene node with ISceneManager::addCameraSceneNode(). This camera is irresponsive to ICameraSceneNode::setRotation(), because of the ICameraSceneNode::setTarget() method. I mean, the target of the camera is set to 0,0,0, so when I move the camera around, it will be rotated so it looks at the position 0,0,0. If I use setRotate() to rotate it, it has no effect, as the camera is rotated automatically again to face the target position.

I think that the setTarget() method should update the camera's rotation when it is called, but not updated automatically each frame. I mean, if I want a camera that is constantly looking at a certain position, I'll use setTarget() each frame for that camera. But if I want a camera which I want to turn around, I want to be able to rotate it with setRotation().
Irish_pilot

I'm having a similar problem...

Post by Irish_pilot »

I'm doing a flight sim...Cameras don't look at any thing, they point where you tell them the plane is aiming in full 3d. I can't get any rotation to bank the camera...and really want it to stay where I put it relitive to world coordinates...the flight dynamics will decide where that is...
What do I do? I've started this questing in the beginners forum too.
Thanks for any work around!
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

Oh nobody knows this? :(
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

If you want to rotate the camera, then you need to rotate the target vector of the camera around the camera's position.

Hmm, what you're saying is that setRotation should modify the target of the camera. Maybe that'll do.
Image
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

The target value of the camera is the position you want it to look at, right?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

yes
Image
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

It's incredible that the camera cannot be rotated using degrees like in ALL the other 3D engines I have seen :(
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

it's pretty easy to implement, why don't you take a look at how to implement, it's the beauty of open-source!
Image
devil20
Posts: 14
Joined: Wed Jan 19, 2005 2:28 pm
Location: UK

Me too

Post by devil20 »

Hi
I am not well experinced in engine But i also found this . If i am right
in CameraSceneNode::OnPrender() function that is calcutating every frame
for camera .

I want ask to experinced programmers to look at code of CameraSceneNode::OnPrender function has sum calcaulation of Upvector and so that calculating 2 time .Normalize() and crossprouduct in one frame
for camera evenif camera not updated (not changed) . So i thing in 3d math .Normalize using sqrt math function that'll be big bottlenek for engine because render call lot times at that time sqrt will calcuated .

So guys just check code in my opnion for optimization :)

If am i wrong please tell me :)

devil20
Guest

Post by Guest »

If so, that would be a bit wasteful when you can just cache the result, but remember: there's not likely to be more than one camera anyway.
sqrt isn't THAT slow.
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

Well, I have found a quick&dirty way which works really fine to rotate the camera using euler angles instead of defining a target position.

When you create a camera, also create an EmptySceneNode which is a child of the camera, and position it at vector3df(0,0,1) (so it is always in front of the camera).

When you want to rotate the camera, use camera->setRotation(). I said that this has no effect, because an ICameraSceneNode has a target position where the camera is always aiming at. But if each frame you do:

Code: Select all

camera->setTarget(child->getAbsolutePosition());
Then you will update the target value to be at the front of the camera (as "child" is the empty scene node you created which is attached to the camera and in the front of it).

Probably there are other ways but this one works perfectly.
Guest

Post by Guest »

Nothing dirty about that - it's quite elegant because you let Irr handle the calculations and Irr has to know how to do it in the first place.

However, you don't incorporate roll - for that you'd need to supply an up-vector.
You can probably extend it by attaching another node at 0,1,0 and then subtracting the camera position from that node's absolute position to get the correct upvector.
Post Reply