Actually have matrixed cubes working
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
#include "locale/LocaleManager.hpp"
|
||||
#include "save/SaveManager.hpp"
|
||||
#include "audio/AudioManager.hpp"
|
||||
#include "scene/SceneItemComponentList.hpp"
|
||||
// #include "scene/SceneItemComponentList.hpp"
|
||||
|
||||
#define DAWN_GAME_INIT_RESULT_SUCCESS 0
|
||||
#define DAWN_GAME_UPDATE_RESULT_SUCCESS 0
|
||||
@ -25,7 +25,7 @@ namespace Dawn {
|
||||
|
||||
class IDawnGame {
|
||||
protected:
|
||||
SceneItemComponentList componentList;
|
||||
// SceneItemComponentList componentList;
|
||||
|
||||
public:
|
||||
Scene *scene = nullptr;
|
||||
|
@ -7,16 +7,6 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Ray3D {
|
||||
glm::vec3 origin;
|
||||
glm::vec3 direction;
|
||||
};
|
||||
|
||||
struct PhysicsSphere {
|
||||
glm::vec3 center;
|
||||
float_t radius;
|
||||
};
|
||||
|
||||
bool_t Dawn::raytestSphere(
|
||||
struct Ray3D ray,
|
||||
struct PhysicsSphere sphere,
|
||||
@ -140,5 +130,32 @@ bool_t Dawn::raytestAABB(
|
||||
}
|
||||
|
||||
// The ray intersects the box
|
||||
return true;
|
||||
}
|
||||
|
||||
bool_t Dawn::raytestCube(
|
||||
struct Ray3D ray,
|
||||
struct AABB3D box,
|
||||
glm::mat4 transform,
|
||||
glm::vec3 *point,
|
||||
glm::vec3 *normal,
|
||||
float_t *distance
|
||||
) {
|
||||
// Compute the inverse transformation matrix
|
||||
glm::mat4 inverseTransform = glm::inverse(transform);
|
||||
|
||||
// Transform the ray into model space
|
||||
struct Ray3D localRay;
|
||||
localRay.origin = glm::vec3(inverseTransform * glm::vec4(ray.origin, 1.0f));
|
||||
localRay.direction = glm::normalize(glm::vec3(inverseTransform * glm::vec4(ray.direction, 0.0f)));
|
||||
|
||||
// Call raytestAABB with the transformed ray and cube
|
||||
bool_t hit = raytestAABB(localRay, box, point, normal, distance);
|
||||
if(!hit) return false;
|
||||
|
||||
// Transform the hit point and normal back into world space
|
||||
*point = glm::vec3(transform * glm::vec4(*point, 1.0f));
|
||||
*normal = glm::normalize(glm::vec3(glm::transpose(inverseTransform) * glm::vec4(*normal, 0.0f)));
|
||||
|
||||
return true;
|
||||
}
|
@ -38,4 +38,13 @@ namespace Dawn {
|
||||
glm::vec3 *normal,
|
||||
float_t *distance
|
||||
);
|
||||
}
|
||||
|
||||
bool_t raytestCube(
|
||||
struct Ray3D ray,
|
||||
struct AABB3D box,
|
||||
glm::mat4 transform,
|
||||
glm::vec3 *point,
|
||||
glm::vec3 *normal,
|
||||
float_t *distance
|
||||
);
|
||||
}
|
||||
|
@ -67,6 +67,18 @@ float_t Camera::getAspect() {
|
||||
return target->getWidth() / target->getHeight();
|
||||
}
|
||||
|
||||
glm::vec3 Camera::getRayDirectionFromScreenSpace(glm::vec2 screenSpace) {
|
||||
glm::vec4 clipCoords(screenSpace.x, -screenSpace.y, -1.0f, 1.0f);
|
||||
glm::mat4 inverseProjectionMatrix = glm::inverse(this->projection);
|
||||
glm::vec4 eyeCoords = inverseProjectionMatrix * clipCoords;
|
||||
eyeCoords = glm::vec4(eyeCoords.x, eyeCoords.y, -1.0f, 0.0f);
|
||||
|
||||
glm::mat4 inverseViewMatrix = glm::inverse(transform->getWorldTransform());
|
||||
glm::vec4 t = inverseViewMatrix * eyeCoords;
|
||||
|
||||
return glm::normalize(glm::vec3(t.x, t.y, t.z));
|
||||
}
|
||||
|
||||
void Camera::onStart() {
|
||||
this->updateProjection();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
@ -79,6 +80,18 @@ namespace Dawn {
|
||||
*/
|
||||
float_t getAspect();
|
||||
|
||||
/**
|
||||
* Creates the directional vector for a given point on the screen space
|
||||
* coordinates provided. This is useful if you want to, say, cast a ray
|
||||
* based on a position on the screen. The directional vector is normalized
|
||||
* between -1 and 1 where -1 is the near clipping plane, and 1 is the
|
||||
* far clipping plane.
|
||||
*
|
||||
* @param screenSpace Screen space vector (-1,-1 to 1,1) on the screen.
|
||||
* @return The vector for the direction to cast from.
|
||||
*/
|
||||
glm::vec3 getRayDirectionFromScreenSpace(glm::vec2 screenSpace);
|
||||
|
||||
/**
|
||||
* Event triggered by the scene item when the item is added to the scene.
|
||||
*/
|
||||
|
@ -29,7 +29,7 @@ struct ShaderPassItem SceneDebugLine::createShaderItem(
|
||||
auto i = *lineIndex;
|
||||
item.mesh = mesh;
|
||||
item.drawMode = MESH_DRAW_MODE_LINES;
|
||||
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND | RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST;
|
||||
item.renderFlags = 0x00;
|
||||
item.start = i * SCENE_DEBUG_LINE_INDICE_COUNT;
|
||||
item.count = SCENE_DEBUG_LINE_INDICE_COUNT;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#define SCENE_DEBUG_LINE_VERTICE_COUNT 2
|
||||
#define SCENE_DEBUG_LINE_INDICE_COUNT 2
|
||||
#define SCENE_DEBUG_LINE_PRIORITY 1
|
||||
#define SCENE_DEBUG_LINE_PRIORITY 100
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShader;
|
||||
|
Reference in New Issue
Block a user