Render cube
This commit is contained in:
parent
cc03214142
commit
1dca5470f6
1 changed files with 74 additions and 12 deletions
|
@ -60,8 +60,8 @@ void cube_system::render_system()
|
|||
Nutzen Sie glPushMatrix um die aktuelle Gesamttransformations-Matrix an die
|
||||
Spitze eines Stacks zu speichern und glPopMatrix um die vorderste Matrix
|
||||
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
|
||||
Variable für Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
|
||||
"angle" zur Verfuegung (die Werte zwischen 0 und 359 enth<EFBFBD>lt). Nutzen Sie diese
|
||||
Variable f<EFBFBD>r Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
|
||||
*********/
|
||||
|
||||
|
||||
|
@ -73,7 +73,26 @@ 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
|
||||
void cube_system::render_cube()
|
||||
|
@ -86,9 +105,52 @@ void cube_system::render_cube()
|
|||
Aufgabe 2.1.1. Tesellieren Sie einen Wuerfel, indem Sie Vertices und Farben mittels
|
||||
der Kommandos glVertex3d und glColor3d spezifizieren. Waehlen Sie
|
||||
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.
|
||||
*********/
|
||||
|
||||
/*
|
||||
|
||||
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
|
||||
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