Norten

03-31-2014, 05:29 AM

Hi i have this problem i was trying coding in OpenGL and i was able to get this Line strip spiral:

gl.glLineWidth(3);

gl.glBegin(GL2.GL_LINE_STRIP);

float x,z;

float y = -10;

float angle;

int numberOfSpirals = 6;

float distance = 0.2f;

for (angle = 0.5f; angle <= (Math.PI * 2.16f * numberOfSpirals); angle += distance) {

x = (float) Math.sin(angle) * 5;

z = (float) Math.cos(angle) * 5;

gl.glColor3f(0.7f, 0.7f, 0.7f);

gl.glVertex3f(x, y, z);

y += 0.05;

}

gl.glEnd();

this code is working just fine but i want to draw spiral built from quads or triangles to make it look like real spiral.

Best i am able to do is this :

gl.glBegin(GL2.GL_QUAD_STRIP);

float x,z;

float y = -10;

float angle;

int numberOfSpirals = 6;

float distance = 0.2f;

for (angle = 0.5f; angle <= (Math.PI * 2.16f * numberOfSpirals); angle += distance) {

x = (float) Math.sin(angle) * 5;

z = (float) Math.cos(angle) * 5;

gl.glColor3f(0.7f, 0.7f, 0.7f);

gl.glVertex3f(x-0.5f, y-0.5f, z-0.5f);

gl.glVertex3f(x+0.5f, y+0.5f, z+0.5f);

y += 0.05;

}

gl.glEnd();

but then spiral is flat and not circle in cross-section.

Does anybody have a clue how to make it looks like real spiral using this code? Thanks a lot.

gl.glLineWidth(3);

gl.glBegin(GL2.GL_LINE_STRIP);

float x,z;

float y = -10;

float angle;

int numberOfSpirals = 6;

float distance = 0.2f;

for (angle = 0.5f; angle <= (Math.PI * 2.16f * numberOfSpirals); angle += distance) {

x = (float) Math.sin(angle) * 5;

z = (float) Math.cos(angle) * 5;

gl.glColor3f(0.7f, 0.7f, 0.7f);

gl.glVertex3f(x, y, z);

y += 0.05;

}

gl.glEnd();

this code is working just fine but i want to draw spiral built from quads or triangles to make it look like real spiral.

Best i am able to do is this :

gl.glBegin(GL2.GL_QUAD_STRIP);

float x,z;

float y = -10;

float angle;

int numberOfSpirals = 6;

float distance = 0.2f;

for (angle = 0.5f; angle <= (Math.PI * 2.16f * numberOfSpirals); angle += distance) {

x = (float) Math.sin(angle) * 5;

z = (float) Math.cos(angle) * 5;

gl.glColor3f(0.7f, 0.7f, 0.7f);

gl.glVertex3f(x-0.5f, y-0.5f, z-0.5f);

gl.glVertex3f(x+0.5f, y+0.5f, z+0.5f);

y += 0.05;

}

gl.glEnd();

but then spiral is flat and not circle in cross-section.

Does anybody have a clue how to make it looks like real spiral using this code? Thanks a lot.