ReactOS 0.4.15-dev-7842-g558ab78
normal.c File Reference
#include "gluos.h"
#include "tess.h"
Include dependency graph for normal.c:

Go to the source code of this file.

Macros

#define TRUE   1
 
#define FALSE   0
 
#define Dot(u, v)   (u[0]*v[0] + u[1]*v[1] + u[2]*v[2])
 
#define ABS(x)   ((x) < 0 ? -(x) : (x))
 
#define S_UNIT_X   1.0
 
#define S_UNIT_Y   0.0
 

Functions

static int LongAxis (GLdouble v[3])
 
static void ComputeNormal (GLUtesselator *tess, GLdouble norm[3])
 
static void CheckOrientation (GLUtesselator *tess)
 
void __gl_projectPolygon (GLUtesselator *tess)
 

Macro Definition Documentation

◆ ABS

#define ABS (   x)    ((x) < 0 ? -(x) : (x))

Definition at line 65 of file normal.c.

◆ Dot

#define Dot (   u,
  v 
)    (u[0]*v[0] + u[1]*v[1] + u[2]*v[2])

Definition at line 49 of file normal.c.

◆ FALSE

#define FALSE   0

Definition at line 46 of file normal.c.

◆ S_UNIT_X

#define S_UNIT_X   1.0

Definition at line 190 of file normal.c.

◆ S_UNIT_Y

#define S_UNIT_Y   0.0

Definition at line 191 of file normal.c.

◆ TRUE

#define TRUE   1

Definition at line 43 of file normal.c.

Function Documentation

◆ __gl_projectPolygon()

void __gl_projectPolygon ( GLUtesselator tess)

Definition at line 198 of file normal.c.

199{
200 GLUvertex *v, *vHead = &tess->mesh->vHead;
201 GLdouble norm[3];
202 GLdouble *sUnit, *tUnit;
203 int i, computedNormal = FALSE;
204
205 norm[0] = tess->normal[0];
206 norm[1] = tess->normal[1];
207 norm[2] = tess->normal[2];
208 if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) {
209 ComputeNormal( tess, norm );
210 computedNormal = TRUE;
211 }
212 sUnit = tess->sUnit;
213 tUnit = tess->tUnit;
214 i = LongAxis( norm );
215
216#if defined(FOR_TRITE_TEST_PROGRAM) || defined(TRUE_PROJECT)
217 /* Choose the initial sUnit vector to be approximately perpendicular
218 * to the normal.
219 */
220 Normalize( norm );
221
222 sUnit[i] = 0;
223 sUnit[(i+1)%3] = S_UNIT_X;
224 sUnit[(i+2)%3] = S_UNIT_Y;
225
226 /* Now make it exactly perpendicular */
227 w = Dot( sUnit, norm );
228 sUnit[0] -= w * norm[0];
229 sUnit[1] -= w * norm[1];
230 sUnit[2] -= w * norm[2];
231 Normalize( sUnit );
232
233 /* Choose tUnit so that (sUnit,tUnit,norm) form a right-handed frame */
234 tUnit[0] = norm[1]*sUnit[2] - norm[2]*sUnit[1];
235 tUnit[1] = norm[2]*sUnit[0] - norm[0]*sUnit[2];
236 tUnit[2] = norm[0]*sUnit[1] - norm[1]*sUnit[0];
237 Normalize( tUnit );
238#else
239 /* Project perpendicular to a coordinate axis -- better numerically */
240 sUnit[i] = 0;
241 sUnit[(i+1)%3] = S_UNIT_X;
242 sUnit[(i+2)%3] = S_UNIT_Y;
243
244 tUnit[i] = 0;
245 tUnit[(i+1)%3] = (norm[i] > 0) ? -S_UNIT_Y : S_UNIT_Y;
246 tUnit[(i+2)%3] = (norm[i] > 0) ? S_UNIT_X : -S_UNIT_X;
247#endif
248
249 /* Project the vertices onto the sweep plane */
250 for( v = vHead->next; v != vHead; v = v->next ) {
251 v->s = Dot( v->coords, sUnit );
252 v->t = Dot( v->coords, tUnit );
253 }
254 if( computedNormal ) {
255 CheckOrientation( tess );
256 }
257}
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
Definition: _complex.h:741
const GLdouble * v
Definition: gl.h:2040
double GLdouble
Definition: gl.h:163
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void ComputeNormal(GLUtesselator *tess, GLdouble norm[3])
Definition: normal.c:76
#define S_UNIT_X
Definition: normal.c:190
static int LongAxis(GLdouble v[3])
Definition: normal.c:67
#define TRUE
Definition: normal.c:43
#define FALSE
Definition: normal.c:46
static void CheckOrientation(GLUtesselator *tess)
Definition: normal.c:141
#define Dot(u, v)
Definition: normal.c:49
#define S_UNIT_Y
Definition: normal.c:191
GLUvertex vHead
Definition: mesh.h:164
GLdouble tUnit[3]
Definition: tess.h:75
GLdouble sUnit[3]
Definition: tess.h:74
GLdouble normal[3]
Definition: tess.h:73
GLUmesh * mesh
Definition: tess.h:66
GLUvertex * next
Definition: mesh.h:115

Referenced by gluTessEndPolygon().

◆ CheckOrientation()

static void CheckOrientation ( GLUtesselator tess)
static

Definition at line 141 of file normal.c.

