Render cube
This commit is contained in:
parent
cc03214142
commit
1dca5470f6
1 changed files with 74 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// This source code is property of the Computer Graphics and Visualization
|
// This source code is property of the Computer Graphics and Visualization
|
||||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||||
//
|
//
|
||||||
#include "cube_system.h"
|
#include "cube_system.h"
|
||||||
|
@ -51,17 +51,17 @@ void cube_system::render_system()
|
||||||
{
|
{
|
||||||
/********
|
/********
|
||||||
Task 2.1.2. Program the transformation tree from the exercise sheet. To store the
|
Task 2.1.2. Program the transformation tree from the exercise sheet. To store the
|
||||||
active aggregated transformation matrix on top of a stack use glPushMatrix
|
active aggregated transformation matrix on top of a stack use glPushMatrix
|
||||||
and to reactivate and remove the top element of the transformation stack
|
and to reactivate and remove the top element of the transformation stack
|
||||||
use glPopMatrix. For animation a variable "angle" (which has values
|
use glPopMatrix. For animation a variable "angle" (which has values
|
||||||
between 0 and 359) is defined. Use it for rotations as defined in
|
between 0 and 359) is defined. Use it for rotations as defined in
|
||||||
the transformation tree.
|
the transformation tree.
|
||||||
Aufgabe 2.1.2. Programmieren Sie den Transformationsbaum aus dem Uebungsblatt.
|
Aufgabe 2.1.2. Programmieren Sie den Transformationsbaum aus dem Uebungsblatt.
|
||||||
Nutzen Sie glPushMatrix um die aktuelle Gesamttransformations-Matrix an die
|
Nutzen Sie glPushMatrix um die aktuelle Gesamttransformations-Matrix an die
|
||||||
Spitze eines Stacks zu speichern und glPopMatrix um die vorderste Matrix
|
Spitze eines Stacks zu speichern und glPopMatrix um die vorderste Matrix
|
||||||
im Stack zu entfernen und zu reaktivieren. Fuer Animationen steht eine Variable
|
im Stack zu entfernen und zu reaktivieren. Fuer Animationen steht eine Variable
|
||||||
"angle" zur Verfuegung (die Werte zwischen 0 und 359 enthält). Nutzen Sie diese
|
"angle" zur Verfuegung (die Werte zwischen 0 und 359 enth<EFBFBD>lt). Nutzen Sie diese
|
||||||
Variable für Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
|
Variable f<EFBFBD>r Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
|
||||||
*********/
|
*********/
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,22 +73,84 @@ void cube_system::render_system()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void render_cube_face(
|
||||||
|
const double color[3],
|
||||||
|
const double p0[3],
|
||||||
|
const double p1[3],
|
||||||
|
const double p2[3],
|
||||||
|
const double p3[3])
|
||||||
|
{
|
||||||
|
glVertex3dv(p0);
|
||||||
|
glColor3dv(color);
|
||||||
|
glVertex3dv(p1);
|
||||||
|
glColor3dv(color);
|
||||||
|
glVertex3dv(p2);
|
||||||
|
glColor3dv(color);
|
||||||
|
glVertex3dv(p2);
|
||||||
|
glColor3dv(color);
|
||||||
|
glVertex3dv(p3);
|
||||||
|
glColor3dv(color);
|
||||||
|
glVertex3dv(p0);
|
||||||
|
glColor3dv(color);
|
||||||
|
}
|
||||||
|
|
||||||
// Render one single cube
|
// Render one single cube
|
||||||
void cube_system::render_cube()
|
void cube_system::render_cube()
|
||||||
{
|
{
|
||||||
/********
|
/********
|
||||||
Task 2.1.1. Tesellate a cube by specifying vertices and colors via the commands
|
Task 2.1.1. Tesellate a cube by specifying vertices and colors via the commands
|
||||||
glVertex3d and glColor3d. Choose appropriate primitives (parameter to
|
glVertex3d and glColor3d. Choose appropriate primitives (parameter to
|
||||||
glBegin) and provide vertices and colors for all 6 sides. The cube shall
|
glBegin) and provide vertices and colors for all 6 sides. The cube shall
|
||||||
range from (-1, -1, -1) to (1, 1, 1).
|
range from (-1, -1, -1) to (1, 1, 1).
|
||||||
Aufgabe 2.1.1. Tesellieren Sie einen Wuerfel, indem Sie Vertices und Farben mittels
|
Aufgabe 2.1.1. Tesellieren Sie einen Wuerfel, indem Sie Vertices und Farben mittels
|
||||||
der Kommandos glVertex3d und glColor3d spezifizieren. Waehlen Sie
|
der Kommandos glVertex3d und glColor3d spezifizieren. Waehlen Sie
|
||||||
zunaechst das passende Zeichenprimitiv (Parameter von glBegin) und
|
zunaechst das passende Zeichenprimitiv (Parameter von glBegin) und
|
||||||
erstellen Sie Vertices und Farben für alle 6 Seiten. Der Wuerfel soll
|
erstellen Sie Vertices und Farben f<EFBFBD>r alle 6 Seiten. Der Wuerfel soll
|
||||||
von (-1, -1, -1) bis (1, 1, 1) reichen.
|
von (-1, -1, -1) bis (1, 1, 1) reichen.
|
||||||
*********/
|
*********/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
4 ----------- 3
|
||||||
|
/. /|
|
||||||
|
/ . / |
|
||||||
|
/ . / |
|
||||||
|
1 ----------- 2 |
|
||||||
|
| 8 . . . . | . 7
|
||||||
|
| . | /
|
||||||
|
| . | /
|
||||||
|
|. |/
|
||||||
|
5 ----------- 6
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
const double vertices[8][3] = {
|
||||||
|
{-1.0, -1.0, 1.0},
|
||||||
|
{ 1.0, -1.0, 1.0},
|
||||||
|
{ 1.0, 1.0, 1.0},
|
||||||
|
{-1.0, 1.0, 1.0},
|
||||||
|
{-1.0, -1.0, -1.0},
|
||||||
|
{ 1.0, -1.0, -1.0},
|
||||||
|
{ 1.0, 1.0, -1.0},
|
||||||
|
{-1.0, 1.0, -1.0}
|
||||||
|
};
|
||||||
|
|
||||||
|
const double colors[6][3] = {
|
||||||
|
{1.0, 0.0, 0.0},
|
||||||
|
{0.0, 1.0, 0.0},
|
||||||
|
{0.0, 0.0, 1.0},
|
||||||
|
{1.0, 1.0, 0.0},
|
||||||
|
{1.0, 0.0, 1.0},
|
||||||
|
{0.0, 1.0, 1.0},
|
||||||
|
};
|
||||||
|
|
||||||
|
render_cube_face(colors[0], vertices[0], vertices[1], vertices[2], vertices[3]);
|
||||||
|
render_cube_face(colors[1], vertices[1], vertices[5], vertices[6], vertices[2]);
|
||||||
|
render_cube_face(colors[2], vertices[5], vertices[4], vertices[7], vertices[6]);
|
||||||
|
render_cube_face(colors[3], vertices[4], vertices[0], vertices[3], vertices[7]);
|
||||||
|
render_cube_face(colors[4], vertices[4], vertices[5], vertices[1], vertices[0]);
|
||||||
|
render_cube_face(colors[5], vertices[6], vertices[7], vertices[3], vertices[2]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,5 +178,5 @@ void cube_system::setup_projection()
|
||||||
// Set debug text
|
// Set debug text
|
||||||
void cube_system::set_text(std::stringstream &stream)
|
void cube_system::set_text(std::stringstream &stream)
|
||||||
{
|
{
|
||||||
stream<<"Showing cube system (with rotation parameter at "<<angle<<"°)";
|
stream<<"Showing cube system (with rotation parameter at "<<angle<<"<EFBFBD>)";
|
||||||
}
|
}
|
Loading…
Reference in a new issue