-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTree.cpp
45 lines (38 loc) · 1.33 KB
/
Tree.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
#ifndef GLEW_STATIC
#include <GL/glew.h>
#include <vector>
#include <glm/gtc/type_ptr.hpp>
#endif
#include "PrimitiveObject.h"
#include "Cylinder.h"
#include "Cone.h"
#include "Textures.h"
#include "Tree.h"
using namespace std;
static vector<glm::vec3> parts_position = {
glm::vec3(0.0f, 0.3f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
};
static vector<glm::vec4> start_rotation = {
glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), //nothing 0
glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), //X axis 1
glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), //Y axis 2
glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), //Z axis 3
glm::vec4(1.0f, 0.0f, 0.0f, -M_PI / 2.0f), //4
glm::vec4(1.0f, 0.0f, 0.0f, M_PI / 2.0f), //5
};
glm::vec3 scalePosition(glm::vec3 pos, GLfloat size);
Tree::Tree(GLfloat size, glm::vec3 position)
{
this->size = size;
this->position = position;
GLuint tex1 = loadTexture("img/tree.png");
GLuint tex2 = loadTexture("img/wood.png");
this->parts.push_back(new Cone(2.0f * size, 0.5f * size, 8, tex1, 0, scalePosition(parts_position[0], size), start_rotation[4]));
this->parts.push_back(new Cylinder(0.3f * size, 0.1f * size, 5, tex2, 0, scalePosition(parts_position[1], size), start_rotation[4]));
}
void Tree::Draw(const glm::mat4& modelTrans, GLuint modelLoc, GLuint shader) const
{
for (int i = 0; i < parts.size(); ++i)
this->parts[i]->Draw(modelTrans, modelLoc, shader);
}