summaryrefslogtreecommitdiff
path: root/polyset.cc
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-25 09:49:28 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-25 09:49:28 (GMT)
commit1ef41a174f64d8ae98d2f727eef9a7613f85934c (patch)
treea349d76ac072e3923399168d7564e98eb9b534ab /polyset.cc
parent4f7d83c00fa2cd56d60cf399ccf848fdd63e1703 (diff)
Clifford Wolf:
Some fixes, some progress (OpenCSG) git-svn-id: http://svn.clifford.at/openscad/trunk@20 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'polyset.cc')
-rw-r--r--polyset.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/polyset.cc b/polyset.cc
index 63d8514..5c56080 100644
--- a/polyset.cc
+++ b/polyset.cc
@@ -41,6 +41,18 @@ void PolySet::insert_vertex(double x, double y, double z)
polygons.last().insert(0, Point(x, y, z));
}
+static void set_opengl_normal(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
+{
+ double ax = x1 - x2, ay = y1 - y2, az = z1 - z2;
+ double bx = x3 - x2, by = y3 - y2, bz = z3 - z2;
+ double nx = ay*bz - az*by;
+ double ny = az*bx - ax*bz;
+ double nz = ax*by - ay*bx;
+ double n_scale = 1.0 / sqrt(nx*nx + ny*ny + nz*nz);
+ nx /= n_scale; ny /= n_scale; nz /= n_scale;
+ glNormal3d(-nx, -ny, -nz);
+}
+
void PolySet::render_surface(colormode_e colormode) const
{
if (colormode == COLOR_MATERIAL)
@@ -50,6 +62,9 @@ void PolySet::render_surface(colormode_e colormode) const
for (int i = 0; i < polygons.size(); i++) {
const Polygon *poly = &polygons[i];
glBegin(GL_POLYGON);
+ set_opengl_normal(poly->at(0).x, poly->at(0).y, poly->at(0).z,
+ poly->at(1).x, poly->at(1).y, poly->at(1).z,
+ poly->at(2).x, poly->at(2).y, poly->at(2).z);
for (int j = 0; j < poly->size(); j++) {
const Point *p = &poly->at(j);
glVertex3d(p->x, p->y, p->z);
contact: Jan Huwald // Impressum