Sign in to follow this  
Jurugi

Need help with 3d-2d

Recommended Posts

First off, Hello. I feel bad that this first post must be a request for help, but I'm really stuck and this forum looks like it's really experienced. I'm having trouble with rendering objects in 3d, or getting screen coordinates of objects that are in 3d. Basically I have hooked a game's D3D (direct 3d 8 interface, not 9), and I want to be able to see text or a sprite over certain object's positions. I have reversed the structs for the XYZ (Vector3) positions of the objects, but now I am unable to use them. I'm able to manipulate the objects in terms of changing their textures, changing how they are rendered, etc.. However, I have no idea how to get the 2D screen position from the 3d origin of the object.. My WTS function is like this, and I've tried it in EndScene where I draw my text, as well as in DrawIndexedPrimitive thinking that perhaps it is called too late in EndScene. D3DXMATRIX viewmat, projectionmat, worldmat; m_pD3Ddev->GetTransform( D3DTS_VIEW, &viewmat ); m_pD3Ddev->GetTransform( D3DTS_PROJECTION, &projectionmat ); m_pD3Ddev->GetTransform( D3DTS_WORLD, &worldmat ); m_pD3Ddev->GetViewport( &vp ); D3DXVec3Project( &vecScreen, &vec3Position, &vp, &projectionmat, &viewmat, &worldmat ); vecScreen returns values like 290424.0000, of course way off balance.. is there another way? Moving away from that.. I am trying to simply render a 3d point-sprite in the origin of the objects, and disable the Z-Buffer so that I can tell where they are by having a circle sprite around them, or something like that. However, in D3D8 I've only found bits and pieces of information to render sprites. Most of them are still just help requests from people who can't get point-sprites to work (in D3D9, which is supposedly even less work). Example files are filled with more clutter than actual rendering code of the sprites, from what I've seen. I already have my devices set up, I only need to set the coordinates, flags, and render the point sprite. I suppose either of these solutions would be great, thanks for reading.

Share this post


Link to post
Share on other sites
Your D3DXVec3Project function looks correct, depending, of course, on the values you're using for vec3Position.
Quote:
I have reversed the structs for the XYZ (Vector3) positions of the objects

What do you mean by "reversed?"

Share this post


Link to post
Share on other sites
I mean that they are in memory of the game, and I had to 'reverse-engineer' or debug the game to find a static pointer to the float in memory. Just leave it as, they are floats that look something like: X: 6834.0959353 Y: 5093.05050 Z: 120.590393

edit: lol you posted like a second before i posted. Thanks I'll try that func right now and get back to you

Share this post


Link to post
Share on other sites
You should also unproject 0,0,0 back into world space as a sanity check so you have an idea that there isn't any other biasing or hierarchical coordinate spaces going on

If you move the camera close to the object you're interested in, unprojecting 0,0,0 should get you close to X: 6834.0959353 Y: 5093.05050 Z: 120.590393... If it doesn't, then there's other trickery going on

And I bet there is, because using floats when you're 7 kilometers away from the origin gets you some nice crappy precision loss

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