Added PartInstance->Collides function

This commit is contained in:
andreja6
2020-03-15 11:46:06 -07:00
parent 73a6b72c20
commit 0090c6c8a1
2 changed files with 29 additions and 1 deletions

View File

@@ -206,8 +206,27 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
// Can probably be deleted // Can probably be deleted
CoordinateFrame PartInstance::getCFrameRenderBased() 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 #ifdef NEW_BOX_RENDER
Box PartInstance::getBox() Box PartInstance::getBox()
{ {
@@ -216,6 +235,13 @@ Box PartInstance::getBox()
itemBox = c.toWorldSpace(box); itemBox = c.toWorldSpace(box);
return itemBox; 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 #else
Box PartInstance::getBox() Box PartInstance::getBox()
{ {

View File

@@ -31,10 +31,12 @@ public:
void setParent(Instance* parent); void setParent(Instance* parent);
void setPosition(Vector3); void setPosition(Vector3);
void setVelocity(Vector3); void setVelocity(Vector3);
bool collides(PartInstance * part);
void setRotVelocity(Vector3); void setRotVelocity(Vector3);
CoordinateFrame getCFrame(); CoordinateFrame getCFrame();
void setCFrame(CoordinateFrame); void setCFrame(CoordinateFrame);
Box getBox(); Box getBox();
Sphere getSphere();
Box getScaledBox(); Box getScaledBox();
CoordinateFrame getCFrameRenderBased(); CoordinateFrame getCFrameRenderBased();
Vector3 getSize(); Vector3 getSize();