diff --git a/exercise3/include/matrix.h b/exercise3/include/matrix.h index bddc786..65697b6 100644 --- a/exercise3/include/matrix.h +++ b/exercise3/include/matrix.h @@ -11,12 +11,12 @@ public: T c0r0, T c0r1, T c0r2, T c0r3, T c1r0, T c1r1, T c1r2, T c1r3, T c2r0, T c2r1, T c2r2, T c2r3, - T c3r0, T c3r1, T c3r2, T c3r3, + T c3r0, T c3r1, T c3r2, T c3r3 ) { - x = tiny_vec(c0r0, c0r1, c0r2, c0r3); - y = tiny_vec(c1r0, c1r1, c1r2, c1r3); - z = tiny_vec(c2r0, c2r1, c2r2, c2r3); - w = tiny_vec(c3r0, c3r1, c3r2, c3r3); + x = tiny_vec(c0r0, c0r1, c0r2, c0r3); + y = tiny_vec(c1r0, c1r1, c1r2, c1r3); + z = tiny_vec(c2r0, c2r1, c2r2, c2r3); + w = tiny_vec(c3r0, c3r1, c3r2, c3r3); } ~Matrix4() { } @@ -26,12 +26,12 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( one, zero, zero, zero, zero, one, zero, zero, zero, zero, one, zero, zero, zero, zero, one - ) + ); } static Matrix4 from_translation(tiny_vec v) @@ -39,17 +39,17 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( one, zero, zero, zero, zero, one, zero, zero, zero, zero, one, zero, - v.x, v.y, v.z, one, - ) + v.x, v.y, v.z, one + ); } static Matrix4 from_scale(T s) { - from_non_uniform_scale(s, s, s) + return from_non_uniform_scale(s, s, s); } static Matrix4 from_non_uniform_scale(T x, T y, T z) @@ -57,12 +57,12 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( x, zero, zero, zero, zero, y, zero, zero, zero, zero, z, zero, - zero, zero, zero, one, - ) + zero, zero, zero, one + ); } static Matrix4 from_angle_x(T a) @@ -73,12 +73,12 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( one, zero, zero, zero, zero, c, s, zero, zero, -s, c, zero, - zero, zero, zero, one, - ) + zero, zero, zero, one + ); } static Matrix4 from_angle_y(T a) @@ -89,12 +89,12 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( c, zero, -s, zero, zero, one, zero, zero, s, zero, c, zero, zero, zero, zero, one - ) + ); } static Matrix4 from_angle_z(T a) @@ -105,12 +105,12 @@ public: T zero = T::value_type(0); T one = T::value_type(1); - Matrix4( + return Matrix4( c, s, zero, zero, -s, c, zero, zero, zero, zero, one, zero, zero, zero, zero, one - ) + ); } @@ -123,4 +123,4 @@ private: tiny_vec z; // fourth column tiny_vec w; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/exercise3/src/cube_system.cpp b/exercise3/src/cube_system.cpp index 610fb86..7d0acad 100644 --- a/exercise3/src/cube_system.cpp +++ b/exercise3/src/cube_system.cpp @@ -4,6 +4,7 @@ // Copyright (C) 2016 CGV TU Dresden - All Rights Reserved // #include "cube_system.h" +#include "matrix.h" // Initialize variables cube_system::cube_system() @@ -11,7 +12,26 @@ cube_system::cube_system() angle = 0; } - +void render_cube_face( + const double color[3], + const double p0[3], + const double p1[3], + const double p2[3], + const double p3[3]) +{ + glColor3dv(color); + glVertex3dv(p0); + glColor3dv(color); + glVertex3dv(p1); + glColor3dv(color); + glVertex3dv(p2); + glColor3dv(color); + glVertex3dv(p2); + glColor3dv(color); + glVertex3dv(p3); + glColor3dv(color); + glVertex3dv(p0); +} // Setup the scene and render cube system void cube_system::render() @@ -68,31 +88,55 @@ void cube_system::render_system() // Remove the following statement (if wanted) as it just serves 2.1.1. // Entfernen Sie die folgende Anweisung gegebenenfalls, da sie lediglich dem Testen // von Aufgabe 2.1.1 dient. - render_cube(); + + glPushMatrix(); + glRotatef(angle, 0.0f, 1.0f, 0.0f); + render_cube(); + glPopMatrix(); + + glPushMatrix(); + glRotatef(-angle, 0.0f, 1.0f, 0.0f); + + glPushMatrix(); + glTranslatef(5.0f, 0.0, 0.0); + + glPushMatrix(); + glScalef(0.6f, 0.6f, 0.6f); + + glPushMatrix(); + glRotatef(2 * angle, 0.0f , 0.0f, 1.0f); + + glPushMatrix(); + glTranslatef(3.0f, 0.0f, 0.0f); + + glPushMatrix(); + glScalef(0.5f, 0.5f, 0.5f); + render_cube(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); + + render_cube(); + + glPushMatrix(); + glRotatef(2*angle + 180.0f, 0.0f, 0.0f, 1.0f); + + glPushMatrix(); + glTranslatef(3.0f, 0.0f, 0.0f); + + glPushMatrix(); + glScalef(0.5f, 0.5f, 0.5f); + render_cube(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); } -void render_cube_face( - const double color[3], - const double p0[3], - const double p1[3], - const double p2[3], - const double p3[3]) -{ - glColor3dv(color); - glVertex3dv(p0); - glColor3dv(color); - glVertex3dv(p1); - glColor3dv(color); - glVertex3dv(p2); - glColor3dv(color); - glVertex3dv(p2); - glColor3dv(color); - glVertex3dv(p3); - glColor3dv(color); - glVertex3dv(p0); -} // Render one single cube void cube_system::render_cube()