Example Collider3D implementation

This commit is contained in:
2023-02-24 22:51:31 -08:00
parent 49272be17c
commit fad58f1430
10 changed files with 104 additions and 81 deletions

View File

@ -6,7 +6,7 @@
#include "TicTacToeGame.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/example/ExampleSpin.hpp"
#include "physics/3d/Ray3D.hpp"
#include "scene/components/physics/3d/CubeCollider.hpp"
using namespace Dawn;
@ -31,32 +31,14 @@ void TicTacToeGame::onSceneUpdate() {
ray.origin = glm::vec3(1,2,3);
ray.direction = camera->getRayDirectionFromScreenSpace(mouse);
struct AABB3D box;
box.min = glm::vec3(-0.5f, -0.5f, -0.5f);
box.max = glm::vec3(0.5f, 0.5f, 0.5f);
auto collider = getScene()->findComponent<CubeCollider>();
if(collider == nullptr) return;
struct SceneDebugCube cube = {
.min = box.min,
.max = box.max,
.color COLOR_GREEN,
.transform = getScene()->findComponent<ExampleSpin>()->transform->getWorldTransform()
};
getScene()->debugCube(cube);
glm::vec3 point, normal;
float_t distance;
auto test = raytestCube(
ray,
box,
cube.transform,
&point,
&normal,
&distance
);
struct Collider3DRayResult result;
auto test = collider->raycast(&result, ray);
if(test) {
getScene()->debugRay((struct SceneDebugRay){ .start = point, .direction = normal, .color = COLOR_BLUE });
getScene()->debugRay((struct SceneDebugRay){ .start = result.point, .direction = result.normal, .color = COLOR_BLUE });
} else {
getScene()->debugRay((struct SceneDebugRay){ .start = ray.origin, .direction = ray.direction });
}