Draw normals on collision map for debug info
This commit is contained in:
@@ -49,7 +49,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.20.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/v0.2.21.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
@@ -59,13 +59,13 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-18.zip
|
||||
)
|
||||
#Causes multiple definition
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-6.zip
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-20.zip
|
||||
)
|
||||
#Broken
|
||||
#CPMAddPackage(
|
||||
#NAME JGL
|
||||
#URL https://git.redacted.cc/josh/JGL/archive/Prerelease-7.zip
|
||||
#)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME SOIL
|
||||
@@ -104,7 +104,7 @@ include_directories(
|
||||
${ASSIMP_SOURCE_DIR}/include
|
||||
${archive_SOURCE_DIR}/include
|
||||
${PROJECT_BINARY_DIR}/glu/include
|
||||
${JGL_SOURCE_DIR}/include
|
||||
#${JGL_SOURCE_DIR}/include
|
||||
${Event_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/vertex.h>
|
||||
#include <J3ML/Geometry/Triangle.h>
|
||||
|
||||
enum class ColliderType : uint8_t {
|
||||
AxisAlignedBoundingBox = 0,
|
||||
@@ -8,9 +9,7 @@ enum class ColliderType : uint8_t {
|
||||
CollisionMap = 2 //This one is the *ultra* slow one. Try not to use it super often.
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
Vector3 v0, v1, v2;
|
||||
};
|
||||
using J3ML::Geometry::Triangle;
|
||||
|
||||
class Collider : public VertexArray {
|
||||
public:
|
||||
|
@@ -8,7 +8,7 @@ set_target_properties(Re3D-RuntimeTest PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
|
||||
# TODO: Link all applicable dependencies to Re3D directly
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML JGL soil uuid_v4 GL glad assimp archive ${PROJECT_BINARY_DIR}/lib/libGLU.so)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil uuid_v4 GL glad assimp archive ${PROJECT_BINARY_DIR}/lib/libGLU.so)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
@@ -11,7 +11,7 @@ int main(int argc, char** argv)
|
||||
engine->init();
|
||||
auto* cube1 = new(Cube);
|
||||
cube1->name = "cube1";
|
||||
cube1->SetPos({-5, 0, 0});
|
||||
cube1->SetPos({-5, -2, 0});
|
||||
cube1->velAngle = cube1->lAngle();
|
||||
cube1->SetParent(engine->world);
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <engine/collision.h>
|
||||
#include <sphere.h>
|
||||
void Cube::pre_render() {
|
||||
hVelocity = 1.4;
|
||||
hVelocity = 1;
|
||||
hMove(velAngle, hVelocity);
|
||||
vMove(vVelocity);
|
||||
|
||||
@@ -36,7 +36,7 @@ void Cube::update(float elapsed) {
|
||||
}
|
||||
|
||||
Collider Cube::getCollider() {
|
||||
Collider collider = Collision::calculateAxisAlignedBoundingBox(*getGeometry());
|
||||
Collider collider = Collision::calculateAxisAlignedBoundingBox(getGeometry()->getBoundingVolume(angle));
|
||||
|
||||
//Scale.
|
||||
for (auto& vertex : collider.vertices) {
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#include <cfloat>
|
||||
#include <engine/collision.h>
|
||||
#include <J3ML/Geometry.h>
|
||||
#include <J3ML/Geometry/AABB.h>
|
||||
#include <J3ML/Geometry/Triangle.h>
|
||||
|
||||
bool Collision::vertexInsideAxisAlignedBoundingBox(const Vector3& position, const Collider& boundingBox) {
|
||||
Vector3 minimum = {boundingBox.vertices.front().x, boundingBox.vertices.front().y, boundingBox.vertices.front().z};
|
||||
@@ -106,33 +109,12 @@ bool Collision::axisAlignedBoundingBoxCollides(const Collider &boundingBox, cons
|
||||
return true; //AABBs Collide.
|
||||
}
|
||||
|
||||
//TODO this isn't very accurate. This is stand in code until SAT can be figured out.
|
||||
//Broken
|
||||
bool Collision::triangleVSAxisAlignedBoundingBoxCollides(const Triangle &triangle, const Collider &boundingBox) {
|
||||
Vertex vert;
|
||||
VertexArray vArray;
|
||||
vert.x = triangle.v0.x;
|
||||
vert.y = triangle.v0.y;
|
||||
vert.z = triangle.v0.z;
|
||||
vArray.vertices.push_back(vert);
|
||||
|
||||
vert.x = triangle.v1.x;
|
||||
vert.y = triangle.v1.y;
|
||||
vert.z = triangle.v1.z;
|
||||
vArray.vertices.push_back(vert);
|
||||
|
||||
vert.x = triangle.v2.x;
|
||||
vert.y = triangle.v2.y;
|
||||
vert.z = triangle.v2.z;
|
||||
vArray.vertices.push_back(vert);
|
||||
Collider boundingBox2 = calculateAxisAlignedBoundingBox(vArray);
|
||||
return axisAlignedBoundingBoxCollides(boundingBox, boundingBox2);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Collision::collisionMapVSAxisAlignedBoundingBoxCollides(const Collider &boundingBox, const Collider& collisionMap) {
|
||||
|
||||
if (!axisAlignedBoundingBoxCollides(boundingBox, Collision::calculateAxisAlignedBoundingBox((VertexArray) collisionMap)))
|
||||
return false;
|
||||
|
||||
for (auto& triangle : collisionMap.getTriangles())
|
||||
if (triangleVSAxisAlignedBoundingBoxCollides(triangle, boundingBox))
|
||||
return true;
|
||||
@@ -155,8 +137,27 @@ void Collider::draw() {
|
||||
glEnd();
|
||||
return;
|
||||
}
|
||||
if (type == ColliderType::CollisionMap)
|
||||
|
||||
if (type == ColliderType::CollisionMap) {
|
||||
drawWireframe();
|
||||
|
||||
for (const auto& triangle : getTriangles()) {
|
||||
Vector3 edge1 = triangle.V1 - triangle.V0;
|
||||
Vector3 edge2 = triangle.V2 - triangle.V0;
|
||||
Vector3 normal = Vector3::Normalize(Vector3::Cross(edge1, edge2));
|
||||
|
||||
Vector3 centroid = (triangle.V0 + triangle.V1 + triangle.V2) / 3.0f;
|
||||
Vector3 normalPoint = centroid + (normal * 0.25);
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(centroid.x, centroid.y, centroid.z);
|
||||
glVertex3f(normalPoint.x, normalPoint.y, normalPoint.z);
|
||||
glEnd();
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<Triangle> Collider::getTriangles() const {
|
||||
@@ -164,9 +165,9 @@ std::vector<Triangle> Collider::getTriangles() const {
|
||||
for (size_t i = 0; i < indices.size(); i += 3) {
|
||||
if (i + 2 < indices.size()) {
|
||||
Triangle triangle;
|
||||
triangle.v0 = {vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z};
|
||||
triangle.v1 = {vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z};
|
||||
triangle.v2 = {vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z};
|
||||
triangle.V0 = vertices[indices[i]];
|
||||
triangle.V1 = vertices[indices[i + 1]];
|
||||
triangle.V2 = vertices[indices[i + 2]];
|
||||
triangles.push_back(triangle);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include "types/entity/camera.h"
|
||||
#include "types/entity/skybox.h"
|
||||
|
||||
#include <JGL/JGL.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
using namespace J3ML;
|
||||
@@ -71,7 +70,6 @@ void Engine::initGL()
|
||||
engine->initGL();
|
||||
engine->loadConfig();
|
||||
|
||||
JGL::InitTextEngine();
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
//glDisable(GL_CULL_FACE);
|
||||
|
@@ -2,8 +2,6 @@
|
||||
#include <engine/occlusion.h>
|
||||
#include <types/entity/camera.h>
|
||||
#include <uuid_v4.h>
|
||||
#include "JGL/JGL.h"
|
||||
#include "JGL/Colors.h"
|
||||
|
||||
//inline LinearAlgebra::Vector3 Entity::GetPos() const
|
||||
//{ return LinearAlgebra::Vector3(coordinates[1]); }
|
||||
@@ -161,10 +159,10 @@ void Entity::render() {
|
||||
|
||||
if (engine->debug) {
|
||||
glPushMatrix();
|
||||
glColor3f(1, 0, 0);
|
||||
glColor4f(1, 0, 0, 1);
|
||||
glTranslatef(0, 0, 0);
|
||||
getCollider().draw();
|
||||
glColor3f(1, 1, 1);
|
||||
glColor4f(1, 1, 1,1);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user