142{
144 GLUface *f, *fHead = &tess->mesh->fHead;
145 GLUvertex *v, *vHead = &tess->mesh->vHead;
146 GLUhalfEdge *e;
147
148 /* When we compute the normal automatically, we choose the orientation
149 * so that the sum of the signed areas of all contours is non-negative.
150 */
151 area = 0;
152 for( f = fHead->next; f != fHead; f = f->next ) {
153 e = f->anEdge;
154 if( e->winding <= 0 ) continue;
155 do {
156 area += (e->Org->s - e->Dst->s) * (e->Org->t + e->Dst->t);
157 e = e->Lnext;
158 } while( e != f->anEdge );
159 }
160 if( area < 0 ) {
161 /* Reverse the orientation by flipping all the t-coordinates */
162 for( v = vHead->next; v != vHead; v = v->next ) {
163 v->t = - v->t;
164 }
165 tess->tUnit[0] = - tess->tUnit[0];
166 tess->tUnit[1] = - tess->tUnit[1];
167 tess->tUnit[2] = - tess->tUnit[2];
168 }
169}
GLfloat f
Definition: glext.h:7540
#define e
Definition: ke_i.h:82
#define f
Definition: ke_i.h:83
static Real area(Real A[2], Real B[2], Real C[2])
Definition: polyDBG.cc:50
Definition: mesh.h:126
GLUface * next
Definition: mesh.h:127
GLUface fHead
Definition: mesh.h:165

Referenced by __gl_projectPolygon().

◆ ComputeNormal()

static void ComputeNormal ( GLUtesselator tess,
GLdouble  norm[3] 
)
static

Definition at line 76 of file normal.c.

77{
78 GLUvertex *v, *v1, *v2;
79 GLdouble c, tLen2, maxLen2;
80 GLdouble maxVal[3], minVal[3], d1[3], d2[3], tNorm[3];
81 GLUvertex *maxVert[3], *minVert[3];
82 GLUvertex *vHead = &tess->mesh->vHead;
83 int i;
84
85 maxVal[0] = maxVal[1] = maxVal[2] = -2 * GLU_TESS_MAX_COORD;
86 minVal[0] = minVal[1] = minVal[2] = 2 * GLU_TESS_MAX_COORD;
87
88 for( v = vHead->next; v != vHead; v = v->next ) {
89 for( i = 0; i < 3; ++i ) {
90 c = v->coords[i];
91 if( c < minVal[i] ) { minVal[i] = c; minVert[i] = v; }
92 if( c > maxVal[i] ) { maxVal[i] = c; maxVert[i] = v; }
93 }
94 }
95
96 /* Find two vertices separated by at least 1/sqrt(3) of the maximum
97 * distance between any two vertices
98 */
99 i = 0;
100 if( maxVal[1] - minVal[1] > maxVal[0] - minVal[0] ) { i = 1; }
101 if( maxVal[2] - minVal[2] > maxVal[i] - minVal[i] ) { i = 2; }
102 if( minVal[i] >= maxVal[i] ) {
103 /* All vertices are the same -- normal doesn't matter */
104 norm[0] = 0; norm[1] = 0; norm[2] = 1;
105 return;
106 }
107
108 /* Look for a third vertex which forms the triangle with maximum area
109 * (Length of normal == twice the triangle area)
110 */
111 maxLen2 = 0;
112 v1 = minVert[i];
113 v2 = maxVert[i];
114 d1[0] = v1->coords[0] - v2->coords[0];
115 d1[1] = v1->coords[1] - v2->coords[1];
116 d1[2] = v1->coords[2] - v2->coords[2];
117 for( v = vHead->next; v != vHead; v = v->next ) {
118 d2[0] = v->coords[0] - v2->coords[0];
119 d2[1] = v->coords[1] - v2->coords[1];
120 d2[2] = v->coords[2] - v2->coords[2];
121 tNorm[0] = d1[1]*d2[2] - d1[2]*d2[1];
122 tNorm[1] = d1[2]*d2[0] - d1[0]*d2[2];
123 tNorm[2] = d1[0]*d2[1] - d1[1]*d2[0];
124 tLen2 = tNorm[0]*tNorm[0] + tNorm[1]*tNorm[1] + tNorm[2]*tNorm[2];
125 if( tLen2 > maxLen2 ) {
126 maxLen2 = tLen2;
127 norm[0] = tNorm[0];
128 norm[1] = tNorm[1];
129 norm[2] = tNorm[2];
130 }
131 }
132
133 if( maxLen2 <= 0 ) {
134 /* All points lie on a single line -- any decent normal will do */
135 norm[0] = norm[1] = norm[2] = 0;
136 norm[LongAxis(d1)] = 1;
137 }
138}
#define GLU_TESS_MAX_COORD
Definition: glu.h:284
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
#define c
Definition: ke_i.h:80
GLdouble coords[3]
Definition: mesh.h:121

Referenced by __gl_projectPolygon().

◆ LongAxis()

static int LongAxis ( GLdouble  v[3])
static

Definition at line 67 of file normal.c.

68{
69 int i = 0;
70
71 if( ABS(v[1]) > ABS(v[0]) ) { i = 1; }
72 if( ABS(v[2]) > ABS(v[i]) ) { i = 2; }
73 return i;
74}
#define ABS(x)
Definition: normal.c:65

Referenced by __gl_projectPolygon(), and ComputeNormal().