forked from Milez213/CityTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameSceneryTree.h
91 lines (70 loc) · 3.06 KB
/
GameSceneryTree.h
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
//
// GameRamp.h
//
//
// Created by Bryan Bell on 1/30/13.
//
// NOTE: Do not rotate this object by anything but the y-axis,
// it will not work properly if the object is not flat.
#ifndef ____GameTree__
#define ____GameTree__
#include <iostream>
#include "GameSceneryObject.h"
PhongMaterial tree_materials[2] = {
{vec3(0.2, 0.2, 0.2), // amb
vec3(H2_3f(0x6d4100)), // diff
vec3(0, 0, 0), // spec
10.0}, // shine
{vec3(0.2, 0.2, 0.2), // amb
vec3(H2_3f(0x0d5600)), // diff
vec3(0.1, 0.8, 0.1), // spec
20.0}, // shine
};
class GameSceneryTree : public GameSceneryObject {
public:
GameSceneryTree() : GameSceneryObject("models/colorCoatRack.obj") {
}
float getHeightAt(float x, float z) {
float dist = glm::distance(getPosition(), vec3(x, getPosition().y, z));
if (dist > 0.5) {
return getPosition().y - getScale().y + 0.5;
}
return getPosition().y + getScale().y;// + boundingInfo.dimension.y*2;
}
virtual void draw(PhongShader *meshShader, RenderingHelper modelViewMatrix, float levelOfDetail)
{
int LoD = lodIndex(levelOfDetail);
modelViewMatrix.pushMatrix();
meshShader->use();
modelViewMatrix.translate(vec3(getPosition().x, getPosition().y - 0.8f * scl.y,getPosition().z));
modelViewMatrix.scale(scl.x, scl.y, scl.z);
modelViewMatrix.rotate(rot.x, vec3(1.0, 0.0, 0.0));
modelViewMatrix.rotate(rot.y, vec3(0.0, 1.0, 0.0));
modelViewMatrix.rotate(rot.z, vec3(0.0, 0.0, 1.0));
meshShader->setModelMatrix(modelViewMatrix.getMatrix());
GLuint h_aPos = meshShader->getPosLocation();
GLuint h_aNorm = meshShader->getNormLocation();
// TODO - add texture buffer
safe_glEnableVertexAttribArray(h_aPos);
glBindBuffer(GL_ARRAY_BUFFER, meshStorage[LoD].vertexBuffer);
safe_glVertexAttribPointer(h_aPos, 3, GL_FLOAT, GL_FALSE, 0, 0);
safe_glEnableVertexAttribArray(h_aNorm);
glBindBuffer(GL_ARRAY_BUFFER, meshStorage[LoD].normalBuffer);
safe_glVertexAttribPointer(h_aNorm, 3, GL_FLOAT, GL_FALSE, 0, 0);
// draw leaves
int i;
for (i = 0; i < meshStorage[LoD].numMeshes-1; i++) {
meshShader->setMaterial(&tree_materials[1]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshStorage[LoD].indexBuffer[i]);
glDrawElements(GL_TRIANGLES, meshStorage[LoD].indexBufferLength[i], GL_UNSIGNED_SHORT, 0);
}
// draw trunk
meshShader->setMaterial(&tree_materials[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshStorage[LoD].indexBuffer[i]);
glDrawElements(GL_TRIANGLES, meshStorage[LoD].indexBufferLength[i], GL_UNSIGNED_SHORT, 0);
safe_glDisableVertexAttribArray(h_aPos);
safe_glDisableVertexAttribArray(h_aNorm);
modelViewMatrix.popMatrix();
}
};
#endif /* defined(____GameBuilding__) */