Added Ray
This commit is contained in:
parent
5b4838c5b9
commit
2fa71f0fd9
|
@ -201,6 +201,11 @@ namespace SHADE
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SHBoundingBox::Raycast(const SHVec3& SHRay, float& distance) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SHBoundingBox::Contains(const SHBoundingBox& rhs) const noexcept
|
||||
{
|
||||
const SHVec3 V = SHVec3::Abs(rhs.center - center);
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace SHADE
|
|||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override;
|
||||
[[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override;
|
||||
[[nodiscard]] bool Raycast (const SHVec3& SHRay, float& distance) noexcept override;
|
||||
|
||||
[[nodiscard]] bool Contains (const SHBoundingBox& rhs) const noexcept;
|
||||
[[nodiscard]] float Volume () const noexcept;
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
#pragma once
|
||||
|
||||
// Project Headers
|
||||
#include "Math/Transform/SHTransform.h"
|
||||
#include "SH_API.h"
|
||||
#include "Math/Transform/SHTransform.h"
|
||||
#include "Math/SHRay.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -69,7 +71,8 @@ namespace SHADE
|
|||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] virtual bool TestPoint (const SHVec3& point) noexcept = 0;
|
||||
[[nodiscard]] virtual bool TestPoint (const SHVec3& point) noexcept = 0;
|
||||
[[nodiscard]] virtual bool Raycast (const SHVec3& SHRay, float& distance) noexcept = 0;
|
||||
|
||||
protected:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -334,6 +334,39 @@ namespace SHADE
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
bool SHMatrix::Decompose(SHVec3& translation, SHVec3& rotation, SHVec3& scale) const noexcept
|
||||
{
|
||||
XMVECTOR s, r, t;
|
||||
const XMMATRIX M = XMLoadFloat4x4(this);
|
||||
|
||||
if (!XMMatrixDecompose(&s, &r, &t, M))
|
||||
return false;
|
||||
|
||||
SHQuaternion orientation;
|
||||
|
||||
XMStoreFloat3(&scale, s);
|
||||
XMStoreFloat4(&orientation, r);
|
||||
XMStoreFloat3(&translation, t);
|
||||
|
||||
rotation = orientation.ToEuler();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHMatrix::Decompose(SHVec3& translation, SHQuaternion& orientation, SHVec3& scale) const noexcept
|
||||
{
|
||||
XMVECTOR s, r, t;
|
||||
const XMMATRIX M = XMLoadFloat4x4(this);
|
||||
|
||||
if (!XMMatrixDecompose(&s, &r, &t, M))
|
||||
return false;
|
||||
|
||||
XMStoreFloat3(&scale, s);
|
||||
XMStoreFloat4(&orientation, r);
|
||||
XMStoreFloat3(&translation, t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Function Member Definitions */
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
// Project Headers
|
||||
#include "SH_API.h"
|
||||
#include "Vector/SHVec4.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -25,7 +24,6 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHVec2;
|
||||
class SHVec3;
|
||||
class SHVec4;
|
||||
class SHQuaternion;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -109,6 +107,24 @@ namespace SHADE
|
|||
[[nodiscard]] float Determinant () const noexcept;
|
||||
[[nodiscard]] std::string ToString () const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Decomposes a transformation matrix into translation, euler angles and scale.
|
||||
* @param[out] scale The scaling factor of the matrix.
|
||||
* @param[out] rotation The euler angles of the matrix.
|
||||
* @param[out] translation The translation of the matrix.
|
||||
* @return True if decomposition was successful.
|
||||
*/
|
||||
bool Decompose (SHVec3& translation, SHVec3& rotation, SHVec3& scale) const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Decomposes a transformation matrix into translation, orientation and scale.
|
||||
* @param[out] scale The scaling factor of the matrix.
|
||||
* @param[out] orientation The orientation of the matrix.
|
||||
* @param[out] translation The translation of the matrix.
|
||||
* @return True if decomposition was successful.
|
||||
*/
|
||||
bool Decompose (SHVec3& translation, SHQuaternion& orientation, SHVec3& scale) const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/****************************************************************************************
|
||||
* \file SHRay.cpp
|
||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
* \brief Implementation for a Ray.
|
||||
*
|
||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
****************************************************************************************/
|
||||
|
||||
#include <SHpch.h>
|
||||
|
||||
// Primary Header
|
||||
#include "SHRay.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
SHRay::SHRay() noexcept
|
||||
: direction { 0.0f, 0.0f, 1.0f }
|
||||
{}
|
||||
|
||||
SHRay::SHRay(const SHVec3& pos, const SHVec3& dir) noexcept
|
||||
: position { pos }
|
||||
, direction { dir }
|
||||
{}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Operator Overload Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
bool SHRay::operator==(const SHRay& rhs) noexcept
|
||||
{
|
||||
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
||||
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
||||
|
||||
const XMVECTOR LHS_DIR = XMLoadFloat3(&direction);
|
||||
const XMVECTOR RHS_DIR = XMLoadFloat3(&rhs.direction);
|
||||
|
||||
return XMVector3Equal(LHS_POS, RHS_POS) && XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
||||
}
|
||||
|
||||
bool SHRay::operator!=(const SHRay& rhs) noexcept
|
||||
{
|
||||
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
||||
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
||||
|
||||
const XMVECTOR LHS_DIR = XMLoadFloat3(&direction);
|
||||
const XMVECTOR RHS_DIR = XMLoadFloat3(&rhs.direction);
|
||||
|
||||
return XMVector3NotEqual(LHS_POS, RHS_POS) || XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
||||
}
|
||||
|
||||
|
||||
} // namespace SHADE
|
|
@ -0,0 +1,54 @@
|
|||
/****************************************************************************************
|
||||
* \file SHRay.h
|
||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
* \brief Interface for a Ray.
|
||||
*
|
||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
****************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DirectXMath.h>
|
||||
|
||||
// Project Headers
|
||||
#include "SH_API.h"
|
||||
#include "Vector/SHVec3.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
struct SH_API SHRay
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
SHVec3 position;
|
||||
SHVec3 direction;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
SHRay() noexcept;
|
||||
SHRay(const SHVec3& pos, const SHVec3& dir) noexcept;
|
||||
SHRay(const SHRay& rhs) noexcept = default;
|
||||
SHRay(SHRay&& rhs) noexcept = default;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
SHRay& operator= (const SHRay& rhs) noexcept = default;
|
||||
SHRay& operator= (SHRay&& rhs) noexcept = default;
|
||||
|
||||
[[nodiscard]] bool operator==(const SHRay& rhs) noexcept;
|
||||
[[nodiscard]] bool operator!=(const SHRay& rhs) noexcept;
|
||||
};
|
||||
} // namespace SHADE
|
Loading…
Reference in New Issue