// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "TicTacToeGame.hpp" #include "game/DawnGame.hpp" #include "scene/components/example/ExampleSpin.hpp" #include "physics/3d/Ray3D.hpp" using namespace Dawn; TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {} void TicTacToeGame::onStart() { this->tiles = getScene()->findComponents(); getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate); } void TicTacToeGame::onSceneUpdate() { // Get mouse in screen space. auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y); mouse *= 2.0f; mouse -= glm::vec2(1, 1); Camera *camera = getScene()->findComponent(); if(camera == nullptr) return; struct Ray3D ray; 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); struct SceneDebugCube cube = { .min = box.min, .max = box.max, .color COLOR_GREEN, .transform = getScene()->findComponent()->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 }); } }