glut primitive object scaling
Posted by bcothren on Mar 18, 2011; 2:57pm
URL: https://forum.jogamp.org/glut-primitive-object-scaling-tp2698207.html
I'm seeing some strange, and not always consistent behavior when it comes to the scaling of primitive objects within the GLUT package. For example, take the three primitives Cylinder, Sphere, and Cube. When you scale the Sphere or Cube in any of the 3 axes, you get what you'd expect to see (the object gets [scaleFactor] size bigger in that axis). However, the Cylinder doesn't have this behavior - a scaling in the Z-axis does not behave like the X and Y axis scaling. When you scale a cylinder in the X axis, it grows in both the +X and -X, and same for the Y axis. The Z axis, however, doesn't do this. A 2x scale in the Z axis will cause the cylinder to grow in only the +Z direction. Is this the correct behavior?
Calling the following method from display() will demonstrate what I'm seeing:
private void drawObjects(GL2 gl){
gl.glPushMatrix();
boolean drawSpheres = true;
boolean drawCylinders = false;
boolean drawCubes = false;
double scaleFactor = 2;
// non-scaled (white)
GLUT glut = new GLUT();
gl.glColor3f(1.0f, 1.0f, 1.0f);
if(drawCylinders){
glut.glutSolidCylinder(50, 50, 20, 1);
}else if(drawSpheres){
glut.glutSolidSphere(25, 25, 25);
}else if(drawCubes){
glut.glutSolidCube(50);
}
// scaled in z (red)
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glScaled(1, 1, scaleFactor);
gl.glTranslated(125, 0, 0);
if(drawCylinders){
glut.glutSolidCylinder(50, 50, 20, 1);
}else if(drawSpheres){
glut.glutSolidSphere(25, 25, 25);
}else if(drawCubes){
glut.glutSolidCube(50);
}
gl.glPopMatrix();
// scaled in x (green)
gl.glPushMatrix();
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glScaled(scaleFactor, 1, 1);
gl.glTranslated(0, 0, -125);
if(drawCylinders){
glut.glutSolidCylinder(50, 50, 20, 1);
}else if(drawSpheres){
glut.glutSolidSphere(25, 25, 25);
}else if(drawCubes){
glut.glutSolidCube(50);
}
gl.glPopMatrix();
// scaled in y (blue)
gl.glPushMatrix();
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glScaled(1, scaleFactor, 1);
gl.glTranslated(-125, 0, 0);
if(drawCylinders){
glut.glutSolidCylinder(50, 50, 20, 1);
}else if(drawSpheres){
glut.glutSolidSphere(25, 25, 25);
}else if(drawCubes){
glut.glutSolidCube(50);
}
gl.glPopMatrix();
}
Thanks,
bcothren