Actually have matrixed cubes working

This commit is contained in:
2023-02-24 22:32:28 -08:00
parent 1d39e86d91
commit 49272be17c
11 changed files with 132 additions and 53 deletions

View File

@ -5,6 +5,8 @@
#include "TicTacToeGame.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/example/ExampleSpin.hpp"
#include "physics/3d/Ray3D.hpp"
using namespace Dawn;
@ -26,9 +28,36 @@ void TicTacToeGame::onSceneUpdate() {
if(camera == nullptr) return;
struct Ray3D ray;
glm::vec3 pos = glm::vec3(mouse.x * camera->orthoRight, mouse.y * camera->orthoBottom, 0.0f);
ray.direction = glm::vec3(0, 0, -15);
ray.origin = pos;
ray.origin = glm::vec3(1,2,3);
ray.direction = camera->getRayDirectionFromScreenSpace(mouse);
getScene()->debugRay((struct SceneDebugRay){ .start = ray.origin, .direction = ray.direction });
struct AABB3D box;
box.min = glm::vec3(-0.5f, -0.5f, -0.5f);
box.max = glm::vec3(0.5f, 0.5f, 0.5f);
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
);
if(test) {
getScene()->debugRay((struct SceneDebugRay){ .start = point, .direction = normal, .color = COLOR_BLUE });
} else {
getScene()->debugRay((struct SceneDebugRay){ .start = ray.origin, .direction = ray.direction });
}
}

View File

@ -22,8 +22,8 @@ namespace Dawn {
camera->transform->lookAt(glm::vec3(1, 2, 3), glm::vec3(0, 0, 0));
float_t s = 2.0f;
camera->orthoTop = -s;
camera->orthoBottom = s;
camera->orthoTop = s;
camera->orthoBottom = -s;
float_t ratio = 1.0f / 9.0f * 16.0f;
camera->orthoLeft = -s * ratio;