[Gcblue-commits] gcb_wx/src/common nsNav.cpp,1.5,1.6 simmath.cpp,1.13,1.14 tcOggStreamer.cpp,1.7,1.8
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-08-05 02:22:45
|
Update of /cvsroot/gcblue/gcb_wx/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29972/src/common Modified Files: nsNav.cpp simmath.cpp tcOggStreamer.cpp tcSound.cpp Log Message: Index: nsNav.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/nsNav.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** nsNav.cpp 28 Mar 2004 18:49:24 -0000 1.5 --- nsNav.cpp 5 Aug 2004 02:22:35 -0000 1.6 *************** *** 41,48 **** (fDeltaLon <= GCDISTANCE_APPROXDELTA); ! if (bUseApprox) { ! return sqrtf(fDeltaLat*fDeltaLat + cosf(a.mfLat_rad)*fDeltaLon*fDeltaLon); } ! else { return acosf(sinf(a.mfLat_rad)*sinf(b.mfLat_rad) + cosf(a.mfLat_rad)*cosf(b.mfLat_rad)*cosf(fDeltaLon)); --- 41,55 ---- (fDeltaLon <= GCDISTANCE_APPROXDELTA); ! ! ! if (bUseApprox) ! { ! float cos_term = cosf(0.5f * (a.mfLat_rad + b.mfLat_rad)); ! float adjustedLon = cos_term * fDeltaLon; ! ! return sqrtf(fDeltaLat*fDeltaLat + adjustedLon*adjustedLon); } ! else ! { return acosf(sinf(a.mfLat_rad)*sinf(b.mfLat_rad) + cosf(a.mfLat_rad)*cosf(b.mfLat_rad)*cosf(fDeltaLon)); *************** *** 50,70 **** } // version that always uses approximation ! float nsNav::GCDistanceApprox_rad(tsGeoPointRad a, tsGeoPointRad b) { float fDeltaLat = a.mfLat_rad - b.mfLat_rad; float fDeltaLon = a.mfLon_rad - b.mfLon_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! return sqrtf(fDeltaLat*fDeltaLat + cosf(a.mfLat_rad)*fDeltaLon*fDeltaLon); } ! float nsNav::GCDistanceApprox_rad(float afLatA_rad, float afLonA_rad, float afLatB_rad, float afLonB_rad) { float fDeltaLat = afLatA_rad - afLatB_rad; float fDeltaLon = afLonA_rad - afLonB_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! return sqrtf(fDeltaLat*fDeltaLat + cosf(afLatA_rad)*fDeltaLon*fDeltaLon); } ! float nsNav::GCDistanceApprox_rad(float afLatA_rad, float afLonA_rad, float afLatB_rad, float afLonB_rad, ! float afAltA_m, float afAltB_m) { float fDeltaLat = afLatA_rad - afLatB_rad; float fDeltaLon = afLonA_rad - afLonB_rad; --- 57,90 ---- } // version that always uses approximation ! float nsNav::GCDistanceApprox_rad(tsGeoPointRad a, tsGeoPointRad b) ! { float fDeltaLat = a.mfLat_rad - b.mfLat_rad; float fDeltaLon = a.mfLon_rad - b.mfLon_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! ! float cos_term = cosf(0.5f * (a.mfLat_rad + b.mfLat_rad)); ! float adjustedLon = cos_term * fDeltaLon; ! ! return sqrtf(fDeltaLat*fDeltaLat + adjustedLon*adjustedLon); } ! float nsNav::GCDistanceApprox_rad(float afLatA_rad, float afLonA_rad, ! float afLatB_rad, float afLonB_rad) ! { float fDeltaLat = afLatA_rad - afLatB_rad; float fDeltaLon = afLonA_rad - afLonB_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! ! float cos_term = cosf(0.5f * (afLatA_rad + afLatB_rad)); ! float adjustedLon = cos_term * fDeltaLon; ! ! return sqrtf(fDeltaLat*fDeltaLat + adjustedLon*adjustedLon); } ! float nsNav::GCDistanceApprox_rad(float afLatA_rad, float afLonA_rad, ! float afLatB_rad, float afLonB_rad, ! float afAltA_m, float afAltB_m) ! { float fDeltaLat = afLatA_rad - afLatB_rad; float fDeltaLon = afLonA_rad - afLonB_rad; *************** *** 72,126 **** if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! return sqrtf(fDeltaLat*fDeltaLat + cosf(afLatA_rad)*fDeltaLon*fDeltaLon + fDeltaAlt*fDeltaAlt); } ! // great circle heading from point a to point b ! // stores distance in *apfDistance_rad if not NULL ! float nsNav::GCHeading_rad(tsGeoPointRad a, tsGeoPointRad b, float *apfDistance_rad) { float fDistanceRad = GCDistance_rad(a,b); if (apfDistance_rad != NULL) {*apfDistance_rad = fDistanceRad;} float fTerm = (sinf(b.mfLat_rad)-cosf(fDistanceRad)*sinf(a.mfLat_rad))/ (sinf(fDistanceRad)*cosf(a.mfLat_rad)); ! if (sinf(a.mfLon_rad-b.mfLon_rad) < 0) { return acosf( max( min( fTerm,1.0f ),-1.0f ) ); } ! else { return C_TWOPI - acosf( max( min(fTerm,1.0f), -1.0f) ); } } ! // approximate heading from point a to point b ! // approximation assuming short distances ! // a few tenths of a deg of error for <= 2 deg lat/lon difference at ! // high (80+ deg) latitudes, less error near equator ! float nsNav::GCHeadingApprox_rad(tsGeoPointRad a, tsGeoPointRad b) { float fCosLatAvg_rad = cosf(0.5f*(a.mfLat_rad+b.mfLat_rad)); float fDeltaLon = b.mfLon_rad - a.mfLon_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! return atan2f(fCosLatAvg_rad*fDeltaLon,b.mfLat_rad-a.mfLat_rad); } ! float nsNav::GCHeadingApprox_rad(float afLatA_rad, float afLonA_rad, float afLatB_rad, float afLonB_rad) { float fCosLatAvg_rad = cosf(0.5f*(afLatA_rad+afLatB_rad)); float fDeltaLon = afLonB_rad - afLonA_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! return atan2f(fCosLatAvg_rad*fDeltaLon,afLatB_rad-afLatA_rad); } ! // sets point b at heading afHeading_rad and range of afRange_rad from point a ! // has accuracy issues (maybe this heading is only the initial heading or similar?) ! void nsNav::Offset(const tsGeoPointRad& a, tsGeoPointRad& b, float afHeading_rad, float afRange_rad) { float fTerm = sinf(a.mfLat_rad)*cosf(afRange_rad) + cosf(a.mfLat_rad)*sinf(afRange_rad)*cosf(afHeading_rad); if (fTerm > 1) {fTerm = 1;} else if (fTerm < -1) {fTerm = -1;} b.mfLat_rad = asinf(fTerm); fTerm = sinf(afHeading_rad)*sinf(afRange_rad)/cosf(a.mfLat_rad); if (fTerm > 1) {fTerm = 1;} else if (fTerm < -1) {fTerm = -1;} b.mfLon_rad = a.mfLon_rad + asinf(fTerm); } ! // sets point b at heading afHeading_rad and range of afRange_rad from point a ! void nsNav::OffsetApprox(const tsGeoPointRad& a, tsGeoPointRad& b, float afHeading_rad, float afRange_rad) { b.mfLat_rad = a.mfLat_rad + cosf(afHeading_rad)*afRange_rad; b.mfLon_rad = a.mfLon_rad + sinf(afHeading_rad)*afRange_rad/cosf(a.mfLat_rad); --- 92,179 ---- if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! ! float cos_term = cosf(0.5f * (afLatA_rad + afLatB_rad)); ! float adjustedLon = cos_term * fDeltaLon; ! ! return sqrtf(fDeltaLat*fDeltaLat + adjustedLon*adjustedLon + fDeltaAlt*fDeltaAlt); } ! /** ! * great circle heading from point a to point b ! * stores distance in *apfDistance_rad if not NULL ! */ ! float nsNav::GCHeading_rad(tsGeoPointRad a, tsGeoPointRad b, float *apfDistance_rad) ! { float fDistanceRad = GCDistance_rad(a,b); if (apfDistance_rad != NULL) {*apfDistance_rad = fDistanceRad;} + float fTerm = (sinf(b.mfLat_rad)-cosf(fDistanceRad)*sinf(a.mfLat_rad))/ (sinf(fDistanceRad)*cosf(a.mfLat_rad)); ! ! if (sinf(a.mfLon_rad-b.mfLon_rad) < 0) ! { return acosf( max( min( fTerm,1.0f ),-1.0f ) ); } ! else ! { return C_TWOPI - acosf( max( min(fTerm,1.0f), -1.0f) ); } } ! /** ! * approximate heading from point a to point b ! * approximation assuming short distances ! * a few tenths of a deg of error for <= 2 deg lat/lon difference at ! * high (80+ deg) latitudes, less error near equator ! */ ! float nsNav::GCHeadingApprox_rad(tsGeoPointRad a, tsGeoPointRad b) ! { float fCosLatAvg_rad = cosf(0.5f*(a.mfLat_rad+b.mfLat_rad)); float fDeltaLon = b.mfLon_rad - a.mfLon_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! ! return atan2f(fCosLatAvg_rad*fDeltaLon, b.mfLat_rad-a.mfLat_rad); } ! ! float nsNav::GCHeadingApprox_rad(float afLatA_rad, float afLonA_rad, ! float afLatB_rad, float afLonB_rad) ! { float fCosLatAvg_rad = cosf(0.5f*(afLatA_rad+afLatB_rad)); float fDeltaLon = afLonB_rad - afLonA_rad; if (fDeltaLon > C_PI) {fDeltaLon -= C_TWOPI;} else if (fDeltaLon < -C_PI) {fDeltaLon += C_TWOPI;} ! ! return atan2f(fCosLatAvg_rad*fDeltaLon, afLatB_rad-afLatA_rad); } ! ! /** ! * sets point b at heading afHeading_rad and range of afRange_rad from point a ! * has accuracy issues (maybe this heading is only the initial heading or similar?) ! */ ! void nsNav::Offset(const tsGeoPointRad& a, tsGeoPointRad& b, ! float afHeading_rad, float afRange_rad) ! { float fTerm = sinf(a.mfLat_rad)*cosf(afRange_rad) + cosf(a.mfLat_rad)*sinf(afRange_rad)*cosf(afHeading_rad); + if (fTerm > 1) {fTerm = 1;} else if (fTerm < -1) {fTerm = -1;} + b.mfLat_rad = asinf(fTerm); fTerm = sinf(afHeading_rad)*sinf(afRange_rad)/cosf(a.mfLat_rad); + if (fTerm > 1) {fTerm = 1;} else if (fTerm < -1) {fTerm = -1;} + b.mfLon_rad = a.mfLon_rad + asinf(fTerm); } ! ! /** ! * sets point b at heading afHeading_rad and range of afRange_rad from point a ! */ ! void nsNav::OffsetApprox(const tsGeoPointRad& a, tsGeoPointRad& b, ! float afHeading_rad, float afRange_rad) ! { b.mfLat_rad = a.mfLat_rad + cosf(afHeading_rad)*afRange_rad; b.mfLon_rad = a.mfLon_rad + sinf(afHeading_rad)*afRange_rad/cosf(a.mfLat_rad); *************** *** 141,166 **** afLonB_rad = afLonA_rad + sinf(afHeading_rad)*afRange_rad/cosf(afLatA_rad); } ! // return latitude of point at afLon_rad along GC path between a and b ! float nsNav::GetLatAlongGCPath(tsGeoPointRad a, tsGeoPointRad b, float afLon_rad) { float fNum, fDen; ! if (b.mfLon_rad == a.mfLon_rad) { b.mfLon_rad = a.mfLon_rad + 0.001f; } fNum = sinf(a.mfLat_rad)*cosf(b.mfLat_rad)*sinf(afLon_rad-b.mfLon_rad) - sinf(b.mfLat_rad)*cosf(a.mfLat_rad)*sinf(afLon_rad-a.mfLon_rad); fDen = cosf(a.mfLat_rad)*cosf(b.mfLat_rad)*sinf(a.mfLon_rad-b.mfLon_rad); return atanf(fNum/fDen); } ! // prints test info to file ! void nsNav::Test() { FILE* testfile=NULL; int nTrials = 8; testfile = fopen("navtest.txt","wt"); ! if (testfile==NULL) { wxMessageBox("Failed to open nav test file"); return; } ! for(int i=0;i<nTrials;i++) { tsGeoPointRad a,b; a.mfLat_rad = 0.9f*randfc(C_PI); --- 194,233 ---- afLonB_rad = afLonA_rad + sinf(afHeading_rad)*afRange_rad/cosf(afLatA_rad); } ! /** ! * @return latitude of point at afLon_rad along GC path between a and b ! */ ! float nsNav::GetLatAlongGCPath(tsGeoPointRad a, tsGeoPointRad b, float afLon_rad) ! { float fNum, fDen; ! ! if (b.mfLon_rad == a.mfLon_rad) ! { b.mfLon_rad = a.mfLon_rad + 0.001f; } + fNum = sinf(a.mfLat_rad)*cosf(b.mfLat_rad)*sinf(afLon_rad-b.mfLon_rad) - sinf(b.mfLat_rad)*cosf(a.mfLat_rad)*sinf(afLon_rad-a.mfLon_rad); + fDen = cosf(a.mfLat_rad)*cosf(b.mfLat_rad)*sinf(a.mfLon_rad-b.mfLon_rad); + return atanf(fNum/fDen); } ! ! /** ! * prints test info to file ! */ ! void nsNav::Test() ! { FILE* testfile=NULL; int nTrials = 8; testfile = fopen("navtest.txt","wt"); ! if (testfile==NULL) ! { wxMessageBox("Failed to open nav test file"); return; } ! for(int i=0; i<nTrials; i++) ! { tsGeoPointRad a,b; a.mfLat_rad = 0.9f*randfc(C_PI); Index: tcOggStreamer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcOggStreamer.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcOggStreamer.cpp 29 Feb 2004 22:51:35 -0000 1.7 --- tcOggStreamer.cpp 5 Aug 2004 02:22:35 -0000 1.8 *************** *** 190,202 **** paused = false; ! bool isPlaying = true; ! if(IsPlaying()) ! return true; ! ! for (int nBuff = 0;nBuff < NUM_BUFFERS;nBuff++) { ! if(!Stream(buffers[nBuff])) isPlaying = false; // out of music for stream alSourceQueueBuffers(source, 1, &buffers[nBuff]); } alSourcePlay(source); --- 190,205 ---- paused = false; ! if (IsPlaying()) return true; ! ! Update(); // new way of doing this ! ! #if 0 ! bool dataAvailable = true; ! for (int nBuff = 0;(nBuff < NUM_BUFFERS) && dataAvailable; nBuff++) { ! if(!Stream(buffers[nBuff])) dataAvailable = false; // out of music for stream alSourceQueueBuffers(source, 1, &buffers[nBuff]); } + #endif alSourcePlay(source); *************** *** 259,282 **** bool active = true; int processed; - int queued; if (paused) return true; ! // Check for stall, and fix if necessary ! alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); ! if (!queued) ! { ! Play(); ! } ! if (!IsPlaying()) ! { ! alSourcePlay(source); ! } // Ask OpenAL how many buffers it has managed to play back alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); ! while (processed--) { alSourceUnqueueBuffers(source, 1, &buffers[bufferIndex]); --- 262,293 ---- bool active = true; int processed; if (paused) return true; ! // Ask OpenAL how many buffers it has managed to play back alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); + nFreeBuffers += processed; + if (nFreeBuffers > NUM_BUFFERS) + { + wxASSERT(false); + nFreeBuffers = NUM_BUFFERS; + } ! ! /* If stall condition then set nFreeBuffers to NUM_BUFFERS ! ** to restart streaming (not sure if this works yet) ! */ ! int nQueued; ! alGetSourcei(source, AL_BUFFERS_QUEUED, &nQueued); ! if ((nFreeBuffers == 0) && (nQueued == 0)) ! { ! nFreeBuffers = NUM_BUFFERS; ! } ! ! ! while (active && nFreeBuffers) { alSourceUnqueueBuffers(source, 1, &buffers[bufferIndex]); *************** *** 285,293 **** active = Stream(buffers[bufferIndex]); ! alSourceQueueBuffers(source, 1, &buffers[bufferIndex]); ! // fprintf(stdout,"Queued buffer: %d\n", bufferIndex); ! bufferIndex = (bufferIndex + 1) % NUM_BUFFERS; Check(); --- 296,308 ---- active = Stream(buffers[bufferIndex]); ! if (active) ! { ! alSourceQueueBuffers(source, 1, &buffers[bufferIndex]); ! // fprintf(stdout,"Queued buffer: %d\n", bufferIndex); ! bufferIndex = (bufferIndex + 1) % NUM_BUFFERS; ! nFreeBuffers--; ! } Check(); *************** *** 299,330 **** bool tcOggStreamer::Stream(ALuint buffer) { - char pcm[BUFFER_SIZE]; int size = 0; int section; int result; ! while(size < BUFFER_SIZE) { ! result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, §ion); ! if(result > 0) size += result; ! else ! if(result < 0) ! throw ErrorString(result); ! else ! { ! if (queuedSong.size() > 2) ! { ! Open(queuedSong); ! queuedSong = ""; ! return true; ! } ! else ! { ! result = ov_time_seek(&oggStream, 0.0); // loop if no queued song ! } ! break; ! } } --- 314,348 ---- bool tcOggStreamer::Stream(ALuint buffer) { int size = 0; int section; int result; ! while (size < BUFFER_SIZE) { ! result = ov_read(&oggStream, ! streamBuffer + size, BUFFER_SIZE - size, 0, 2, 1, §ion); ! if (result > 0) ! { size += result; ! } ! else if (result < 0) ! { ! fprintf(stderr, "%s\n", ErrorString(result).c_str()); ! } ! else ! { ! if (queuedSong.size() > 2) ! { ! Open(queuedSong); ! queuedSong = ""; ! return false; ! } ! else ! { ! result = ov_time_seek(&oggStream, 0.0); // loop if no queued song ! } ! break; ! } } *************** *** 332,336 **** return false; ! alBufferData(buffer, format, pcm, size, vorbisInfo->rate); Check(); --- 350,354 ---- return false; ! alBufferData(buffer, format, streamBuffer, size, vorbisInfo->rate); Check(); *************** *** 355,358 **** --- 373,379 ---- Check(); } + + bufferIndex = 0; + nFreeBuffers = NUM_BUFFERS; } *************** *** 407,410 **** --- 428,432 ---- volume = 0.2f; bufferIndex = 0; + nFreeBuffers = NUM_BUFFERS; queuedSong == ""; paused = false; Index: tcSound.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcSound.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tcSound.cpp 9 Apr 2004 14:15:18 -0000 1.15 --- tcSound.cpp 5 Aug 2004 02:22:35 -0000 1.16 *************** *** 105,108 **** --- 105,109 ---- LoadWavDataFromFile("intercom.wav",SEFFECT_INTERCOM); LoadWavDataFromFile("fslide.wav",SEFFECT_FSLIDE); + LoadWavDataFromFile("NavalGun1.wav", SEFFECT_NAVALGUN); if((alGetError())!=AL_NO_ERROR) Index: simmath.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/simmath.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** simmath.cpp 27 Jul 2004 00:16:23 -0000 1.13 --- simmath.cpp 5 Aug 2004 02:22:35 -0000 1.14 *************** *** 492,496 **** * @return range in km including range due to altitude difference */ ! float tcKinematics::RangeToKmAlt(tcKinematics& k) { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, (float)k.mfLat_rad,(float)k.mfLon_rad, --- 492,497 ---- * @return range in km including range due to altitude difference */ ! float tcKinematics::RangeToKmAlt(tcKinematics& k) ! { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, (float)k.mfLat_rad,(float)k.mfLon_rad, *************** *** 498,506 **** } ! float tcKinematics::RangeToKm(const tsGeoPoint *apGeoPoint) { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, apGeoPoint->mfLat_rad,apGeoPoint->mfLon_rad); } /** * @return approximate range in km, altitude difference is neglected --- 499,509 ---- } ! float tcKinematics::RangeToKm(const tsGeoPoint *apGeoPoint) ! { return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, apGeoPoint->mfLat_rad,apGeoPoint->mfLon_rad); } + /** * @return approximate range in km, altitude difference is neglected *************** *** 515,518 **** --- 518,530 ---- /** + * @return approximate range in km, altitude difference is neglected + */ + float tcKinematics::RangeToKm(float lon_rad, float lat_rad) + { + return C_RADTOKM * nsNav::GCDistanceApprox_rad((float)mfLat_rad,(float)mfLon_rad, + lat_rad, lon_rad); + } + + /** * Load state from stream */ |