PRetty good collision detection but there is still some small bug I don't know about
This commit is contained in:
@ -28,18 +28,19 @@ void TicTacToeGame::onSceneUpdate() {
|
||||
if(camera == nullptr) return;
|
||||
|
||||
struct Ray3D ray;
|
||||
ray.origin = glm::vec3(1,2,3);
|
||||
ray.origin = camera->transform->getWorldPosition();
|
||||
ray.direction = camera->getRayDirectionFromScreenSpace(mouse);
|
||||
std::cout << "World " << ray.origin.x << ", " << ray.origin.y << ", " << ray.origin.z << std::endl;
|
||||
|
||||
auto collider = getScene()->findComponent<CubeCollider>();
|
||||
if(collider == nullptr) return;
|
||||
|
||||
struct Collider3DRayResult result;
|
||||
auto test = collider->raycast(&result, ray);
|
||||
|
||||
if(test) {
|
||||
getScene()->debugRay((struct SceneDebugRay){ .start = result.point, .direction = result.normal, .color = COLOR_BLUE });
|
||||
} else {
|
||||
getScene()->debugRay((struct SceneDebugRay){ .start = ray.origin, .direction = ray.direction });
|
||||
auto results = getPhysics()->raycast3DAll(ray);
|
||||
auto itResult = results.begin();
|
||||
while(itResult != results.end()) {
|
||||
auto result = *itResult;
|
||||
getScene()->debugRay((struct SceneDebugRay){
|
||||
.start = result.point,
|
||||
.direction = result.normal,
|
||||
.color = COLOR_BLUE
|
||||
});
|
||||
++itResult;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
#include "scene/components/display/MeshHost.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/physics/2d/BoxCollider.hpp"
|
||||
#include "scene/components/physics/3d/CubeCollider.hpp"
|
||||
#include "components/TicTacToeTile.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
@ -28,7 +28,7 @@ namespace Dawn {
|
||||
MeshRenderer *meshRenderer;
|
||||
SimpleTexturedMaterial *material;
|
||||
TicTacToeTile *ticTacToe;
|
||||
BoxCollider *boxCollider;
|
||||
CubeCollider *collider;
|
||||
|
||||
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
|
||||
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
|
||||
@ -52,9 +52,9 @@ namespace Dawn {
|
||||
sprite->setSize(glm::vec2(1, 1));
|
||||
sprite->setTile(0x01);
|
||||
|
||||
boxCollider = this->addComponent<BoxCollider>();
|
||||
boxCollider->min = glm::vec2();
|
||||
boxCollider->max = glm::vec2(1, 1);
|
||||
collider = this->addComponent<CubeCollider>();
|
||||
collider->min = glm::vec3(-0.5f, -0.5f, -0.1f);
|
||||
collider->max = glm::vec3( 0.5f, 0.5f, 0.1f);
|
||||
|
||||
ticTacToe = this->addComponent<TicTacToeTile>();
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ namespace Dawn {
|
||||
camera = Camera::create(this);
|
||||
// camera->transform->lookAt(glm::vec3(0, 0, 5), glm::vec3(0, 0, 0));
|
||||
// camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
|
||||
camera->transform->lookAt(glm::vec3(1, 2, 3), glm::vec3(0, 0, 0));
|
||||
// camera->transform->lookAt(glm::vec3(1, 2, 3), glm::vec3(0, 0, 0));
|
||||
camera->transform->lookAt(glm::vec3(0, 0, 3), glm::vec3(0, 0, 0));
|
||||
|
||||
float_t s = 2.0f;
|
||||
camera->orthoTop = s;
|
||||
@ -29,10 +30,6 @@ namespace Dawn {
|
||||
camera->orthoLeft = -s * ratio;
|
||||
camera->orthoRight = s * ratio;
|
||||
|
||||
auto cube = SimpleSpinningCubePrefab::create(this);
|
||||
// TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
|
||||
// SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16);
|
||||
|
||||
auto gameItem = this->createSceneItem();
|
||||
auto game = gameItem->addComponent<TicTacToeGame>();
|
||||
|
||||
|
Reference in New Issue
Block a user