2 ** License Applicability. Except to the extent portions of this file are
\r
3 ** made subject to an alternative license as permitted in the SGI Free
\r
4 ** Software License B, Version 2.0 (the "License"), the contents of this
\r
5 ** file are subject only to the provisions of the License. You may not use
\r
6 ** this file except in compliance with the License. You may obtain a copy
\r
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
\r
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
\r
10 ** http://oss.sgi.com/projects/FreeB
\r
12 ** Note that, as provided in the License, the Software is distributed on an
\r
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
\r
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
\r
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
\r
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
\r
18 ** NOTE: The Original Code (as defined below) has been licensed to Sun
\r
19 ** Microsystems, Inc. ("Sun") under the SGI Free Software License B
\r
20 ** (Version 1.1), shown above ("SGI License"). Pursuant to Section
\r
21 ** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
\r
22 ** you under an alternative license ("Alternative License"). This
\r
23 ** Alternative License includes all of the provisions of the SGI License
\r
24 ** except that Section 2.2 and 11 are omitted. Any differences between
\r
25 ** the Alternative License and the SGI License are offered solely by Sun
\r
28 ** Original Code. The Original Code is: OpenGL Sample Implementation,
\r
29 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
\r
30 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
\r
31 ** Copyright in any portions created by third parties is as indicated
\r
32 ** elsewhere herein. All Rights Reserved.
\r
34 ** Additional Notice Provisions: The application programming interfaces
\r
35 ** established by SGI in conjunction with the Original Code are The
\r
36 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
\r
37 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
\r
38 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
\r
39 ** Window System(R) (Version 1.3), released October 19, 1998. This software
\r
40 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
\r
41 ** published by SGI, but has not been independently verified as being
\r
42 ** compliant with the OpenGL(R) version 1.2.1 Specification.
\r
44 ** $Date: 2009-03-04 17:23:34 -0800 (Wed, 04 Mar 2009) $ $Revision: 1856 $
\r
49 * Copyright (c) 2002-2004 LWJGL Project
\r
50 * All rights reserved.
\r
52 * Redistribution and use in source and binary forms, with or without
\r
53 * modification, are permitted provided that the following conditions are
\r
56 * * Redistributions of source code must retain the above copyright
\r
57 * notice, this list of conditions and the following disclaimer.
\r
59 * * Redistributions in binary form must reproduce the above copyright
\r
60 * notice, this list of conditions and the following disclaimer in the
\r
61 * documentation and/or other materials provided with the distribution.
\r
63 * * Neither the name of 'LWJGL' nor the names of
\r
64 * its contributors may be used to endorse or promote products derived
\r
65 * from this software without specific prior written permission.
\r
67 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
68 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
\r
69 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
70 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
71 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
72 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
73 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
\r
74 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
75 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
76 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
77 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
81 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
\r
83 * Redistribution and use in source and binary forms, with or without
\r
84 * modification, are permitted provided that the following conditions are
\r
87 * - Redistribution of source code must retain the above copyright
\r
88 * notice, this list of conditions and the following disclaimer.
\r
90 * - Redistribution in binary form must reproduce the above copyright
\r
91 * notice, this list of conditions and the following disclaimer in the
\r
92 * documentation and/or other materials provided with the distribution.
\r
94 * Neither the name of Sun Microsystems, Inc. or the names of
\r
95 * contributors may be used to endorse or promote products derived from
\r
96 * this software without specific prior written permission.
\r
98 * This software is provided "AS IS," without a warranty of any kind. ALL
\r
99 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\r
100 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\r
101 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\r
102 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\r
103 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\r
104 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
\r
105 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
\r
106 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\r
107 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\r
108 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\r
109 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
111 * You acknowledge that this software is not designed or intended for use
\r
112 * in the design, construction, operation or maintenance of any nuclear
\r
115 package net.sf.openrocket.gui.figure3d;
\r
117 import javax.media.opengl.GL;
\r
118 import javax.media.opengl.GL2;
\r
120 import net.sf.openrocket.rocketcomponent.MassObject;
\r
122 public final class MassObjectRenderer {
\r
123 private static final boolean textureFlag = true;
\r
125 private MassObjectRenderer() {
\r
128 public static final void drawMassObject(final GL2 gl, final MassObject o,
\r
129 final int slices, final int stacks) {
\r
132 double x, y, z, nz, nsign;
\r
137 da = 2.0f * PI / slices;
\r
138 dz = o.getLength() / stacks;
\r
140 double ds = 1.0f / slices;
\r
141 double dt = 1.0f / stacks;
\r
144 for (j = 0; j < stacks; j++) {
\r
145 r = getRadius(o, z);
\r
146 double rNext = getRadius(o, z + dz);
\r
147 if (j == stacks - 1)
\r
150 if (j == stacks - 1)
\r
153 // Z component of normal vectors
\r
154 nz = -(rNext - r) / dz;
\r
157 glBegin(gl, GL2.GL_QUAD_STRIP);
\r
158 for (i = 0; i <= slices; i++) {
\r
166 if (nsign == 1.0f) {
\r
167 normal3d(gl, (x * nsign), (y * nsign), (nz * nsign));
\r
168 TXTR_COORD(gl, s, t);
\r
169 glVertex3d(gl, (x * r), (y * r), z);
\r
170 normal3d(gl, (x * nsign), (y * nsign), (nz * nsign));
\r
171 TXTR_COORD(gl, s, t + dt);
\r
172 glVertex3d(gl, (x * rNext), (y * rNext), (z + dz));
\r
174 normal3d(gl, x * nsign, y * nsign, nz * nsign);
\r
175 TXTR_COORD(gl, s, t);
\r
176 glVertex3d(gl, (x * r), (y * r), z);
\r
177 normal3d(gl, x * nsign, y * nsign, nz * nsign);
\r
178 TXTR_COORD(gl, s, t + dt);
\r
179 glVertex3d(gl, (x * rNext), (y * rNext), (z + dz));
\r
190 private static final double getRadius(MassObject o, double z) {
\r
191 double arc = Math.min(o.getLength(), 2 * o.getRadius()) * 0.35f;
\r
192 double r = o.getRadius();
\r
193 if (z == 0 || z == o.getLength())
\r
196 double zz = z - arc;
\r
197 return (r - arc) + Math.sqrt(arc * arc - zz * zz);
\r
199 if (z > o.getLength() - arc) {
\r
200 double zz = (z - o.getLength() + arc);
\r
201 return (r - arc) + Math.sqrt(arc * arc - zz * zz);
\r
203 return o.getRadius();
\r
206 // ----------------------------------------------------------------------
\r
207 // Internals only below this point
\r
210 private static final double PI = Math.PI;
\r
212 private static final void glBegin(GL gl, int mode) {
\r
213 gl.getGL2().glBegin(mode);
\r
216 private static final void glEnd(GL gl) {
\r
217 gl.getGL2().glEnd();
\r
220 private static final void glVertex3d(GL gl, double x, double y, double z) {
\r
221 gl.getGL2().glVertex3d(x, y, z);
\r
224 private static final void glNormal3d(GL gl, double x, double y, double z) {
\r
225 gl.getGL2().glNormal3d(x, y, z);
\r
228 private static final void glTexCoord2d(GL gl, double x, double y) {
\r
229 gl.getGL2().glTexCoord2d(x, y);
\r
233 * Call glNormal3f after scaling normal to unit length.
\r
239 private static final void normal3d(GL gl, double x, double y, double z) {
\r
242 mag = Math.sqrt(x * x + y * y + z * z);
\r
243 if (mag > 0.00001F) {
\r
248 glNormal3d(gl, x, y, z);
\r
251 private static final void TXTR_COORD(GL gl, double x, double y) {
\r
253 glTexCoord2d(gl, x, y);
\r
256 private static final double sin(double r) {
\r
257 return Math.sin(r);
\r
260 private static final double cos(double r) {
\r
261 return Math.cos(r);
\r