-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloor.cpp
More file actions
109 lines (79 loc) · 2.33 KB
/
Floor.cpp
File metadata and controls
109 lines (79 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "stdafx.h"
#include "Floor.h"
//---------------------------------------------------------------------
// Method: init
// Author: Eric Bachmann
// Function: Initializes the "checker board" floor xyz location.
// Initializes the "checker board" floor size.
// The floor is oriented in the the xz plane.
// Compiles a display list to be used when drawing the floor.
// Parameters:
// x - x coordinate of the middle of the floor
// y - y coordinate of the middle of the floor
// z - z coordinate of the middle of the floor
// sideLength - the length of the sides of the square board.
//
// Returns: None
// Called By:
// Calls: None
//---------------------------------------------------------------------
void Floor::init(float x, float y, float z, float sideLength)
{
GLfloat v[3]={0};
GLfloat board_spec[] = {0.25, 0.25, 0.25, 1.0};
short color = 1;
floorList = glGenLists(1);
glNewList(floorList, GL_COMPILE);
GLfloat tileWidth = sideLength / 8.0f;
GLfloat tileX = x - (4.0f * tileWidth);
GLfloat tileZ = z + (4.0f * tileWidth);
// define the two colors
GLfloat color1[3] = { 0.9f, 0.9f, 0.9f };
GLfloat color2[3] = { 0.05f, 0.05f, 0.05f };
glNormal3f(0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_SPECULAR, board_spec);
for ( int j = 0 ; j < 8; j++ ) {
glColor3fv( (color++)%2 ? color1 : color2 );
for ( int i = 0 ; i < 8 ; i++ ) {
glBegin (GL_POLYGON );
glColor3fv( (color++)%2 ? color1 : color2 );
v[0] = tileX;
v[1] = y;
v[2] = tileZ-tileWidth;
glVertex3fv(v);
v[0] = tileX;
v[1] = y;
v[2] = tileZ;
glVertex3fv(v);
tileX++;
v[0] = tileX;
v[1] = y;
v[2] = tileZ;
glVertex3fv(v);
v[0] = tileX;
v[1] = y;
v[2] = tileZ-tileWidth;
glVertex3fv(v);
glEnd();
} // end for
tileX = x - (4.0f * tileWidth);
tileZ -= tileWidth;
}
glEndList();
} // end initFloor
//---------------------------------------------------------------------
// Method: draw
// Function: Draws a floor object with the size and location specified
// by the class data members.
// Parameters:
// None
//
// Returns: Void
// Called By:
// Calls: None
//---------------------------------------------------------------------
void Floor::draw()
{
glCallList(floorList);
} // end draw
// *********************** END FLOOR CLASS *****************************