-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (37 loc) · 1.41 KB
/
main.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
#pragma once
#include "vector"
#include "ManifestMath/QuickHull.h"
#include "Include/ManifestSimulation/CollisionEngine/Queries/GJK.h";
using namespace Manifest_Simulation;
using namespace Manifest_Math;
const std::vector<MFpoint3> pointCloud
{
{-1, -1, -1},{-1, 1, -1},{1, 1, -1},{1, -1, -1},
{-1, -1, 1},{1, -1, 1},{-1, 1, 1},{1, 1, 1}
};
int main()
{
BoundingSphere boundingSphere{ .center = {0,3.0,0}, .radius = 1.0 };
ConvexHull hull;
hull.worldSpace = Identity();
hull.mesh = QuickHull(pointCloud);
MFbool collision{ false };
constexpr MFfloat dt{ 1.0f / 20.0f };
constexpr MFfloat dt2{ dt * dt };
const MFvec3 gravity{ 0,-9.8,0.0 };
const MFvec3 step{ gravity * dt2 };
while (!collision)
{
Simplex_T<Support> simplex;
MFfloat distanceSquared;
DLOG({ CONSOLE_BOLD }, "Beginning GJK Test with Sphere at:", boundingSphere.center, "and radius:", boundingSphere.radius, "and Hull at:", hull.worldSpace.GetTranslation());
GJK(boundingSphere.center, hull, simplex, distanceSquared);
if (distanceSquared <= boundingSphere.radius * boundingSphere.radius)
collision = true;
if (collision)
DLOG({ CONSOLE_BG_GREEN,CONSOLE_BLACK, CONSOLE_BOLD, CONSOLE_BLINK }, "Shallow Contact Detected, distanceSquared:", distanceSquared);
else
DLOG({ CONSOLE_BG_RED,CONSOLE_BLACK, CONSOLE_BOLD, CONSOLE_BLINK }, "Separation Detected, distanceSquared:", distanceSquared);
boundingSphere.center += step;
}
};