From 0090c6c8a1775b0d1de2fbc8c741bdf59eccef44 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 15 Mar 2020 11:46:06 -0700 Subject: [PATCH] Added PartInstance->Collides function --- PartInstance.cpp | 28 +++++++++++++++++++++++++++- PartInstance.h | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index cc95f0f..9c244e3 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -206,8 +206,27 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame) // Can probably be deleted CoordinateFrame PartInstance::getCFrameRenderBased() { - return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); + return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); } + +bool PartInstance::collides(PartInstance * part) +{ + if(shape == Enum::Shape::Block) + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(part->getSphere(), getBox()); + } + else + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(getSphere(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere(getSphere(), part->getSphere()); + } +} + #ifdef NEW_BOX_RENDER Box PartInstance::getBox() { @@ -216,6 +235,13 @@ Box PartInstance::getBox() itemBox = c.toWorldSpace(box); return itemBox; } +Sphere PartInstance::getSphere() +{ + Sphere sphere = Sphere(Vector3(0,0,0), size.y/2); + CoordinateFrame c = getCFrameRenderBased(); + //itemBox = c.toWorldSpace(Sphere); + return sphere;//itemBox; +} #else Box PartInstance::getBox() { diff --git a/PartInstance.h b/PartInstance.h index b47e22b..6df56b7 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -31,10 +31,12 @@ public: void setParent(Instance* parent); void setPosition(Vector3); void setVelocity(Vector3); + bool collides(PartInstance * part); void setRotVelocity(Vector3); CoordinateFrame getCFrame(); void setCFrame(CoordinateFrame); Box getBox(); + Sphere getSphere(); Box getScaledBox(); CoordinateFrame getCFrameRenderBased(); Vector3 getSize();