#### Archived

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

# Simple problem!! Help plz! ( normals)

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

## Recommended Posts

Hi guys, I've looked aroudn the web and I'm having problems finding any decent understandable tutorial for my little problem, also tried searching but again, having trouble understanding. Basically all I need to do, is calculate whether three vertices are in a clockwise, or anti-clockwise rotation starting from the first point. I'm building a 3D design program so each face has 3 vertices (at the moment beacuse I'm at a very early stage!), and when I build the mesh, depending on how the mesh is created, sometimes the x/y/z coordinates get mixed up, inverting it, so before the normals are calculated, I must convert them into a clockwise order. Thanks for any help. [edited by - Striken on February 28, 2004 6:25:12 PM]

##### Share on other sites
hmmm,

This isn''t really a simple problem. If the winding order of your verticies varies from triangle to triangle and you are dealing with a polygon-soup situation then you really don''t have any way of knowing which way a triangle is supposed to face. It''s a real pickle.

How exactly does the winding order get reversed in the first place? Maybe you should just prevent that from happening.

##### Share on other sites
That''s very reassuring as i''ve been busting my brain trying to figure it out! (I thought it would be simple!)

Basically when I create a mesh, I drag with the cursor open a 2D box in one of the viewports, which creates the two components from this viewport in an orthographic perspective, that generate the two components of the mesh. After that, the third dimension is calculated as a factor of the two existing components (for example front viewport show x and y components, z component is (x + y) / 2;

The centre of the world is 0,0,0, view stretching -2 to +2 (orthographic).

Basically the problem arises when I drag a box, and the dimensions are such that the mesh becomes inverted, I''m not exactly sure how that happens, but the mesh is calculated from a starting x position, to a current x position, and so forth.

for example: point 0 ALWAYS represents the top left front corner on a mesh:

tempMesh.pt[0].x = start.x;
tempMesh.pt[0].y = start.y;
tempMesh.pt[0].z = start.z;

point 6 ALWAYS represents bottom right back corner of a mesh

tempMesh.pt[6].x = current.x;
tempMesh.pt[6].y = current.y;
tempMesh.pt[6].z = current.z;

However, it is easy to drag the mesh out in such the fashion that these vertices don''t actually represent the position they should (and therefore vertex order is anti clockwise).

So I suppose the best thing to do is make sure the coordinates coming in do specify how it''s being made in the first place?

Well thanks nonoptimalrobot, unless there are any other suggestions I''ll have to give this some serious thought.

##### Share on other sites
just to make sure I understand...

so, you drag the mouse in a viewport, and it generates a cube by extruding the rectangle drawn in the viewport by the mouse drag.

if you drag from right to left, or bottom to top, then there is a chance the cube will be inverted, yes.

you have to make sure that the segments of the dragged rectangle are listed also anti-clockwise in the viewport, or you can limit the drag only into one direction (left to right AND top to bottom only).

it''s the same if you start drawing rooms in a 2D viewport (a la Doom). make sure the walls of the room are listed anti-clockwise in the viewport, or they will be facing the other way round.

when drawing segments in the viewport, you can also render a normal from the segment, to tell which way the wall will be facing (normal should be N = Vector((E0.y - E1.y), (E1.x - E0.x)). And alternatively, if it is the wrong direction, have an icon to pick and flip edges (swap vertices E0 and E1 of the segment).

##### Share on other sites
Thanks for your help! Yep that was the way to do it, catch the inverted mesh before it was made.

if(((current.x > start.x) && (current.y < start.y)) || ((start.x > current.x) && (start.y < current.y) ))
current.z = -abs(current.x + current.y) / 2;
else
current.z = abs( current.x + current.y ) / 2;

that was basically how i fixed it for the front viewport.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633758
• Total Posts
3013713
×