Having trouble keeping track of the screen coordinates of an object (d3d)

Started by
2 comments, last by Staffan E 18 years, 10 months ago
Just started learning direct3D and i was trying to make a 2D asteroids clone. Ive managed to create a triangle (which is the ship) on screen and use DirectInput to rotate it and move it about the screen no problem. Ive put in the model coordinates of the triangle and transformed it to world coords' to display it, but im not sure exactly where it is at any given time. I'm working on the collision detection and am trying to have a 'sun' in the middle of the screen creating gravity constantly pull the ship towards it. But i'm stuck as to how to do it without knowing exactly where the ship is on the screen. anyone give me some good advice on what i'm missing. Thanks.
Advertisement
well you have to have a variable(variables x, y) that you increment when it moves

.....:P
doh. ok i was overstating the problem i guess, that answers one part of it (something which i honestly never thought of doing o.O)

But,
How do i find the initial coordinates??

Ive got my local vertices:
x y
-2, 1 //top
-3, -1 //bl
-1, -1 //br

Im not sure how to transform these to any specific coordinates in the world. My code blits it to what looks like the center of the screen. The tutorials i'm learning from dont seem concerned with exactly where it initially blits it to, just how to move it afterwards.
How could i make it so, say, the bottom left corner of the triangle is put at the bottom left corner of the screen (0,0) or (0,screen_height).

Sorry for the stupid question, i'm just starting out thats my excuse :)

I did a bit of 2d graphics work in java and i had to write all my own matrices for transformations.
It's not a stupid question. 3D math isn't all that easy and can be a real pain sometimes.

If your project is supposed to be in 2D and you're using DX, then you don't have to worry about 3D transformations that much. Have a look at the ID3DXSprite interface. It lets you draw 2D images from textures to screen space positions, making positioning on screen somewhat easier than when using Local->World->View transforms. Check it out.

Otherwise if you want to be hardcore there is a D3DX function called D3DXVec3Unproject( ) which performs backward transformation on a given vector and with some given transformation matrices.

If you want one of your vertices on a specific position then set pV to that vector and set pViewport, pProjection, pView, pWorld to the viewport and transformation matrices matching your scene. The vector you get in return will represent the position that would be located at your desired screen position when transformed.

Stay sharp.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker

This topic is closed to new replies.

Advertisement