Example Collider3D implementation
This commit is contained in:
@ -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 });
|
||||
}
|
||||
|
Reference in New Issue
Block a user