diff --git a/include/light.h b/include/light.h index 025a5d7..070bb75 100755 --- a/include/light.h +++ b/include/light.h @@ -12,11 +12,12 @@ class Light : public Thing { protected: GLUquadricObj* sphere; + bool showtrace; bool enabled; GLenum num; Vec *pos; Material *mat; - + Vec *rot; public: @@ -29,6 +30,7 @@ void show(); void hide(); void draw(); + void trace(bool _s); }; class SpotLight: public Light{ diff --git a/include/material.h b/include/material.h index a06f6bb..0a1f208 100644 --- a/include/material.h +++ b/include/material.h @@ -13,11 +13,12 @@ Material(); Material(Color _ambient); Material(Color _ambient, Color _specular); + void init(Color _ambient, Color _specular); Material* clone(); void vardump(std::string whitespace); void ptdump(std::string whitespace); - void drawMaterial(); + void draw(); }; #endif diff --git a/include/model.h b/include/model.h index 697d929..fd9af66 100755 --- a/include/model.h +++ b/include/model.h @@ -43,3 +43,28 @@ void scale(float f); }; #endif + +class GluModel : public Thing { + public: + GLUquadricObj* pt; + Vec* pos; + Vec* rot; + Material* mat; + float scale; + bool enabled; + GluModel(); + GluModel(Vec _pos, Material _mat); + void init(Vec _pos, Material _mat); + + void setMaterial(Color _amb); + void setMaterial(Color _amb, Color _spec); +}; + +class GluSphere : public GluModel { + public: + float rad; + GluSphere(); + GluSphere(Vec _pos, Material _mat, float _rad); + void init(Vec _pos, Material _mat, float _rad); + void draw(); +}; diff --git a/sources/light.cpp b/sources/light.cpp index 941231c..ecf84b5 100755 --- a/sources/light.cpp +++ b/sources/light.cpp @@ -14,6 +14,7 @@ pos = _pos.clone(); mat = _mat.clone(); rot = new Vec(0,0,0); + showtrace = true; sphere = gluNewQuadric(); //glLightfv(num, GL_AMBIENT, mat->ambient->v()); @@ -25,6 +26,10 @@ show(); } +void Light::trace(bool _s) { + showtrace = _s; +} + void Light::show() { enabled = true; glEnable(num); @@ -54,10 +59,12 @@ float p[] = {0.0f, 0.0f, 0.0f, 1.0f}; glLightfv(num, GL_POSITION, p); - //sphere - float c[] = {1,1,1,1}; - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c); - gluSphere(sphere, 1, 10, 10); + if (showtrace) { + //sphere + float c[] = {1,1,1,1}; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, c); + gluSphere(sphere, 1, 10, 10); + } glPopMatrix(); } @@ -87,11 +94,13 @@ GLfloat dir[] = {0.0f, -1.0f, 0.0f, 1.0f}; glLightfv(num, GL_SPOT_DIRECTION, dir); + + if (showtrace) { + //cone + glTranslatef(0,5.5,0); + glRotatef(90, 1, 0, 0); + gluCylinder (cone, 0, 1, 5, 10, 20); - //cone - glTranslatef(0,5.5,0); - glRotatef(90, 1, 0, 0); - gluCylinder (cone, 0, 1, 5, 10, 20); - + } glPopMatrix(); } diff --git a/sources/main.cpp b/sources/main.cpp index e75793d..f2cb99e 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -239,6 +239,10 @@ int fog = 3; + GluSphere mysphere (Vec(0,-50,0), + Material(Color(1,1,0)), + 50); + /* begin cube */ Vec* ulh = new Vec(0 ,0 ,0 ); Vec* ulv = new Vec(0 ,0 ,10); @@ -387,15 +391,15 @@ SpotLight light0(GL_LIGHT0, - Vec (3, 50, 3), + Vec (0, 50, 0), Material(Color(0.5,0.5,0.5), //Color(0.5,0.5,0.5), - Color(0,0,0)), + Color(1,1,1)), 90); Light light1(GL_LIGHT1, Vec (20, 20, 20), Material(Color(0.5,0.5,0.5), - Color(0,0,0))); + Color(1,1,1))); //Vec l1_pos(-10.0f, -10.0f, -10.0f); //Color l1_col(0.0f, 0.5f, 1.0f); @@ -510,22 +514,24 @@ glEnd(); //sphere - glPushMatrix(); - float mat[] = {0.5,0.5,0.5}; - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat); - glMaterialfv(GL_FRONT, GL_SPECULAR, mat); - glTranslatef(0,-60,0); - gluSphere(gluNewQuadric(), 50, 300, 300); - glPopMatrix(); - - cube->draw(); - myModel->draw(); +// glPushMatrix(); +// Material m = Material(Color(0.5,0.5,0.5),Color(0.5,0.5,0.5)); +// m.draw(); +// //float mat[] = {0.5,0.5,0.5,1.0}; +// //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat); +// //glMaterialfv(GL_FRONT, GL_SPECULAR, mat); +// //glMateriali(GL_FRONT, GL_SHININESS, 96); +// glTranslatef(0,-60,0); +// gluSphere(gluNewQuadric(), 50, 300, 300); +// glPopMatrix(); + mysphere.draw(); //draw cube - //cube->draw(); - //cube->rotate(Vec(0.1f, 0.5f, 1.0f)); - //myModel->draw(); - //myModel->rotate(Vec(0.2f, 0.3f, 1.2f)); + cube->draw(); + + //draw imported model + myModel->draw(); + //////////////// diff --git a/sources/material.cpp b/sources/material.cpp index 37653a1..0aa87a1 100644 --- a/sources/material.cpp +++ b/sources/material.cpp @@ -4,23 +4,30 @@ #include Material::Material() { - ambient = new Color(0,0,0); - specular = new Color(0.1,0.1,0.1); + Color _ambient = Color(0.5,0.5,0.5); + Color _specular = Color(0.5,0.5,0.5); + init(_ambient, _specular); + } Material::Material(Color _ambient) { - ambient = _ambient.clone(); - specular = new Color(0,0,0); + Color _specular = Color(0.5,0.5,0.5); + init(_ambient, _specular); } Material::Material(Color _ambient, Color _specular) { + init(_ambient, _specular); +} + +void Material::init(Color _ambient, Color _specular) { ambient = _ambient.clone(); specular = _specular.clone(); } -void Material::drawMaterial() { +void Material::draw() { ambient->drawColor(); specular->drawColor(GL_SPECULAR); + glMateriali(GL_FRONT, GL_SHININESS, 45); } Material* Material::clone() { diff --git a/sources/model.cpp b/sources/model.cpp index 0a0319f..8d05112 100755 --- a/sources/model.cpp +++ b/sources/model.cpp @@ -158,3 +158,54 @@ faces.at(i)->setPosition(p); } } + + +//------------------------------------------------------- + +GluModel::GluModel() { + init(Vec(0,0,0), Material()); +} + +GluModel::GluModel(Vec _pos, Material _mat) { + init(_pos, _mat); +} + +void GluModel::init(Vec _pos, Material _mat) { + pos = _pos.clone(); + rot = new Vec(0,0,0); + scale = 1; + mat = _mat.clone(); + pt = gluNewQuadric(); + enabled = true; +} + +GluSphere::GluSphere() { + init(Vec(0,0,0), Material(Color(1,0,1)), 10); +} + +GluSphere::GluSphere(Vec _pos, Material _mat, float _rad) { + init(_pos, _mat, _rad); +} + +void GluSphere::init(Vec _pos, Material _mat, float _rad) { + GluModel::init(_pos, _mat); + rad = _rad; +} + +void GluSphere::draw() { + glPushMatrix(); + + glRotatef(rot->x(), 1.0f, 0.0f, 0.0f); + glRotatef(rot->y(), 0.0f, 1.0f, 0.0f); + glRotatef(rot->z(), 0.0f, 0.0f, 1.0f); + + glTranslatef(pos->x(), pos->y(), pos->z()); + + if (enabled) { + mat->draw(); + gluSphere(gluNewQuadric(), rad, 300, 300); + } + glPopMatrix(); + +} + diff --git a/sources/poly.cpp b/sources/poly.cpp index 8503834..8f3323a 100755 --- a/sources/poly.cpp +++ b/sources/poly.cpp @@ -37,8 +37,7 @@ center = new Vec(0,0,0); normal = new Vec(0,0,0); - Color c2 = Color(0,0,0); - material = new Material(_color, c2); + material = new Material(_color); for (std::vector::size_type i = 0 ; i < _points.size(); i++ ) { addPoint(_points.at(i)); @@ -242,7 +241,7 @@ glNormal3fv(n.c); } - material->drawMaterial(); + material->draw(); glVertex3fv((*initpoints.at(i)).c); }