sources:
attribute.cpp (1.1k)
attribute.h (1.5k)
cgapplication.cpp (4.1k)
cgapplication.h (4.8k)
cgrobot.cpp (7.9k)
cgrobot.h (716 bytes)
node.cpp (2.4k)
node.h (2.3k)
shape.cpp (3.2k)
shape.h (966 bytes)
transformation.cpp (2.9k)
transformation.h (2.4k)
vector.cpp (1.4k)
vector.h (5.3k)


website:
more info here


screenshot:
studies/grafik/Computergrafik-Code8/transformation.cpp
download file

  1 // Computergraphik I
  2 // Prof. Dr. Juergen Doellner
  3 // Sommersemester 2001
  4 //
  5 // Rahmenprogramm fuer Aufgabenzettel 8
  6
  7 #include "transformation.h"
  8
  9 #include <iostream.h>
 10 #include <GL/glut.h>
 11
 12 //
 13 // Camera
 14 //
 15
 16 Camera::Camera(const Vector& from, const Vector& to, const Vector& up)
 17        : from_(from), to_(to), up_(up)
 18 {
 19 }
 20
 21 void Camera::set()
 22 {
 23     glMatrixMode(GL_MODELVIEW);
 24     glPushMatrix();
 25     glLoadIdentity();
 26     gluLookAt(from_[0], from_[1], from_[2],
 27               to_[0],   to_[1],   to_[2],
 28               up_[0],   up_[1],   up_[2])
;
 29 }
 30
 31 void Camera::unset()
 32 {
 33     glMatrixMode(GL_MODELVIEW);
 34     glPopMatrix();
 35 }
 36
 37 void Camera::setFrom(const Vector& from)
 38 {
 39     from_ = from;
 40 }
 41
 42 void Camera::setTo(const Vector& to)
 43 {
 44     to_ = to;
 45 }
 46
 47 void Camera::setUp(const Vector& up)
 48 {
 49     up_ = up;
 50 }
 51
 52 Vector Camera::getFrom() const
 53 {
 54     return from_;
 55 }
 56
 57 Vector Camera::getTo() const
 58 {
 59     return to_;
 60 }
 61
 62 Vector Camera::getUp() const
 63 {
 64     return up_;
 65 }
 66
 67
 68 //
 69 // Translation
 70 //
 71
 72 Translation::Translation(const Vector& trans)
 73     : trans_(trans) {
 74 }
 75
 76 const Vector& Translation::getTranslation() const {
 77     return trans_;
 78 }
 79
 80 void Translation::setTranslation(const Vector& trans) {
 81     trans_ = trans;
 82 }
 83
 84 void Translation::set() {
 85     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
 86     glPushMatrix(); // Speichere die aktuelle Matrix
 87     glTranslated(trans_[0], trans_[1], trans_[2]); // Transliere
 88 }
 89
 90 void Translation::unset() {
 91     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
 92     glPopMatrix(); // Restauriere die vorherige Matrix
 93 }
 94
 95 //
 96 // Scaling
 97 //
 98
 99 Scaling::Scaling(const Vector& scale)
100     : scale_(scale) {
101 }
102
103 const Vector& Scaling::getScaling() const {
104     return scale_;
105 }
106
107 void Scaling::setScaling(const Vector& scale) {
108     scale_ = scale;
109 }
110
111 void Scaling::set() {
112     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
113     glPushMatrix(); // Speichere die aktuelle Matrix
114     glScaled(scale_[0], scale_[1], scale_[2]); // Skaliere
115 }
116
117 void Scaling::unset() {
118     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
119     glPopMatrix(); // Restauriere die vorherige Matrix
120 }
121
122 //
123 // Rotation
124 //
125
126 Rotation::Rotation(double angle, const Vector& axis)
127     : axis_(axis) {
128     setAngle(angle);
129 }
130
131 double Rotation::getAngle() const {
132     return angle_;
133 }
134
135 const Vector& Rotation::getAxis() const {
136     return axis_;
137 }
138
139 void Rotation::setAngle(double angle) {
140     angle_ = angle;
141     while(angle_ >= 360) { angle_ -= 360; }
142     while(angle_ <    0) { angle_ += 360; }
143 }
144
145 void Rotation::setAxis(const Vector& axis) {
146     axis_ = axis;
147 }
148
149 void Rotation::set() {
150     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
151     glPushMatrix(); // Speichere die aktuelle Matrix
152     glRotated(angle_, axis_[0], axis_[1], axis_[2]); // Rotiere
153 }
154
155 void Rotation::unset() {
156     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
157     glPopMatrix(); // Restauriere die vorherige Matrix
158 }
159