bool CDynamics2DSingleBodyObjectModel::IsCollidingWithSomething() const { for(cpShape* pt_shape = m_ptBody->shapeList; pt_shape != NULL; pt_shape = pt_shape->next) { if(cpSpaceShapeQuery( const_cast<CDynamics2DSingleBodyObjectModel*>(this)-> GetDynamics2DEngine().GetPhysicsSpace(), pt_shape, NULL, NULL) > 0) { return true; } } return false; }
bool CDynamics2DBoxEntity::MoveTo(const CVector3& c_position, const CQuaternion& c_orientation, bool b_check_only) { SInt32 nCollision; /* Check whether the box is movable or not */ if(m_cBoxEntity.GetEmbodiedEntity().IsMovable()) { /* The box is movable */ /* Save body position and orientation */ cpVect tOldPos = m_ptBody->p; cpFloat fOldA = m_ptBody->a; /* Move the body to the desired position */ m_ptBody->p = cpv(c_position.GetX(), c_position.GetY()); CRadians cXAngle, cYAngle, cZAngle; c_orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle); cpBodySetAngle(m_ptBody, cZAngle.GetValue()); /* Create a shape sensor to test the movement */ /* First construct the vertices */ CVector3 cHalfSize = m_cBoxEntity.GetSize() * 0.5f; cpVect tVertices[] = { cpv(-cHalfSize.GetX(), -cHalfSize.GetY()), cpv(-cHalfSize.GetX(), cHalfSize.GetY()), cpv( cHalfSize.GetX(), cHalfSize.GetY()), cpv( cHalfSize.GetX(), -cHalfSize.GetY()) }; /* Then create the shape itself */ cpShape* ptTestShape = cpPolyShapeNew(m_ptBody, 4, tVertices, cpvzero); /* Check if there is a collision */ nCollision = cpSpaceShapeQuery(m_cEngine.GetPhysicsSpace(), ptTestShape, NULL, NULL); /* Dispose of the sensor shape */ cpShapeFree(ptTestShape); if(b_check_only || nCollision) { /* Restore old body state if there was a collision or it was only a check for movement */ m_ptBody->p = tOldPos; cpBodySetAngle(m_ptBody, fOldA); } else { /* Update the active space hash if the movement is actual */ cpSpaceReindexShape(m_cEngine.GetPhysicsSpace(), m_ptShape); } } else { /* The box is not movable, so you can't move it :-) */ nCollision = 1; } /* The movement is allowed if there is no collision */ return !nCollision; }
bool CDynamics2DMultiBodyObjectModel::IsCollidingWithSomething() const { if(m_vecBodies.empty()) return false; for(size_t i = 0; i < m_vecBodies.size(); ++i) { for(cpShape* pt_shape = m_vecBodies[i].Body->shapeList; pt_shape != NULL; pt_shape = pt_shape->next) { if(cpSpaceShapeQuery( const_cast<CDynamics2DMultiBodyObjectModel*>(this)-> GetDynamics2DEngine().GetPhysicsSpace(), pt_shape, NULL, NULL) > 0) { return true; } } } return false; }
void cpSpaceActivateShapesTouchingShape(cpSpace *space, cpShape *shape){ cpArray *bodies = NULL; cpSpaceShapeQuery(space, shape, (cpSpaceShapeQueryFunc)activateTouchingHelper, &bodies); }
cpBool Space::shapeQuery(cpShape *shape,SpaceShapeQueryFunc func) { return cpSpaceShapeQuery(space,shape,*SpaceShapeQuery,&func); }
cpBool Space::shapeQuery(cp::Shape *shape,cpSpaceShapeQueryFunc func,void *data) { return cpSpaceShapeQuery(space,shape ? shape->get() : 0,func,data); }
bool PhysicsShape::isOverlapping() { int isOverlapping = 0; cpSpaceShapeQuery(m_world->space, this->m_shape, checkOverlappingBool, (void*)&isOverlapping); return (bool)isOverlapping; }