# Direction in DirectX

4 replies to this topic

### #1Anddos

Valued Member

• Members
• 177 posts

Posted 18 January 2010 - 04:08 AM

Ok so i have a triangle rendering thats in the world like

http://img85.imagesh...3561/tridir.jpg

what i want todo is translate an object in the direction the face is facing , heres the code i already have

D3DXMatrixRotationY(&Rot,Amount);
d3ddev->SetTransform(D3DTS_WORLD,&Rot);
D3DXVec3TransformCoord(&TriVert1Out,&TriVert1,&Rot);
D3DXVec3TransformCoord(&TriVert2Out,&TriVert2,&Rot);
D3DXVec3TransformCoord(&TriVert3Out,&TriVert3,&Rot);

D3DXVECTOR3 Sub1 = TriVert1Out - TriVert2Out;
D3DXVECTOR3 Sub2 = TriVert1Out - TriVert3Out;
D3DXVECTOR3 Cross;
D3DXVec3Cross(&Cross,&Sub1,&Sub2);
D3DXVec3Normalize(&Cross,&Cross);

RECT textbox;
SetRect(&textbox, 0, 0, 640, 480);

sprintf(Buffer,"%s %f %f %f\n","The triangle's direction is",Cross.x,Cross.y,Cross.z);

dxfont->DrawTextA(NULL,
Buffer,
strlen(Buffer),
&textbox,
NULL,
D3DCOLOR_ARGB(255, 255, 0, 0));



so next i want to say use D3DXMatrixTranslation on a box and make the box fire outwards from the direction the face is facing, i am not sure how to make the box keep moving in that diagonal path thats the direction etc...
can anyone help?

### #2rouncer

Senior Member

• Members
• 2718 posts

Posted 18 January 2010 - 05:35 AM

Im not sure what your problem is, youve written it all right so far.
Just find the triangles normal, Which it looks like your code is doing, normalize it.

then go D3DXMatrixTranslation(&tra, centre_of_tri.x+normal_of_tri.x*time, centre_of_tri.y+normal_of_tri.y*time, centre_of_tri.z+normal_of_tri.z*time);

Increment time by say 0.01f every cycle and it should shoot out of the triangle normal from the centre of the triangle.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #3Anddos

Valued Member

• Members
• 177 posts

Posted 18 January 2010 - 06:13 AM

Thanks alot exactly what i wanted

### #4Anddos

Valued Member

• Members
• 177 posts

Posted 01 February 2010 - 08:16 PM

Another Question..

Can you do this to find the direction the camera is looking?

### #5Nerd_Skywalker

Valued Member

• Members
• 215 posts

Posted 01 February 2010 - 10:34 PM

I am not even close to a 3D programmer yet, but i would say it could likely be adapted to (almost) anything.