-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.cpp
executable file
·158 lines (134 loc) · 3.17 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <GL/glut.h>
#include <math.h>
#include "md2model.h"
using namespace std;
//GLfloat angle = 0.0f;
class Banana {
public:
MD2Model *bananaModel;
Banana(char *filename) {
bananaModel = MD2Model::load(filename);
if (!bananaModel) {
cout<<"Error loading banana!!!"<<endl;
exit(0);
}
}
void draw() {
glPushMatrix();
glRotatef(-60, 1.0, 0.0, 0.0);
glRotatef(180, 0.0, 0.0, 1.0);
glScalef(0.04, 0.04, 0.04);
bananaModel->draw();
glPopMatrix();
}
};
class GroundPlant {
public:
MD2Model *groundPlantModel;
GroundPlant(char *filename) {
groundPlantModel = MD2Model::load(filename);
if (!groundPlantModel) {
cout<<"Error loading ground plant!!!"<<endl;
exit(0);
}
}
void draw() {
glPushMatrix();
glRotatef(-60, 1.0, 0.0, 0.0);
glRotatef(180, 0.0, 0.0, 1.0);
glScalef(0.04, 0.04, 0.04);
groundPlantModel->draw();
glPopMatrix();
}
};
class Plant {
public:
MD2Model *plantModel;
Plant(char *filename) {
plantModel = MD2Model::load(filename);
if (!plantModel) {
cout<<"Error loading plant 1 !!!"<<endl;
exit(0);
}
}
void draw() {
glPushMatrix();
glRotatef(-60, 1.0, 0.0, 0.0);
glRotatef(180, 0.0, 0.0, 1.0);
glScalef(0.04, 0.04, 0.04);
plantModel->draw();
glPopMatrix();
}
};
class Fern {
public:
MD2Model *fernModel;
Fern(char *filename) {
fernModel = MD2Model::load(filename);
if (!fernModel) {
cout<<"Error loading fern!!!"<<endl;
exit(0);
}
}
void draw() {
glPushMatrix();
glRotatef(-60, 1.0, 0.0, 0.0);
glRotatef(180, 0.0, 0.0, 1.0);
glScalef(0.04, 0.04, 0.04);
fernModel->draw();
glPopMatrix();
}
};
/*Banana *banana;
GroundPlant *groundPlant;
Fern *fern;
Plant *plant1, *plant2;
void display(void) {
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat lightPos[] = {-0.2f, 0.3f, -1, 0.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glTranslatef(0.0, 0.0, -20.0);
banana->draw();
// gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0,1.0, 0.0);
glutSwapBuffers();
}
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float)w / (float)h, 1.0, 100.0);
}
void initRendering(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
glEnable(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
banana = new Banana("banana.md2");
groundPlant = new GroundPlant("plant3.md2");
fern = new Fern("fern.md2");
plant1 = new Plant("plant1.md2");
plant2 = new Plant("plant2.md2");
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("Test");
initRendering();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}*/