void CBuilding::ForcedMove(const float3& newPos, int facing) { buildFacing = facing; speed = ZeroVector; heading = GetHeadingFromFacing(buildFacing); frontdir = GetVectorFromHeading(heading); Move3D(CGameHelper::Pos2BuildPos(BuildInfo(unitDef, newPos, buildFacing), true), false); UpdateMidAndAimPos(); CUnit::ForcedMove(pos); unitLoader->FlattenGround(this); }
void Camera::Update(float msec) { m_msec = msec; Move3D(); glm::mat4 rotationMatrix = GetMatrixUsingYawPitchRoll(m_yaw, m_pitch, 0.0f); m_position += m_translation; m_translation = glm::vec3(0.0f); m_lookAt = glm::vec3(rotationMatrix * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f)); m_target = m_position + m_lookAt; m_up = glm::vec3(rotationMatrix * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f)); m_right = glm::cross(m_up, m_lookAt); m_view = glm::lookAt(m_position, m_target, m_up); }
void CFeature::ForcedMove(const float3& newPos, bool snapToGround) { if (blocking) { UnBlock(); } // remove from managers qf->RemoveFeature(this); if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->DeleteTree(pos); } Move3D(newPos - pos, true); eventHandler.FeatureMoved(this); // setup finalHeight (pos == newPos now) if (snapToGround) { if (def->floating) { finalHeight = ground->GetHeightAboveWater(pos.x, pos.z); } else { finalHeight = ground->GetHeightReal(pos.x, pos.z); } } else { finalHeight = pos.y; } // setup the visual transformation matrix CalculateTransform(); // insert into managers qf->AddFeature(this); if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->AddTree(def->drawType - 1, pos, 1.0f); } if (blocking) { Block(); } }
bool CFeature::UpdatePosition() { if (udef != NULL) { // we are a wreck of a dead unit if (!reachedFinalPos) { // def->floating is unreliable (true for land unit wrecks), // so just assume wrecks always sink even if their "owner" // was a floating object (as is the case for ships anyway) const float realGroundHeight = ground->GetHeightReal(pos.x, pos.z); const bool reachedWater = ( pos.y <= 0.1f); const bool reachedGround = ((pos.y - realGroundHeight) <= 0.1f); deathSpeed *= 0.999999f; deathSpeed *= (1.0f - (int(reachedWater ) * 0.05f)); deathSpeed *= (1.0f - (int(reachedGround) * 0.10f)); if (deathSpeed.SqLength2D() > 0.01f) { UnBlock(); qf->RemoveFeature(this); // update our forward speed (and quadfield // position) if it is still greater than 0 Move3D(deathSpeed, true); qf->AddFeature(this); Block(); } else { deathSpeed.x = 0.0f; deathSpeed.z = 0.0f; } if (!reachedGround) { if (!reachedWater) { // quadratic acceleration if not in water deathSpeed.y += mapInfo->map.gravity; } else { // constant downward speed otherwise deathSpeed.y = mapInfo->map.gravity; } Move1D(deathSpeed.y, 1, true); } else { deathSpeed.y = 0.0f; // last Update() may have sunk us into // ground if pos.y was only marginally // larger than ground height, correct Move1D(realGroundHeight, 1, false); } reachedFinalPos = (deathSpeed == ZeroVector); if (!pos.IsInBounds()) { pos.ClampInBounds(); // ensure that no more forward-speed updates are done // (prevents wrecks floating in mid-air at edge of map // due to gravity no longer being applied either) deathSpeed = ZeroVector; } eventHandler.FeatureMoved(this); CalculateTransform(); } } else { if (pos.y > finalHeight) { // feature is falling (note: gravity is negative) if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->DeleteTree(pos); } if (pos.y > 0.0f) { speed.y += mapInfo->map.gravity; } else { speed.y = mapInfo->map.gravity; } Move1D(speed.y, 1, true); if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->AddTree(def->drawType - 1, pos, 1.0f); } transMatrix[13] += speed.y; } else if (pos.y < finalHeight) { // if ground is restored, make sure feature does not get buried if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->DeleteTree(pos); } const float dy = finalHeight - pos.y; speed.y = 0.0f; transMatrix[13] += dy; Move1D(dy, 1, true); if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->AddTree(def->drawType - 1, pos, 1.0f); } } reachedFinalPos = (pos.y == finalHeight); } isUnderWater = ((pos.y + height) < 0.0f); return reachedFinalPos; }
void CFeature::Initialize(const float3& _pos, const FeatureDef* _def, short int _heading, int facing, int _team, int _allyteam, const UnitDef* _udef, const float3& speed, int _smokeTime) { def = _def; udef = _udef; defID = def->id; heading = _heading; buildFacing = facing; team = _team; allyteam = _allyteam; emitSmokeTime = _smokeTime; mass = def->mass; crushResistance = def->crushResistance; health = def->maxHealth; blocking = def->blocking; xsize = ((facing & 1) == 0) ? def->xsize : def->zsize; zsize = ((facing & 1) == 1) ? def->xsize : def->zsize; noSelect = def->noSelect; // set position before mid-position Move3D(_pos.cClampInMap(), false); if (def->drawType == DRAWTYPE_MODEL) { if ((model = def->LoadModel()) == NULL) { LOG_L(L_ERROR, "Features: Couldn't load model for %s", def->name.c_str()); } else { SetMidAndAimPos(model->relMidPos, model->relMidPos, true); SetRadiusAndHeight(model->radius, model->height); } } else { if (def->drawType >= DRAWTYPE_TREE) { // LoadFeaturesFromMap() doesn't set a scale for trees SetMidAndAimPos(UpVector * TREE_RADIUS, UpVector * TREE_RADIUS, true); SetRadiusAndHeight(TREE_RADIUS, TREE_RADIUS * 2.0f); } } UpdateMidAndAimPos(); CalculateTransform(); // note: gets deleted in ~CSolidObject collisionVolume = new CollisionVolume(def->collisionVolume, radius); featureHandler->AddFeature(this); qf->AddFeature(this); // maybe should not be here, but it prevents crashes caused by team = -1 ChangeTeam(team); if (blocking) { Block(); } if (def->floating) { finalHeight = ground->GetHeightAboveWater(pos.x, pos.z); } else { finalHeight = ground->GetHeightReal(pos.x, pos.z); } if (speed != ZeroVector) { deathSpeed = speed; } reachedFinalPos = (speed == ZeroVector && pos.y == finalHeight); }