• Create Account

# Manually computing draw positions...

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Raptisoft  Members   -  Reputation: 147

Like
0Likes
Like

Posted 17 October 2013 - 08:34 AM

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, 17 October 2013 - 08:37 AM.

### #2Zaoshi Kaba  Crossbones+   -  Reputation: 2287

Like
0Likes
Like

Posted 17 October 2013 - 10:11 AM

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

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


### #3Raptisoft  Members   -  Reputation: 147

Like
0Likes
Like

Posted 17 October 2013 - 10:47 AM

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

### #4Brother Bob  Moderators   -  Reputation: 6470

Like
0Likes
Like

Posted 17 October 2013 - 10:52 AM

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.

### #5unbird  Crossbones+   -  Reputation: 3494

Like
0Likes
Like

Posted 17 October 2013 - 01:02 PM

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, 17 October 2013 - 01:03 PM.

### #6Anddos  Members   -  Reputation: 400

Like
0Likes
Like

Posted 18 October 2013 - 06:33 AM

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);

### #7phil_t  Crossbones+   -  Reputation: 1936

Like
0Likes
Like

Posted 18 October 2013 - 12:47 PM

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.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS