Fixed collision for object not in world

This commit is contained in:
Robin Engman 2014-02-12 12:38:52 +01:00
parent 1841685edb
commit 15cc7cb85e
4 changed files with 33 additions and 26 deletions

View File

@ -297,10 +297,10 @@ void API_Impl::ApplyEffect(Oyster::Collision3D::ICollideable* collideable, void*
case ICollideable::Type::Type_cone: case ICollideable::Type::Type_cone:
cone = dynamic_cast<Cone*>(collideable); cone = dynamic_cast<Cone*>(collideable);
// Add collision shape // Add collision shape
shape = new btConeShape(cone->radius, cone->height.GetLength()); shape = new btConeShapeZ(cone->radius, cone->length);
// Add motion state // Add motion state
state = new btDefaultMotionState(btTransform(btQuaternion(btVector3(cone->height.x, cone->height.y, cone->height.z).normalized(), 0.0f),btVector3(cone->position.x, cone->position.y, cone->position.z))); state = new btDefaultMotionState(btTransform(btQuaternion(cone->quaternion.x, cone->quaternion.y, cone->quaternion.z, cone->quaternion.w),btVector3(cone->center.x, cone->center.y, cone->center.z)));
// Add rigid body // Add rigid body
rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo (0, state, shape); rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo (0, state, shape);

View File

@ -39,7 +39,7 @@ namespace Oyster
} }
else else
{ {
assert(colObj1->m_collisionObject == &body && "Body does not match either collision object"); //assert(colObj1->m_collisionObject == &body && "Body does not match either collision object");
pt = cp.m_localPointB; pt = cp.m_localPointB;
this->func((ICustomBody*)(colObj0->getCollisionObject()->getUserPointer()), this->args); this->func((ICustomBody*)(colObj0->getCollisionObject()->getUserPointer()), this->args);
} }

View File

@ -11,22 +11,36 @@ using namespace ::Oyster::Math3D;
Cone::Cone( ) : ICollideable(Type_cone) Cone::Cone( ) : ICollideable(Type_cone)
{ {
this->center = Float3(0, 0, 0);
this->quaternion = Float4(0, 0, 0, 1);
this->radius = 1; this->radius = 1;
this->height = Oyster::Math::Float3(0,0,0); this->length = 0;
} }
Cone::Cone( const ::Oyster::Math::Float3 &height, const Oyster::Math::Float3 &position, const ::Oyster::Math::Float &radius ) : ICollideable(Type_cone) Cone & Cone::operator = ( const Cone &Cone )
{ {
this->radius = radius; this->center = Cone.center;
this->height = height; this->quaternion = Cone.quaternion;
this->position = position; this->radius = Cone.radius;
this->length = Cone.length;
return *this;
} }
Cone::Cone( const ::Oyster::Math::Float4 &height, const Oyster::Math::Float4 &position, const ::Oyster::Math::Float &radius ) : ICollideable(Type_cone) Cone::Cone( const ::Oyster::Math::Float &height, const Oyster::Math::Float3 &position, const Oyster::Math::Float4 &quaternion, const ::Oyster::Math::Float &radius ) : ICollideable(Type_cone)
{ {
this->center = position;
this->quaternion = quaternion;
this->radius = radius; this->radius = radius;
this->height = (Oyster::Math::Float3)height; this->length = height;
this->position = (Oyster::Math::Float3)position; }
Cone::Cone( const ::Oyster::Math::Float &height, const Oyster::Math::Float4 &position, const Oyster::Math::Float4 &quaternion, const ::Oyster::Math::Float &radius ) : ICollideable(Type_cone)
{
this->center = position;
this->quaternion = quaternion;
this->radius = radius;
this->length = height;
} }
Cone::~Cone( ) Cone::~Cone( )
@ -34,14 +48,6 @@ Cone::~Cone( )
} }
Cone & Cone::operator = ( const Cone &cone )
{
this->radius = cone.radius;
this->height = cone.height;
this->position = cone.position;
return *this;
}
::Utility::DynamicMemory::UniquePointer<ICollideable> Cone::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Cone::Clone( ) const
{ {
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Cone(*this) ); return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Cone(*this) );

View File

@ -18,9 +18,15 @@ namespace Oyster
{ {
public: public:
union
{
struct{ ::Oyster::Math::Float3 center; ::Oyster::Math::Float4 quaternion; ::Oyster::Math::Float radius; ::Oyster::Math::Float length; };
char byte[sizeof(::Oyster::Math::Float3) + sizeof(::Oyster::Math::Float4) + sizeof(::Oyster::Math::Float) + sizeof(::Oyster::Math::Float)];
};
Cone(); Cone();
Cone( const ::Oyster::Math::Float3 &height, const Oyster::Math::Float3 &position, const ::Oyster::Math::Float &radius ); Cone( const ::Oyster::Math::Float &height, const Oyster::Math::Float3 &position, const Oyster::Math::Float4 &quaternion, const ::Oyster::Math::Float &radius );
Cone( const ::Oyster::Math::Float4 &height, const Oyster::Math::Float4 &position, const ::Oyster::Math::Float &radius ); Cone( const ::Oyster::Math::Float &height, const Oyster::Math::Float4 &position, const Oyster::Math::Float4 &quaternion, const ::Oyster::Math::Float &radius );
virtual ~Cone( ); virtual ~Cone( );
Cone & operator = ( const Cone &Cone ); Cone & operator = ( const Cone &Cone );
@ -32,11 +38,6 @@ namespace Oyster
bool Contains( const ICollideable &target ) const{return false;}; bool Contains( const ICollideable &target ) const{return false;};
::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const{return 0;}; ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const{return 0;};
Oyster::Math::Float3 height;
Oyster::Math::Float3 position;
Oyster::Math::Float radius;
}; };
} }