View Full Version : Math - Algebra - counterclockwise
05-19-2001, 02:35 AM
how can I now (thro some formula) the order of vertex to be sure I'm render them
I mean :
v1= - 15,0,0
v1= - 15,0,0
is there any formula that can tell me form which vertex to start and from which to and
so I can be sure about counterclockwise ????
05-19-2001, 11:26 AM
You can't do this without also determining where the camera is, and which way its facing.
This would be no simple problem and the maths involved would be very complicated
The simplest solution could be to just turn off backface cull, that if your problem is certain triangles not being drawn.
05-19-2001, 02:30 PM
I you are
1)only dealing with 3 points
2)are dealing with more than 3 points AND you know they are either clockwise or counterclockwise (that is, they arent jumbled up in a random order)
you can take the 3 point (if there are more than 3, pick any 3 sequential points). We will call these v1, v2, and v3 in order. Now calculate the surface normal which is:
Normal = (v1-v2) X (v3-v2)
note that X above is the cross product.
Next, take the camera view direction vector (lets call this "View"). Now calculate the dot product of the View and Normal vectors. If the dot product is negative, the points are in counterclockwise order. If it is positive, they are in clockwise order (note: I might have my signs mixed up, so it might be the other way around). If you get a dot product of 0, you are looking at the triangle/poly edge on, so clockwise/counterclockwise really doesnt make much sense.
Actually thinking about it further, it might be more correct to take the normalized direction from the camera to one of the 3 points instead of the view direction.
Thinking even further, I guess you have to make sure that your 3 verticies arent co-linear, so things get a little more complex. Luckily, just take the dot product of (v1-v2)and (v3-v2). If you get 1 or -1,they are colinear, so you have to choose 3 differnt points (or your triangle isnt actually a triangle).
I probably missed something else too, but give this a shot.
05-19-2001, 03:06 PM
99 out of 100 people asking this question do so because they haven't yet thought through what they're trying to do. This just shouldn't be a problem in any working, implemented program. Either you're rendering modeled data you read from disk, in which case the data is supposed to be correct and you shouldn't spend time fixing it, OR you're generating the data yourself, in which case you should get your generation algorithm right rather than trying to compensate after-the-fact. In the cases where neither of these is true, it's probably the case that your data is supposed to be double-sided in the first place, and you should turn off back-face culling.
Hint: whatever abstraction you are using for a camera probably has an up vector, a forward vector and a right vector. These are very useful if you're trying to generate something (like a billboard) which faces the camera.
jwatte, one of the reasons this is a useful thing to know how to do, is that you will want to verify that the data you're getting is really built this way. Obviously it's supposed to be correct, but it not always is. But I agree that there's usually not a really good reason to put such a test in your main rendering path.
05-20-2001, 12:20 AM
I dont want to put this calc in my main rendering path , but i do want do now if my data file support the CCW and if not to change the order from let sat V1 V2 V3
to V2 ,V1 ,V3 ... if this required for suport
So , is it any formula to determine CCW support ? http://www.opengl.org/discussion_boards/ubb/confused.gif
05-20-2001, 01:42 AM
The orientation is CCW if polygon's signed area is positive.
To compute signed area use :
2*A = N*sum( v[i]xv[i+1] ))
N - polygon normal
v[i] - polygon vertex i
* - dot product
x - cross product
05-20-2001, 02:55 AM
2*A ??? for what ??? and i do want the orientation befor i calc the normal ,
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.