To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cad.devOpen lugnet.cad.dev in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / Development / 3052
3051  |  3053
Special: 
[DAT] (requires LDraw-compatible viewer)
Subject: 
Clipping / CCW / CW / INVERT
Newsgroups: 
lugnet.cad.dev
Date: 
Wed, 6 Oct 1999 18:15:40 GMT
Reply-To: 
Rui.Martins@link&spamless&.pt
Viewed: 
422 times
  
First, let me apologise, if you get this message twice.
It seams that the old e-Mail address (L-CAD@LISTSERV.UH.EDU)
does not work completelly. Because I got the message back, but couldn't
see it in www.lugnet.com/cad/dev

note: i am subscribed in the old server, by e-mail.

-- Forwarded Message --------------------------------------------------

I guys,

I haven't posted here for a long while, but after seeing this long
discussion about this mail title, I had to participate again.

Bear with me, because this is a long mail !

This problem appeared, because we needed to have faster renderers.
One way to do this is to not render what does not need to be rendered.

So if a solid object is Opaque, then from any view point there are some
faces that are invisible, because they are facing away from the viewer.

From this we now know that "Opaque solids" can have some faces "Clipped"
and that transparent object (solid or not) CAN'T have any faces clipped.

Now, about the problem of marking files has CW or CCW, you have been
missing or confusing something IMHO.
The fact that the file has been checked for it's CW and CCW-ness
and the fact that this or that polygon (quad/triangle) is defined in CW or
CCW order, is beeing confused.

What I suggest is this.
tag each file that was checked with a comment line like this:

0 WINDING CHECKED

or whatever name is decided to be better (that is not the issue here),
so that in the future, we (humans), not the computer, knkow that this
file was checked (for parsers this is just a comment).


ORDER, WINDING and CW/CCW
-------------------------
One other thing that is also beeing confused is the correct order of the
points defining a polygon (Quad/Triangle)

Remember this:
the same Quad can be represented in several correct ways (actually 8),
but I will use only 2 relevant to explain.
imagine a quad defined by 4 points (P1,P2,P3,P4)

for example:
P1---P2
|     |
P4---P3

facing you (the viewer)

it can be defined as:
P4 P3 P2 P1 using CCW WINDING

it can be defined as:
P1 P2 P3 P4 using CW WINDING

the order of points is exactly the same (P1, P2, P3, P4), we only go from
left to right or from right to left, we can even start at the middle and
loop to the other side, until we have 4 points (example P2, P1, P4, P3,
using CW WINDING), this allows for the total number of combinations beeing
8.
OK here you have the 8 possible combinations
CW WINDING
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3

CCW WINDING
4 3 2 1
3 2 1 4
2 1 4 3
1 4 3 2

Assume you have a closed line with marks on it, you start on one, go in
one of the 2 possible directions, until you reach the same mark again
(which is not included twice).

Experiment (you can assign numbers to them)
o---o 1---2
|   | |   |
o---o 4---3

(the lego piece builders may find this ofensive, but bare with me, it will
be worth the effort)

So the order (NOT CW or CCW, witch is the WINDING) is always the same,
after correcting the bow tie problem, of course.


CLIPPING, CCW and CW
--------------------
Taking has a good example the rules guiding the OpenGL standard, each of
these TAGS, define states of processing/drawing.

when CLIPPING is ENABLED
- the GL driver CLIPS the polygons which fail to fall in the current
   WINDING state, this is:
- if it's [ CCW ], only polygons that are CCW after beeing project
  to the screen get drawn.
- if it's [  CW ], only polygons that are  CW after beeing project
  to the screen get drawn.

when CCW is ENABLED (the default)
- the GL driver defines WINDING as beeing CCW, to be used when CLIPPING
   is enabled.

when CW is ENABLED
- the GL driver defines WINDING as beeing CW, to be used when CLIPPING
   is enabled.


Now to map this in LCAD:
- each unchecked file would be marked with CLIPPING DISABLED or OFF (which
  makes this the obvious choice for default, no need to be in the file).

- after a CCW tag, all polygons are considered with a CCW WINDING, but
  this only applyes if CLIPPING is ENABLED or ON

