@Override public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); gl.glBegin(GL2.GL_LINES); gl.glColor3f(color.x, color.y, color.z); gl.glVertex3f(p1.x, p1.y, 0); gl.glVertex3f(p2.x, p2.y, 0); gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS; float c = MathUtils.cos(theta); float s = MathUtils.sin(theta); float x = radius; float y = 0; float cx = center.x; float cy = center.y; gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); // apply the rotation matrix float temp = x; x = c * x - s * y; y = s * temp + c * y; } gl.glEnd(); gl.glBegin(GL2.GL_LINES); gl.glVertex3f(cx, cy, 0); gl.glVertex3f(cx + axis.x * radius, cy + axis.y * radius, 0); gl.glEnd(); gl.glPopMatrix(); }
gl.glColor4f(color.x, color.y, color.z, .4f); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); gl.glColor4f(color.x, color.y, color.z, 1); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); gl.glVertex3f(cx, cy, 0); gl.glVertex3f(cx + axis.x * radius, cy + axis.y * radius, 0); gl.glEnd(); gl.glPopMatrix();
@Override public void drawCircle(Vec2 center, float radius, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS; float c = MathUtils.cos(theta); float s = MathUtils.sin(theta); float x = radius; float y = 0; float cx = center.x; float cy = center.y; gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); // apply the rotation matrix float temp = x; x = c * x - s * y; y = s * temp + c * y; } gl.glEnd(); gl.glPopMatrix(); }
gl.glVertex3f(x + cx, y + cy, 0); float temp = x; x = c * x - s * y;
gl.glVertex3f(x + cx, y + cy, 0); float temp = x; x = c * x - s * y;
gl.glNormal3fv(n[i], 0); float[] vt = v[faces[i][0]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); vt = v[faces[i][1]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); vt = v[faces[i][2]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); vt = v[faces[i][3]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); gl.glEnd();
private final void glVertex3f(final GL gl, final float x, final float y, final float z) { if(immModeSinkEnabled) { immModeSink.glVertex3f(x, y, z); } else { gl.getGL2().glVertex3f(x, y, z); } }
gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, (float) r * sinPhi); gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); gl.glVertex3f(cosTheta * dist, -sinTheta * dist, (float) r * sinPhi);
gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), mVertCoords.get()); gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), mVertCoords.get()); gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), mVertCoords.get()); gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), mVertCoords.get());
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // clear // color // and depth // buffers gl.glLoadIdentity(); // reset the model-view matrix // ----- Your OpenGL rendering code here (Render a white triangle for // testing) ----- gl.glTranslatef(0.0f, 0.0f, -6.0f); // translate into the screen gl.glColor3f(r, g, b); gl.glBegin(GL.GL_TRIANGLES); // draw using triangles long delay = System.currentTimeMillis() - time; double angle = speed * delay * Math.PI / 2000; float c = (float) Math.cos(angle); float s = (float) Math.sin(angle); gl.glVertex3f(c, s, 0.0f); gl.glVertex3f(-s, c, 0.0f); gl.glVertex3f(-c, -s, 0.0f); gl.glEnd(); } @Override
@Override public void drawMajorTickGridline( final double location, final AxisConfig<float[]> config ) { final GL2 gl = this.glad.getGL().getGL2(); gl.glPushMatrix(); this.orient( gl ); gl.glLineWidth( (float)config.getRenderingConfig().getMajorGridThickness() ); gl.glColor3f( config.getRenderingConfig().getMajorGridColour()[0], config.getRenderingConfig().getMajorGridColour()[1], config.getRenderingConfig().getMajorGridColour()[2] ); final float ll = this.calculatePosition( location ).floatValue(); final float zero = 0.001f; gl.glBegin( GL.GL_LINE_STRIP ); { // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( ll, zero, zero ); gl.glVertex3f( ll, 1, zero ); } gl.glEnd(); gl.glBegin( GL.GL_LINE_STRIP ); { // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( ll, zero, zero ); gl.glVertex3f( ll, zero, 1*this.gridDirection ); } gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawMajorTick( final double location, final AxisConfig<float[]> config ) { final GL2 gl = this.glad.getGL().getGL2(); gl.glPushMatrix(); this.orient( gl ); gl.glLineWidth( (float)config.getRenderingConfig().getMajorTickThickness() ); gl.glColor3f( config.getRenderingConfig().getMajorTickColour()[0], config.getRenderingConfig().getMajorTickColour()[1], config.getRenderingConfig().getMajorTickColour()[2] ); final float l = (float)config.getRenderingConfig().getMajorTickLength(); final float l2 = -l; final float ll = this.calculatePosition( location ).floatValue(); final float zero = 0.001f; gl.glBegin( GL.GL_LINE_STRIP ); { // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( ll, l, zero ); gl.glVertex3f( ll, l2, zero ); } gl.glEnd(); gl.glBegin( GL.GL_LINE_STRIP ); { // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( ll, zero, l ); gl.glVertex3f( ll, zero, l2 ); } gl.glEnd(); gl.glPopMatrix(); }
gl.glBegin(GL2GL3.GL_QUADS); gl.glTexCoord2f(coords.left(), coords.bottom()); gl.glVertex3f(x, y, z); gl.glTexCoord2f(coords.right(), coords.bottom()); gl.glVertex3f(x + width * scaleFactor, y, z); gl.glTexCoord2f(coords.right(), coords.top()); gl.glVertex3f(x + width * scaleFactor, y + height * scaleFactor, z); gl.glTexCoord2f(coords.left(), coords.top()); gl.glVertex3f(x, y + height * scaleFactor, z); gl.glEnd();
@Override public void drawAxis( final AxisConfig<float[]> config ) { final GL2 gl = this.glad.getGL().getGL2(); gl.glPushMatrix(); this.orient( gl ); final float zero = 0.001f; gl.glBegin( GL.GL_LINE_STRIP ); { gl.glLineWidth( (float)config.getRenderingConfig().getThickness() ); gl.glColor3f( config.getRenderingConfig().getColour()[0], config.getRenderingConfig().getColour()[1], config.getRenderingConfig().getColour()[2] ); final float n1 = this.calculatePosition( config.getMinValue() ).floatValue(); final float n2 = this.calculatePosition( config.getMaxValue() ).floatValue(); // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( n1, zero, zero ); gl.glVertex3f( n2, zero, zero ); } gl.glEnd(); gl.glPopMatrix(); }
gl.glVertex3f( ll, zero, zero ); gl.glVertex3f( ll, 1, zero ); gl.glVertex3f( ll, zero, zero ); gl.glVertex3f( ll, zero, 1*this.gridDirection );
gl.glVertex3f( ll, l, zero ); gl.glVertex3f( ll, l2, zero );