forked from adoptware/pinball
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmisc.cpp
95 lines (81 loc) · 2.24 KB
/
misc.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
/***************************************************************************
Triangle point distance test.
***************************************************************************/
#include <iostream>
#include "Private.h"
#include "Engine.h"
#include "Camera.h"
#include "Cube.h"
#include "Cone.h"
#include "Keyboard.h"
#include "KeyBehavior.h"
#include "KeyRotBehavior.h"
#include "Shape3D.h"
#include "Polygon.h"
#include "CollisionBounds.h"
#include "EMath.h"
#include "CollisionVisitor.h"
#include "Cube.h"
/** A Triangle */
class TriClass : public Shape3D {
public:
TriClass();
~TriClass() {};
};
TriClass::TriClass() {
this->add(1, -1, 0, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
this->add(-1, -1, 0, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
this->add(0, 1, 0, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
this->add(1, 1, 0, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
Polygon3D * p = new Polygon3D(this, 3);
p->add(0);
p->add(1);
p->add(2);
p->add(3);
this->add(p);
this->countNormals();
}
/** Main */
int main(int argc, char *argv[]) {
cerr << "Simple emilia test." << endl;
// Create the engine.
Engine* engine = new Engine(argc, argv);
engine->setLightning(0.5f, 0.1f);
// Add a camera. Move a bit.
Camera* camera = new Camera();
Group* groupCamera = new Group();
engine->add(groupCamera);
groupCamera->setCamera(camera);
groupCamera->setTranslation(0, 0, 2);
engine->setEngineCamera(groupCamera);
engine->addShape3D(new Cube(0.1f, 1.0f, 1.0f, 1.0f, 1.0f));
Group * gt = new Group();
engine->add(gt);
gt->setBehavior(new KeyBehavior());
Group * gr = new Group();
gt->add(gr);
gr->setBehavior(new KeyRotBehavior());
TriClass * tri = new TriClass();
gr->addShape3D(tri);
Vertex3D vtx = {0.0f, 0.0f, 0.0f};
Vertex3D vtxDist;
engine->resetTick();
engine->setSpeed(10);
while (!Keyboard::isKeyDown(SDLK_ESCAPE)) {
if (engine->nextTick()) {
engine->tick();
float sqrdist = CollisionVisitor::getInstance()->
vtxPolySqrDist(vtx, tri->getPolygon(0), vtxDist);
cerr << EMath::emSqrt(sqrdist) <<" : "<<
vtxDist.x <<" "<< vtxDist.y <<" "<< vtxDist.z << endl;
} else {
engine->render();
engine->swap();
}
}
delete(engine);
return 0;
}
#if EM_USE_ALLEGRO
END_OF_MAIN();
#endif