Sign in to follow this  

Manually computing draw positions...

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.



Edited by Raptisoft

Share this post

Link to post
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 this post

Link to post
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 this post

Link to post
Share on other sites
D3DXMATRIX Projection;

Share this post

Link to post
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.

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