Starting basic physics, nothing fancy
This commit is contained in:
@ -43,7 +43,7 @@ namespace Dawn {
|
||||
|
||||
// Shared
|
||||
float_t clipNear = 0.001f;
|
||||
float_t clipFar = 1000.0f;
|
||||
float_t clipFar = 50.0f;
|
||||
|
||||
/**
|
||||
* Create a new Camera Component.
|
||||
|
@ -1,4 +1,13 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
RayTester3D.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(collider)
|
42
src/dawn/scene/components/physics/3d/RayTester3D.cpp
Normal file
42
src/dawn/scene/components/physics/3d/RayTester3D.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "RayTester3D.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RayTester3D::RayTester3D(SceneItem *item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
||||
|
||||
void RayTester3D::onStart() {
|
||||
this->getScene()->eventSceneUpdate.addListener(this, &RayTester3D::onUpdate);
|
||||
}
|
||||
|
||||
void RayTester3D::onUpdate() {
|
||||
prefab->transform.setLocalPosition(glm::vec3(0, 0, 0));
|
||||
box.max = glm::vec3( 0.5f, 0.5f, 0.5f);
|
||||
box.min = glm::vec3(-0.5f, -0.5f, -0.5f);
|
||||
|
||||
auto mouse = this->getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
|
||||
mouse *= 2.0f;
|
||||
mouse -= glm::vec2(1, 1);
|
||||
|
||||
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;
|
||||
|
||||
// prefab->transform.setLocalPosition(pos);
|
||||
// ray.origin = glm::vec3(0, 0, 5);
|
||||
|
||||
bool_t x = raytestAABB(ray, box, &hit, &normal, &distance);
|
||||
|
||||
if(x) {
|
||||
prefab->material->color = COLOR_RED;
|
||||
} else {
|
||||
prefab->material->color = COLOR_WHITE;
|
||||
}
|
||||
}
|
27
src/dawn/scene/components/physics/3d/RayTester3D.hpp
Normal file
27
src/dawn/scene/components/physics/3d/RayTester3D.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class RayTester3D : public SceneItemComponent {
|
||||
public:
|
||||
SimpleSpinningCubePrefab *prefab;
|
||||
Camera *camera;
|
||||
struct AABB3D box;
|
||||
struct Ray3D ray;
|
||||
glm::vec3 hit;
|
||||
glm::vec3 normal;
|
||||
float_t distance;
|
||||
|
||||
RayTester3D(SceneItem *item);
|
||||
void onStart() override;
|
||||
void onUpdate();
|
||||
};
|
||||
}
|
11
src/dawn/scene/components/physics/3d/collider/CMakeLists.txt
Normal file
11
src/dawn/scene/components/physics/3d/collider/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Collider3D.cpp
|
||||
CubeCollider.cpp
|
||||
)
|
12
src/dawn/scene/components/physics/3d/collider/Collider3D.cpp
Normal file
12
src/dawn/scene/components/physics/3d/collider/Collider3D.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Collider3D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Collider3D::Collider3D(SceneItem *item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
22
src/dawn/scene/components/physics/3d/collider/Collider3D.hpp
Normal file
22
src/dawn/scene/components/physics/3d/collider/Collider3D.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Collider3DRayResult {
|
||||
glm::vec3 normal;
|
||||
glm::vec3 point;
|
||||
};
|
||||
|
||||
class Collider3D : public SceneItemComponent {
|
||||
public:
|
||||
Collider3D(SceneItem *item);
|
||||
|
||||
virtual bool_t raycast(struct Ray3D ray, struct Collider3DRayResult *out) = 0;
|
||||
};
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
CubeCollider::CubeCollider(SceneItem *item) : Collider3D(item) {
|
||||
|
||||
}
|
||||
|
||||
bool_t CubeCollider::raycast(struct Ray3D ray, struct Collider3DRayResult *out){
|
||||
return false;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class CubeCollider : public Collider3D {
|
||||
public:
|
||||
glm::vec3 center = glm::vec3(0, 0, 0);
|
||||
glm::vec3 size = glm::vec3(1, 1, 1);
|
||||
|
||||
CubeCollider(SceneItem *item);
|
||||
|
||||
bool_t raycast(struct Ray3D ray, struct Collider3DRayResult *out)override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user