-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnTheOrigin.cpp
168 lines (148 loc) · 4.01 KB
/
OnTheOrigin.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
159
160
161
162
163
164
165
166
167
168
/*
* OnTheOrigin.cpp
*
* Created on: Mar 1, 2014
* Author: Theron
*/
// This will now be our main source for running the actual program. All other main()s will remain in Tests, as tests and only tests.
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include "Resources/VectorIntLib.h"
#include "TreeGen/TreeGen.h"
#include "TreeRender/TreeRender.h"
#include "Engine/Engine.h"
#include "Engine/VertexArrayUtils.h"
VertexArrayUtils::Data drawdata;
DimensionStruct DimInfo;
vector<VectorStruct> ResourceVector;
TreeGen::forest forest; //all trees
void createForest() {
srand(time(NULL));
rand(); //First value of rand is the seed, so this gets rid of it
int depth = 45;
int length = 1000;
int width = 1000;
int TopsoilDepth = 1;
DimInfo.length = length;
DimInfo.width = width;
DimInfo.depth = depth;
DimInfo.TopsoilDepth = TopsoilDepth;
ResourceVector=initializeResources(DimInfo);
cout << "Water Test: " << WaterGrab(0,0,0,DimInfo, ResourceVector) << endl;
int startingtrees;
cout << "How many trees to start?" << endl;
cin >> startingtrees;
int originpointx = 500;
int originpointy = 500;
while(startingtrees > 0)
{
cout << "Spawning origin tree. " << endl;
TreeGen::seed treeSeed=TreeGen::generateSeed();
char PlantIDArray[10];
sprintf( PlantIDArray, "%d",forest.trees.size());
string newPlantID=PlantIDArray;
int treex=originpointx + TreeGen::randInt(-499,499);
if(treex > length-1)
{
treex = length-1;
}
if(treex < 0)
{
treex = 0;
}
int treey = originpointy+ TreeGen::randInt(-499,499);
if(treey > width-1)
{
treey = width-1;
}
if(treey < 0)
{
treey = 0;
}
TreeGen::tree newTree=spawnTree(treex,treey,depth,treeSeed, DimInfo, ResourceVector, newPlantID);
forest.trees.push_back(newTree);
startingtrees -= 1;
}
}
bool lighting=false;
void toggleLighting() {
lighting = !lighting;
if (lighting) {
printf("Toggleing lighting ON\n");
}
else {
printf("Toggleing lighting OFF\n");
}
}
void renderScene() {
if (lighting) {
glEnable(GL_LIGHTING);
}
else {
glDisable(GL_LIGHTING);
}
float light0pos[4] = {0,70-128,0,1};
float light0color[4] = {.6,.45,.4,0};
float light1pos[4] = {5,20,7,0};
float light1color[4] = {0.2,0.2,0.5};
/*for (int i=0; i<3; i++) {
light0color[i]*=.5;
light1color[i]*=.5;
}*/
//float light1spec[4] = {1,1,1,0};
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0color);
glLightfv(GL_LIGHT0, GL_SPECULAR, light0color);
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT1, GL_POSITION, light1pos);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1color);
//glLightfv(GL_LIGHT1, GL_SPECULAR, light1spec);
glColor3f(1,1,1);
VertexArrayUtils::drawData(&drawdata);
}
int main(int argc, char **argv) {
Engine::Settings engine;
Engine::Camera_settings camera;
Engine::setup(&engine, &camera);
Engine::setDrawFunc(&renderScene);
Engine::addKeyDownBinding(SDLK_F6,&toggleLighting);
engine.run = true;
#define threaded
#ifdef threaded
Engine::startUpdateLoop();
#endif
#ifndef threaded
Engine::setupSDL();
Engine::setupGL();
#endif
createForest();
while (engine.run) {
forest=TreeGen::generateForest(forest,DimInfo, ResourceVector, 0, 0, 0);
for (unsigned int i = 0; i < forest.trees.size();)
{
forest.trees.at(i) = TreeRender::CalcXYZ(forest.trees.at(i));
i++;
}
TreeRender::drawForest(&forest,&drawdata,0,0,10000.);
#ifdef threaded
SDL_mutexP(Engine::renderLock);
#endif
VertexArrayUtils::finishData(&drawdata);
#ifdef threaded
SDL_mutexV(Engine::renderLock);
#endif
#ifndef threaded
VertexArrayUtils::drawData(&drawdata);
Engine::updateMouseMode();
Engine::update();
Engine::display();
#endif
}
#ifdef threaded
Engine::finishUpdateLoop();
#endif
return 0;
}