Skip to content

Commit

Permalink
fix MoveCtrl.SetRelativeVelocity
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Jan 22, 2012
1 parent 56f9479 commit aa5d050
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
16 changes: 7 additions & 9 deletions rts/Sim/MoveTypes/ScriptMoveType.cpp
Expand Up @@ -124,20 +124,18 @@ bool CScriptMoveType::Update()
owner->speed = vel;

if (extrapolate) {
// quadratic drag does not work well here
// NOTE: also affects speed gained through gravity
vel *= (1.0f - drag);

if (useRelVel) {
// add the speed terms relative to the unit (if any)
vel += (owner->frontdir * relVel.z);
vel += (owner->updir * relVel.y);
vel += (owner->rightdir * -relVel.x); // x is left
// apply the speed terms relative to the unit (if any)
owner->Move3D(owner->frontdir * relVel.z, true);
owner->Move3D(owner->updir * relVel.y, true);
owner->Move3D(owner->rightdir * -relVel.x, true); // x is left
}

// NOTE: strong wind plus low gravity can cause substantial position drift
// NOTE: strong wind plus low gravity can cause substantial drift
vel.y += (mapInfo->map.gravity * gravityFactor);
vel += (wind.GetCurrentWind() * windFactor);
// quadratic drag does not work well here
vel *= (1.0f - drag);

owner->Move3D(vel, true);
}
Expand Down
11 changes: 0 additions & 11 deletions rts/Sim/Objects/SolidObject.cpp
Expand Up @@ -108,17 +108,6 @@ CSolidObject::~CSolidObject() {



void CSolidObject::UpdateMidPos()
{
const float3 dz = (frontdir * relMidPos.z);
const float3 dy = (updir * relMidPos.y);
const float3 dx = (rightdir * relMidPos.x);

midPos = pos + dz + dy + dx;
}



void CSolidObject::UnBlock() {
if (isMarkedOnBlockingMap) {
groundBlockingObjectMap->RemoveGroundBlockingObject(this);
Expand Down
9 changes: 8 additions & 1 deletion rts/Sim/Objects/SolidObject.h
Expand Up @@ -45,10 +45,17 @@ class CSolidObject: public CWorldObject {
pos[d] += dv;
midPos[d] += dv;
}

// this should be called whenever the direction
// vectors are changed (ie. after a rotation) in
// eg. movetype code
void UpdateMidPos();
void UpdateMidPos() {
const float3 dz = (frontdir * relMidPos.z);
const float3 dy = (updir * relMidPos.y);
const float3 dx = (rightdir * relMidPos.x);

midPos = pos + dz + dy + dx;
}

/**
* Adds this object to the GroundBlockingMap if and only if its collidable
Expand Down

0 comments on commit aa5d050

Please sign in to comment.