[SOLVED]View transformation help for tilting the camera

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

[SOLVED]View transformation help for tilting the camera

Post by christianclavet »

Hi, Found this function in the SDK.

Code: Select all

virtual void irr::video::IVideoDriver::setTransform  (  E_TRANSFORMATION_STATE  state,  
  const core::matrix4 &  mat 
 )  [pure virtual] 
I would like to rotate the view on the local Z axis 5-45 degrees. But I need to do this on the view transform because:

- Don't want to affect the UPvector if possible
- The camera is rotating itseft (X,Y)

Can I use this to rotate using a matrix the view?
If possible do you have any "code" suggestion to make it so?
Last edited by christianclavet on Tue Jan 15, 2008 10:59 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Please check the patch by mandrav from the SF patch tracker. There's a camera view matrix patch contained. Maybe this is what you're looking for. In case you find it useful and you think that it could be also useful for others we could consider adding it to the core library, too.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi. Hybrid.

I've looked at the code and it this it's exactly what I need.

From the docs and source of the patch. The view matrix cannot be modified once defined. This will useful for me, for the new camera rigs I'm developping (Source is available and I'll make a small demo source showing the rigs once I have all the needed functions)

On another subject (somewhat related to this), is the camera target coordinates are local to the camera or are global to the entire scene? (I parent the STD camera to empty scene nodes to create the rigs) Had strange behavior when rotating a empty node (theses are used as pivots)...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Hey Christian, what problems were you having with my solution to this?

I would have thought it would work fine, if you need to help on it then send me a little demo app with your camera class included and i'll try and implement it for you :)
Image Image Image
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

"- Don't want to affect the UPvector if possible "

This sounds like you're doing something wrong. Are you using the camera scene node as the player's representation? If so: bad.

I suggest you have a scene node (empty if you dont want to draw anything) that represents the player, and have the camera scene node separate from that, but update its position to stay with the player's scene node.

In this way, you can modify the camera scene node to rotate however you wish, independent from the player's facing; which seems to be what you are trying to do.

Always remember to keep your ideas (and data) separate: player != camera, they're just similar in position.
a screen cap is worth 0x100000 DWORDS
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

"On another subject (somewhat related to this), is the camera target coordinates are local to the camera or are global to the entire scene? "

They are in global coordinates, IIRC.
a screen cap is worth 0x100000 DWORDS
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Ok. Thanks for the info about the camera target coordinate position.

For the test application it's on the SVN site. First-king. [EDIT] Also updated the binary and source from the download page at sourceforge.

I would like to keep the camera upvector intact. Would surely want to have the camera look upside down or tilt the view.

I think I could store the base UpVector somewhere and then do the manipulation over it.

It's will be easy to TILT the camera upvector if the local axis match the global axis, but they dont. I have to account for the rotation of the node (camera) then rotate a LOCAL Z axis.

[EDIT] Hi! Solved the problem!!! :D
This was easy, but I coulnt figure it out. :oops:

Here is the solution:
1. Define a standard UPVECTOR
2. Rotate this vector on the Z Axis for the desired TILT rotation
3. Rotate this vector again but on the Y axis of the current camera Y rotation.

Here what it look like in code:

Code: Select all

          vector3df upv = vector3df(0,1,0);
          upv.rotateXYBy(RelativeRotation.Z,vector3df(0,0,0));
          upv.rotateXZBy(-RelativeRotation.Y,vector3df(0,0,0));
          cam->setUpVector(upv);
Remark: For an unknown reason, I had to reverse the Y rotation because the tilt angle was inverted when the cam was on rotated in certain angle. Inversing the Y rotation value solved the problem.

Using that like this, I'm not sure if the base upvector was not (0,1,0), it would work again (Would like to permit to "walk" on ceiling or wall, or still have the option to do so.)
Post Reply