-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (123 loc) · 4.66 KB
/
main.cpp
File metadata and controls
148 lines (123 loc) · 4.66 KB
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
// main
// -------------------------------------------------------------------
// Copyright (C) 2007 OpenEngine.dk (See AUTHORS)
//
// This program is free software; It is covered by the GNU General
// Public License version 2 or any later version.
// See the GNU General Public License for more details (see LICENSE).
//--------------------------------------------------------------------
// OpenEngine stuff
#include <Meta/Config.h>
#include <Meta/CUDA.h>
#include <Logging/Logger.h>
#include <Logging/StreamLogger.h>
#include <Core/Engine.h>
// Math
#include <Math/Tensor.h>
#include <Display/Camera.h>
#include <Scene/BlendingNode.h>
#include <Scene/RenderStateNode.h>
#include <Scene/PointLightNode.h>
// SimpleSetup
#include <Utils/SimpleSetup.h>
#include <Utils/MoveHandler.h>
#include <Utils/RenderStateHandler.h>
#include "TLEDNode.h"
#include "GridNode.h"
#include "CoordSystemNode.h"
#include "KeyHandler.h"
// name spaces that we will be using.
// this combined with the above imports is almost the same as
// fx. import OpenEngine.Logging.*; in Java.
using namespace OpenEngine::Logging;
using namespace OpenEngine::Core;
using namespace OpenEngine::Display;
using namespace OpenEngine::Utils;
using namespace OpenEngine::Math;
using namespace OpenEngine::Resources;
/**
* Main method for the first quarter project of CGD.
* Corresponds to the
* public static void main(String args[])
* method in Java.
*/
int main(int argc, char** argv) {
// Create simple setup
SimpleSetup* setup = new SimpleSetup("TLED");
setup->GetRenderer().SetBackgroundColor(Vector<4,float>(1.0));
if (argc == 3) {
// Print usage info.
logger.info << "========= Running OpenEngine Test Project =========";
logger.info << logger.end;
//Vector<3,float> position(-7, 2, 15);
//Vector<3,float> lookat(-2, 0, 0);
//Vector<3,float> lookat(-50, 10, 0);
Vector<3,float> position(0,30,200);
Vector<3,float> lookat(0,10,0);
// tooth viewpoint
//Vector<3,float> position(10,40,100);
//Vector<3,float> lookat(0,12,0);
//Vector<3,float> position(30,56,27);
//Vector<3,float> lookat(0,47,0);
// Move the camera
Camera* camera = setup->GetCamera();
camera->SetPosition(position);
camera->LookAt(lookat);
// Register movement handler to be able to move the camera
MoveHandler* move_h =
new MoveHandler(*camera, setup->GetMouse());
move_h->SetObjectMove(false);
setup->GetKeyboard().KeyEvent().Attach(*move_h);
setup->GetEngine().InitializeEvent().Attach(*move_h);
setup->GetEngine().ProcessEvent().Attach(*move_h);
setup->GetEngine().DeinitializeEvent().Attach(*move_h);
// Get root node of scene
ISceneNode* root = setup->GetScene();
RenderStateNode* rsn = new RenderStateNode();
rsn->DisableOption(RenderStateNode::WIREFRAME);
root->AddNode(rsn);
RenderStateHandler* rsh = new RenderStateHandler(*rsn);
setup->GetKeyboard().KeyEvent().Attach(*rsh);
PointLightNode* pln = new PointLightNode();
TransformationNode* lightPos = new TransformationNode();
lightPos->AddNode(pln);
lightPos->SetPosition(Vector<3,float>(500,1000,500));
// lightPos->SetPosition(Vector<3,float>(5000,10000,-5500));
root->AddNode(lightPos);
Scene::BlendingNode* bn = new Scene::BlendingNode();
rsn->AddNode(bn);
Vector<3,float> color(0.0,0.0,0.0);
bn->AddNode(new GridNode(1000,30,color));
bn->AddNode(new CoordSystemNode());
// must be done before using memory!
//INITIALIZE_CUDA();
CHECK_FOR_CUDA_ERROR();
logger.info << "CUDA info:" << PRINT_CUDA_DEVICE_INFO() << logger.end;
std::string solidname = argv[1];
std::string mpname = argv[2];
Solid* solid = SolidFactory::Create(solidname);
solid->SetMaterialProperties(MaterialPropertiesFactory::Create(mpname));
TLEDNode* tled = new TLEDNode(solid);
bn->AddNode(tled);
setup->GetEngine().InitializeEvent().Attach(*tled);
setup->GetEngine().ProcessEvent().Attach(*tled);
setup->GetEngine().DeinitializeEvent().Attach(*tled);
KeyHandler* kh = new KeyHandler(*camera, tled, setup->GetEngine(),
solidname, mpname);
kh->SetEye(position);
kh->SetPoint(lookat);
setup->GetKeyboard().KeyEvent().Attach(*kh);
setup->AddDataDirectory("projects/FractureSim/data/models/");
// Start the engine.
setup->GetEngine().Start();
// delete the entire scene
delete setup->GetScene();
// Return when the engine stops.
}
else {
logger.info << "please specify solid name and material properties: ex "
<< argv[0] << " bar5 concrete" << logger.end;
}
delete setup;
return EXIT_SUCCESS;
}