default
This commit is contained in:
@@ -12,4 +12,5 @@ namespace Collision {
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray& vA, const Vector3& rotation); //Faster due to using the cached OBB.
|
||||
Sphere genMinimallyEnclosingSphere(const VertexArray& vA); //Faster due to using the cached OBB.
|
||||
OBB genMinimallyEnclosingOBB(const VertexArray& vA, const Vector3& rotation);
|
||||
VertexArray getDrawable(const Shape& collider);
|
||||
}
|
||||
|
@@ -4,18 +4,21 @@
|
||||
|
||||
void Cube::pre_render() {
|
||||
//hVelocity = 1;
|
||||
getGeometry();
|
||||
hMove(velAngle, hVelocity);
|
||||
vMove(vVelocity);
|
||||
|
||||
angle.x = angle.x + 24*engine->frameDelta;
|
||||
angle.y = angle.y + 24*engine->frameDelta;
|
||||
angle.z = angle.z + 24*engine->frameDelta;
|
||||
|
||||
OBB obb = getGeometry()->getCachedOBB(angle);
|
||||
VertexArray drawable = Collision::getDrawable(getGeometry()->getCachedOBB(angle));
|
||||
}
|
||||
|
||||
void Cube::update(float elapsed) {
|
||||
|
||||
}
|
||||
|
||||
Cube::Cube() {
|
||||
name = "cube";
|
||||
modelPath = "assets/models/cube.obj";
|
||||
|
@@ -54,4 +54,15 @@ OBB Collision::genMinimallyEnclosingOBB(const VertexArray& vA, const Vector3& ro
|
||||
radii.z = std::max(radii.z, std::abs(diff.z));
|
||||
}
|
||||
return {centroid, radii, axis0, axis1, axis2};
|
||||
}
|
||||
|
||||
VertexArray Collision::getDrawable(const Shape& collider) {
|
||||
if (const auto* c = static_cast<const AABB*>(&collider)) {
|
||||
std::cout << "We passed in an AABB" << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
if (const auto* c = static_cast<const OBB*>(&collider)) {
|
||||
std::cout << "We passed in an OBB" << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <Collage/types/model.h>
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
auto m = new Model(filename);
|
||||
auto* m = new Model(filename);
|
||||
vertices = m->getVertices();
|
||||
indices = m->getIndices();
|
||||
texCoords = m->getTextureInformation()[0].textureCoordinates;
|
||||
@@ -33,7 +33,7 @@ void VertexArray::load (const std::string& filename) {
|
||||
}
|
||||
|
||||
//Cached OBB.
|
||||
cachedOBB = Collision::genMinimallyEnclosingOBB(*this, {0, 0, 0});
|
||||
this->cachedOBB = Collision::genMinimallyEnclosingOBB(*this, (Vector3) {0, 0, 0});
|
||||
}
|
||||
|
||||
void VertexArray::draw() {
|
||||
@@ -170,18 +170,18 @@ const OBB& VertexArray::getCachedOBB(const Matrix3x3& rotationMatrix) const {
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
}
|
||||
|
||||
const OBB &VertexArray::getCachedOBB(const Vector3 &rotation) const {
|
||||
const OBB& VertexArray::getCachedOBB(const Vector3& rotation) const {
|
||||
Matrix3x3 rotationMatrix = Matrix3x3::FromQuat(Quaternion((EulerAngle) rotation));
|
||||
Vector3 axis0 = Vector3(rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]);
|
||||
Vector3 axis1 = Vector3(rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]);
|
||||
Vector3 axis2 = Vector3(rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]);
|
||||
Vector3 axis0 = {rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]};
|
||||
Vector3 axis1 = {rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]};
|
||||
Vector3 axis2 = {rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]};
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
}
|
||||
|
||||
const OBB &VertexArray::getCachedOBB(const EulerAngle &rotation) const {
|
||||
const OBB& VertexArray::getCachedOBB(const EulerAngle &rotation) const {
|
||||
Matrix3x3 rotationMatrix = Matrix3x3::FromQuat(Quaternion( rotation));
|
||||
Vector3 axis0 = Vector3(rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]);
|
||||
Vector3 axis1 = Vector3(rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]);
|
||||
Vector3 axis2 = Vector3(rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]);
|
||||
Vector3 axis0 = {rotationMatrix[0][0], rotationMatrix[1][0], rotationMatrix[2][0]};
|
||||
Vector3 axis1 = {rotationMatrix[0][1], rotationMatrix[1][1], rotationMatrix[2][1]};
|
||||
Vector3 axis2 = {rotationMatrix[0][2], rotationMatrix[1][2], rotationMatrix[2][2]};
|
||||
return OBB(cachedOBB.pos, cachedOBB.r, axis0, axis1, axis2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user