Gary Harper

I am working with some vector graphics that consists only of an ordered set of 2D points in XY space. The order of points determines the path that a line is drawn through them.

I would like to be able to rotate the points in 3D so that I can flip and rotate the vector picture. After performing a rotate of some degree I want to be able to write the new set of points to an array or file or whatever. I also want to be able to display my vector image in a Window.

So I have two questions:

1) Is there anything in DirectX that will help me rotate some XY points in a 3D space and then give me the resulting XY coordinates

2) What do I use to draw these points to the Window using DirectX In the past I have used normal Windows drawing methods but they are slow.

Detailed answers are not needed at this point. If you can point me to some DirectX classes that would help or some samples that would be a great start.

Thanks,

Gary



Re: Game Technologies: Graphics Rotating points in 3D

BLANC Guillaume

1) Is there anything in DirectX that will help me rotate some XY points in a 3D space and then give me the resulting XY coordinates

You could use
D3DXVec2Transform or D3DXVec3Transform depending on if your expecting a transformed z result. The equivalent functions for arrays also exists (D3DXVec2TransformArray) to transform your entire set using a single call.

2) What do I use to draw these points to the Window using DirectX In the past I have used normal Windows drawing methods but they are slow.

Simply follow the 3 first Direct3D tutorials and you'll be able to render anything you want : points, lines, ...

I hope it helps...






Re: Game Technologies: Graphics Rotating points in 3D

Gary Harper

Thanks for the lead. I will look into those and see how far I can get.

Gary





Re: Game Technologies: Graphics Rotating points in 3D

Gary Harper

OK. I didn't get very far. I see those transform functions require a transform matrix as a parameter but I don't remember much about matrices from college. :) Could you help me out with some examples Lets say I want to rotate around X by 10 degrees, what matrix would I use What about for Y and Z What if I wanted to move it 10 steps to the left

Thanks again

Gary





Re: Game Technologies: Graphics Rotating points in 3D

saliksyed

I'm not sure if this is helpful specifically to DirectX but I can give you a general overview on transforming points in 3d, and on rendering 3d points on to a 2d plane.

In 3d space you have the 3 standard basis vectors e1 e2 and e3, one is pointing in positive x dir (length 1) the other in y, the next in z.
So we have:
e1 = (1,0,0) e2 = (0,1,0) and e3= (0,0,1)

Now if you want to rotate a vector by n degrees on some axis.
simply rotate e1 , e2, and e3 by n degrees on that axis , the new values for e1, e2 and e3 will be the columns of your transform matrix.

For example if we rotate e1(the x Axis) 90 degrees about the z Axis in the negative x direction
the new vector will obviously be pointing towards the y Axis
so the transformed vector is : (0 1 0)
now rotate e2 and we get (-1, 0, 0)
rotating e3 about the z axis gives no change
so t(e3) = (0,0,1)

from this we make our transform matrix:
0 -1 0
1 0 0
0 0 1
that's all there is to it,
if you use angles other than 90 you might need to figure out the components of the vector using simple trig but other than that it's easy


Projecting points on to a plane is a bit tricky to explain

To find the Y coordinate:
You calculate the distance of the object (point) from you in the xy plane:
dist = sqrt((myX-objX)^2 + (myY-objY)^2)
you can then find the Y coordinate using this inequality:
(ObjZ-MyZ)/dist = (screenY) / focalLength
You choose an arbitrary focal Length (this will determine how skewed the image is!)

Finding X coordinate is done in much the same way:
(ObjY-MyY)/(ObjX-MyX) = otherFocalLength/(screenX)

MyX, Y, Z are your camera coordinates, you might have to play around with the camera position and focalLengths to get it to look perfect.

All you are really doing is using properties of similar triangles

I dunno if that helps you at all but it's good to know how things work, and transform matrices are certainly very important






Re: Game Technologies: Graphics Rotating points in 3D

BLANC Guillaume

Now you've got math basis, you can have a look to the D3DX math function in the sdk documentation. See for exemple D3DXMatrixRotationZ that will create a rotation matrix an an angle in radian around Y axis. That's all you need, isn't it Then, you can compose matrix transformations using D3DXMatrixMultiply and soon you'll be matrix ready!

Have a try with those functions and I'm sure you'll get your results soon.

If you need some more math, see The Matrix and Quaternions FAQ which is always helpful.






Re: Game Technologies: Graphics Rotating points in 3D

tkdhanglide

Saliksyed,

Please excuse my ignorance but would you mind running through an example using cartesian coords so I can visualize the solution

I'm just trying to understand the process/math so if you could skip any D3D function calls I would appreciate it :-)

How would I rotate a point that lies at -say 2,4,6 about another point say 10,12,14 (on an axis parallel to the X axis) by 25 degrees

Thanks

Scott

 

 





Re: Game Technologies: Graphics Rotating points in 3D


Re: Game Technologies: Graphics Rotating points in 3D

windozer_

Scott,

So to elaborate on an explanation of how to do the scenario that you layed out, here is my 2 cents:

You should keep in mind that anytime you are rotating you pay attention to the order of mulitiplication of matrices as this affects which origin you are rotating about (ie. model space or world space). With that being said, after you have built your object and are ready to rotate it about a known vertex you would do this:

// setup global variables
D3DXMATRIX mtxPitch;

// setup point to rotate around
D3DXVECTOR3 rotationVectorAxis(10.0f, 0.0f, 0.0f);

// rotate this amount
float RotationPitch = D3DXToRadian(2.5f);

// build rotation matrix
D3DXMatrixRotationAxis(&mtxPitch, &rotationVectorAxis, RotationPitch);

// apply rotation to object's matrix (world)
D3DXMatrixMultiply(&object.mtxWorld, &object.mtxWorld, &mtxPitch);

To explain more of what is going on is to understand how rotations with matrices works:
(where O = radians of rotation)

X Axis Rotation:

1 0 0
0 cos(O) sin(O) New Y Coord = Old Y Coord x cos(O) - Old Z Coord x sin(O)
0 -sin(O) cos(O) New Z Coord = Old Y Coord x sin(O) + Old Z Coord x cos(O)

Y Axis Rotation:

cos(O) 0 -sin(O) New X Coord = Old X Coord x cos(O) + Old Z Coord x sin(O)
0 1 0
sin(O) 0 cos(O) New Z Coord = Old X Coord x -sin(O) + Old Z Coord x cos(O)

Z Axis Rotation

cos(O) sin(O) 0 New X Coord = Old X Coord x cos(O) - Old Y Coord x sin(O)
-sin(O) cos(O) 0 New Y Coord = Old X Coord x sin(O) + Old Y Coord x cos(O)
0 0 1

Hope this helps!

Cale





Re: Game Technologies: Graphics Rotating points in 3D

abcdefgqwerty2

I remember reading that without hardware support 2d rotations are too slow for real time and so directx7 didnt have a bitmap rotation function.