Skip to content

Commit

Permalink
fix #6215
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed May 2, 2019
1 parent cb78083 commit 36ce4ad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 39 deletions.
9 changes: 4 additions & 5 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -528,12 +528,11 @@ static int SetSolidObjectRotation(lua_State* L, CSolidObject* o, bool isFeature)


o->SetDirVectorsEuler(float3(luaL_checkfloat(L, 2), luaL_checkfloat(L, 3), luaL_checkfloat(L, 4))); o->SetDirVectorsEuler(float3(luaL_checkfloat(L, 2), luaL_checkfloat(L, 3), luaL_checkfloat(L, 4)));


if (isFeature) { // not a hack: ForcedSpin() and CalculateTransform() calculate a
// not a hack: ForcedSpin() and CalculateTransform() calculate a // transform based only on frontdir and assume the helper y-axis
// transform based only on frontdir and assume the helper y-axis // points up
// points up if (isFeature)
static_cast<CFeature*>(o)->UpdateTransform(o->pos, true); static_cast<CFeature*>(o)->UpdateTransform(o->pos, true);
}


return 0; return 0;
} }
Expand Down
26 changes: 12 additions & 14 deletions rts/Sim/Objects/SolidObject.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -343,24 +343,23 @@ float3 CSolidObject::GetWantedUpDir(bool useGroundNormal) const
const float3 gn = CGround::GetSmoothNormal(pos.x, pos.z) * ( useGroundNormal); const float3 gn = CGround::GetSmoothNormal(pos.x, pos.z) * ( useGroundNormal);
const float3 wn = UpVector * (1 - useGroundNormal); const float3 wn = UpVector * (1 - useGroundNormal);


if (moveDef == nullptr) { // aircraft cannot use updir reliably or their
// aircraft cannot use updir reliably or their // coordinate-system would degenerate too much
// coordinate-system would degenerate too much // over time without periodic re-ortho'ing
// over time without periodic re-ortho'ing if (moveDef == nullptr)
return (gn + UpVector * (1 - useGroundNormal)); return (gn + UpVector * (1 - useGroundNormal));
}


// not an aircraft if we get here, prevent pitch changes // not an aircraft if we get here, prevent pitch changes
// if(f) the object is neither on the ground nor in water // if(f) the object is neither on the ground nor in water
// for whatever reason (GMT also prevents heading changes) // for whatever reason (GMT also prevents heading changes)
if (!IsInAir()) { if (!IsInAir()) {
switch (moveDef->speedModClass) { switch (moveDef->speedModClass) {
case MoveDef::Tank: { return ((gn + wn) * IsOnGround() + updir * (1 - IsOnGround())); } break; case MoveDef::Tank: { return mix(float3(updir), gn + wn, IsOnGround()); } break;
case MoveDef::KBot: { return ((gn + wn) * IsOnGround() + updir * (1 - IsOnGround())); } break; case MoveDef::KBot: { return mix(float3(updir), gn + wn, IsOnGround()); } break;


case MoveDef::Hover: { return ((UpVector * IsInWater()) + (gn + wn) * (1 - IsInWater())); } break; case MoveDef::Hover: { return mix(UpVector, gn + wn, 1 - IsInWater()); } break;
case MoveDef::Ship : { return ((UpVector * IsInWater()) + (gn + wn) * (1 - IsInWater())); } break; case MoveDef::Ship : { return mix(UpVector, gn + wn, 1 - IsInWater()); } break;
default : { } break; default : { } break;
} }
} }


Expand All @@ -378,13 +377,12 @@ void CSolidObject::SetDirVectorsEuler(const float3 angles)
// whenever these angles are retrieved, the handedness is converted again // whenever these angles are retrieved, the handedness is converted again
SetDirVectors(matrix.RotateEulerXYZ(angles)); SetDirVectors(matrix.RotateEulerXYZ(angles));
SetHeadingFromDirection(); SetHeadingFromDirection();
SetFacingFromHeading();
UpdateMidAndAimPos(); UpdateMidAndAimPos();
} }


void CSolidObject::SetHeadingFromDirection() void CSolidObject::SetHeadingFromDirection() { heading = GetHeadingFromVector(frontdir.x, frontdir.z); }
{ void CSolidObject::SetFacingFromHeading() { buildFacing = GetFacingFromHeading(heading); }
heading = GetHeadingFromVector(frontdir.x, frontdir.z);
}


