-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,731 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "BoundBox.hh" | ||
|
||
#include "egg/math/Math.hh" | ||
|
||
namespace EGG { | ||
|
||
BoundBox2f::BoundBox2f() { | ||
resetBound(); | ||
} | ||
|
||
BoundBox2f::~BoundBox2f() = default; | ||
|
||
void BoundBox2f::resetBound() { | ||
mMin.set(std::numeric_limits<f32>::max()); | ||
mMax.set(-std::numeric_limits<f32>::max()); | ||
} | ||
|
||
void BoundBox2f::setDirect(const Vector2f &min, const Vector2f &max) { | ||
mMax = max; | ||
mMin = min; | ||
} | ||
|
||
void BoundBox2f::setMin(const Vector2f &min) { | ||
mMin = min; | ||
} | ||
|
||
void BoundBox2f::setMax(const Vector2f &max) { | ||
mMax = max; | ||
} | ||
|
||
BoundBox3f::BoundBox3f() { | ||
resetBound(); | ||
} | ||
|
||
BoundBox3f::~BoundBox3f() = default; | ||
|
||
void BoundBox3f::resetBound() { | ||
mMin.set(std::numeric_limits<f32>::max()); | ||
mMax.set(-std::numeric_limits<f32>::max()); | ||
} | ||
|
||
void BoundBox3f::setDirect(const Vector3f &min, const Vector3f &max) { | ||
mMax = max; | ||
mMin = min; | ||
} | ||
|
||
void BoundBox3f::setMin(const Vector3f &min) { | ||
mMin = min; | ||
} | ||
|
||
void BoundBox3f::setMax(const Vector3f &max) { | ||
mMax = max; | ||
} | ||
|
||
} // namespace EGG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include "egg/math/Vector.hh" | ||
|
||
namespace EGG { | ||
|
||
struct BoundBox2f { | ||
BoundBox2f(); | ||
~BoundBox2f(); | ||
|
||
void resetBound(); | ||
void setDirect(const Vector2f &max, const Vector2f &min); | ||
void setMin(const Vector2f &min); | ||
void setMax(const Vector2f &max); | ||
|
||
Vector2f mMin; | ||
Vector2f mMax; | ||
}; | ||
|
||
struct BoundBox3f { | ||
BoundBox3f(); | ||
~BoundBox3f(); | ||
|
||
void resetBound(); | ||
void setDirect(const Vector3f &max, const Vector3f &min); | ||
void setMin(const Vector3f &min); | ||
void setMax(const Vector3f &max); | ||
|
||
Vector3f mMin; | ||
Vector3f mMax; | ||
}; | ||
|
||
} // namespace EGG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "Matrix.hh" | ||
|
||
namespace EGG { | ||
|
||
Matrix34f::Matrix34f() { | ||
makeZero(); | ||
} | ||
|
||
Matrix34f::Matrix34f(f32 _e00, f32 _e01, f32 _e02, f32 _e03, f32 _e10, f32 _e11, f32 _e12, f32 _e13, | ||
f32 _e20, f32 _e21, f32 _e22, f32 _e23) { | ||
mtx[0][0] = _e00; | ||
mtx[0][1] = _e01; | ||
mtx[0][2] = _e02; | ||
mtx[0][3] = _e03; | ||
mtx[1][0] = _e10; | ||
mtx[1][1] = _e11; | ||
mtx[1][2] = _e12; | ||
mtx[1][3] = _e13; | ||
mtx[2][0] = _e20; | ||
mtx[2][1] = _e21; | ||
mtx[2][2] = _e22; | ||
mtx[2][3] = _e23; | ||
} | ||
|
||
Matrix34f::~Matrix34f() = default; | ||
|
||
void Matrix34f::makeQT(const Quatf &q, const Vector3f &t) { | ||
mtx[0][0] = 1.0f - 2.0f * (q.v.y * q.v.y + q.v.z * q.v.z); | ||
mtx[0][1] = 2.0f * (q.v.x * q.v.y - q.w * q.v.z); | ||
mtx[0][2] = 2.0f * (q.v.x * q.v.z + q.w * q.v.y); | ||
mtx[0][3] = t.x; | ||
mtx[1][0] = 2.0f * (q.v.x * q.v.y + q.w * q.v.y); | ||
mtx[1][1] = 1.0 - 2.0f * (q.v.x * q.v.x + q.v.z * q.v.z); | ||
mtx[1][2] = 2.0f * (q.v.y * q.v.z - q.w * q.v.x); | ||
mtx[1][3] = t.y; | ||
mtx[2][0] = 2.0f * (q.v.x * q.v.z - q.w * q.v.y); | ||
mtx[2][1] = 2.0f * (q.v.y * q.v.z + q.w * q.v.x); | ||
mtx[2][2] = 1.0 - 2.0f * (q.v.x * q.v.x + q.v.y * q.v.y); | ||
mtx[2][3] = t.z; | ||
} | ||
|
||
void Matrix34f::makeZero() { | ||
for (auto &n : a) { | ||
n = 0.0f; | ||
} | ||
} | ||
|
||
const Matrix34f Matrix34f::ident(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, | ||
0.0f); | ||
|
||
} // namespace EGG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "egg/math/Quat.hh" | ||
|
||
namespace EGG { | ||
|
||
class Matrix34f { | ||
public: | ||
Matrix34f(); | ||
Matrix34f(f32 _e00, f32 _e01, f32 _e02, f32 _e03, f32 _e10, f32 _e11, f32 _e12, f32 _e13, | ||
f32 _e20, f32 _e21, f32 _e22, f32 _e23); | ||
~Matrix34f(); | ||
|
||
f32 &operator()(int i, int j) { | ||
return mtx[i][j]; | ||
} | ||
|
||
// Q for Quaternion, T for translation | ||
void makeQT(const Quatf &q, const Vector3f &t); | ||
void makeZero(); | ||
|
||
static const Matrix34f ident; | ||
|
||
private: | ||
union { | ||
std::array<std::array<f32, 4>, 3> mtx; | ||
std::array<f32, 12> a; | ||
}; | ||
}; | ||
|
||
} // namespace EGG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "CollisionDirector.hh" | ||
|
||
namespace Field { | ||
|
||
bool CollisionDirector::checkSphereFullPush(f32 radius, const EGG::Vector3f &v0, | ||
const EGG::Vector3f &v1, KCLTypeMask flags, CourseColMgr::CollisionInfo *pInfo, | ||
KCLTypeMask *pFlagsOut, u32 /*param_8*/) { | ||
if (pInfo) { | ||
pInfo->m_bbox.mMin = EGG::Vector3f::zero; | ||
pInfo->m_bbox.mMax = EGG::Vector3f::zero; | ||
pInfo->_50 = -std::numeric_limits<f32>::min(); | ||
pInfo->m_wallDist = -std::numeric_limits<f32>::min(); | ||
pInfo->m_floorDist = -std::numeric_limits<f32>::min(); | ||
pInfo->m_perpendicularity = 0.0f; | ||
} | ||
|
||
if (pFlagsOut) { | ||
resetCollisionEntries(pFlagsOut); | ||
} | ||
|
||
bool colliding = false; | ||
|
||
if (flags && | ||
CourseColMgr::Instance()->checkSphereFullPush(1.0f, radius, nullptr, v0, v1, flags, | ||
pInfo, pFlagsOut)) { | ||
colliding = true; | ||
} | ||
|
||
if (colliding && pInfo) { | ||
pInfo->m_minPlusMax = pInfo->m_bbox.mMin + pInfo->m_bbox.mMax; | ||
} | ||
|
||
return colliding; | ||
} | ||
|
||
void CollisionDirector::resetCollisionEntries(KCLTypeMask *ptr) { | ||
*ptr = 0; | ||
m_collisionEntryCount = 0; | ||
m_closestCollisionEntry = nullptr; | ||
} | ||
|
||
void CollisionDirector::pushCollisionEntry(f32 dist, KCLTypeMask *typeMask, KCLTypeMask kclTypeBit, | ||
u16 attribute) { | ||
*typeMask = *typeMask | kclTypeBit; | ||
if (m_collisionEntryCount >= m_entries.size()) { | ||
m_collisionEntryCount = m_entries.size() - 1; | ||
} | ||
|
||
m_entries[m_collisionEntryCount++] = CollisionEntry(kclTypeBit, attribute, dist); | ||
} | ||
|
||
CollisionDirector *CollisionDirector::CreateInstance() { | ||
assert(!s_instance); | ||
s_instance = new CollisionDirector; | ||
return s_instance; | ||
} | ||
|
||
CollisionDirector *CollisionDirector::Instance() { | ||
return s_instance; | ||
} | ||
|
||
void CollisionDirector::DestroyInstance() { | ||
assert(s_instance); | ||
delete s_instance; | ||
s_instance = nullptr; | ||
} | ||
|
||
CollisionDirector::CollisionDirector() { | ||
m_collisionEntryCount = 0; | ||
m_closestCollisionEntry = nullptr; | ||
CourseColMgr::CreateInstance()->init(); | ||
} | ||
|
||
CollisionDirector::~CollisionDirector() { | ||
CourseColMgr::DestroyInstance(); | ||
} | ||
|
||
CollisionDirector *CollisionDirector::s_instance = nullptr; | ||
|
||
} // namespace Field |
Oops, something went wrong.