• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
giugio

normal and wind order

6 posts in this topic

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 conterclowise triangle with and A,B,C indexes?
thanks.
0

Share this post


Link to post
Share on other sites
Normally if you already have triangle normal you do not need to do any other back-face/front face testing - if normal is towards you, triangle is front-faceing and vice versa.

Now, if you want to know the winding order of triangle ABC, you have to calculate the cross product AB X AC. If this is oriented towards you (can be checked with dot product), triangle if CCW.

1

Share this post


Link to post
Share on other sites
[quote name='Lauris Kaplinski' timestamp='1316281925' post='4862857']
Normally if you already have triangle normal you do not need to do any other back-face/front face testing - if normal is towards you, triangle is front-faceing and vice versa.

Now, if you want to know the winding order of triangle ABC, you have to calculate the cross product AB X AC. If this is oriented towards you (can be checked with dot product), triangle if CCW.


[/quote]

thanks Lauris, but my project is an importer and i can't have my position. but
I have the normal of the plane of the 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 ?

thanks.

by
0

Share this post


Link to post
Share on other sites
[quote name='Lauris Kaplinski' timestamp='1316281925' post='4862857']
if normal is towards you, triangle is front-faceing and vice versa.
Now, if you want to know the winding order of triangle ABC, you have to calculate the cross product AB X AC. If this is oriented towards you (can be checked with dot product), triangle if CCW.
[/quote]
Thanks Lauris , but whats mean "towards you" if i don't have a camera position?

my problem is that if i try to calculate back/front face in the shader with this simple formula:

float4 Dir = dot(Normal,CameraModelPosition);
if(Dir >0.0)

and works 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 the camera position?
thanks.

ps.
i see the gl_frontFacing formula at:
http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FrontFacing.xml

but i'm not understand how i can coding it in c++.
0

Share this post


Link to post
Share on other sites
Hello!

I am not sure I understand your problem completely.

I.e. what does front-facing mean for you? The order of triangle is not a property of triangle itself (i.e. a function of its vertices), but property of triangle and some direction (i.e. a function of the vertices of triangle AND the direction vector). Thus it is always relative to that direction. Usually you have some reason to test the order of triangle and and thus the direction is determined by the semantic meaning of test.

Commonly we want to test the order (CW or CCW) of triangles relative to camera direction, because we want to optimize and not render backwards facing triangles. As the order is relative to direction, using any other axis will not give you the same results as using camera direction.

Testing triangle order against arbitrary axis usually does not have any real meaning.

If you have triangle normal, you can also test the order of triangle against that normal. If you know, that normal is always pointing outside from your mesh, it detects whether triangle is CW or CCW relative to the mesh surface. Although I think that all normal modeling programs keep triangles always in fixed order relative to their normals.

0

Share this post


Link to post
Share on other sites
[quote name='Lauris Kaplinski' timestamp='1316774297' post='4865102']
Hello!
If you have triangle normal, you can also test the order of triangle against that normal. If you know, that normal is always pointing outside from your mesh, it detects whether triangle is CW or CCW relative to the mesh surface. Although I think that all normal modeling programs keep triangles always in fixed order relative to their normals.
[/quote]

very thanks Lauris, yes , the normal must always pointing outside my mesh, if not it's a backface, what that i'm searching .
but how i can test if the normal point outside the mesh or in the mesh?

thanks
0

Share this post


Link to post
Share on other sites
[quote name='giugio' timestamp='1316775583' post='4865111']
very thanks Lauris, yes , the normal must always pointing outside my mesh, if not it's a backface, what that i'm searching .
but how i can test if the normal point outside the mesh or in the mesh?
[/quote]
So you are not sure, whether it is the case with your model? I reiterate, that most well-formed models exported from 3D programs always have normals pointing outside.

As of determining the normal direction, I think the only foolproof way is to "trace" the normal (as ray directed to your normal). I.e starting from the plane of your triangle (excluding this triangle itself) count all triangles that intersect with ray. If the number is odd, normal is pointing inside mesh (as it has to "escape" from the mesh through at least one triangle. if the number is even (or 0) it is pointing outwards.

It expects, that mesh is closed and well-formed (i.e. all edges are shared by exactly 2 triangles and there are no coincident triangles).

This has a still potential of nasty numerical errors unfortunately. To be sure, you may want to repeat tracings few times.

Once you have determined the proper direction of normal for at least one triangle, you can "walk" over surface to determine the directions of other normals - i.e.

[list=1][*]Say you have triangle ABC with normal N and you determine, that this normal is pointing outwards[*]Determine the order of given triangle relative to normal - let's say it is CCW[*]Thus (AB)X(AC) dot N > 0[*]Now find another triangle sharing angle with ABC, say it is DAC[*]Individual edges shared by adjacent triangles have to be in opposite winding order, so[*]The edge "AC" would be "wrong" order on ABC - thus it is in "right" order on adjacent DAC[*]Thus DAC is with the same order as ABS - i.e. also CCW[*]Thus the outwards pointing normal of DAC is DAxDC[*]Say you have another triangle EBC[*]As the edge "BC" would be in right order on ABC, it is in "wrong" order on EBC[*]Thus EBC is CW[*]Thus the outwards pointing normal of EBC would be -1 * EBXEC[/list]It is a bit messy, but I hope it helps

I.e. if you now that all normals are pointing outwards, it is easy to determine the winding order of all triangles (relative to mesh surface). And vice versa - if you know the winding order of traingles, it is easy to calculate outwards pointing normals. But if you do not know either, you have to start from somewhere - i.e. determine the direction of at least one normal.

Also if the mesh is not well-formed there probably is not generic algorithm, as the outside and inside of mesh are not properly defined.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0