Orthographic perspective
by Ivan Alduan · in Torque X 2D · 12/14/2008 (8:56 am) · 6 replies
I'm figuring out how to make an orthographic perspective view of the scene,
I look around code and API and I found ISceneCamera, Frustum, ...
anyone knows where finally is defined the projection matrix?
Another thing I'm managing to do is projecting a 3D point to the 2D screen to put some GUIs based on scene objects positions.
If anyone knows something to help me save some time... other way I will put some ideas here when I do this things.
Thanks!
I look around code and API and I found ISceneCamera, Frustum, ...
anyone knows where finally is defined the projection matrix?
Another thing I'm managing to do is projecting a 3D point to the 2D screen to put some GUIs based on scene objects positions.
If anyone knows something to help me save some time... other way I will put some ideas here when I do this things.
Thanks!
About the author
#2
It's the robust way I think. If someone want more detailed information I can write it.
Our project is growing fast, I will put some screenshots or videos soon.
12/17/2008 (5:18 pm)
And the second thing is also done :), basically I do in code what the clasic GPU pipeline will done, World to View, View to Perspective, Perspective to ScreenSpace.It's the robust way I think. If someone want more detailed information I can write it.
Our project is growing fast, I will put some screenshots or videos soon.
#3
Do you mind sharing how you did the World to View, View to Perspective, Perspective to ScreenSpace?
I'm looking to achieve the same effect you are going for.
02/11/2009 (10:08 pm)
Hey Ivan,Do you mind sharing how you did the World to View, View to Perspective, Perspective to ScreenSpace?
I'm looking to achieve the same effect you are going for.
#4
// project to screen coordinates
Vector4 viewPosition = new Vector4(crosshairPosition - _camera.Position, 1);
Vector4 screenPosition = Vector4.Transform(viewPosition, _sceneGraph.Projection);
screenPosition = screenPosition / screenPosition.W;
Vector2 _crosshair.Position = new Vector2(screenPosition.X * _midWidth + _midWidth, -screenPosition.Y * _midHeight + _midHeight);
The hard trick was that you need to obtain from some place the actual Projection matrix (BaseSceneGraph.SceneRenderState.Projection) but SceneRenderState was protected, so I inherit from BaseSceneGraph and I create my own with a property to access this matrix;
(_midWidth, _midHeight are the screen sizes half)
Ivan.
02/11/2009 (10:58 pm)
Some like this (crosshairPosition is my 3D point to project):// project to screen coordinates
Vector4 viewPosition = new Vector4(crosshairPosition - _camera.Position, 1);
Vector4 screenPosition = Vector4.Transform(viewPosition, _sceneGraph.Projection);
screenPosition = screenPosition / screenPosition.W;
Vector2 _crosshair.Position = new Vector2(screenPosition.X * _midWidth + _midWidth, -screenPosition.Y * _midHeight + _midHeight);
The hard trick was that you need to obtain from some place the actual Projection matrix (BaseSceneGraph.SceneRenderState.Projection) but SceneRenderState was protected, so I inherit from BaseSceneGraph and I create my own with a property to access this matrix;
(_midWidth, _midHeight are the screen sizes half)
Ivan.
#5
You will have to do a coordinates transform (Translation + Rotation) to change to camera view.
Ivan.
02/11/2009 (11:11 pm)
Something I forget, my camera is always looking Y+ (our game is something like a Smashbrosh clone, aka 2.5D). So I can obtain viewPosition that way.You will have to do a coordinates transform (Translation + Rotation) to change to camera view.
Ivan.
#6
I had no idea about the SceneRenderState, you're a life saver. I modified your algorithm to suit my camera and all is working well. If you want to check it out, I posted my solution here:
www.garagegames.com/community/forums/viewthread/84895/1#comment-586411
Best of luck with your game!
02/12/2009 (9:51 am)
Thanks a lot Ivan!I had no idea about the SceneRenderState, you're a life saver. I modified your algorithm to suit my camera and all is working well. If you want to check it out, I posted my solution here:
www.garagegames.com/community/forums/viewthread/84895/1#comment-586411
Best of luck with your game!
Torque Owner Ivan Alduan
the results aren't what I have suposed for my game, but I have upload the classes for anyone who wants orthographic view, They are a sceneGraph with _SetupProjection(..) changed, and a Camera with new necessary properties to the sceneGraph.
www.megaupload.com/?d=Z51EN5EQ
If there is some place to upload code, tell me and I change the links that are in megaupload provisionally.