Hi guys help please…i have a code below that supposedly move the text around the circle but im not sure if that is the right way to do it as it leaves the previous text from the previous position visible which is not supposed to be the case. Any help please…Thanks in advance!
package lesson1;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author bubz
*/
import java.awt.*;
// JOGL: OpenGL functions
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;
import java.awt.event.*;
public class ShowName extends Frame implements GLEventListener
{
static int HEIGHT = 600, WIDTH = 600;
int rCircle = 200;
double numAngle = .01;
int xMiddle, yMiddle;
int CurXCoor, CurYCoor;
GLUT glut = new GLUT();
static GL gl; //interface to OpenGL
static GL glname;
static GLCanvas canvas; // drawable in a frame
static GLCanvas canvasName;
GLCapabilities capabilities; // OpenGL capabilities
GLCapabilities capabilitiesName;
static Animator animator;
static float cVdata[][] = { {1.0f, 0.0f, 0.0f}
, {0.0f, 1.0f, 0.0f}
, {-1.0f, 0.0f, 0.0f}
, {0.0f, -1.0f, 0.0f}
};
public ShowName()
{
//1. specify a drawable: canvas
capabilities = new GLCapabilities();
canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);
//canvasName = GLDrawableFactory.getFactory().createGLCanvas(capabilitiesName);
//2. listen to the events related to canvas: reshape
canvas.addGLEventListener(this);
//3. add the canvas to fill the Frame container
add(canvas, BorderLayout.CENTER);
gl = canvas.getGL();
glname = canvas.getGL();
capabilities.setDoubleBuffered(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main(String[] args)
{
ShowName frame = new ShowName();
//4. set the size of the frame and make it visible
frame.setTitle("Show My Name");
frame.setSize(WIDTH, HEIGHT);
frame.setVisible(true);
//Thread.currentThread().interrupt();
}
public void init(GLDrawable drawable)
{
animator = new Animator(canvas);
animator.start(); // start animator thread
}
public void display(GLDrawable drawable)
{
CurXCoor = (int)(rCircle * Math.cos(numAngle));
CurYCoor = (int)(rCircle * Math.sin(numAngle));
glname.glColor3f(1, 1, 1);
glname.glMatrixMode(GL.GL_PROJECTION);
glname.glLoadIdentity();
glname.glOrtho(0, WIDTH, 0, HEIGHT, -1.0, 1.0);
//gl.glPushMatrix();
glname.glTranslatef((CurXCoor + xMiddle), (CurYCoor + yMiddle), 0); // end position
glname.glScalef(0.2f, 0.2f, 0.2f);
//glut.glutStrokeCharacter(glname, GLUT.STROKE_ROMAN, 'B');
glut.glutStrokeString(glname, GLUT.STROKE_ROMAN, "Bubz");
//gl.glClear(GL.GL_COLOR_BUFFER_BIT);
//gl.glPopMatrix();
numAngle += .01;
if(numAngle == 360)
numAngle = 0;
try
{
Thread.sleep(10);
}
catch (Exception ignore){}
}
public void displayChanged(GLDrawable drawable, boolean modeChanged,boolean deviceChanged)
{
}
public void reshape(GLDrawable drawable, int x, int y, int w, int h)
{
WIDTH = w;
HEIGHT = h;
xMiddle = WIDTH/2;
yMiddle = HEIGHT/2;
//3. origin at the center of the drawing area
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-w/2, w/2, -h/2, h/2, -1, 1);
drawCircle(rCircle, 12);
}
// subdivide a triangle recursively, and draw them
private void subdivideCircle(int radius, float[] v1, float[] v2, int depth)
{
float v11[] = new float[3];
float v22[] = new float[3];
float v00[] = {0, 0, 0};
float v12[] = new float[3];
if (depth==0)
{
//5. specify a color related to triangle location
//gl.glColor3f(v1[0]*v1[0], v1[1]*v1[1], v1[2]*v1[2]);
gl.glColor3f(1.0f, 0.0f, 0.0f);
for (int i = 0; i<3; i++)
{
v11[i] = v1[i]*radius;
v22[i] = v2[i]*radius;
}
drawtriangle(v11, v22, v00);
return;
}
v12[0] = v1[0]+v2[0];
v12[1] = v1[1]+v2[1];
v12[2] = v1[2]+v2[2];
normalize(v12);
// subdivide a triangle recursively, and draw them
subdivideCircle(radius, v1, v12, depth-1);
subdivideCircle(radius, v12, v2, depth-1);
}
// draw a circle with center at the origin in xy plane
public void drawCircle(int cRadius, int depth)
{
subdivideCircle(cRadius, cVdata[0], cVdata[1], depth);
subdivideCircle(cRadius, cVdata[1], cVdata[2], depth);
subdivideCircle(cRadius, cVdata[2], cVdata[3], depth);
subdivideCircle(cRadius, cVdata[3], cVdata[0], depth);
}
// normalize a 3D vector
public void normalize(float vector[])
{
float d = (float)Math.sqrt(vector[0]*vector[0]
+vector[1]*vector[1] + vector[2]*vector[2]);
if (d==0)
{
System.out.println("0 length vector: normalize().");
return;
}
vector[0] /= d;
vector[1] /= d;
vector[2] /= d;
}
public void drawtriangle(float[] v1, float[] v2, float[] v3)
{
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3fv(v1);
gl.glVertex3fv(v2);
gl.glVertex3fv(v3);
gl.glEnd();
}
}