[Gcblue-commits] gcb_wx/src/sim tcBallisticWeapon.cpp,NONE,1.1 tcLauncher.cpp,1.2,1.3 tcLauncherStat
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-07-27 23:26:16
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16280/src/sim Modified Files: tcLauncher.cpp tcLauncherState.cpp tcMissileObject.cpp Added Files: tcBallisticWeapon.cpp Log Message: --- NEW FILE: tcBallisticWeapon.cpp --- /** @file tcBallisticWeapon.cpp */ /* * Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) * All rights reserved. * * This file is part of the Global Conflict Blue (GCB) program. * GCB is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * GCB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GCB; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "tcBallisticWeapon.h" #include "common/tcStream.h" #include "common/tcObjStream.h" #include "tc3DModel.h" #include "tcParticleEffect.h" #include "tcLauncher.h" #include "tcSimState.h" /** * Load state from update stream */ tcUpdateStream& tcBallisticWeapon::operator<<(tcUpdateStream& stream) { tcWeaponObject::operator<<(stream); return stream; } /** * Save state to update stream */ tcUpdateStream& tcBallisticWeapon::operator>>(tcUpdateStream& stream) { tcWeaponObject::operator>>(stream); return stream; } /** * Initializes ballistic weapon state for launch from game object. * Adds self to simulation * * @param obj launching game object * @param launcher index of launcher */ void tcBallisticWeapon::LaunchFrom(tcGameObject* obj, unsigned nLauncher) { const tcLauncher* pLauncher = obj->GetLauncher(nLauncher); mfStatusTime = obj->mfStatusTime; mcKin = obj->mcKin; mcKin.mfHeading_rad += pLauncher->pointingAngle; mcKin.mfPitch_rad += pLauncher->pointingElevation; if (mpDBObject->launchSpeed_mps != 0) { mcKin.mfSpeed_kts = C_MPSTOKTS * mpDBObject->launchSpeed_mps; } tcString s; s.Format("Ball %s", obj->mzUnit.mz); mzUnit = s.GetBuffer(); mnAlliance = obj->mnAlliance; simState->AddPlatform(static_cast<tcGameObject*>(this)); // Set intended target (has to be done after alliance and id is set). // This is a tcWeaponObject method SetIntendedTarget(pLauncher->mnTargetID); } /** * */ void tcBallisticWeapon::Update(double afStatusTime) { float dt_s = (float)(afStatusTime - mfStatusTime); wxASSERT(mpDBObject); // initialize local kinematic state variables if vxy_mps == 0 if (vxy_mps == 0) { float v = C_KTSTOMPS * mcKin.mfSpeed_kts; vz_mps = v * sinf(mcKin.mfPitch_rad); float cospitch = cosf(mcKin.mfPitch_rad); vxy_mps = v * cospitch; } vz_mps += -C_G * dt_s; float dist = C_MTORAD * dt_s * vxy_mps; float dlon = dist * sinf(mcKin.mfHeading_rad) / cosf(mcKin.mfLat_rad); float dlat = dist * cosf(mcKin.mfHeading_rad); mcKin.mfLon_rad += dlon; mcKin.mfLat_rad += dlat; mcKin.mfAlt_m += vz_mps * dt_s; mcKin.mfPitch_rad = atan2f(vxy_mps, vz_mps); mcKin.mfClimbAngle_rad = mcKin.mfPitch_rad; mcKin.mfSpeed_kts = C_MPSTOKTS * sqrtf(vxy_mps*vxy_mps + vz_mps*vz_mps); if (clientMode) return; /*** check for impact ***/ float terrainHeight_m = mcTerrain.mfHeight_m; if (terrainHeight_m < 0) terrainHeight_m = 0; float dz = mcTerrain.mfHeight_m - mcKin.mfAlt_m; // height above ground or sea level float t_impact = dz / vz_mps; if (t_impact <= 0.03f) { Detonate(t_impact); } } /** * */ void tcBallisticWeapon::Clear() { tcGameObject::Clear(); vz_mps = 0; vxy_mps = 0; } /** * */ void tcBallisticWeapon::PrintToFile(tcFile& file) { tcString s; tcWeaponObject::PrintToFile(file); s.Format(" Ballistic Weapon Object\n"); file.WriteString(s.GetBuffer()); } /** * */ void tcBallisticWeapon::SaveToFile(tcFile& file) { tcWeaponObject::SaveToFile(file); } /** * */ void tcBallisticWeapon::LoadFromFile(tcFile& file) { tcWeaponObject::LoadFromFile(file); } /** * */ void tcBallisticWeapon::Serialize(tcFile& file, bool mbLoad) { if (mbLoad) { LoadFromFile(file); } else { SaveToFile(file); } } /** * */ tcBallisticWeapon::tcBallisticWeapon() : tcWeaponObject() { Clear(); mnModelType = MTYPE_BALLISTIC; } /** * Copy constructor. */ tcBallisticWeapon::tcBallisticWeapon(tcBallisticWeapon& o) : tcWeaponObject(o) { mnModelType = MTYPE_BALLISTIC; vz_mps = o.vz_mps; vxy_mps = o.vxy_mps; } /** * Constructor that initializes using info from database entry. */ tcBallisticWeapon::tcBallisticWeapon(tcWeaponDBObject* obj) : tcWeaponObject(obj), vz_mps(0), vxy_mps(0) { mnModelType = MTYPE_BALLISTIC; } /** * */ tcBallisticWeapon::~tcBallisticWeapon() { } Index: tcLauncher.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncher.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcLauncher.cpp 29 May 2004 00:11:54 -0000 1.2 --- tcLauncher.cpp 27 Jul 2004 23:26:07 -0000 1.3 *************** *** 1,5 **** /** @file tcLauncher.cpp ! ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** --- 1,5 ---- /** @file tcLauncher.cpp ! */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** *************** *** 174,177 **** --- 174,178 ---- buffer >> mnTargetFlags; buffer >> pointingAngle; + buffer >> pointingElevation; buffer >> fireControlSensorIdx; *************** *** 201,204 **** --- 202,206 ---- buffer << mnTargetFlags; buffer << pointingAngle; + buffer << pointingElevation; buffer << fireControlSensorIdx; Index: tcMissileObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcMissileObject.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** tcMissileObject.cpp 23 Jul 2004 00:45:47 -0000 1.14 --- tcMissileObject.cpp 27 Jul 2004 23:26:07 -0000 1.15 *************** *** 140,143 **** --- 140,144 ---- mcKin = obj->mcKin; mcKin.mfHeading_rad += pLauncher->pointingAngle; + mcKin.mfPitch_rad += pLauncher->pointingElevation; tcString s; Index: tcLauncherState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncherState.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcLauncherState.cpp 19 Jul 2004 00:53:01 -0000 1.12 --- tcLauncherState.cpp 27 Jul 2004 23:26:07 -0000 1.13 *************** *** 81,84 **** --- 81,85 ---- tcLauncher new_launcher; + // this code should be moved to tcLauncher class new_launcher.mnChildDBKey = nChildKey; new_launcher.mpChildDBObj = pChildDBObj; *************** *** 94,97 **** --- 95,99 ---- new_launcher.mnUncommitted = new_launcher.mnCurrent; new_launcher.pointingAngle = azimuth_rad; + new_launcher.pointingElevation = 0; new_launcher.fireControlSensor = NULL; new_launcher.errorCode = 0; |