about fps camera

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
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

about fps camera

Post by Mirror »

hi. i have noticed that in the fpscamerascenenode, it's plane is always horizontal. is there any way to change this ? I want this because im trying to "walk" on a "planet" but if i go below the equator, i can't rotate the camera down, because it's already more than 90 degrees. In other words, what i want is having the plane of the camera, always perpendicular to the vector camera->getPosition(). can i make this with the fpscamera or i must code a custom one ?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I think you'll have to make your own custom camera, though i would imagine it wouldn't be too much code to change so just copy the code from CCameraFPSSceneNode.cpp in the source folder and make the necessary changes.
Image Image Image
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

I wonder if it would be wiser to rotate the planet instead.
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

shogun wrote:I wonder if it would be wiser to rotate the planet instead.
no, because i want to attach the camera to a player, and wouldn't also want to rotate all existing objects as well
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

If you want to do this, you will have to create your own camera controller.
All camera can use a UPvector. So you define the angle and put the UPvector and the camera will be aligned to it. It will be relatively easy to make that. But the mouse movement are not following the upvector.

A better alternative (as Shogun talked about)would be create a empty node then use it as a parent for the whole scene and rotate it on the direction needed. The camera and player would need NOT be parented to this empty node for this to work.
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

christianclavet wrote:If you want to do this, you will have to create your own camera controller.
All camera can use a UPvector. So you define the angle and put the UPvector and the camera will be aligned to it. It will be relatively easy to make that. But the mouse movement are not following the upvector.

A better alternative (as Shogun talked about)would be create a empty node then use it as a parent for the whole scene and rotate it on the direction needed. The camera and player would need NOT be parented to this empty node for this to work.
wouldn't this approach be very expensive ? imagine thousands of objects needed to be rotated. plus, that if i need a multiplayer game, this is not a good solution i think.

p.s. where can i look about the upvector ? the irrlicht help file doesnt seem to have a reference on this.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You would only be rotating the parent of all the rotatable objects which would not in turn apply rotations to all the children, instead their absolute rotations are calculated based on the rotation of their parent.
Image Image Image
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

All the items will rotate anyway in the camera. So I think it would be about the same. (It would be calculated for change only on the parent and not the childrens (that have their own local coordinate system). It shoulnt be calculated twice.

Unless there some culling algorithm in there that does this (frustum culling).
Last edited by christianclavet on Thu Dec 20, 2007 5:41 am, edited 1 time in total.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

If you're actually writing a game rather than a simple disposable demo, do yourself a favour and forget about the built in cameras, and for that matter the Irrlicht event system. They're only really suitable for demos, and you'll spend more time trying to work around them than you will writing something that's actually suitable for your requirements. IMO.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

thank you for your answers guys
mqrk
Posts: 16
Joined: Mon Dec 10, 2007 5:55 am

Post by mqrk »

I think this has already been covered but I just wanted to clarify that the up-vector is not handled by the fpscamera to suit your needs.

I played around with it a bit and it looks like moving your mouse up rotates the camera in the original "up" direction (what would now be "left" or something).

You might just copy the CCameraFPSSceneNode class and change the Animate function to factor the up-vector into the calculations. I'm not really sure how to do it but I'm pretty sure that's where you start.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

mqrk You are talking about the source of the FPS camera. And it surely cannot be used like that (I know. I had to retake and adapt the code so it can work.) For the UPVector, you are wrong. This is a feature on all cameras (Normal since it was created for the standard camera and that the other camera inherit the STD Camera class.

For example, to reverse the camera view upside down:

Code: Select all

camera->setUpVector(vector3DF(0,-1,0));
This should take your camera view and have it upside down (For Any camera definition you have (FPSCamera, MayaCamera, or STD camera)
You should move the right way, but the mouse rotation will be inverted.

What he has to do is to take the CCamera source as a reference point(or download my current code for the FIRST KING), and do some math so that mouse movements will rotate the camera the right way.

The moving part is accounted for, in the source, it's using the UpVector of the camera for the calcultation (Strafing), it should "strafe" the right way. It's only have to do some calculations of the mouse move increment of the relative rotation of the camera relative to the UPvector. So the relative movement is going the right way.

So you could take my current code for FIRST KING project and take the part of the camera and implement this (Align the upvector of the camera with the relative rotation based on the mouse movement). Or do what we suggested previously. If you are very strong in math, physic and expert at programming, I would recommend the same thing that proposed RogerBorg.

But starting up with IRRlicht could also be good, if you need a prototype fast for a "proof of concept".
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

thanks for your reply christian and mqrk.

my first step was using

Code: Select all

camera->setUpVector(core::vector3df(loc.X, loc.Y, loc.Z));
this assuming that the center is (0,0,0) updates the upvector to be perpendicular to the plane that is tangent with the planet in the intersection point of the line (0,0,0-x,y,z) with the planet.

( or simply put, aligns the upvector with the (0,0,0-x,y,z) vector ).

but as you previously also said i have to tweak the fpscamera code for the mouse movement ( it doesn't work correctly, doesn't update ). i will look also your code ( the first king ) and post in this topic any good results.

@roger, im still on my initial steps though but yes you are right.

i hope my studying maths will help me on this :D
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

i think i have found a workaround about this issue.

from CCameraFPSSceneNode.cpp :

Code: Select all

const f32 MAX_VERTICAL_ANGLE = 88.0f;
if that is changed to some huge value like 3600000.0f then it will solve the problem.

( needs recompile i think )
Post Reply