Hello,
I’m having trouble at drawing lines so that they start
from the center of spheres that I have just drawn. Here
is the code:
public void display(GLDrawable arg0) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); // Reset The View
gl.glInitNames(); // Initialize object names
int selectBuffer[] = null;
if (isClicked)
selectBuffer = setupSelection();
float xtrans = -xpos;
float ytrans = -ypos;
float ztrans = -zpos;
float sceneroty = 360.0f - yrot;
gl.glRotatef(lookupdown,1.0f,0,0);
gl.glRotatef(sceneroty,0,1.0f,0);
gl.glTranslatef(xtrans, ytrans, ztrans);
// Draws the spheres
for (Iterator iter = graphClassModels.iterator(); iter.hasNext();) {
GraphicalClassModel model = (GraphicalClassModel) iter.next();
Integer classId = (Integer) classModelIds.get(model);
Point centerPoint = model.getCoord();
RGB color = model.getRgb();
gl.glPushName(classId.intValue());
gl.glTranslatef(centerPoint.getX(), centerPoint.getY(), centerPoint.getZ());
gl.glColor3f(color.getRed(),color.getGreen(),color.getBlue());
glut.glutSolidSphere(glu,1.3f, 32, 32);
gl.glPopName();
// PROBLEM IN HERE!! Why these lines doesn't start from the center of the sphere !?
gl.glBegin(GL.GL_LINES);
gl.glVertex3f(centerPoint.getX(),centerPoint.getY(),centerPoint.getZ());
gl.glVertex3f(centerPoint.getX() +3,centerPoint.getY()+3,centerPoint.getZ()+3);
gl.glEnd();
gl.glRasterPos3f(centerPoint.getX() +3,centerPoint.getY()+3,centerPoint.getZ()+3);
glut.glutBitmapString(gl, GLUT.BITMAP_TIMES_ROMAN_24, "Some text");
}
if (isClicked) {
selection = getSelection(selectBuffer);
isClicked = false;
}
if (selection != 0)
printObjectsClass(selection);
processKeyboard();
}