// Computergraphik I // Prof. Dr. Juergen Doellner // Sommersemester 2001 // // Rahmenprogramm fuer Aufgabenzettel 8 #include "transformation.h" #include #include // // Camera // Camera::Camera(const Vector& from, const Vector& to, const Vector& up) : from_(from), to_(to), up_(up) { } void Camera::set() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt(from_[0], from_[1], from_[2], to_[0], to_[1], to_[2], up_[0], up_[1], up_[2]); } void Camera::unset() { glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void Camera::setFrom(const Vector& from) { from_ = from; } void Camera::setTo(const Vector& to) { to_ = to; } void Camera::setUp(const Vector& up) { up_ = up; } Vector Camera::getFrom() const { return from_; } Vector Camera::getTo() const { return to_; } Vector Camera::getUp() const { return up_; } // // Translation // Translation::Translation(const Vector& trans) : trans_(trans) { } const Vector& Translation::getTranslation() const { return trans_; } void Translation::setTranslation(const Vector& trans) { trans_ = trans; } void Translation::set() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPushMatrix(); // Speichere die aktuelle Matrix glTranslated(trans_[0], trans_[1], trans_[2]); // Transliere } void Translation::unset() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPopMatrix(); // Restauriere die vorherige Matrix } // // Scaling // Scaling::Scaling(const Vector& scale) : scale_(scale) { } const Vector& Scaling::getScaling() const { return scale_; } void Scaling::setScaling(const Vector& scale) { scale_ = scale; } void Scaling::set() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPushMatrix(); // Speichere die aktuelle Matrix glScaled(scale_[0], scale_[1], scale_[2]); // Skaliere } void Scaling::unset() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPopMatrix(); // Restauriere die vorherige Matrix } // // Rotation // Rotation::Rotation(double angle, const Vector& axis) : axis_(axis) { setAngle(angle); } double Rotation::getAngle() const { return angle_; } const Vector& Rotation::getAxis() const { return axis_; } void Rotation::setAngle(double angle) { angle_ = angle; while(angle_ >= 360) { angle_ -= 360; } while(angle_ < 0) { angle_ += 360; } } void Rotation::setAxis(const Vector& axis) { axis_ = axis; } void Rotation::set() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPushMatrix(); // Speichere die aktuelle Matrix glRotated(angle_, axis_[0], axis_[1], axis_[2]); // Rotiere } void Rotation::unset() { glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix glPopMatrix(); // Restauriere die vorherige Matrix }