opengl draw a circle outline on the x/y plane, located at the given z position. - Java javax.media.opengl

Java examples for javax.media.opengl:Draw

Description

opengl draw a circle outline on the x/y plane, located at the given z position.

Demo Code


import java.awt.Color;
import javax.media.opengl.GL;
import javax.vecmath.Point3d;

public class Main{
    /**//from   w ww .  j ava  2  s . c om
     * This draw a circle outline on the x/y plane, located at the given z
     * position.
     * 
     * @param gl
     * @param radius
     * @param x
     * @param y
     * @param z
     */
    public static void drawCircle(GL gl, float radius, float x, float y,
            float z) {

        drawEllipse(gl, radius, radius, x, y, z);
    }
    /**
     * This draw a circle outline on the x/y plane, located at the given z
     * position.
     * 
     * @param gl
     * @param xRadius
     * @param yRadius
     * @param x
     * @param y
     * @param z
     */
    public static void drawEllipse(GL gl, double xRadius, double yRadius,
            float x, float y, float z) {

        gl.glBegin(GL.GL_LINE_LOOP);

        for (int i = 0; i < 360; i++) {
            float angle = (float) Math.toRadians(i);
            gl.glVertex3d(x + Math.cos(angle) * xRadius,
                    y + Math.sin(angle) * yRadius, z);
        }

        gl.glEnd();

    }
}

Related Tutorials