Skip to content

Commit

Permalink
fixing bug due to bullet's rel_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
xbpeng committed May 19, 2016
1 parent f58d228 commit acb9b7a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 81 deletions.
4 changes: 2 additions & 2 deletions render/DrawPerturb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ void cDrawPerturb::Draw(const tPerturb& perturb)

void cDrawPerturb::DrawForce(const tPerturb& perturb)
{
tVector pos = perturb.mObj->LocalToWorldPos(perturb.mPosRel);
tVector pos = perturb.mObj->LocalToWorldPos(perturb.mLocalPos);
const tVector& force = perturb.mPerturb;
DrawForce2D(pos, force);
}

void cDrawPerturb::DrawTorque(const tPerturb& perturb)
{
tVector pos = perturb.mObj->LocalToWorldPos(perturb.mPosRel);
tVector pos = perturb.mObj->LocalToWorldPos(perturb.mLocalPos);
const tVector& torque = perturb.mPerturb;
DrawTorque2D(pos, torque);
}
2 changes: 1 addition & 1 deletion scenarios/ScenarioSimChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void cScenarioSimChar::ApplyRandForce(double min_force, double max_force,
assert(obj != nullptr);
tPerturb perturb = tPerturb::BuildForce();
perturb.mObj = obj;
perturb.mPosRel.setZero();
perturb.mLocalPos.setZero();
perturb.mPerturb[0] = cMathUtil::RandSign() * cMathUtil::RandDouble(0, 1);
perturb.mPerturb[1] = cMathUtil::RandSign() * cMathUtil::RandDouble(0, 1);
perturb.mPerturb[2] = cMathUtil::RandSign() * cMathUtil::RandDouble(0, 1);
Expand Down
10 changes: 5 additions & 5 deletions sim/Perturb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ tPerturb::tPerturb()
Clear();
}

tPerturb::tPerturb(ePerturb type, cSimObj* obj, const tVector& pos_rel,
const tVector& perturb, double duration)
tPerturb::tPerturb(ePerturb type, cSimObj* obj, const tVector& local_pos,
const tVector& perturb, double duration)
: tPerturb()
{
assert(type != ePerturbInvalid);
mType = type;
mObj = obj;
mPosRel = pos_rel;
mLocalPos = local_pos;
mPerturb = perturb;
mDuration = duration;
}
Expand All @@ -38,7 +38,7 @@ void tPerturb::Clear()
{
mType = ePerturbInvalid;
mObj = nullptr;
mPosRel.setZero();
mLocalPos.setZero();
mPerturb.setZero();
mDuration = 0;
mTime = 0;
Expand Down Expand Up @@ -69,7 +69,7 @@ void tPerturb::Update(double time_step)
void tPerturb::ApplyForce()
{
assert(mType == ePerturbForce);
mObj->ApplyForce(mPerturb, mPosRel);
mObj->ApplyForce(mPerturb, mLocalPos);
}

void tPerturb::ApplyTorque()
Expand Down
6 changes: 3 additions & 3 deletions sim/Perturb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ struct tPerturb

ePerturb mType;
cSimObj* mObj;
tVector mPosRel;
tVector mLocalPos;
tVector mPerturb;
double mDuration;
double mTime;

tPerturb();
tPerturb(ePerturb type, cSimObj* obj, const tVector& pos_rel,
const tVector& perturb, double duration);
tPerturb(ePerturb type, cSimObj* obj, const tVector& local_pos,
const tVector& perturb, double duration);

virtual ~tPerturb();

Expand Down
7 changes: 5 additions & 2 deletions sim/SimCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ void cSimCharacter::GetRootRotation(tVector& out_axis, double& out_theta) const

tVector cSimCharacter::GetRootVel() const
{
const std::shared_ptr<cSimObj>& root = mBodyParts[GetRootID()];
return root->GetLinearVelocity();
int root_id = GetRootID();
const std::shared_ptr<cSimObj>& root = mBodyParts[root_id];
tVector attach_pt = cKinTree::GetBodyAttachPt(mBodyDefs, root_id);
tVector vel = root->GetLinearVelocity(-attach_pt);
return vel;
}

tVector cSimCharacter::GetRootAngVel() const
Expand Down
4 changes: 2 additions & 2 deletions sim/SimObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void cSimObj::ApplyForce(const tVector& force)
ApplyForce(force, tVector::Zero());
}

void cSimObj::ApplyForce(const tVector& force, const tVector& rel_pos)
void cSimObj::ApplyForce(const tVector& force, const tVector& local_pos)
{
mWorld->ApplyForce(force, rel_pos, this);
mWorld->ApplyForce(force, local_pos, this);
}

void cSimObj::ApplyTorque(const tVector& torque)
Expand Down
2 changes: 1 addition & 1 deletion sim/SimObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class cSimObj : public btDefaultMotionState
virtual tMatrix3 GetLocalToWorldRotMat() const;

virtual void ApplyForce(const tVector& force);
virtual void ApplyForce(const tVector& force, const tVector& rel_pos);
virtual void ApplyForce(const tVector& force, const tVector& local_pos);
virtual void ApplyTorque(const tVector& torque);
virtual void ClearForces();

Expand Down
Loading

0 comments on commit acb9b7a

Please sign in to comment.