1 // Copyright (C) 2006 Erik Dahlberg
3 // This file is part of LSystem3d.
5 // LSystem3D is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // LSystem3D is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with LSystem3D; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 _displayList
= glGenLists(1);
45 glDeleteLists(_displayList
, 1);
52 * @param diameter diameter of segment
53 * @param x1 x start point
54 * @param y1 y start point
55 * @param z1 z start point
56 * @param x2 x end point
57 * @param y2 y end point
58 * @param z2 z end point
60 void Model::segment(double diameter
, double x1
, double y1
, double z1
, double x2
, double y2
, double z2
)
66 // glVertex3d(x1, y1, z1);
67 // glVertex3d(x2, y2, z2);
74 // find rotation vector and angle of cylinder
76 Vector
initial(0.0, 1.0, 0.0); // initial rotation of cylinder
77 Vector
desired(x2
-x1
, y2
-y1
, z2
-z1
); // desired rotation of cylinder
81 double angle
= initial
.getAngle(desired
);
84 Vector crossProduct
= initial
.getCrossProduct(desired
);
85 crossProduct
.normalize();
88 // render the cylinder
90 GLUquadric
*quadric
= gluNewQuadric();
92 glColor3f(1.0, 0.5, 0.0);
95 glTranslatef(x1
, y1
, z1
);
96 glRotatef(angle
, crossProduct
.getX(), crossProduct
.getY(), crossProduct
.getZ());
97 glRotatef(-90, 1, 0, 0);
99 gluCylinder(quadric
, diameter
, diameter
, 1.0, 6, 6);
106 * Draw model to screen
110 glCallList(_displayList
);
126 * Start recording of drawing operations
130 glNewList(_displayList
, GL_COMPILE
);
136 * Stop recording of drawing operations
146 * Begin creation of a filled surface
148 void Model::fillBegin()
150 glColor3f(0.0, 0.5, 0.0);
157 * End creation of a filled surface
159 void Model::fillEnd()
167 * Create one vertex in the filled surface
168 * @param x x-coordinate
169 * @param y y-coordinate
170 * @param z z-coordinate
172 void Model::point(double x
, double y
, double z
)