View Full Version : triangle backface or frontface

giuseppe500

09-17-2011, 09:07 AM

Hello.

I have a triangle and his normal.

The triangle stores the wind order of vertexes for create it A,B,C.

Is possible to calculate if the triangle is backface triangle or a frontface triangle respect to a default conterclockwise normal?

Is sufficent to do a dot product with this default normal and test if is > 0?

thanks.

ZbuffeR

09-17-2011, 11:44 AM

If you have wind order, no need to use normal to determine if it is front facing or not (this what OpenGL does).

If you want to use the normal only, why not, but this will not give the same results as OpenGL.

Can you give some more info about what you want to do ?

_arts_

09-18-2011, 02:04 AM

If you have wind order, no need to use normal to determine if it is front facing or not (this what OpenGL does).

Can you elaborate ? I always thought that normals were used, ie do the cross product of 2 edges and compare the result with a dot product with a camera vector.

ZbuffeR

09-18-2011, 04:46 AM

In OpenGL, normals are something which is specified, not computed.

So "do the cross product of 2 edges and compare the result with a dot product with a camera vector" is correct.

But the "normal" part is completely irrelevant on the GL side :

http://www.opengl.org/sdk/docs/man/xhtml/glFrontFace.xml

From what you write, you seem to tie the normal to the crossproduct of edges, so there should not be a difference. Just mentioning it to be precise about what GL does, depending on the context you use it may or may not be important :)

giuseppe500

09-22-2011, 04:54 AM

My project is an importer.

then i haven't camera position but

I have the normal of the plane of each triangle.

I have also the cartesian axes of the model.

Is possible do a dot product of the normal vector with one of the axis that compose the matrix of cartesian axis?

the problem is that there are 3 axes in the cartesian axis , with what axis i must do the dot product of the normal?

if the dot product of normal with the correct axes is < 0 i think that is a backface.

have you any advice ?

how i can resolve withowt camera?

thanks.

Dan Bartlett

09-22-2011, 05:21 AM

You could calculate the normal of the triangle from the 3 vertices given, then dot product this calculated normal with the normal you have been given. If the resulting dot product is positive, then the vertices are counter-clockwise (I think, might need to check this), if the result is negative, then they are in the opposite order and need to be reversed.

// for triangle given by p0, p1, p2 + normal

calculated_normal = VectorCrossProduct(p1-p0, p2-p0);

reverse_order_needed = VectorDotProduct(normal, calculated_normal) > 0;

if (reverse_order_needed)

{

// swap p0 + p2

}

giuseppe500

09-23-2011, 02:17 AM

my problem is that if the back/front face is calculated in the shader with this simple formula:

float4 Dir = dot(Normal,CameraModelPosition);

if(Dir >0.0)

work fine .

The problem is that this is a dinamic calculation relative to the position of the camera, i can do this in a "static" calculation without camera position?

i see the frontfacing formula at:

http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FrontFacing.xml

but i'm not understand how i can translate it to code.

thanks.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.