# Manually computing draw positions...

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

## Recommended Posts

Hi all,

I've set up world/view/projection matrixes for a game.  In another part of the program, where I don't have easy access to the information used to set up the matrixes, I want to manually transform some points to make them float over the 3D objects.

I tried to do it this way:

1. Get the world matrix from DirectX

2. Get the view matrix from DirectX

3. Get the projeciton matrix from DirectX

4. Multiply those together

5. Use those matrixes to transform a point

When I do this... well, plenty goes wrong.  For one thing, rotations seem to be flipped horizontally, and it also doesn't scale correctly to the screen's resolution.

Is there a specific way to manually transform a point to match the matrixes that have already been sent to DirectX?

Short version: I want to manually transform an xyz position as if it went through the pipeline.

Thanks!

Edited by Raptisoft

##### Share on other sites

How did your step 5 look like? Should be equivalent to:

point = point * world;
point = point * view;
point = point * proj;
point = point / point.w;


##### Share on other sites

I had everything except your operation with point.w ... my points have xyz... what's w?  Far plane?  Viewport?

##### Share on other sites

It is the fourth component of your vector. If you want to do the operations manually, you need to work with four-dimensional homogeneous vectors; 3-dimensional vectors with only X, Y and Z-components are not enough.

##### Share on other sites
6. Apply the viewport transformation e.g. (left, top, width, height defining the viewport):
  screenX = (1.0f + v.X) * 0.5f * width + left;
screenY = (1.0f - v.Y) * 0.5f * height + top;

Usually, graphics math libraries already have such a function, called Project, e.g. D3DXVec3Project or XMVector3Project Edited by unbird

##### Share on other sites
D3DVIEWPORT9 v9;
D3DXMATRIX World;
D3DXMATRIX View;
D3DXMATRIX Projection;
D3DXMatrixIdentity(&World);
g_pDevice->GetViewport(&v9);
g_pDevice->GetTransform(D3DTS_VIEW,&View);
g_pDevice->GetTransform(D3DTS_PROJECTION,&Projection);
D3DXVECTOR3 Vec3Dst2D;
D3DXVec3Project(&Vec3Dst2D,&SrcVec3,&v9,&Projection,&View,&World);

##### Share on other sites

As an aside, using the DirectX device as a mechanism to get a matrix from one portion of your program to another seems like poor design (and prone to breakage). Consider refactoring your code so that required information is explicitly given to the place where it's needed.

• 13
• 18
• 29
• 11
• 27