Sign in to follow this  

Multiple projectings in a scene graph

Recommended Posts

Although I am writing this with regards to XNA, this is more of a generalized question about using multiple projections for varying objects on my scene graph. My game engine is structured as a tree, and the tree can contain a mix of models / sprites; with sprites being dynamically textured quads. My vertices are setup in local space and transformed into world space prior to rendering. As it stands, most objects are childed to the root scene ( Matrix.Identity ) so everyone's coordinates are more or less in world space... So now to my question :) How do you align the orthographic projection of the sprite so that it is always pixel perfect in the render but mantain its depth value in the scene ? My 3D objects are using the following projection: ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, _graphicsDevice.Viewport.AspectRatio, 0.01f, 10000); ViewMatrix = Matrix.CreateLookAt(Vector3.Backward, Vector3.Forward, Vector3.Up); and if I use this projection for my sprites, I get a less than accurate floating billboard (expected). In my sprite class I try to use an orthographic projection: renderer.BasicEffect.World = renderer.WorldMatrix; renderer.BasicEffect.View = renderer.ViewMatrix; renderer.BasicEffect.Projection = Matrix.CreateOrthographic(1920, 1080, 1, 10000); //renderer.ProjectionMatrix; and the billboards are rendered perfectly but then do not appear behind or in front of the model accordingly. Idealing, a 3d object at z = 0 and 2 sprites at z = 1000 and z =-1000 would wield a render of SPRITE - MODEL - SPRITE.... What I am seeing right now is a SPRITE - SPRITE - MODEL My vertices are set every frame and are straight foward: Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f); Vector2 textureUpperRight = new Vector2(1.0f, 0.0f); Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f); Vector2 textureLowerRight = new Vector2(1.0f, 1.0f); Vertices[0].Position = new Vector3(0, -Height, 0); Vertices[0].TextureCoordinate = textureLowerLeft; Vertices[1].Position = new Vector3(0, 0, 0); Vertices[1].TextureCoordinate = textureUpperLeft; Vertices[2].Position = new Vector3(Width, -Height, 0); Vertices[2].TextureCoordinate = textureLowerRight; Vertices[3].Position = new Vector3(Width, 0, 0); Vertices[3].TextureCoordinate = textureUpperRight; Vertices[0].Position = Vector3.Transform(Vertices[0].Position, LocalToWorld); Vertices[1].Position = Vector3.Transform(Vertices[1].Position, LocalToWorld); Vertices[2].Position = Vector3.Transform(Vertices[2].Position, LocalToWorld); Vertices[3].Position = Vector3.Transform(Vertices[3].Position, LocalToWorld); Any ideas would be a big help. An alternative method might be, how do I create the verts off a perspective matrix such that they are aligned on the screen orthagonally

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this