Incomplete collision code
This commit is contained in:
@@ -64,7 +64,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-10.zip
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-11.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -12,7 +12,7 @@ void Cube::pre_render() {
|
||||
angle.y = angle.y + 24*engine->frameDelta;
|
||||
angle.z = angle.z + 24*engine->frameDelta;
|
||||
|
||||
OBB obb = getGeometry()->getCachedOBB(angle);
|
||||
//AABB aabb = Collision::genMinimallyEnclosingAABB(getGeometry());
|
||||
}
|
||||
|
||||
void Cube::update(float elapsed) {
|
||||
|
@@ -31,8 +31,11 @@ AABB Collision::genMinimallyEnclosingAABB(const VertexArray* vA) {
|
||||
AABB Collision::genMinimallyEnclosingAABB(const VertexArray* vA, const Vector3& rotation) {
|
||||
return vA->getCachedOBB(rotation).MinimalEnclosingAABB();
|
||||
}
|
||||
|
||||
Sphere Collision::genMinimallyEnclosingSphere(const VertexArray* vA) {
|
||||
return vA->getCachedOBB(Vector3(0, 0, 0)).MinimalEnclosingSphere();
|
||||
//std::cout << vA->getCachedOBB(Vector3(0, 0, 0)).MinimalEnclosingSphere().Radius << std::endl;
|
||||
return Collision::genMinimallyEnclosingAABB(vA).MinimalEnclosingSphere();
|
||||
//return Collision::genMinimallyEnclosingAABB(vA)
|
||||
}
|
||||
|
||||
OBB Collision::genMinimallyEnclosingOBB(const VertexArray* vA, const Vector3& rotation) {
|
||||
@@ -58,15 +61,94 @@ OBB Collision::genMinimallyEnclosingOBB(const VertexArray* vA, const Vector3& ro
|
||||
|
||||
//TODO
|
||||
VertexArray Collision::getDrawable(const Shape& collider) {
|
||||
|
||||
if (const auto* s = dynamic_cast<const AABB*>(&collider)) {
|
||||
std::cout << "We passed in an AABB" << std::endl;
|
||||
VertexArray result;
|
||||
GLuint indices[36] = {
|
||||
0, 1, 5,0, 5, 4,2, 3, 7,2, 7, 6,0, 1, 3,0, 3,
|
||||
2,4, 5, 7,4, 7,6,0,2, 6,0, 6, 4,1, 3, 7,
|
||||
1, 7, 5
|
||||
};
|
||||
result.vertices.push_back(s->minPoint);
|
||||
result.vertices.emplace_back(s->maxPoint.x, s->minPoint.y, s->minPoint.z);
|
||||
result.vertices.emplace_back(s->minPoint.x, s->maxPoint.y, s->minPoint.z);
|
||||
result.vertices.emplace_back(s->maxPoint.x, s->maxPoint.y, s->minPoint.z);
|
||||
result.vertices.emplace_back(s->minPoint.x, s->minPoint.y, s->maxPoint.z);
|
||||
result.vertices.emplace_back(s->maxPoint.x, s->minPoint.y, s->maxPoint.z);
|
||||
result.vertices.emplace_back(s->minPoint.x, s->maxPoint.y, s->maxPoint.z);
|
||||
result.vertices.push_back(s->maxPoint); // 7: Top-back-right
|
||||
|
||||
for (unsigned int ind : indices)
|
||||
result.indices.push_back(ind);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (const auto* s = dynamic_cast<const OBB*>(&collider)) {
|
||||
std::cout << "We passed in an OBB" << std::endl;
|
||||
VertexArray result;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (const auto* s = dynamic_cast<const Sphere*>(&collider)) {
|
||||
std::cout << "We passed in a Sphere" << std::endl;
|
||||
if (const auto* s = dynamic_cast<const Sphere*>(&collider)) { //Returns a pre-generated VertexArray of an icosphere.
|
||||
VertexArray result;
|
||||
std::vector<Vertex> verts = {
|
||||
{0.000f, -1.000f, 0.000f}, {0.724f, -0.447f, 0.526f},
|
||||
{-0.276f, -0.447f, 0.851f}, {-0.894f, -0.447f, 0.000f},
|
||||
{-0.276f, -0.447f, -0.851f}, {0.724f, -0.447f, -0.526f},
|
||||
{0.276f, 0.447f, 0.851f}, {-0.724f, 0.447f, 0.526f},
|
||||
{-0.724f, 0.447f, -0.526f},{0.276f, 0.447f, -0.851f},
|
||||
{0.894f, 0.447f, 0.000f}, {0.000f, 1.000f, 0.000f},
|
||||
{-0.162f, -0.851f, 0.500f}, {0.425f, -0.851f, 0.309f},
|
||||
{0.263f, -0.526f, 0.809f}, {0.851f, -0.526f, 0.000f},
|
||||
{0.425f, -0.851f, -0.309f}, {-0.526f, -0.851f, 0.000f},
|
||||
{-0.688f, -0.526f, 0.500f}, {-0.162f, -0.851f, -0.500f},
|
||||
{-0.688f, -0.526f, -0.500f}, {0.263f, -0.526f, -0.809f},
|
||||
{0.951f, 0.000f, 0.309f}, {0.951f, 0.000f, -0.309f},
|
||||
{0.000f, 0.000f, 1.000f}, {0.588f, 0.000f, 0.809f},
|
||||
{-0.951f, 0.000f, 0.309f}, {-0.588f, 0.000f, 0.809f},
|
||||
{-0.588f, 0.000f, -0.809f}, {-0.951f, 0.000f, -0.309f},
|
||||
{0.588f, 0.000f, -0.809f}, {0.000f, 0.000f, -1.000f},
|
||||
{0.688f, 0.526f, 0.500f}, {-0.263f, 0.526f, 0.809f},
|
||||
{-0.851f, 0.526f, 0.000f}, {-0.263f, 0.526f, -0.809f},
|
||||
{0.688f, 0.526f, -0.500f}, {0.162f, 0.851f, 0.500f},
|
||||
{0.526f, 0.851f, 0.000f}, {-0.425f, 0.851f, 0.309f},
|
||||
{-0.425f, 0.851f, -0.309f}, {0.162f, 0.851f, -0.500f}
|
||||
};
|
||||
|
||||
std::vector<unsigned int> indices = {
|
||||
0, 13, 12, 1, 13, 15, 0, 12, 17,
|
||||
0, 17, 19, 0, 19, 16, 1, 15, 22,
|
||||
2, 14, 24, 3, 18, 26, 4, 20, 28,
|
||||
5, 21, 30, 1, 22, 25, 2, 24, 27,
|
||||
3, 26, 29, 4, 28, 31, 5, 30, 23,
|
||||
6, 32, 37, 7, 33, 39, 8, 34, 40,
|
||||
9, 35, 41, 10, 36, 38, 38, 41, 11,
|
||||
38, 36, 41, 36, 9, 41, 41, 40, 11,
|
||||
41, 35, 40, 35, 8, 40, 40, 37, 11,
|
||||
40, 34, 37, 34, 7, 37, 37, 38, 11,
|
||||
37, 33, 38, 33, 10, 38, 23, 36, 10,
|
||||
23, 30, 36, 30, 9, 36, 31, 35, 9,
|
||||
31, 28, 35, 28, 8, 35, 29, 34, 8,
|
||||
29, 26, 34, 26, 7, 34, 27, 33, 7,
|
||||
27, 24, 33, 24, 6, 33, 25, 32, 6,
|
||||
25, 22, 32, 22, 10, 32, 30, 31, 9,
|
||||
30, 21, 31, 21, 4, 31, 28, 29, 8,
|
||||
28, 20, 29, 20, 3, 29, 26, 27, 7,
|
||||
26, 18, 27, 18, 2, 27, 22, 23, 10,
|
||||
22, 15, 23, 15, 5, 23, 16, 21, 5,
|
||||
16, 19, 21, 19, 4, 21, 19, 20, 4,
|
||||
19, 17, 20, 17, 3, 20, 17, 18, 3,
|
||||
17, 12, 18, 12, 2, 18, 15, 16, 5,
|
||||
15, 13, 16, 13, 0, 16, 12, 14, 2,
|
||||
12, 13, 14, 13, 1, 14
|
||||
};
|
||||
|
||||
for (auto& v : verts) {
|
||||
v *= s->Radius;
|
||||
v += s->Position;
|
||||
}
|
||||
result.vertices = verts;
|
||||
result.indices = indices;
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -122,8 +122,8 @@ void Engine::initGL()
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glEnable(GL_BLEND);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
if (e->draw)
|
||||
e->render();
|
||||
@@ -134,8 +134,7 @@ void Engine::initGL()
|
||||
exit(0);
|
||||
}
|
||||
glColor4f(0.f, 0.f, 0.f, 0.f);
|
||||
JGL::J3D::DrawString3D(JGL::Colors::Blue, "JGL Sample Text", {0.5f, 0, 0.5f}, 0.1f);
|
||||
glDisable(GL_BLEND);
|
||||
//JGL::J3D::DrawString3D(JGL::Colors::Blue, "JGL Sample Text", {0.5f, 0, 0.5f}, 0.1f);
|
||||
//JGL::J2D::FillRect2D(JGL::Colors::Purples::BlueViolet, {0.f, -5.f}, {24, 24});
|
||||
}
|
||||
|
||||
|
@@ -171,7 +171,7 @@ void Entity::render() {
|
||||
glDisable(GL_LIGHTING);
|
||||
glPushMatrix();
|
||||
glColor4f(1, 0, 0, 1);
|
||||
//getCollider().draw();
|
||||
Collision::getDrawable(getSphere()).drawWireframe();
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glPopMatrix();
|
||||
glEnable(GL_LIGHTING);
|
||||
@@ -218,11 +218,16 @@ void Entity::erase() {
|
||||
}
|
||||
|
||||
AABB Entity::getAABB() {
|
||||
return Collision::genMinimallyEnclosingAABB(getGeometry());
|
||||
AABB aabb = Collision::genMinimallyEnclosingAABB(getGeometry());
|
||||
aabb.minPoint += position;
|
||||
aabb.maxPoint += position;
|
||||
return aabb;
|
||||
}
|
||||
|
||||
Sphere Entity::getSphere() {
|
||||
return Collision::genMinimallyEnclosingSphere(getGeometry());
|
||||
Sphere sphere = Collision::genMinimallyEnclosingSphere(getGeometry());
|
||||
sphere.Position = position;
|
||||
return sphere;
|
||||
}
|
||||
|
||||
OBB Entity::getOBB() {
|
||||
|
@@ -167,7 +167,7 @@ OBB VertexArray::getCachedOBB(const Matrix3x3& rotationMatrix) const {
|
||||
Vector3 axis0 = Vector3(rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]);
|
||||
Vector3 axis1 = Vector3(rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]);
|
||||
Vector3 axis2 = Vector3(rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]);
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
return {cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2};
|
||||
}
|
||||
|
||||
OBB VertexArray::getCachedOBB(const Vector3& rotation) const {
|
||||
@@ -175,7 +175,7 @@ OBB VertexArray::getCachedOBB(const Vector3& rotation) const {
|
||||
Vector3 axis0 = {rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]};
|
||||
Vector3 axis1 = {rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]};
|
||||
Vector3 axis2 = {rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]};
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
return {cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2};
|
||||
}
|
||||
|
||||
OBB VertexArray::getCachedOBB(const EulerAngle &rotation) const {
|
||||
@@ -183,5 +183,5 @@ OBB VertexArray::getCachedOBB(const EulerAngle &rotation) const {
|
||||
Vector3 axis0 = {rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]};
|
||||
Vector3 axis1 = {rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]};
|
||||
Vector3 axis2 = {rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]};
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
return {cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2};
|
||||
}
|
||||
|
Reference in New Issue
Block a user