Improved Transition & Cone Rendering

Smooth normals better.
Take better care of the tip normals.

Use TransitionRenderer for cones too

Use higher LOD near tip of cones

Reduce the LOD smartly in a couple places
This commit is contained in:
bkuker 2013-03-10 16:00:53 -04:00
parent 9a8b4852a3
commit fe61fc4b7d
2 changed files with 42 additions and 37 deletions

View File

@ -17,6 +17,7 @@ import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RingComponent; import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.Transition;
import net.sf.openrocket.rocketcomponent.Transition.Shape;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
@ -127,12 +128,7 @@ public class ComponentRenderer {
if (which == Surface.INSIDE) { if (which == Surface.INSIDE) {
gl.glFrontFace(GL.GL_CCW); gl.glFrontFace(GL.GL_CCW);
} }
if (t.getType() == Transition.Shape.CONICAL) { TransitionRenderer.drawTransition(gl, t, LOD, t.getType() == Shape.CONICAL ? 4 : LOD / 2);
glu.gluCylinder(q, t.getForeRadius(), t.getAftRadius(),
t.getLength(), LOD, 1);
} else {
TransitionRenderer.drawTransition(gl, t, LOD, LOD);
}
if (which == Surface.INSIDE) { if (which == Surface.INSIDE) {
gl.glFrontFace(GL.GL_CW); gl.glFrontFace(GL.GL_CW);
} }
@ -248,7 +244,7 @@ public class ComponentRenderer {
private void renderMassObject(GL2 gl, MassObject o) { private void renderMassObject(GL2 gl, MassObject o) {
gl.glRotated(90, 0, 1.0, 0); gl.glRotated(90, 0, 1.0, 0);
MassObjectRenderer.drawMassObject(gl, o, LOD, LOD); MassObjectRenderer.drawMassObject(gl, o, LOD / 2, LOD / 2);
} }
private void renderMotor(final GL2 gl, Motor motor) { private void renderMotor(final GL2 gl, Motor motor) {

View File

@ -128,29 +128,29 @@ final class TransitionRenderer {
static final void drawTransition(final GL2 gl, final Transition tr, static final void drawTransition(final GL2 gl, final Transition tr,
final int slices, final int stacks) { final int slices, final int stacks) {
double da, r, dz; double da, r, dzBase;
double x, y, z, nz, nsign; double x, y, z, nz, lnz = 0;
int i, j; int i;
nsign = 1.0f;
da = 2.0f * PI / slices; da = 2.0f * PI / slices;
dz = (double) tr.getLength() / stacks; dzBase = (double) tr.getLength() / stacks;
double ds = 1.0f / slices; double ds = 1.0f / slices;
double dt = 1.0f / stacks;
double t = 0.0f;
z = 0.0f; z = 0.0f;
r = (double) tr.getForeRadius(); r = (double) tr.getForeRadius();
for (j = 0; j < stacks; j++) { while (z < tr.getLength()) {
r = (double) tr.getRadius(z); double t = z / tr.getLength();
double rNext = (double) tr.getRadius(z + dz);
double dz = t < 0.025 ? dzBase / 8.0 : dzBase;
double zNext = Math.min(z + dz, tr.getLength());
r = tr.getRadius(z);
double rNext = tr.getRadius(zNext);
if (j == stacks - 1)
rNext = (double) tr.getRadius(tr.getLength());
// Z component of normal vectors // Z component of normal vectors
nz = -(rNext - r) / dz; nz = (r - rNext) / dz;
double s = 0.0f; double s = 0.0f;
glBegin(gl, GL2.GL_QUAD_STRIP); glBegin(gl, GL2.GL_QUAD_STRIP);
@ -162,27 +162,36 @@ final class TransitionRenderer {
x = sin((i * da)); x = sin((i * da));
y = cos((i * da)); y = cos((i * da));
} }
if (nsign == 1.0f) {
normal3d(gl, (x * nsign), (y * nsign), (nz * nsign)); if (r == 0) {
TXTR_COORD(gl, s, t); switch (tr.getType()) {
glVertex3d(gl, (x * r), (y * r), z); case CONICAL:
normal3d(gl, (x * nsign), (y * nsign), (nz * nsign)); case OGIVE:
TXTR_COORD(gl, s, t + dt); case PARABOLIC:
glVertex3d(gl, (x * rNext), (y * rNext), (z + dz)); normal3d(gl, x, y, nz);
} else { break;
normal3d(gl, x * nsign, y * nsign, nz * nsign); case ELLIPSOID:
TXTR_COORD(gl, s, t); case POWER:
glVertex3d(gl, (x * r), (y * r), z); case HAACK:
normal3d(gl, x * nsign, y * nsign, nz * nsign); normal3d(gl, 0, 0, -1);
TXTR_COORD(gl, s, t + dt); break;
glVertex3d(gl, (x * rNext), (y * rNext), (z + dz));
} }
} else {
normal3d(gl, x, y, lnz);
}
TXTR_COORD(gl, s, z / tr.getLength());
glVertex3d(gl, (x * r), (y * r), z);
normal3d(gl, x, y, nz);
TXTR_COORD(gl, s, zNext / tr.getLength());
glVertex3d(gl, (x * rNext), (y * rNext), zNext);
s += ds; s += ds;
} // for slices } // for slices
glEnd(gl); glEnd(gl);
// r += dr; lnz = nz;
t += dt; z = Math.min(z + dz, tr.getLength());
z += dz;
} // for stacks } // for stacks
} }