void GOCube::makeCollisionShape() { switch (getCollisionShapeType()) { case CST_AUTOMATIC: case CST_AUTOMATIC_BOX: makeBoxShape(size); break; case CST_AUTOMATIC_SPHERE: { float radius = size.x; if (radius < size.y) radius = size.y; if (radius < size.z) radius = size.z; makeSphereShape(radius); } break; case CST_AUTOMATIC_CYLINDER: { float diameter = sqrt(size.x * size.x + size.z * size.z); makeCylinderShape(CVector(diameter, size.y)); } break; default: break; } PhysicObject::makeCollisionShape(); }
void GOGround::makeCollisionShape() { switch (getCollisionShapeType()) { case CST_AUTOMATIC: { GOCompoundCollisionShape* s = new GOCompoundCollisionShape(); GOBoxCollisionShape* b1 = new GOBoxCollisionShape(CVector(size.x * OBJ_MAP_CELL_SIZE * 2 + OBJ_MAP_CELL_SIZE * 4, OBJ_MAP_CELL_SIZE * 4, size.z * OBJ_MAP_CELL_SIZE * 2 + OBJ_MAP_CELL_SIZE * 4)); b1->setOffset(CVector(0, -(OBJ_MAP_CELL_SIZE * 1), 0)); s->addChild(b1); GOBoxCollisionShape* b2 = new GOBoxCollisionShape(CVector(size.x * OBJ_MAP_CELL_SIZE * 2, size.y * OBJ_MAP_CELL_SIZE * 2, size.z * OBJ_MAP_CELL_SIZE * 2)); b2->setOffset(CVector(0, -(size.y * OBJ_MAP_CELL_SIZE + OBJ_MAP_CELL_SIZE * 2), 0)); s->addChild(b2); setCollisionShape(s); } break; case CST_AUTOMATIC_BOX: makeBoxShape(size * OBJ_MAP_CELL_SIZE * 2); break; case CST_AUTOMATIC_SPHERE: { float radius = size.x; if (radius < size.y) radius = size.y; if (radius < size.z) radius = size.z; makeSphereShape(radius); } break; case CST_AUTOMATIC_CYLINDER: { float diameter = sqrt(size.x * size.x + size.z * size.z); makeCylinderShape(CVector(diameter, size.y)); } break; default: break; } PhysicObject::makeCollisionShape(); }
Object::Object(b2World* world,const float &x, const float & y, const float&xScale, const float&yScale,SDL_Renderer* renderer,Shapes wShape, bool staticX,float wRadius,float wDensity):tWidth(0.0f), tHeight(0.0f),keepAspect(false),radius(0.0f),density(wDensity) { shape = wShape; if(wRadius>0.001) makeCircleShape(world,x,y,wRadius,renderer,staticX,xScale,yScale); else makeBoxShape(world,x,y,xScale,yScale,renderer,staticX); }