mirror of https://github.com/axmolengine/axmol.git
issue #2771: delete PhysicsSlidingJoint and PhysicsSpringJoint. add joint tests, fix bugs
This commit is contained in:
parent
02e5d44955
commit
0710cfa526
|
@ -130,7 +130,7 @@ float PhysicsContactPreSolve::getElasticity() const
|
||||||
return static_cast<cpArbiter*>(_contactInfo)->e;
|
return static_cast<cpArbiter*>(_contactInfo)->e;
|
||||||
}
|
}
|
||||||
|
|
||||||
float PhysicsContactPreSolve::getFriciton() const
|
float PhysicsContactPreSolve::getFriction() const
|
||||||
{
|
{
|
||||||
return static_cast<cpArbiter*>(_contactInfo)->u;
|
return static_cast<cpArbiter*>(_contactInfo)->u;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ float PhysicsContactPostSolve::getElasticity() const
|
||||||
return static_cast<cpArbiter*>(_contactInfo)->e;
|
return static_cast<cpArbiter*>(_contactInfo)->e;
|
||||||
}
|
}
|
||||||
|
|
||||||
float PhysicsContactPostSolve::getFriciton() const
|
float PhysicsContactPostSolve::getFriction() const
|
||||||
{
|
{
|
||||||
return static_cast<cpArbiter*>(_contactInfo)->u;
|
return static_cast<cpArbiter*>(_contactInfo)->u;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,16 +130,6 @@ PhysicsJointFixed::~PhysicsJointFixed()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsJointSliding::PhysicsJointSliding()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicsJointSliding::~PhysicsJointSliding()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicsJointLimit::PhysicsJointLimit()
|
PhysicsJointLimit::PhysicsJointLimit()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -296,41 +286,6 @@ float PhysicsJointPin::getMaxForce() const
|
||||||
return PhysicsHelper::cpfloat2float(_info->getJoints().front()->maxForce);
|
return PhysicsHelper::cpfloat2float(_info->getJoints().front()->maxForce);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsJointSliding* PhysicsJointSliding::construct(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr)
|
|
||||||
{
|
|
||||||
PhysicsJointSliding* joint = new PhysicsJointSliding();
|
|
||||||
|
|
||||||
if (joint && joint->init(a, b, grooveA, grooveB, anchr))
|
|
||||||
{
|
|
||||||
return joint;
|
|
||||||
}
|
|
||||||
|
|
||||||
CC_SAFE_DELETE(joint);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PhysicsJointSliding::init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
CC_BREAK_IF(!PhysicsJoint::init(a, b));
|
|
||||||
|
|
||||||
cpConstraint* joint = cpGrooveJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
|
|
||||||
PhysicsHelper::point2cpv(grooveA),
|
|
||||||
PhysicsHelper::point2cpv(grooveB),
|
|
||||||
PhysicsHelper::point2cpv(anchr));
|
|
||||||
|
|
||||||
CC_BREAK_IF(joint == nullptr);
|
|
||||||
|
|
||||||
_info->add(joint);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} while (false);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PhysicsJointLimit* PhysicsJointLimit::construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2)
|
PhysicsJointLimit* PhysicsJointLimit::construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2)
|
||||||
{
|
{
|
||||||
PhysicsJointLimit* joint = new PhysicsJointLimit();
|
PhysicsJointLimit* joint = new PhysicsJointLimit();
|
||||||
|
@ -354,7 +309,7 @@ bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1
|
||||||
PhysicsHelper::point2cpv(anchr1),
|
PhysicsHelper::point2cpv(anchr1),
|
||||||
PhysicsHelper::point2cpv(anchr2),
|
PhysicsHelper::point2cpv(anchr2),
|
||||||
0,
|
0,
|
||||||
PhysicsHelper::float2cpfloat(anchr1.getDistance(anchr2)));
|
PhysicsHelper::float2cpfloat(_bodyA->local2World(anchr1).getDistance(_bodyB->local2World(anchr2))));
|
||||||
|
|
||||||
CC_BREAK_IF(joint == nullptr);
|
CC_BREAK_IF(joint == nullptr);
|
||||||
|
|
||||||
|
@ -407,7 +362,8 @@ bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Point& anc
|
||||||
|
|
||||||
cpConstraint* joint = cpPinJointNew(getBodyInfo(a)->getBody(),
|
cpConstraint* joint = cpPinJointNew(getBodyInfo(a)->getBody(),
|
||||||
getBodyInfo(b)->getBody(),
|
getBodyInfo(b)->getBody(),
|
||||||
PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr2));
|
PhysicsHelper::point2cpv(anchr1),
|
||||||
|
PhysicsHelper::point2cpv(anchr2));
|
||||||
|
|
||||||
CC_BREAK_IF(joint == nullptr);
|
CC_BREAK_IF(joint == nullptr);
|
||||||
|
|
||||||
|
|
|
@ -100,45 +100,13 @@ protected:
|
||||||
virtual ~PhysicsJointFixed();
|
virtual ~PhysicsJointFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* @brief A sliding joint allows the two bodies to slide along a chosen axis.
|
|
||||||
*/
|
|
||||||
class PhysicsJointSliding : public PhysicsJoint
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static PhysicsJointSliding* construct(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PhysicsJointSliding();
|
|
||||||
virtual ~PhysicsJointSliding();
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @brief A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies.
|
|
||||||
*/
|
|
||||||
class PhysicsJointSpring : public PhysicsJoint
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhysicsJointSpring* construct();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PhysicsJointSpring();
|
|
||||||
virtual ~PhysicsJointSpring();
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
|
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
|
||||||
*/
|
*/
|
||||||
class PhysicsJointLimit : public PhysicsJoint
|
class PhysicsJointLimit : public PhysicsJoint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PhysicsJointLimit* construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
static PhysicsJointLimit* construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
||||||
|
|
||||||
float getMin() const;
|
float getMin() const;
|
||||||
void setMin(float min);
|
void setMin(float min);
|
||||||
|
@ -174,7 +142,6 @@ protected:
|
||||||
|
|
||||||
class PhysicsJointDistance : public PhysicsJoint
|
class PhysicsJointDistance : public PhysicsJoint
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static PhysicsJointDistance* construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
static PhysicsJointDistance* construct(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
||||||
|
|
||||||
|
|
|
@ -405,7 +405,6 @@ bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event)
|
||||||
|
|
||||||
if (shape != nullptr)
|
if (shape != nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
Node* mouse = Node::create();
|
Node* mouse = Node::create();
|
||||||
mouse->setPhysicsBody(PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY));
|
mouse->setPhysicsBody(PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY));
|
||||||
mouse->getPhysicsBody()->setDynamic(false);
|
mouse->getPhysicsBody()->setDynamic(false);
|
||||||
|
@ -759,6 +758,37 @@ void PhysicsDemoJoints::onEnter()
|
||||||
this->addChild(sp2);
|
this->addChild(sp2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
|
||||||
|
auto sp1 = makeBall(offset - Point(30, 0), 10);
|
||||||
|
sp1->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
|
||||||
|
auto sp2 = makeBox(offset + Point(30, 0), Size(30, 10));
|
||||||
|
sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
|
||||||
|
|
||||||
|
PhysicsJointDistance* joint = PhysicsJointDistance::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Point::ZERO, Point::ZERO);
|
||||||
|
_scene->getPhysicsWorld()->addJoint(joint);
|
||||||
|
|
||||||
|
this->addChild(sp1);
|
||||||
|
this->addChild(sp2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
auto sp1 = makeBall(offset - Point(30, 0), 10);
|
||||||
|
sp1->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
|
||||||
|
auto sp2 = makeBox(offset + Point(30, 0), Size(30, 10));
|
||||||
|
sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
|
||||||
|
|
||||||
|
PhysicsJointLimit* joint = PhysicsJointLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Point::ZERO, Point::ZERO);
|
||||||
|
joint->setMin(30.0f);
|
||||||
|
joint->setMax(60.0f);
|
||||||
|
_scene->getPhysicsWorld()->addJoint(joint);
|
||||||
|
|
||||||
|
this->addChild(sp1);
|
||||||
|
this->addChild(sp2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue