开发者

Perspective/orthographic projection conversion in XNA?

I'm drawing some geometry in orthographic projection in XNA for a sidescroller type game. What I want to do is to render background geometry in perspective projection.

However I obviously need the background geometry to 'line up' with the foreground, i.e. if in perspective I set the position of a 3D model to 300, 30 then in the orthographic projection it lines up to 300, 30.

Is there a way I can accomplish this? I've been looking into world to screen proje开发者_StackOverflow社区ction but not sure if I'm on the right track.

Thanks for any help!


Heh, here lie monsters ... this is easier said than done for sure :-) Yes, you are on the right track with world/screen projection. What you need to do is pick a "Z" plane that you will render all of your 2d perspective projections onto. Then what you do is covert any given point that you're interested in on that "Z" plane to screen coordinates, and render your orthographic projection at that spot.


Joel is right, it would be ideal if you could combine 2d and 3d. 2d acts as orthographic view, and 3d for perspective view. Use multiple 2d sprites for 2d rendering inplace of orthographic view. With respect to geometry you best choice will be, using the helper functions of the Matrix structure.. something like,

Matrix view = Matrix.CreatePerspective(.......)

and other similar static helper functions....

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix_members.aspx

Additionally to transform the models by scale, rotation, translation, can be achieved by the matrix structure itself.

Matrix oldWorld = Matrix.CreateWorld(...);

// something happens ; next update

Matrix scaleMat = Matrix.CreateScale(...);
Matrix rotXMat = Matrix.CreateRotationX(...);
Matrix rotYMat = Matrix.CreateRotationY(...);
Matrix rotZMat = Matrix.CreateRotationZ(...);
Matrix translationMat = Matrix.CreateTranslation(...);

Matrix newWorldMat = scaleMat*rotXMat*rotYMat*rotZMat*translationMat*oldWorldMat;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