-
Notifications
You must be signed in to change notification settings - Fork 0
/
Impostor.cpp
82 lines (69 loc) · 1.53 KB
/
Impostor.cpp
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
#include "Impostor.h"
#include "Cube.h"
Impostor::Impostor() {
_numDivisions = 1;
_domain = 1;
_delta = 0;
}
Impostor::Impostor(int divisions, double domain, double delta) {
_numDivisions = divisions;
_domain = domain;
_delta = delta;
}
float Impostor::getTextureX(int opt) {
switch (opt) {
case 0:
return -1;
case 1:
return 0.04;
case 2:
return 0.96;
case 3:
return 2;
}
}
float Impostor::getTextureZ(int opt) {
switch (opt) {
case 0:
return -1;
case 1:
return 0.05;
case 2:
return 0.95;
case 3:
return 2;
}
}
Impostor::~Impostor(void) {
}
void Impostor::draw() {
glPushMatrix();
glRotatef(180.0, 1, 0, 0);
glTranslatef(-0.5, 0.0, -0.5);
glScalef(1.0 / (double) _numDivisions, 1, 1.0 / (double) _numDivisions);
glNormal3f(0, -1, 0);
for (int bx = 0; bx < _numDivisions; bx++) {
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(getTextureX(bx), getTextureZ(0));
glVertex3f(bx, 0, 0);
for (int bz = 0; bz < _numDivisions; bz++) {
if (bz == 1 && bx == 1) {
glTexCoord2d(getTextureX(bx + 1), getTextureZ(bz));
glVertex3f(bx + 1, 0, bz);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(getTextureX(bx), getTextureZ(bz + 1));
glVertex3f(bx, 0, bz + 1);
} else {
glTexCoord2d(getTextureX(bx + 1), getTextureZ(bz));
glVertex3f(bx + 1, 0, bz);
glTexCoord2d(getTextureX(bx), getTextureZ(bz + 1));
glVertex3f(bx, 0, bz + 1);
}
}
glTexCoord2d(getTextureX(bx + 1), getTextureZ(_numDivisions));
glVertex3d(bx + 1, 0, _numDivisions);
glEnd();
}
glPopMatrix();
}