Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Convert plane normal to triangle data?

This topic is 5467 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose I have a plane normal. How do I define a triangle within a plane that is defined by its normal? Greetz&thanks, Vich

Share this post

Link to post
Share on other sites
Well, if you just want an arbitrary triangle, you could find 3 intersections with the plain using arbitrary rays I suppose... Perhaps an explanation of what you want to do with these would help.

Share this post

Link to post
Share on other sites
One way you could do it (maybe not the easiest/best way), is to take the plane normal, and find two vectors that are parallel with the surface, then multiply them appropriately to get your four coordinates.

In other words, take the cross product of the normal and the up vector, then take the cross product of this result and the plane equation. That should give you two vectors that are parallel to the surface and perpendicular to each other.

Share this post

Link to post
Share on other sites
Thanks drslush!
Your suggestion worked!

I did it this way:

upVector = Normalize(upVector);
CVector3 cross1 = Normalize(Cross(normal, upV));
CVector3 cross2 = Normalize(Cross(normal, cross2));
CVector3 cross3 = Normalize(Invert(cross1));
CVector3 cross4 = Normalize(Invert(cross2));
cross1 = cross1;
cross2 = cross2;

cross1-4 are the vectors that define the 4 points that I needed

Share this post

Link to post
Share on other sites
I''m having a simular problem, I''m trying to make a bullet hole on a plane.

I have the plane defined by 3 verts, and I know the normal of the plane, and I know the 2 vectors making up the plane, but I just cant figure out the rest :-(
Now what Do i have to multiply or cross product in order to find the equation of my plane?

Share this post

Link to post
Share on other sites
say you have triangle T(V0, V1, V2), where V0, V1, V2 are listed anti-clockwise (right-handed coordinate system). So the normal, pointing up from the triangle would be

N = (V1-V0) x (V2-V1)

l, the length of the normal is

l = sqrt(N.N)

also, the area of the triangle a = l / 2

you normalise N by doing N /= l

The equation of the plane is then

N . P = d, where P is any point on the plane

So, P could be V0, V1, V2

so your plane is defined by

(N, d), where N = |(V1-V0)x(V2-V1)|, and d = N * V0

say you fire a bullet using a ray (O, L, l)

O is the start position of the ray, L is the direction of the ray, l is the length of the ray

a point P is on the ray if P = O + L.t (0.0f <= t <= l). (Eq. 1)

also P is on the plane (N, d) if N . P = d (Eq. 2)

replace P in (Eq. 2) by P in (Eq. 1)

=> N . (O + L.t) = d
=> t = (d - O.N) / (L.N)

Now, you have t, you can find the point of intersection between the ray and the plane (P = O + L.t).

you have the normal of the triangle and the point of intersection, you should be able to apply a quad at that position to draw your bullet hole.

say you have a base quad with vertices V0, V1, V2, V3, where

V0 = (-w/2, 0, -h/2) T0(0, 0)
V1 = ( w/2, 0, -h/2) T1(1, 0)
V2 = ( w/2, 0, h/2) T2(1, 1)
V3 = (-w/2, 0, h/2) T3(0, 1)

where w and h are the size of the decal, and T0...T3 are the texture coordinates of the decal.

To decal the quad, you need a function like

Matrix CreateRotation(const Vector& InNormal, const Vector& OutNormal);

where InNormal would be the normal of your base quad (in this case (0, 1, 0)), and OutNoprmal, the normal of the triangle you want to put the decal on (in this case N).

The function CreateRotation() would create a rotation matrix to orientate the quad (V0, V1, V2, V3) on the plane with normal N

Then all you have to do is

Matrix Rotation = CreateReorientationMatrix(Vector(0, 1, 0), N);

float sizew, sizeh;
int decalTextureIndex;

CVertices W0(Vector(-sizew/2, 0, -sizeh/2), CTextureCoord(0, 0));
CVertices W1(Vector( sizew/2, 0, -sizew/2), CTextureCoord(1, 0));
CVertices W2(Vector( sizew/2, 0, sizew/2), CTextureCoord(1, 1));
CVertices W3(Vector(-sizew/2, 0, sizew/2), CTextureCoord(0, 1));

W0.Pos *= Rotation;
W1.Pos *= Rotation;
W2.Pos *= Rotation;
W3.Pos *= Rotation;

W0.Pos += P;
W1.Pos += P;
W2.Pos += P;
W3.Pos += P;

DrawQuad(W0, W1, W2, W3, decalTextureIndex);

for the reorientation matrix, I am too tired. tomorrow

Share this post

Link to post
Share on other sites
Wow, thats a bunch man, I totally get it. Now I have nice pretty bullet holes in my map. Now they are diamond shaped instead of squares, but I''ll figure out why that is happening another day, but thanks once again man!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!