Jump to content
  • Advertisement
Sign in to follow this  
Jurugi

Need help with 3d-2d

This topic is 3186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

Are you sure the point is on-screen?

The docs of D3DXVec3TransformCoord look better, I'd try that... It's unclear to me from the docs exactly what D3DXVec3Project does...

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!