Commit 070fb195 by Alisa Jung

cylinder and cone

parent e41ab5d8
......@@ -172,10 +172,10 @@ void MyGLWidget::paintGL(){
Primitive* p = (*i)->getChild();
int tesselation = p->getTesselation();
Primitive::Type type = p->getType();
qDebug() << "draw type " << type;
if (type == Primitive::Type::SPHERE){
drawSphere(tesselation);
}
else if (type == Primitive::Type::BOX){
}else if (type == Primitive::Type::BOX){
drawBox(tesselation);
}else if (type == Primitive::Type::CYLINDER){
drawCylinder(tesselation);
......@@ -336,8 +336,6 @@ void MyGLWidget::drawSphere(int tesselation){
GLUquadric* q = gluNewQuadric();
// gluQuadricDrawStyle(q, GLU_FILL);
gluSphere(q, 0.5, tesselation, tesselation);
glEnd();
}
......@@ -346,8 +344,6 @@ void MyGLWidget::drawBox(int tesselation){
double qubeWidth = 1.0;
double dist = qubeWidth / (double)tesselation;
//4.1.1 Unit Qube + Tesselation + Diffuse Material
......@@ -449,11 +445,50 @@ void MyGLWidget::drawBox(int tesselation){
}
void MyGLWidget::drawCylinder(int tesselation){
//Todo
qDebug("draw cylinder");
GLfloat specularColor[] = { 0.3, 0.5, 0.5 };
GLfloat shininess[] = { 120 };//specular exponent
glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
GLfloat cylinderColor[] = { 0.8,0.2,0.5 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, cylinderColor);
glNormal3f(0, 0, 1);
glBegin(GL_LINE_LOOP);
GLUquadric* quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_FILL);
gluCylinder(quadric,0.5,0.5,1,tesselation,tesselation);
gluQuadricOrientation(quadric,GLU_INSIDE);
gluDisk( quadric, 0.0, 0.5, tesselation, 1);
glTranslatef( 0,0,1 );
gluQuadricOrientation(quadric,GLU_OUTSIDE);
gluDisk( quadric, 0.0, 0.5, tesselation, 1);
gluDeleteQuadric(quadric);
glEnd();
}
void MyGLWidget::drawCone(int tesselation){
qDebug("draw cone");
GLfloat specularColor[] = { 0.3, 0.5, 0.5 };
GLfloat shininess[] = { 120 };//specular exponent
glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
GLfloat coneColor[] = { 0.8,0.8,0 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, coneColor);
glNormal3f(0, 0, 1);
glBegin(GL_LINE_LOOP);
GLUquadric* quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_FILL);
gluCylinder(quadric,0.5,0,1,tesselation,1);
gluQuadricOrientation(quadric,GLU_INSIDE);
gluDisk( quadric, 0.0, 0.5, tesselation, 1);
gluQuadricOrientation(quadric,GLU_OUTSIDE);
gluDeleteQuadric(quadric);
glEnd();
}
void MyGLWidget::drawTorus(int tesselation){
......
......@@ -45,18 +45,30 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
}
RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
qDebug("TODO add cylinder to scenegraph");
return addBox(1);
nextCylName = "Cylinder " + cylIndex;
Primitive* p = new Primitive(idCounter,nextCylName, tesselation+2, Primitive::Type::CYLINDER);
idCounter++;
cylIndex++;
qDebug("added Cylinder to scenegraph");
return addPrimitive(p);
}
RigidBodyTransformation* SceneGraph::addCone(int tesselation){
qDebug("TODO add cone to scenegraph");
return addBox(tesselation);
nextConeName = "Cone " + coneIndex;
Primitive* p = new Primitive(idCounter,nextConeName, tesselation+2, Primitive::Type::CONE);
idCounter++;
coneIndex++;
return addPrimitive(p);
}
RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
qDebug("TODO add torus to scenegraph");
return addBox(1);
nextTorusName = "Torus " + torusIndex;
Primitive* p = new Primitive(idCounter,nextTorusName, tesselation, Primitive::Type::TORUS);
idCounter++;
torusIndex++;
return addPrimitive(p);
}
RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment