True car rear view mirror
by Eric Lafrance · in Torque Game Engine · 01/27/2004 (1:26 am) · 18 replies
Okay, let's say I get a transform matrix from a certain camera.
Now, I want to have my new rear-view camera to rotate 180 degrees and mirror the x axis
Another way to do the same thing
Finally, multiply the MirrorXForm with the camera Xform to get the new rear-view camera Xform
Everything works like it should, diffs, objects etc. are perfect. The 2 exeptions are:
1- The terrain's texture is now "below?!?" the terrain. In a way, the terrain doesn't render.
2- The wheels of a wheeled vehicle(doh!) aren't in the right direction, when the mirrored camera is near of the vehicle.
I've seen threads and ressources about a rear-view mirror, but none of them actually do the mirroring effect, they only rotate the camera 180 degrees... maybe because they've encountered the same problems?!?
If I can't get this thing to work, we'll have to offer an "optional external mirror kit" with our game! The user would have to put one (true) mirror on his monitor's corner and another angled mirror on his shoulder that reflects his monitor. lol Oups, that wouldn't work either :-( Sorry it's getting late here ;-p
Any suggestion to help resolve this mystery would be greatly appreciated!
Ohhh and also, I've noticed that ANY mirroring effect will make these problems occur
getControlCameraTransform(0.032, &query->cameraMatrix)
Now, I want to have my new rear-view camera to rotate 180 degrees and mirror the x axis
//Rotate 180 degrees around the z axis MatrixF MirrorXForm(true); F32 angle = M_PI; //180 degres in rad MirrorXForm.setColumn(0, Point3F(mCos(angle), -mSin(angle),0)); MirrorXForm.setColumn(1, Point3F(mSin(angle), mCos(angle),0)); MirrorXForm.setColumn(2, Point3F(0,0,1)); //Mirror the x axis MatrixF MirrorXForm2(true); MirrorXForm2.setColumn(0, Point3F(-1,0,0)); MirrorXForm2.setColumn(1, Point3F(0,1,0)); MirrorXForm2.setColumn(2, Point3F(0,0,1)); //Multiply both Matrices to get only one MirrorXForm.mul(MirrorXForm2);
Another way to do the same thing
//Rotate 180 degrees and mirror the x axis MatrixF MirrorXForm(true); MirrorXForm.setColumn(0, Point3F(1,0,0)); MirrorXForm.setColumn(1, Point3F(0,-1,0)); MirrorXForm.setColumn(2, Point3F(0,0,1));
Finally, multiply the MirrorXForm with the camera Xform to get the new rear-view camera Xform
query->cameraMatrix.mul(MirrorXForm);
Everything works like it should, diffs, objects etc. are perfect. The 2 exeptions are:
1- The terrain's texture is now "below?!?" the terrain. In a way, the terrain doesn't render.
2- The wheels of a wheeled vehicle(doh!) aren't in the right direction, when the mirrored camera is near of the vehicle.
I've seen threads and ressources about a rear-view mirror, but none of them actually do the mirroring effect, they only rotate the camera 180 degrees... maybe because they've encountered the same problems?!?
If I can't get this thing to work, we'll have to offer an "optional external mirror kit" with our game! The user would have to put one (true) mirror on his monitor's corner and another angled mirror on his shoulder that reflects his monitor. lol Oups, that wouldn't work either :-( Sorry it's getting late here ;-p
Any suggestion to help resolve this mystery would be greatly appreciated!
Ohhh and also, I've noticed that ANY mirroring effect will make these problems occur
About the author
#2
(1) F10->New Control->GameTSCtrl
(2) Position and size the view area
(3) Under the properties of the control, change cameraZRot to 180
(4) Click 'Apply'
(5) Presto!
Sorry if this is not what you're looking for. Take it easy.
-Greg
01/27/2004 (11:32 am)
Ok, I'm a rather newbie to Torque so this is probably not what you're looking for/ way off topic. But, I thought I'd post it just in case it helps.(1) F10->New Control->GameTSCtrl
(2) Position and size the view area
(3) Under the properties of the control, change cameraZRot to 180
(4) Click 'Apply'
(5) Presto!
Sorry if this is not what you're looking for. Take it easy.
-Greg
#3
01/27/2004 (3:52 pm)
Lol Greg....mirrored....
#4
@Adam - That could be it. But the terrain is mirrored like it should, just the texture bitmap gets under the terrain?!?
I think it could be related to the upside down terrains from bitmaps problem? I had in mind it had been fixed? I can't find a way to make my mirror work, might also have something to do with the GL commands in my mirror renderWorld(const RectI & updateRect)? Is there any command to "tell" GL to invert the terrain bitmap?!? (I sadly don't know anything about OpenGL).
01/29/2004 (12:55 am)
@Gregory - Yes that does rotate the camera to see behind, but it doesn't do the mirroring effect ;-p Thanks though!@Adam - That could be it. But the terrain is mirrored like it should, just the texture bitmap gets under the terrain?!?
I think it could be related to the upside down terrains from bitmaps problem? I had in mind it had been fixed? I can't find a way to make my mirror work, might also have something to do with the GL commands in my mirror renderWorld(const RectI & updateRect)? Is there any command to "tell" GL to invert the terrain bitmap?!? (I sadly don't know anything about OpenGL).
#5
www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=11168
It's a long thread, and his post of a guiMirrorport is near the middle. It may not address your problem, or do what you want, but if you haven't seen it you should take a looksee.
01/29/2004 (5:39 pm)
Have you looked through the mirror code that Melv may posted in this thread?www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=11168
It's a long thread, and his post of a guiMirrorport is near the middle. It may not address your problem, or do what you want, but if you haven't seen it you should take a looksee.
#6
Because the double mirroring effect returns a non-mirror ;-p (mirror the y and mirror the x means a 180 degree rotation, non-mirrored).
Thanks Martin, could have been!
01/29/2004 (6:21 pm)
@Martin - ehhh, I just realize that's the code I'm using that Gilles had put in ;-p. The way Melv has created the matrixMatrixF MirrorXForm(true); MirrorXForm.setColumn(0, Point3F(-1,0,0)); MirrorXForm.setColumn(1, Point3F(0,-1,0)); //MirrorXForm.setColumn(2, Point3F(0,0,1));returns to the same point of only rotating the camera 180 degrees :-(
Because the double mirroring effect returns a non-mirror ;-p (mirror the y and mirror the x means a 180 degree rotation, non-mirrored).
Thanks Martin, could have been!
#7
But say, Torque supports mirrored surfaces in .dif's (not that I have messed with them) you might dig around in that code.
01/30/2004 (2:07 pm)
Darn, I was hoping that was it, I could use a good mirror....But say, Torque supports mirrored surfaces in .dif's (not that I have messed with them) you might dig around in that code.
#8
01/31/2004 (6:55 am)
I'm just curious, the download demo of the SDK has a mirror in it. Do we have access to the code for that?
#9
01/31/2004 (8:19 am)
Yes, its under engine/interior/mirrorSubObject.cc
#10
02/05/2004 (3:31 am)
I looked at the code of the mirrorSubObject and that thing doesn't work as easily as just multiplying a mirroring matrix ;-p Now, making a GUI out of that seems impossible for me to do :-(. I guess the way I was trying to make the rear-view mirror work is not the right way, unless I'm missing something.
#11
Also, I want to add a different "mirror" viewing forward (not rear) but at a different world location (i.e. same direction, different place). What would be the best way to do that?
Any help would be very much appreciated!
04/09/2006 (2:24 am)
HI, I'm a newbie and I would very much like to integrate the above code in my game. Where do I add it (which cc file) ?Also, I want to add a different "mirror" viewing forward (not rear) but at a different world location (i.e. same direction, different place). What would be the best way to do that?
Any help would be very much appreciated!
#12
04/09/2006 (5:30 am)
This is already in 1.4, from memory it's called GameTSCtrl. You'll find it in the gui editor (F10). Drop it in your playGui and you can rotate the camera in any direction you want, change field of view etc etc.
#13
Actually, the GameTSCtrl only does half of what I need - I also need to change the view location, and not only its rotation. Is this possible?
04/11/2006 (2:22 am)
Thanx Tim.Actually, the GameTSCtrl only does half of what I need - I also need to change the view location, and not only its rotation. Is this possible?
#14
Actually, the GameTSCtrl only does half of what I need - I also need to change the view location, and not only its rotation. Is this possible?
04/11/2006 (2:28 am)
Thanx Tim.Actually, the GameTSCtrl only does half of what I need - I also need to change the view location, and not only its rotation. Is this possible?
#15
I'm not sure what else you need?
If you're wanting to change the location of the camera itself you'd have to modify the car model. I'm guessing the camera goes of the root node, so shifting the location of it within your model should do the trick. You also have access to the vertical offset within the scripted datablock for your vehicle so that gives you another form of control. I'm not exactly sure which node it goes off, something you'll have to look up in the head code.
04/11/2006 (5:38 am)
Well cameraZRot allows you to change the rotation of the camera, so setting it to 180 will give you rear vission and forceFOV allows you to set the zoom. I'm not sure what else you need?
If you're wanting to change the location of the camera itself you'd have to modify the car model. I'm guessing the camera goes of the root node, so shifting the location of it within your model should do the trick. You also have access to the vertical offset within the scripted datablock for your vehicle so that gives you another form of control. I'm not exactly sure which node it goes off, something you'll have to look up in the head code.
#16
In SceneGraph::renderScene(), the scenegraph creates a SceneState object called pBaseState, that is the root state for all rendering. SceneStates have a public lag called mFlipCull. Find a way to set that to true only when rendering your mirror, and everything should render correctly.
You could add a flag to the scenegraph itself (like mMirrorScene) and set it to true when drawing mirrored views, and to false when drawing normal views, then change the pBaseState mFlipCull based on it.
04/11/2006 (10:05 am)
Mirroring the camera transform in any axis will cause all objects to be drawn "inside out", being front-face culled instead of back-face culled, since the normals will end up inverted. You need to tell the sceneGraph to flip the culling before rendering the mirror.In SceneGraph::renderScene(), the scenegraph creates a SceneState object called pBaseState, that is the root state for all rendering. SceneStates have a public lag called mFlipCull. Find a way to set that to true only when rendering your mirror, and everything should render correctly.
You could add a flag to the scenegraph itself (like mMirrorScene) and set it to true when drawing mirrored views, and to false when drawing normal views, then change the pBaseState mFlipCull based on it.
#17
I would like to add another item (possible a small floating robot), which moves together with the player (maybe later I will create separate movement for it), but with a small offset to the left (or right) of him.
Now, I would like to show this item's "viewpoint" on the screen, using a TSCtrl object (or some other object if you reccommend differently). Now, using the standard TSCtrl is not good enough, since it only allows me to rotate the player's view, while what I'm looking for if moving it a bit to the left (or right)
Can this be done by a newbie such as myself? If so, how?
04/29/2006 (3:03 pm)
Thanx for you're help. I think I should clarify myself a bit:I would like to add another item (possible a small floating robot), which moves together with the player (maybe later I will create separate movement for it), but with a small offset to the left (or right) of him.
Now, I would like to show this item's "viewpoint" on the screen, using a TSCtrl object (or some other object if you reccommend differently). Now, using the standard TSCtrl is not good enough, since it only allows me to rotate the player's view, while what I'm looking for if moving it a bit to the left (or right)
Can this be done by a newbie such as myself? If so, how?
#18
Manoel, we have added the following code to void SceneGraph::renderScene, right after SceneState* pBaseState and we are still getting the terrain flipped.
if(mMirrorScene==1)
{
pBaseState->mFlipCull= true;
mMirrorScene=0;
}
else
{
pBaseState->mFlipCull= false;
mMirrorScene=1;
}
I will be grateful if someone could help on this.
07/06/2007 (3:57 pm)
We are trying to add a true vehicle mirror. We are getting the objects to draw as they should on a mirror but still having some trouble with the terrain.Manoel, we have added the following code to void SceneGraph::renderScene, right after SceneState* pBaseState and we are still getting the terrain flipped.
if(mMirrorScene==1)
{
pBaseState->mFlipCull= true;
mMirrorScene=0;
}
else
{
pBaseState->mFlipCull= false;
mMirrorScene=1;
}
I will be grateful if someone could help on this.
Torque Owner Adam Beaumont