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     return from_;
 54 }
 55
 56 Vector Camera::getTo() const {
 57     return to_;
 58 }
 59
 60 Vector Camera::getUp() const {
 61     return up_;
 62 }
 63
 64
 65 //
 66 // Translation
 67 //
 68
 69 Translation::Translation(const Vector& trans)
 70     : trans_(trans) {
 71 }
 72
 73 const Vector& Translation::getTranslation() const {
 74     return trans_;
 75 }
 76
 77 void Translation::setTranslation(const Vector& trans) {
 78     trans_ = trans;
 79 }
 80
 81 void Translation::set() {
 82     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
 83     glPushMatrix(); // Speichere die aktuelle Matrix
 84     glTranslated(trans_[0], trans_[1], trans_[2]); // Transliere
 85 }
 86
 87 void Translation::unset() {
 88     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
 89     glPopMatrix(); // Restauriere die vorherige Matrix
 90 }
 91
 92 //
 93 // Scaling
 94 //
 95
 96 Scaling::Scaling(const Vector& scale)
 97     : scale_(scale) {
 98 }
 99
100 const Vector& Scaling::getScaling() const {
101     return scale_;
102 }
103
104 void Scaling::setScaling(const Vector& scale) {
105     scale_ = scale;
106 }
107
108 void Scaling::set() {
109     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
110     glPushMatrix(); // Speichere die aktuelle Matrix
111     glScaled(scale_[0], scale_[1], scale_[2]); // Skaliere
112 }
113
114 void Scaling::unset() {
115     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
116     glPopMatrix(); // Restauriere die vorherige Matrix
117 }
118
119 //
120 // Rotation
121 //
122
123 Rotation::Rotation(double angle, const Vector& axis)
124     : axis_(axis) {
125     setAngle(angle);
126 }
127
128 double Rotation::getAngle() const {
129     return angle_;
130 }
131
132 const Vector& Rotation::getAxis() const {
133     return axis_;
134 }
135
136 void Rotation::setAngle(double angle) {
137     angle_ = angle;
138     while(angle_ >= 360) { angle_ -= 360; }
139     while(angle_ <    0) { angle_ += 360; }
140 }
141
142 void Rotation::setAxis(const Vector& axis) {
143     axis_ = axis;
144 }
145
146 void Rotation::set() {
147     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
148     glPushMatrix(); // Speichere die aktuelle Matrix
149     glRotated(angle_, axis_[0], axis_[1], axis_[2]); // Rotiere
150 }
151
152 void Rotation::unset() {
153     glMatrixMode(GL_MODELVIEW); // Aktiviere die Modelview-Matrix
154     glPopMatrix(); // Restauriere die vorherige Matrix
155 }
156
157