0
103 Jan 18, 2010 at 04:08

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

http://img85.imageshack.us/img85/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?

#### 4 Replies

0
103 Jan 18, 2010 at 05:35

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.

0
103 Jan 18, 2010 at 06:13

Thanks alot exactly what i wanted

0
103 Feb 01, 2010 at 20:16

Another Question..

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

0
101 Feb 01, 2010 at 22:34

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