diff --git a/include/glumodel.h b/include/glumodel.h new file mode 100644 index 0000000..626aab5 --- /dev/null +++ b/include/glumodel.h @@ -0,0 +1,32 @@ +#ifndef _GLUMODEL_H +#define _GLUMODEL_H + +#include "vec.h" +#include + +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(); +}; + +#endif diff --git a/include/model.h b/include/model.h index fd9af66..f53c4b1 100755 --- a/include/model.h +++ b/include/model.h @@ -44,27 +44,3 @@ }; #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/glumodel.cpp b/sources/glumodel.cpp new file mode 100644 index 0000000..1b9a06b --- /dev/null +++ b/sources/glumodel.cpp @@ -0,0 +1,51 @@ +#include "glumodel.h" + +#include + +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/main.cpp b/sources/main.cpp index f2cb99e..e6a3b76 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -53,6 +53,7 @@ #include "thing.h" #include "poly.h" #include "model.h" +#include "glumodel.h" #include "animation.h" #include "light.h" diff --git a/sources/model.cpp b/sources/model.cpp index 8d05112..c7560f3 100755 --- a/sources/model.cpp +++ b/sources/model.cpp @@ -159,53 +159,3 @@ } } - -//------------------------------------------------------- - -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(); - -} -