- after a  CW tag, all polygons are considered with a  CW WINDING, but
  this only applys if CLIPPING is ENABLED or ON

- These tags should be local to the file

- CCW should be the default, since angles are positive in CCW direction

- CLIPPING must be off by default


To resume this mess, an example file:
-------------------------------------
0 WINDING CHECKED (this is just for us humans, but could be used by
0 one of those auto correcting tools to see if the file is already
0 winding correct)

0 the following primitives are always drawn
0 some primitives (quads triangles lines)

0 CLIPPING ON

0 assuming CCW by default, only CCW polygons are drawn
0 some primitives (quads triangles lines)

0 CLIPPING OFF

0 the following primitives are always drawn AGAIN
0 some primitives (quads triangles lines)

0 CW

0 Only changes the WINDING STATE (locally, for this file only)
0 the following primitives are STILL always drawn (no CLIPPING)
0 some primitives (quads triangles lines)

0 CLIPPING ON

0 The WINDING state is currently CW so, only CW polygons are drawn
0 some primitives (quads triangles lines)


About the stair case quads
--------------------------
For Quads used has front and back:

Correct the problem, by defining N subparts of the same quad (as much as
needed) until each of the subparts winding can be defined. This probably
must be done by hand.

OR

In the simple case, just disable CLIPPING, before the problematic quad and
enable it again after. this way the quad is drawn as a two sided quad.

You should keep in mind, the ideia of a flag (not a LEGO flag, but a real
flag), it is thin, an must be represented in both sides (front and back),
so there are cases in which this is needed, just disable clipping
(because thi is not a solid, there is no inside or outside, and because
this quad is required to be represented in both situations).


About the INVERT tag
--------------------
To know if the file should be inverted, we could look if the determinant
is negative or not (Someone already said that).

Why would we use a tag to inform the parser of something that he can find
out?

Obvious, to SPEED THINGS UP.

if we use this tag as a LABEL, informing the parser, the result of the
determinant (NOT the exact result, only if it should invert or not). the
parser will not have to calculate the determinant.

if you have this
0 INVERT ON
or simply
0 INVERT

the parser would assume that in the next reference the matrix determinate
is (for example) ( -1 ), so it should be inverted.

if you have this
0 INVERT OFF
or simply
0 NOINVERT

the parser would assume that in the next reference the matrix determinate
is (for example) ( +1 ), so it should NOT be inverted.

by invert I mean:
INVERT RELATIVE to the FILE CURRENTLY beeing PARSED

The parser has to keep track of the invert state, because if one file
inverts a reference to a file that already has an inverted reference to
another file, this should be accounted for.

I propose that this flag scope is only valid until the next file
reference, where it is used, after that (in this file, the one with the
reference to another) it is disabled.

Example:
0 INVERT ON

0 some polygons are possible here

0 a file reference [here]
0 now the INVERT SCOPE ended

0 some more polygons


0 INVERT OFF

0 some polygons are possible here

0 a file reference [here]
0 now the INVERT SCOPE ended


---
The use of this tag will only SPEED THINGS UP, it's not a requirement!


I hope this will clear things up and Possible give some new guide lines !

Any comments, suggestions or errors just reply ?


Rui Martins



Message has 2 Replies:
  Re: Clipping / CCW / CW / INVERT
 
Lots of good stuff in your post, Rui! (...) (Side note: there are not actually any solids in LDraw. Only lines and polygons). (...) Actually, since LDraw doesn't do shading, transparent surfaces *can* be clipped. Only edges, the top-most solid (...) (25 years ago, 7-Oct-99, to lugnet.cad.dev)
  Re: Clipping / CCW / CW / INVERT
 
On Wed, 6 Oct 1999 18:15:40 GMT, Rui Martins <Rui.Martins@link.pt> wrote: Follow-up note: the more I look at this, the more I like using WINDING / CLIPPING instead of FACE. For reasons listed by Rui, for more flexibility, for the ability to enable (...) (25 years ago, 8-Oct-99, to lugnet.cad.dev)

18 Messages in This Thread:






Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR