Sign in to follow this  
BLiTZWiNG

[MDX] Vector3.Project doesn't work. [Edited]

Recommended Posts

After Jack told me it was the right way to go (and I had suspected so), I started trying to implement it, never having done it before but thinking I understood how it worked. Well, I obviously don't. I see that I'm not the first person to have a problem with it, but it seems that most others are trying to mouse pick, where as I'm trying project a model's location onto the 2D screen. When I do it, the resultant vector appears to be identical to the actualy x,y,z of the model, which is of course, not what I'm looking for. Up close my model will go off the screen in about 67 or so units, but the name tag is still only 67 units off the center. I say off the center because I'm adding the screen_width / 2 to the resultant vector.x. Would really appreciate an insight into what i may be doing wrong. - Screen res: 800x600. - Projection: 1.0 - 1000.0f; 1.33 aspect; 90d FoV;
name_bar.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortDepthBackToFront | SpriteFlags.SortTexture);
LinkedListNode<GameClient> nbclient = game.clients.First;
while (nbclient != null)
{
    Vector3 pos = new Vector3((float) (nbclient.Value.x), (float) (nbclient.Value.y), (float) (nbclient.Value.z));
    pos.Unproject(Graphics.device.Viewport, Graphics.device.Transform.Projection, Graphics.device.Transform.View, Matrix.Identity); //Graphics.device.Transform.World);
    int sx = (int) pos.X + screen_width;
    int sy = (int) (screen_height - pos.Y);
			
    dxfont.DrawText(name_bar, nbclient.Value.name, sx, sy, Color.Yellow);
    nbclient = nbclient.Next;
}
name_bar.End();



[Edited by - BLiTZWiNG on April 16, 2006 8:11:26 PM]

Share this post


Link to post
Share on other sites
If you want the screen space location of an object, and have it's world location, you'd want to Project it. This is as opposed to having the screen space location (of a click) and wanting the world position of where it happened, which requires an Unproject.

The two operations are exactly the opposite of eachother.

Hope this helps.

Share this post


Link to post
Share on other sites
hmmm, this must be MDX1.1, since the syntax is a bit different.

I think it should be:
pos = pos.Project(...);

This method was made static in MDX2, so I'm assuming it returns the result, and doesn't alter the vector.

Hope this helps.

Share this post


Link to post
Share on other sites
Yes it is MDX 1.1

But the function definition returns void. Only the static method of Vector3 returns a Vector3, but that of course returns the same thing as calling Project on the vector itself :(

I have checked my references are 1.1.4322 for DirectX, Direct3D & Direct3DX.

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