void CSolidObject::UpdateDirVectors(bool useGroundNormal) void CSolidObject::UpdateDirVectors(bool useGroundNormal)
{ {
Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Objects/SolidObject.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class CSolidObject: public CWorldObject {
// update object's <heading> from current frontdir // update object's <heading> from current frontdir
// should always be called after a SetDirVectors() // should always be called after a SetDirVectors()
void SetHeadingFromDirection(); void SetHeadingFromDirection();
// update object's <buildFacing> from current heading
void SetFacingFromHeading();
// update object's local coor-sys from current <heading> // update object's local coor-sys from current <heading>
// (unlike ForcedSpin which updates from given <updir>) // (unlike ForcedSpin which updates from given <updir>)
// NOTE: movetypes call this directly // NOTE: movetypes call this directly
Expand Down
34 changes: 14 additions & 20 deletions rts/Sim/Units/UnitTypes/Factory.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -379,14 +379,11 @@ void CFactory::SendToEmptySpot(CUnit* unit)
// (and should also be more than CMD_CANCEL_DIST // (and should also be more than CMD_CANCEL_DIST
// elmos distant from foundPos) // elmos distant from foundPos)
// //
if (!unit->unitDef->canfly && exitPos.IsInBounds()) { if (!unit->unitDef->canfly && exitPos.IsInBounds())
Command c0(CMD_MOVE, SHIFT_KEY, exitPos); unit->commandAI->GiveCommand(Command(CMD_MOVE, SHIFT_KEY, exitPos));
unit->commandAI->GiveCommand(c0);
}


// second actual empty-spot waypoint // second actual empty-spot waypoint
Command c1(CMD_MOVE, SHIFT_KEY, foundPos); unit->commandAI->GiveCommand(Command(CMD_MOVE, SHIFT_KEY, foundPos));
unit->commandAI->GiveCommand(c1);
} }


void CFactory::AssignBuildeeOrders(CUnit* unit) { void CFactory::AssignBuildeeOrders(CUnit* unit) {
Expand All @@ -410,22 +407,19 @@ void CFactory::AssignBuildeeOrders(CUnit* unit) {
// move-order. However, this order can *itself* cause the PF // move-order. However, this order can *itself* cause the PF
// system to consider the path blocked if the extra waypoint // system to consider the path blocked if the extra waypoint
// falls within the factory's confines, so use a wide berth. // falls within the factory's confines, so use a wide berth.
const float xs = unitDef->xsize * SQUARE_SIZE * 0.5f; const float3 fpSize = {unitDef->xsize * SQUARE_SIZE * 0.5f, 0.0f, unitDef->zsize * SQUARE_SIZE * 0.5f};
const float zs = unitDef->zsize * SQUARE_SIZE * 0.5f; const float3 fpMins = {unit->pos.x - fpSize.x, 0.0f, unit->pos.z - fpSize.z};
const float3 fpMaxs = {unit->pos.x + fpSize.x, 0.0f, unit->pos.z + fpSize.z};


float tmpDst = 2.0f; float3 tmpVec;
float3 tmpPos = unit->pos + (frontdir * this->radius * tmpDst); float3 tmpPos;


if (buildFacing == FACING_NORTH || buildFacing == FACING_SOUTH) { for (int i = 0, k = 2 * (math::fabs(frontdir.z) > math::fabs(frontdir.x)); i < 128; i++) {
while ((tmpPos.z >= unit->pos.z - zs) && (tmpPos.z <= unit->pos.z + zs)) { tmpVec = frontdir * radius * (2.0f + i * 0.5f);
tmpDst += 0.5f; tmpPos = unit->pos + tmpVec;
tmpPos = unit->pos + (frontdir * this->radius * tmpDst);
} if ((tmpPos[k] < fpMins[k]) || (tmpPos[k] > fpMaxs[k]))
} else { break;
while ((tmpPos.x >= unit->pos.x - xs) && (tmpPos.x <= unit->pos.x + xs)) {
tmpDst += 0.5f;
tmpPos = unit->pos + (frontdir * this->radius * tmpDst);
}
} }


c.PushPos(tmpPos.cClampInBounds()); c.PushPos(tmpPos.cClampInBounds());
Expand Down

0 comments on commit 36ce4ad

Please sign in to comment.