Creating in-game interfaces?

nikhilhs

Newcomer
Joined
Feb 22, 2004
Messages
22
I have a game where ships fly around, input and everything working... Now I need to figure out how to draw the user interface. Is there a way to draw it without manually finding where the vertices need to be so that they're right in front of the camera?

I'm going to include things such as radar, other ships, messages, etc.

I've attached an example of what I'm trying to do. I've taken this from Freelancer screen shots.

I'm talking about things like the health bars in the center, #weapons left, options at the top right, etc.

One idea would be somehow switching to ortho view, and then drawing the gui, but I'm not sure if it's possible to draw the main game in perspective view, switch to ortho, give it some new vertices, and then have it draw both.

Any ideas?

Thanks.

-Nick
 

Attachments

What you need is to use transformed vertices. Or just use Sprite class as it does that for you in the background.
 
nikhilhs said:
One idea would be somehow switching to ortho view, and then drawing the gui, but I'm not sure if it's possible to draw the main game in perspective view, switch to ortho, give it some new vertices, and then have it draw both.

Yes, this works fine and is a good way to go.
 
Unfortunately, it doesn't seem to be working. I've added this code between begin scene and end scene. All the 3d graphics still work fine. It's just not drawing anything that I specify after I switch to ortho.

Code:
device.SetTransform(TransformType.Projection, Matrix.OrthoLH(1.0f, 1.0f, 0.0f, 1.0f));
device.VertexFormat = CustomVertex.PositionNormalColored.Format;

CustomVertex.PositionNormalColored[] radarB = new CustomVertex.PositionNormalColored[2];
radarB[0].SetPosition(new Vector3(0.25f, 0.25f, 0.01f));
radarB[0].Color = System.Drawing.Color.Black.ToArgb();
radarB[0].SetNormal(new Vector3(0.0f, 0.0f, -1.0f));
radarB[1].SetPosition(new Vector3(0.40f, 0.25f, 0.01f));
radarB[1].Color = System.Drawing.Color.Black.ToArgb();
radarB[1].SetNormal(new Vector3(0.0f, 0.0f, -1.0f));
device.DrawUserPrimitives(PrimitiveType.LineStrip, 1, radarB);
 
Back
Top