Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
eefb0c817f
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
sdk/* linguist-vendored
|
||||
vendor/* linguist-vendored
|
@ -14,7 +14,7 @@ such that we have a working game at all times.
|
||||
|
||||
## How can I try it?
|
||||
|
||||
- re3 requires game assets to work, so you **must** own a copy of GTA III.
|
||||
- re3 requires game assets to work, so you **must** own [a copy of GTA III](https://store.steampowered.com/app/12100/Grand_Theft_Auto_III/).
|
||||
- Build re3 or download it from one of the above links (Debug or Release).
|
||||
- (Optional) If you want to use optional features like Russian language or menu map, copy the files in /gamefiles folder to your game root folder.
|
||||
- Move re3.exe to GTA 3 directory and run it.
|
||||
|
@ -165,7 +165,7 @@ cAudioManager::SetUpLoopingCollisionSound(const cAudioCollision &col, uint8 coun
|
||||
if(m_sQueueSample.m_nVolume) {
|
||||
m_sQueueSample.m_nCounter = counter;
|
||||
m_sQueueSample.m_vecPos = col.m_vecPosition;
|
||||
m_sQueueSample.m_nBankIndex = SAMPLEBANK_MAIN;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = false;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 7;
|
||||
m_sQueueSample.m_nLoopCount = 0;
|
||||
@ -306,7 +306,7 @@ cAudioManager::SetUpOneShotCollisionSound(const cAudioCollision &col)
|
||||
m_sQueueSample.m_nCounter = counter++;
|
||||
if(counter >= 255) counter = 28;
|
||||
m_sQueueSample.m_vecPos = col.m_vecPosition;
|
||||
m_sQueueSample.m_nBankIndex = SAMPLEBANK_MAIN;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = false;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 11;
|
||||
m_sQueueSample.m_nLoopCount = 1;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,7 @@ cAudioManager::Terminate()
|
||||
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
|
||||
PreTerminateGameSpecificShutdown();
|
||||
|
||||
for (uint32 i = 0; i < MAX_SAMPLEBANKS; i++) {
|
||||
for (uint32 i = 0; i < MAX_SFX_BANKS; i++) {
|
||||
if (SampleManager.IsSampleBankLoaded(i))
|
||||
SampleManager.UnloadSampleBank(i);
|
||||
}
|
||||
@ -917,7 +917,7 @@ cAudioManager::ClearActiveSamples()
|
||||
m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE;
|
||||
m_asActiveSamples[i].m_nCounter = 0;
|
||||
m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE;
|
||||
m_asActiveSamples[i].m_nBankIndex = SAMPLEBANK_INVALID;
|
||||
m_asActiveSamples[i].m_nBankIndex = INVALID_SFX_BANK;
|
||||
m_asActiveSamples[i].m_bIs2D = false;
|
||||
m_asActiveSamples[i].m_nReleasingVolumeModificator = 5;
|
||||
m_asActiveSamples[i].m_nFrequency = 0;
|
||||
|
@ -213,7 +213,7 @@ public:
|
||||
float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; }
|
||||
int32 GetRandomNumber(int32 idx) const { return m_anRandomTable[idx]; }
|
||||
int32 GetRandomNumberInRange(int32 idx, int32 low, int32 high) const { return (m_anRandomTable[idx] % (high - low + 1)) + low; }
|
||||
bool IsMissionAudioSamplePlaying() const { return m_sMissionAudio.m_nPlayStatus == 1; }
|
||||
bool ShouldDuckMissionAudio() const { return m_sMissionAudio.m_nPlayStatus == 1; }
|
||||
|
||||
// "Should" be in alphabetic order, except "getXTalkSfx"
|
||||
void AddDetailsToRequestedOrderList(uint8 sample);
|
||||
|
@ -26,12 +26,12 @@ cMusicManager::cMusicManager()
|
||||
m_bIsInitialised = false;
|
||||
m_bDisabled = false;
|
||||
m_nMusicMode = MUSICMODE_DISABLED;
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
m_bFrontendTrackFinished = false;
|
||||
m_bPlayInFrontend = false;
|
||||
m_bSetNextStation = false;
|
||||
m_nAnnouncement = NO_STREAMED_SOUND;
|
||||
m_nAnnouncement = NO_TRACK;
|
||||
m_bPreviousPlayerInCar = false;
|
||||
m_bPlayerInCar = false;
|
||||
m_bAnnouncementInProgress = false;
|
||||
@ -224,7 +224,7 @@ cMusicManager::Initialise()
|
||||
m_bRadioSetByScript = false;
|
||||
m_nRadioStation = HEAD_RADIO;
|
||||
m_nRadioPosition = -1;
|
||||
m_nRadioInCar = NO_STREAMED_SOUND;
|
||||
m_nRadioInCar = NO_TRACK;
|
||||
gNumRetunePresses = 0;
|
||||
gRetuneCounter = 0;
|
||||
m_bIsInitialised = true;
|
||||
@ -239,8 +239,8 @@ cMusicManager::Terminate()
|
||||
|
||||
if (SampleManager.IsStreamPlaying(0)) {
|
||||
SampleManager.StopStreamedFile(0);
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
}
|
||||
m_bIsInitialised = false;
|
||||
}
|
||||
@ -274,8 +274,8 @@ cMusicManager::ChangeMusicMode(uint8 mode)
|
||||
}
|
||||
SampleManager.StopStreamedFile(0);
|
||||
}
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
m_bFrontendTrackFinished = false;
|
||||
m_bPlayInFrontend = false;
|
||||
m_bSetNextStation = false;
|
||||
@ -301,14 +301,14 @@ cMusicManager::GetRadioInCar(void)
|
||||
CVehicle *veh = FindPlayerVehicle();
|
||||
if (veh != nil){
|
||||
if (UsesPoliceRadio(veh)) {
|
||||
if (m_nRadioInCar == NO_STREAMED_SOUND || (CReplay::IsPlayingBack() && AudioManager.m_nUserPause == 0))
|
||||
if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && AudioManager.m_nUserPause == 0))
|
||||
return POLICE_RADIO;
|
||||
return m_nRadioInCar;
|
||||
} else return veh->m_nRadioStation;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_nRadioInCar == NO_STREAMED_SOUND || (CReplay::IsPlayingBack() && AudioManager.m_nUserPause == 0))
|
||||
if (m_nRadioInCar == NO_TRACK || (CReplay::IsPlayingBack() && AudioManager.m_nUserPause == 0))
|
||||
return RADIO_OFF;
|
||||
return m_nRadioInCar;
|
||||
}
|
||||
@ -347,7 +347,7 @@ cMusicManager::ResetMusicAfterReload()
|
||||
m_bRadioSetByScript = false;
|
||||
m_nRadioStation = 0;
|
||||
m_nRadioPosition = -1;
|
||||
m_nAnnouncement = NO_STREAMED_SOUND;
|
||||
m_nAnnouncement = NO_TRACK;
|
||||
m_bAnnouncementInProgress = false;
|
||||
m_bSetNextStation = false;
|
||||
gRetuneCounter = 0;
|
||||
@ -384,7 +384,7 @@ cMusicManager::Service()
|
||||
m_nLastTrackServiceTime = m_nTimer;
|
||||
} else m_bDoTrackService = false;
|
||||
|
||||
if (m_nCurrentStreamedSound == NO_STREAMED_SOUND && SampleManager.IsStreamPlaying(0))
|
||||
if (m_nCurrentStreamedSound == NO_TRACK && SampleManager.IsStreamPlaying(0))
|
||||
SampleManager.StopStreamedFile(0);
|
||||
else switch (m_nMusicMode) {
|
||||
case MUSICMODE_FRONTEND: ServiceFrontEndMode(); break;
|
||||
@ -410,8 +410,8 @@ cMusicManager::ServiceFrontEndMode()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
}
|
||||
} else if (bHasStarted) {
|
||||
if (!SampleManager.IsStreamPlaying(0))
|
||||
@ -434,6 +434,7 @@ cMusicManager::ServiceGameMode()
|
||||
{
|
||||
bool bRadioOff = false;
|
||||
static int8 nFramesSinceCutsceneEnded = -1;
|
||||
uint8 volume;
|
||||
|
||||
m_bPreviousPlayerInCar = m_bPlayerInCar;
|
||||
m_bPlayerInCar = PlayerInCar();
|
||||
@ -516,29 +517,29 @@ cMusicManager::ServiceGameMode()
|
||||
m_bPlayerInCar = false;
|
||||
if (FindPlayerVehicle())
|
||||
FindPlayerVehicle()->m_nRadioStation = m_nCurrentStreamedSound;
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
}
|
||||
if (CTimer::GetIsSlowMotionActive()) {
|
||||
if (TheCamera.pTargetEntity != nil) {
|
||||
float dist = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr();
|
||||
if (dist >= 3025.0f) {
|
||||
float DistToTargetSq = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr();
|
||||
if (DistToTargetSq >= SQR(55.0f)) {
|
||||
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
|
||||
} else if (dist >= 100.0f) {
|
||||
int8 volume = ((45.0f - (Sqrt(dist) - 10.0f)) / 45.0f * 100.0f);
|
||||
int8 pan;
|
||||
if (AudioManager.IsMissionAudioSamplePlaying())
|
||||
} else if (DistToTargetSq >= SQR(10.0f)) {
|
||||
volume = ((45.0f - (Sqrt(DistToTargetSq) - 10.0f)) / 45.0f * 100.0f);
|
||||
uint8 pan;
|
||||
if (AudioManager.ShouldDuckMissionAudio())
|
||||
volume /= 4;
|
||||
if (volume != 0) {
|
||||
CVector trVec;
|
||||
AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &trVec);
|
||||
pan = AudioManager.ComputePan(55.0f, &trVec);
|
||||
if (volume > 0) {
|
||||
CVector panVec;
|
||||
AudioManager.TranslateEntity(&TheCamera.pTargetEntity->GetPosition(), &panVec);
|
||||
pan = AudioManager.ComputePan(55.0f, &panVec);
|
||||
} else {
|
||||
pan = 0;
|
||||
}
|
||||
if (gRetuneCounter)
|
||||
volume /= 4;
|
||||
SampleManager.SetStreamedVolumeAndPan(volume, pan, 0, 0);
|
||||
} else if (AudioManager.IsMissionAudioSamplePlaying()) {
|
||||
} else if (AudioManager.ShouldDuckMissionAudio()) {
|
||||
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
|
||||
} else if (gRetuneCounter) {
|
||||
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
|
||||
@ -546,26 +547,24 @@ cMusicManager::ServiceGameMode()
|
||||
SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0);
|
||||
}
|
||||
}
|
||||
} else if (AudioManager.IsMissionAudioSamplePlaying()) {
|
||||
} else if (AudioManager.ShouldDuckMissionAudio()) {
|
||||
SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0);
|
||||
nFramesSinceCutsceneEnded = 0;
|
||||
} else {
|
||||
int8 volume;
|
||||
if (nFramesSinceCutsceneEnded == -1) {
|
||||
volume = 100;
|
||||
} else if (nFramesSinceCutsceneEnded >= 20) {
|
||||
if (nFramesSinceCutsceneEnded >= 40) {
|
||||
nFramesSinceCutsceneEnded = -1;
|
||||
volume = 100;
|
||||
} else {
|
||||
volume = 3 * (nFramesSinceCutsceneEnded - 20) + 25;
|
||||
nFramesSinceCutsceneEnded++;
|
||||
}
|
||||
} else {
|
||||
} else if (nFramesSinceCutsceneEnded < 20) {
|
||||
nFramesSinceCutsceneEnded++;
|
||||
volume = 25;
|
||||
} else if (nFramesSinceCutsceneEnded < 40) {
|
||||
volume = 3 * (nFramesSinceCutsceneEnded - 20) + 25;
|
||||
nFramesSinceCutsceneEnded++;
|
||||
} else {
|
||||
nFramesSinceCutsceneEnded = -1;
|
||||
volume = 100;
|
||||
}
|
||||
if (gRetuneCounter) volume /= 4;
|
||||
if (gRetuneCounter != 0)
|
||||
volume /= 4;
|
||||
SampleManager.SetStreamedVolumeAndPan(volume, 63, 0, 0);
|
||||
}
|
||||
return;
|
||||
@ -585,7 +584,7 @@ cMusicManager::ServiceGameMode()
|
||||
} else {
|
||||
m_nCurrentStreamedSound = m_nRadioStation;
|
||||
if (FindPlayerVehicle()->m_nRadioStation == m_nCurrentStreamedSound) {
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
|
||||
SampleManager.StopStreamedFile(0);
|
||||
}
|
||||
@ -608,19 +607,19 @@ cMusicManager::ServiceGameMode()
|
||||
}
|
||||
} else {
|
||||
m_bPlayerInCar = false;
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cMusicManager::StopFrontEndTrack()
|
||||
{
|
||||
if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nCurrentStreamedSound != NO_STREAMED_SOUND) {
|
||||
if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nCurrentStreamedSound != NO_TRACK) {
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
|
||||
SampleManager.StopStreamedFile(0);
|
||||
m_nPreviousStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nPreviousStreamedSound = NO_TRACK;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -636,9 +635,9 @@ cMusicManager::PlayFrontEndTrack(uint8 track, uint8 bPlayInFrontend)
|
||||
{
|
||||
if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS) {
|
||||
if (m_nMusicMode == MUSICMODE_GAME) {
|
||||
if (m_nCurrentStreamedSound != NO_STREAMED_SOUND) {
|
||||
if (m_nCurrentStreamedSound != NO_TRACK) {
|
||||
if (m_bAnnouncementInProgress) {
|
||||
m_nAnnouncement = NO_STREAMED_SOUND;
|
||||
m_nAnnouncement = NO_TRACK;
|
||||
m_bAnnouncementInProgress = false;
|
||||
}
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
|
||||
@ -646,7 +645,7 @@ cMusicManager::PlayFrontEndTrack(uint8 track, uint8 bPlayInFrontend)
|
||||
}
|
||||
SampleManager.StopStreamedFile(0);
|
||||
} else if (m_nMusicMode == MUSICMODE_FRONTEND) {
|
||||
if (m_nCurrentStreamedSound != NO_STREAMED_SOUND) {
|
||||
if (m_nCurrentStreamedSound != NO_TRACK) {
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
|
||||
}
|
||||
@ -691,23 +690,22 @@ cMusicManager::StopCutSceneMusic(void)
|
||||
{
|
||||
if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_CUTSCENE) {
|
||||
SampleManager.StopStreamedFile(0);
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
uint32
|
||||
cMusicManager::GetTrackStartPos(uint8 track)
|
||||
{
|
||||
uint32 result;
|
||||
uint32 timer = m_aTracks[track].m_nLastPosCheckTimer;
|
||||
if (CTimer::GetTimeInMillisecondsPauseMode() <= timer) {
|
||||
result = m_aTracks[track].m_nPosition;
|
||||
uint32 pos = m_aTracks[track].m_nPosition;
|
||||
if (CTimer::GetTimeInMillisecondsPauseMode() > m_aTracks[track].m_nLastPosCheckTimer)
|
||||
pos += Min(CTimer::GetTimeInMillisecondsPauseMode() - m_aTracks[track].m_nLastPosCheckTimer, 90000);
|
||||
else
|
||||
m_aTracks[track].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
|
||||
} else
|
||||
result = Min(CTimer::GetTimeInMillisecondsPauseMode() - timer, 90000) + m_aTracks[track].m_nPosition;
|
||||
|
||||
if (result > m_aTracks[track].m_nLength) result %= m_aTracks[track].m_nLength;
|
||||
return result;
|
||||
if (pos > m_aTracks[track].m_nLength)
|
||||
pos %= m_aTracks[track].m_nLength;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
@ -733,7 +731,7 @@ cMusicManager::ServiceAmbience()
|
||||
uint8 volume;
|
||||
|
||||
if (m_bAnnouncementInProgress) {
|
||||
m_nAnnouncement = NO_STREAMED_SOUND;
|
||||
m_nAnnouncement = NO_TRACK;
|
||||
m_bAnnouncementInProgress = false;
|
||||
}
|
||||
if (m_nCurrentStreamedSound < STREAMED_SOUND_CITY_AMBIENT) {
|
||||
@ -741,13 +739,13 @@ cMusicManager::ServiceAmbience()
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
|
||||
SampleManager.StopStreamedFile(0);
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
return;
|
||||
}
|
||||
m_nCurrentStreamedSound = STREAMED_SOUND_CITY_AMBIENT;
|
||||
}
|
||||
if (CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING && !SampleManager.IsStreamPlaying(0)) {
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -774,7 +772,7 @@ cMusicManager::ServiceAmbience()
|
||||
SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0);
|
||||
m_bDontServiceAmbienceTrack = true;
|
||||
} else
|
||||
m_nCurrentStreamedSound = NO_STREAMED_SOUND;
|
||||
m_nCurrentStreamedSound = NO_TRACK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -813,7 +811,7 @@ cMusicManager::ServiceAnnouncement()
|
||||
static int8 cCheck = 0;
|
||||
if (m_bAnnouncementInProgress) {
|
||||
if (!SampleManager.IsStreamPlaying(0)) {
|
||||
m_nAnnouncement = NO_STREAMED_SOUND;
|
||||
m_nAnnouncement = NO_TRACK;
|
||||
m_bAnnouncementInProgress = false;
|
||||
}
|
||||
return true;
|
||||
@ -823,7 +821,7 @@ cMusicManager::ServiceAnnouncement()
|
||||
cCheck = 0;
|
||||
int pos = SampleManager.GetStreamedFilePosition(0);
|
||||
if (SampleManager.IsStreamPlaying(0)) {
|
||||
if (m_nCurrentStreamedSound != NO_STREAMED_SOUND) {
|
||||
if (m_nCurrentStreamedSound != NO_TRACK) {
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nPosition = pos;
|
||||
m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
|
||||
SampleManager.StopStreamedFile(0);
|
||||
@ -832,7 +830,7 @@ cMusicManager::ServiceAnnouncement()
|
||||
|
||||
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
|
||||
if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) {
|
||||
SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0);
|
||||
SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
|
||||
m_bAnnouncementInProgress = true;
|
||||
m_nPreviousStreamedSound = m_nCurrentStreamedSound;
|
||||
m_nCurrentStreamedSound = m_nAnnouncement;
|
||||
@ -905,7 +903,7 @@ cMusicManager::ChangeRadioChannel()
|
||||
return false;
|
||||
if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, GetTrackStartPos(m_nCurrentStreamedSound), 0))
|
||||
return false;
|
||||
SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0);
|
||||
SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ cAudioManager::DoPoliceRadioCrackle()
|
||||
m_sQueueSample.m_nEntityIndex = m_nPoliceChannelEntity;
|
||||
m_sQueueSample.m_nCounter = 0;
|
||||
m_sQueueSample.m_nSampleIndex = SFX_POLICE_RADIO_CRACKLE;
|
||||
m_sQueueSample.m_nBankIndex = SAMPLEBANK_MAIN;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = true;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 10;
|
||||
m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_POLICE_RADIO_CRACKLE);
|
||||
|
@ -224,7 +224,7 @@ enum eStreamedSounds
|
||||
STREAMED_SOUND_MISSION_K1_B,
|
||||
STREAMED_SOUND_MISSION_CAT1,
|
||||
TOTAL_STREAMED_SOUNDS,
|
||||
NO_STREAMED_SOUND,
|
||||
NO_TRACK,
|
||||
};
|
||||
|
||||
enum AudioEntityHandle {
|
||||
|
@ -16,83 +16,83 @@ struct tSample {
|
||||
#ifdef GTA_PS2
|
||||
#define PS2BANK(e) e
|
||||
#else
|
||||
#define PS2BANK(e) e = SAMPLEBANK_MAIN
|
||||
#define PS2BANK(e) e = SFX_BANK_0
|
||||
#endif // GTA_PS2
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
SAMPLEBANK_MAIN,
|
||||
SFX_BANK_0,
|
||||
|
||||
CAR_SAMPLEBANKS_OFFSET,
|
||||
SAMPLEBANK_CAR_PACARD = CAR_SAMPLEBANKS_OFFSET,
|
||||
SAMPLEBANK_CAR_PATHFINDER,
|
||||
SAMPLEBANK_CAR_PORSCHE,
|
||||
SAMPLEBANK_CAR_SPIDER,
|
||||
SAMPLEBANK_CAR_MERC,
|
||||
SAMPLEBANK_CAR_MACKTRUCK,
|
||||
SAMPLEBANK_CAR_HOTROD,
|
||||
SAMPLEBANK_CAR_COBRA,
|
||||
SAMPLEBANK_CAR_NONE,
|
||||
CAR_SFX_BANKS_OFFSET,
|
||||
SFX_BANK_PACARD = CAR_SFX_BANKS_OFFSET,
|
||||
SFX_BANK_PATHFINDER,
|
||||
SFX_BANK_PORSCHE,
|
||||
SFX_BANK_SPIDER,
|
||||
SFX_BANK_MERC,
|
||||
SFX_BANK_TRUCK,
|
||||
SFX_BANK_HOTROD,
|
||||
SFX_BANK_COBRA,
|
||||
SFX_BANK_NONE,
|
||||
|
||||
PS2BANK(SAMPLEBANK_FRONTEND),
|
||||
PS2BANK(SFX_BANK_FRONT_END_MENU),
|
||||
|
||||
PS2BANK(SAMPLEBANK_TRAIN),
|
||||
PS2BANK(SFX_BANK_TRAIN),
|
||||
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_1),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_2),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_3),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_4),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_5),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_6),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_7),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_8),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_9),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_10),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_11),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_12),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CLUB_RAGGA),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_STRIP_CLUB_1),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_STRIP_CLUB_2),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_WORKSHOP),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_PIANO_BAR),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_SAWMILL),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_DOG_FOOD_FACTORY),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_LAUNDERETTE),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RESTAURANT_CHINATOWN),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RESTAURANT_ITALY),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RESTAURANT_GENERIC_1),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RESTAURANT_GENERIC_2),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_AIRPORT),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_SHOP),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_CINEMA),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_DOCKS),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_HOME),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_PORN_1),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_PORN_2),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_PORN_3),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_POLICE_BALL),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_BANK_ALARM),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RAVE_INDUSTRIAL),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RAVE_COMMERCIAL),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RAVE_SUBURBAN),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_RAVE_COMMERCIAL_2),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_1),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_2),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_3),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_4),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_5),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_6),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_7),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_8),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_9),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_10),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_11),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_12),
|
||||
PS2BANK(SFX_BANK_BUILDING_CLUB_RAGGA),
|
||||
PS2BANK(SFX_BANK_BUILDING_STRIP_CLUB_1),
|
||||
PS2BANK(SFX_BANK_BUILDING_STRIP_CLUB_2),
|
||||
PS2BANK(SFX_BANK_BUILDING_WORKSHOP),
|
||||
PS2BANK(SFX_BANK_BUILDING_PIANO_BAR),
|
||||
PS2BANK(SFX_BANK_BUILDING_SAWMILL),
|
||||
PS2BANK(SFX_BANK_BUILDING_DOG_FOOD_FACTORY),
|
||||
PS2BANK(SFX_BANK_BUILDING_LAUNDERETTE),
|
||||
PS2BANK(SFX_BANK_BUILDING_RESTAURANT_CHINATOWN),
|
||||
PS2BANK(SFX_BANK_BUILDING_RESTAURANT_ITALY),
|
||||
PS2BANK(SFX_BANK_BUILDING_RESTAURANT_GENERIC_1),
|
||||
PS2BANK(SFX_BANK_BUILDING_RESTAURANT_GENERIC_2),
|
||||
PS2BANK(SFX_BANK_BUILDING_AIRPORT),
|
||||
PS2BANK(SFX_BANK_BUILDING_SHOP),
|
||||
PS2BANK(SFX_BANK_BUILDING_CINEMA),
|
||||
PS2BANK(SFX_BANK_BUILDING_DOCKS),
|
||||
PS2BANK(SFX_BANK_BUILDING_HOME),
|
||||
PS2BANK(SFX_BANK_BUILDING_PORN_1),
|
||||
PS2BANK(SFX_BANK_BUILDING_PORN_2),
|
||||
PS2BANK(SFX_BANK_BUILDING_PORN_3),
|
||||
PS2BANK(SFX_BANK_BUILDING_POLICE_BALL),
|
||||
PS2BANK(SFX_BANK_BUILDING_BANK_ALARM),
|
||||
PS2BANK(SFX_BANK_BUILDING_RAVE_INDUSTRIAL),
|
||||
PS2BANK(SFX_BANK_BUILDING_RAVE_COMMERCIAL),
|
||||
PS2BANK(SFX_BANK_BUILDING_RAVE_SUBURBAN),
|
||||
PS2BANK(SFX_BANK_BUILDING_RAVE_COMMERCIAL_2),
|
||||
|
||||
PS2BANK(SAMPLEBANK_BUILDING_39),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_40),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_41),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_42),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_43),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_44),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_45),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_46),
|
||||
PS2BANK(SAMPLEBANK_BUILDING_47),
|
||||
PS2BANK(SFX_BANK_BUILDING_39),
|
||||
PS2BANK(SFX_BANK_BUILDING_40),
|
||||
PS2BANK(SFX_BANK_BUILDING_41),
|
||||
PS2BANK(SFX_BANK_BUILDING_42),
|
||||
PS2BANK(SFX_BANK_BUILDING_43),
|
||||
PS2BANK(SFX_BANK_BUILDING_44),
|
||||
PS2BANK(SFX_BANK_BUILDING_45),
|
||||
PS2BANK(SFX_BANK_BUILDING_46),
|
||||
PS2BANK(SFX_BANK_BUILDING_47),
|
||||
|
||||
PS2BANK(SAMPLEBANK_EXTRAS),
|
||||
PS2BANK(SFX_BANK_GENERIC_EXTRA),
|
||||
|
||||
SAMPLEBANK_PED,
|
||||
MAX_SAMPLEBANKS,
|
||||
SAMPLEBANK_INVALID
|
||||
SFX_BANK_PED_COMMENTS,
|
||||
MAX_SFX_BANKS,
|
||||
INVALID_SFX_BANK
|
||||
};
|
||||
|
||||
#define MAX_PEDSFX 7
|
||||
@ -216,7 +216,7 @@ public:
|
||||
};
|
||||
|
||||
extern cSampleManager SampleManager;
|
||||
extern uint32 BankStartOffset[MAX_SAMPLEBANKS];
|
||||
extern uint32 BankStartOffset[MAX_SFX_BANKS];
|
||||
|
||||
#ifdef AUDIO_OPUS
|
||||
static char StreamedNameTable[][25] = {
|
||||
|
@ -21,7 +21,7 @@
|
||||
#pragma comment( lib, "mss32.lib" )
|
||||
|
||||
cSampleManager SampleManager;
|
||||
uint32 BankStartOffset[MAX_SAMPLEBANKS];
|
||||
uint32 BankStartOffset[MAX_SFX_BANKS];
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
char SampleBankDescFilename[] = "AUDIO\\SFX.SDT";
|
||||
@ -29,10 +29,10 @@ char SampleBankDataFilename[] = "AUDIO\\SFX.RAW";
|
||||
|
||||
FILE *fpSampleDescHandle;
|
||||
FILE *fpSampleDataHandle;
|
||||
bool bSampleBankLoaded [MAX_SAMPLEBANKS];
|
||||
int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS];
|
||||
int32 nSampleBankSize [MAX_SAMPLEBANKS];
|
||||
int32 nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS];
|
||||
bool bSampleBankLoaded [MAX_SFX_BANKS];
|
||||
int32 nSampleBankDiscStartOffset [MAX_SFX_BANKS];
|
||||
int32 nSampleBankSize [MAX_SFX_BANKS];
|
||||
int32 nSampleBankMemoryStartAddress[MAX_SFX_BANKS];
|
||||
int32 _nSampleDataEndOffset;
|
||||
|
||||
int32 nPedSlotSfx [MAX_PEDSFX];
|
||||
@ -896,7 +896,7 @@ cSampleManager::Initialise(void)
|
||||
|
||||
_nSampleDataEndOffset = 0;
|
||||
|
||||
for ( int32 i = 0; i < MAX_SAMPLEBANKS; i++ )
|
||||
for ( int32 i = 0; i < MAX_SFX_BANKS; i++ )
|
||||
{
|
||||
bSampleBankLoaded[i] = false;
|
||||
nSampleBankDiscStartOffset[i] = 0;
|
||||
@ -948,14 +948,14 @@ cSampleManager::Initialise(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (int32)AIL_mem_alloc_lock(nSampleBankSize[SAMPLEBANK_MAIN]);
|
||||
if ( !nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] )
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_0] = (int32)AIL_mem_alloc_lock(nSampleBankSize[SFX_BANK_0]);
|
||||
if ( !nSampleBankMemoryStartAddress[SFX_BANK_0] )
|
||||
{
|
||||
Terminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (int32)AIL_mem_alloc_lock(PED_BLOCKSIZE*MAX_PEDSFX);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = (int32)AIL_mem_alloc_lock(PED_BLOCKSIZE*MAX_PEDSFX);
|
||||
|
||||
}
|
||||
|
||||
@ -1176,7 +1176,7 @@ cSampleManager::Initialise(void)
|
||||
|
||||
TRACE("bank");
|
||||
|
||||
LoadSampleBank(SAMPLEBANK_MAIN);
|
||||
LoadSampleBank(SFX_BANK_0);
|
||||
|
||||
// mp3
|
||||
TRACE("mp3");
|
||||
@ -1271,16 +1271,16 @@ cSampleManager::Terminate(void)
|
||||
|
||||
_DeleteMP3Entries();
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != 0 )
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_0] != 0 )
|
||||
{
|
||||
AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN]);
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = 0;
|
||||
AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SFX_BANK_0]);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_0] = 0;
|
||||
}
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != 0 )
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] != 0 )
|
||||
{
|
||||
AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED]);
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = 0;
|
||||
AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS]);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = 0;
|
||||
}
|
||||
|
||||
if ( DIG )
|
||||
@ -1429,7 +1429,7 @@ cSampleManager::LoadSampleBank(uint8 nBank)
|
||||
|
||||
if ( MusicManager.IsInitialised()
|
||||
&& MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
|
||||
&& nBank != SAMPLEBANK_MAIN )
|
||||
&& nBank != SFX_BANK_0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1526,10 +1526,10 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 )
|
||||
return false;
|
||||
|
||||
if ( fread((void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
|
||||
if ( fread((void *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
|
||||
return false;
|
||||
|
||||
nPedSlotSfxAddr[nCurrentPedSlot] = nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot;
|
||||
nPedSlotSfxAddr[nCurrentPedSlot] = nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot;
|
||||
nPedSlotSfx [nCurrentPedSlot] = nComment;
|
||||
|
||||
if ( ++nCurrentPedSlot >= MAX_PEDSFX )
|
||||
@ -1541,13 +1541,13 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
int32
|
||||
cSampleManager::GetBankContainingSound(uint32 offset)
|
||||
{
|
||||
if ( offset >= BankStartOffset[SAMPLEBANK_PED] )
|
||||
return SAMPLEBANK_PED;
|
||||
if ( offset >= BankStartOffset[SFX_BANK_PED_COMMENTS] )
|
||||
return SFX_BANK_PED_COMMENTS;
|
||||
|
||||
if ( offset >= BankStartOffset[SAMPLEBANK_MAIN] )
|
||||
return SAMPLEBANK_MAIN;
|
||||
if ( offset >= BankStartOffset[SFX_BANK_0] )
|
||||
return SFX_BANK_0;
|
||||
|
||||
return SAMPLEBANK_INVALID;
|
||||
return INVALID_SFX_BANK;
|
||||
}
|
||||
|
||||
int32
|
||||
@ -2289,7 +2289,7 @@ cSampleManager::IsStreamPlaying(uint8 nStream)
|
||||
bool
|
||||
cSampleManager::InitialiseSampleBanks(void)
|
||||
{
|
||||
int32 nBank = SAMPLEBANK_MAIN;
|
||||
int32 nBank = SFX_BANK_0;
|
||||
|
||||
fpSampleDescHandle = fopen(SampleBankDescFilename, "rb");
|
||||
if ( fpSampleDescHandle == NULL )
|
||||
@ -2316,17 +2316,17 @@ cSampleManager::InitialiseSampleBanks(void)
|
||||
for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
if (nBank >= MAX_SAMPLEBANKS) break;
|
||||
if (nBank >= MAX_SFX_BANKS) break;
|
||||
#endif
|
||||
if ( BankStartOffset[nBank] == BankStartOffset[SAMPLEBANK_MAIN] + i )
|
||||
if ( BankStartOffset[nBank] == BankStartOffset[SFX_BANK_0] + i )
|
||||
{
|
||||
nSampleBankDiscStartOffset[nBank] = m_aSamples[i].nOffset;
|
||||
nBank++;
|
||||
}
|
||||
}
|
||||
|
||||
nSampleBankSize[SAMPLEBANK_MAIN] = nSampleBankDiscStartOffset[SAMPLEBANK_PED] - nSampleBankDiscStartOffset[SAMPLEBANK_MAIN];
|
||||
nSampleBankSize[SAMPLEBANK_PED] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SAMPLEBANK_PED];
|
||||
nSampleBankSize[SFX_BANK_0] = nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS] - nSampleBankDiscStartOffset[SFX_BANK_0];
|
||||
nSampleBankSize[SFX_BANK_PED_COMMENTS] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
cSampleManager SampleManager;
|
||||
bool _bSampmanInitialised = false;
|
||||
|
||||
uint32 BankStartOffset[MAX_SAMPLEBANKS];
|
||||
uint32 BankStartOffset[MAX_SFX_BANKS];
|
||||
uint32 nNumMP3s;
|
||||
|
||||
cSampleManager::cSampleManager(void)
|
||||
@ -131,20 +131,20 @@ cSampleManager::SetMonoMode(uint8 nMode)
|
||||
bool
|
||||
cSampleManager::LoadSampleBank(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
cSampleManager::UnloadSampleBank(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
}
|
||||
|
||||
bool
|
||||
cSampleManager::IsSampleBankLoaded(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -174,7 +174,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
int32
|
||||
cSampleManager::GetBankContainingSound(uint32 offset)
|
||||
{
|
||||
return SAMPLEBANK_INVALID;
|
||||
return INVALID_SFX_BANK;
|
||||
}
|
||||
|
||||
int32
|
||||
|
@ -43,7 +43,7 @@
|
||||
cSampleManager SampleManager;
|
||||
bool _bSampmanInitialised = false;
|
||||
|
||||
uint32 BankStartOffset[MAX_SAMPLEBANKS];
|
||||
uint32 BankStartOffset[MAX_SFX_BANKS];
|
||||
|
||||
int prevprovider=-1;
|
||||
int curprovider=-1;
|
||||
@ -77,10 +77,10 @@ OggOpusFile *fpSampleDataHandle;
|
||||
#else
|
||||
FILE *fpSampleDataHandle;
|
||||
#endif
|
||||
bool bSampleBankLoaded [MAX_SAMPLEBANKS];
|
||||
int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS];
|
||||
int32 nSampleBankSize [MAX_SAMPLEBANKS];
|
||||
uintptr nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS];
|
||||
bool bSampleBankLoaded [MAX_SFX_BANKS];
|
||||
int32 nSampleBankDiscStartOffset [MAX_SFX_BANKS];
|
||||
int32 nSampleBankSize [MAX_SFX_BANKS];
|
||||
uintptr nSampleBankMemoryStartAddress[MAX_SFX_BANKS];
|
||||
int32 _nSampleDataEndOffset;
|
||||
|
||||
int32 nPedSlotSfx [MAX_PEDSFX];
|
||||
@ -541,7 +541,7 @@ cSampleManager::Initialise(void)
|
||||
fpSampleDescHandle = NULL;
|
||||
fpSampleDataHandle = NULL;
|
||||
|
||||
for ( int32 i = 0; i < MAX_SAMPLEBANKS; i++ )
|
||||
for ( int32 i = 0; i < MAX_SFX_BANKS; i++ )
|
||||
{
|
||||
bSampleBankLoaded[i] = false;
|
||||
nSampleBankDiscStartOffset[i] = 0;
|
||||
@ -586,17 +586,17 @@ cSampleManager::Initialise(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (uintptr)malloc(nSampleBankSize[SAMPLEBANK_MAIN]);
|
||||
ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != 0);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_0] = (uintptr)malloc(nSampleBankSize[SFX_BANK_0]);
|
||||
ASSERT(nSampleBankMemoryStartAddress[SFX_BANK_0] != 0);
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] == 0 )
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_0] == 0 )
|
||||
{
|
||||
Terminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (uintptr)malloc(PED_BLOCKSIZE*MAX_PEDSFX);
|
||||
ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != 0);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = (uintptr)malloc(PED_BLOCKSIZE*MAX_PEDSFX);
|
||||
ASSERT(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] != 0);
|
||||
}
|
||||
|
||||
|
||||
@ -644,7 +644,7 @@ cSampleManager::Initialise(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
LoadSampleBank(SAMPLEBANK_MAIN);
|
||||
LoadSampleBank(SFX_BANK_0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -666,16 +666,16 @@ cSampleManager::Terminate(void)
|
||||
|
||||
CStream::Terminate();
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != 0 )
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_0] != 0 )
|
||||
{
|
||||
free((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN]);
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = 0;
|
||||
free((void *)nSampleBankMemoryStartAddress[SFX_BANK_0]);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_0] = 0;
|
||||
}
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != 0 )
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] != 0 )
|
||||
{
|
||||
free((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED]);
|
||||
nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = 0;
|
||||
free((void *)nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS]);
|
||||
nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = 0;
|
||||
}
|
||||
|
||||
_bSampmanInitialised = false;
|
||||
@ -751,14 +751,14 @@ cSampleManager::SetMonoMode(uint8 nMode)
|
||||
bool
|
||||
cSampleManager::LoadSampleBank(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
|
||||
if ( CTimer::GetIsCodePaused() )
|
||||
return false;
|
||||
|
||||
if ( MusicManager.IsInitialised()
|
||||
&& MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
|
||||
&& nBank != SAMPLEBANK_MAIN )
|
||||
&& nBank != SFX_BANK_0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -792,7 +792,7 @@ cSampleManager::LoadSampleBank(uint8 nBank)
|
||||
void
|
||||
cSampleManager::UnloadSampleBank(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
|
||||
bSampleBankLoaded[nBank] = false;
|
||||
}
|
||||
@ -800,7 +800,7 @@ cSampleManager::UnloadSampleBank(uint8 nBank)
|
||||
bool
|
||||
cSampleManager::IsSampleBankLoaded(uint8 nBank)
|
||||
{
|
||||
ASSERT( nBank < MAX_SAMPLEBANKS );
|
||||
ASSERT( nBank < MAX_SFX_BANKS );
|
||||
|
||||
return bSampleBankLoaded[nBank];
|
||||
}
|
||||
@ -881,7 +881,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
int samplesSize = m_aSamples[nComment].nSize / 2;
|
||||
op_pcm_seek(fpSampleDataHandle, m_aSamples[nComment].nOffset / 2);
|
||||
while (samplesSize > 0) {
|
||||
int size = op_read(fpSampleDataHandle, (opus_int16 *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE * nCurrentPedSlot + samplesRead),
|
||||
int size = op_read(fpSampleDataHandle, (opus_int16 *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE * nCurrentPedSlot + samplesRead),
|
||||
samplesSize, NULL);
|
||||
if (size <= 0) {
|
||||
return false;
|
||||
@ -893,7 +893,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 )
|
||||
return false;
|
||||
|
||||
if ( fread((void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
|
||||
if ( fread((void *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
|
||||
return false;
|
||||
|
||||
#endif
|
||||
@ -901,7 +901,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
|
||||
alBufferData(pedBuffers[nCurrentPedSlot],
|
||||
AL_FORMAT_MONO16,
|
||||
(void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot),
|
||||
(void *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot),
|
||||
m_aSamples[nComment].nSize,
|
||||
m_aSamples[nComment].nFrequency);
|
||||
|
||||
@ -914,13 +914,13 @@ cSampleManager::LoadPedComment(uint32 nComment)
|
||||
int32
|
||||
cSampleManager::GetBankContainingSound(uint32 offset)
|
||||
{
|
||||
if ( offset >= BankStartOffset[SAMPLEBANK_PED] )
|
||||
return SAMPLEBANK_PED;
|
||||
if ( offset >= BankStartOffset[SFX_BANK_PED_COMMENTS] )
|
||||
return SFX_BANK_PED_COMMENTS;
|
||||
|
||||
if ( offset >= BankStartOffset[SAMPLEBANK_MAIN] )
|
||||
return SAMPLEBANK_MAIN;
|
||||
if ( offset >= BankStartOffset[SFX_BANK_0] )
|
||||
return SFX_BANK_0;
|
||||
|
||||
return SAMPLEBANK_INVALID;
|
||||
return INVALID_SFX_BANK;
|
||||
}
|
||||
|
||||
int32
|
||||
@ -1421,7 +1421,7 @@ cSampleManager::Service(void)
|
||||
bool
|
||||
cSampleManager::InitialiseSampleBanks(void)
|
||||
{
|
||||
int32 nBank = SAMPLEBANK_MAIN;
|
||||
int32 nBank = SFX_BANK_0;
|
||||
|
||||
fpSampleDescHandle = fopen(SampleBankDescFilename, "rb");
|
||||
if ( fpSampleDescHandle == NULL )
|
||||
@ -1453,17 +1453,17 @@ cSampleManager::InitialiseSampleBanks(void)
|
||||
for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
if (nBank >= MAX_SAMPLEBANKS) break;
|
||||
if (nBank >= MAX_SFX_BANKS) break;
|
||||
#endif
|
||||
if ( BankStartOffset[nBank] == BankStartOffset[SAMPLEBANK_MAIN] + i )
|
||||
if ( BankStartOffset[nBank] == BankStartOffset[SFX_BANK_0] + i )
|
||||
{
|
||||
nSampleBankDiscStartOffset[nBank] = m_aSamples[i].nOffset;
|
||||
nBank++;
|
||||
}
|
||||
}
|
||||
|
||||
nSampleBankSize[SAMPLEBANK_MAIN] = nSampleBankDiscStartOffset[SAMPLEBANK_PED] - nSampleBankDiscStartOffset[SAMPLEBANK_MAIN];
|
||||
nSampleBankSize[SAMPLEBANK_PED] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SAMPLEBANK_PED];
|
||||
nSampleBankSize[SFX_BANK_0] = nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS] - nSampleBankDiscStartOffset[SFX_BANK_0];
|
||||
nSampleBankSize[SFX_BANK_PED_COMMENTS] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1080,11 +1080,11 @@ void CCarCtrl::SlowCarDownForCarsSectorList(CPtrList& lst, CVehicle* pVehicle, f
|
||||
void CCarCtrl::SlowCarDownForOtherCar(CEntity* pOtherEntity, CVehicle* pVehicle, float* pSpeed, float curSpeed)
|
||||
{
|
||||
CVector forwardA = pVehicle->GetForward();
|
||||
((CVector2D)forwardA).Normalise();
|
||||
((CVector2D)forwardA).NormaliseSafe();
|
||||
if (DotProduct2D(pOtherEntity->GetPosition() - pVehicle->GetPosition(), forwardA) < 0.0f)
|
||||
return;
|
||||
CVector forwardB = pOtherEntity->GetForward();
|
||||
((CVector2D)forwardB).Normalise();
|
||||
((CVector2D)forwardB).NormaliseSafe();
|
||||
forwardA.z = forwardB.z = 0.0f;
|
||||
CVehicle* pOtherVehicle = (CVehicle*)pOtherEntity;
|
||||
/* why is the argument CEntity if it's always CVehicle anyway and is casted? */
|
||||
@ -1337,7 +1337,7 @@ void CCarCtrl::WeaveForOtherCar(CEntity* pOtherEntity, CVehicle* pVehicle, float
|
||||
pVehicle->GetModelInfo()->GetColModel()->boundingSphere.radius < distance)
|
||||
return;
|
||||
CVector2D forward = pVehicle->GetForward();
|
||||
forward.Normalise();
|
||||
forward.NormaliseSafe();
|
||||
float forwardAngle = CGeneral::GetATanOfXY(forward.x, forward.y);
|
||||
float angleDiff = angleBetweenVehicles - forwardAngle;
|
||||
float lenProjection = ABS(pOtherCar->GetColModel()->boundingBox.max.y * sin(angleDiff));
|
||||
@ -2276,7 +2276,7 @@ float CCarCtrl::FindMaxSteerAngle(CVehicle* pVehicle)
|
||||
void CCarCtrl::SteerAICarWithPhysicsFollowPath(CVehicle* pVehicle, float* pSwerve, float* pAccel, float* pBrake, bool* pHandbrake)
|
||||
{
|
||||
CVector2D forward = pVehicle->GetForward();
|
||||
forward.Normalise();
|
||||
forward.NormaliseSafe();
|
||||
CCarPathLink* pCurrentLink = &ThePaths.m_carPathLinks[pVehicle->AutoPilot.m_nCurrentPathNodeInfo];
|
||||
CCarPathLink* pNextLink = &ThePaths.m_carPathLinks[pVehicle->AutoPilot.m_nNextPathNodeInfo];
|
||||
CVector2D currentPathLinkForward(pCurrentLink->GetDirX() * pVehicle->AutoPilot.m_nCurrentDirection,
|
||||
@ -2410,7 +2410,7 @@ void CCarCtrl::SteerAICarWithPhysicsHeadingForTarget(CVehicle* pVehicle, CPhysic
|
||||
{
|
||||
*pHandbrake = false;
|
||||
CVector2D forward = pVehicle->GetForward();
|
||||
forward.Normalise();
|
||||
forward.NormaliseSafe();
|
||||
float angleToTarget = CGeneral::GetATanOfXY(targetX - pVehicle->GetPosition().x, targetY - pVehicle->GetPosition().y);
|
||||
float angleForward = CGeneral::GetATanOfXY(forward.x, forward.y);
|
||||
if (pVehicle->AutoPilot.m_nDrivingStyle == DRIVINGSTYLE_AVOID_CARS)
|
||||
@ -2497,7 +2497,7 @@ void CCarCtrl::SteerAICarWithPhysicsTryingToBlockTarget_Stop(CVehicle* pVehicle,
|
||||
void CCarCtrl::SteerAIBoatWithPhysicsHeadingForTarget(CBoat* pBoat, float targetX, float targetY, float* pSwerve, float* pAccel, float* pBrake)
|
||||
{
|
||||
CVector2D forward(pBoat->GetForward());
|
||||
forward.Normalise();
|
||||
forward.NormaliseSafe();
|
||||
CVector2D distanceToTarget = CVector2D(targetX, targetY) - pBoat->GetPosition();
|
||||
float angleToTarget = CGeneral::GetATanOfXY(distanceToTarget.x, distanceToTarget.y);
|
||||
float angleForward = CGeneral::GetATanOfXY(forward.x, forward.y);
|
||||
@ -2733,7 +2733,7 @@ bool CCarCtrl::GenerateOneEmergencyServicesCar(uint32 mi, CVector vecPos)
|
||||
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
|
||||
pVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
|
||||
CVector2D direction = vecPos - spawnPos;
|
||||
direction.Normalise();
|
||||
direction.NormaliseSafe();
|
||||
pVehicle->GetForward() = CVector(direction.x, direction.y, 0.0f);
|
||||
pVehicle->GetRight() = CVector(direction.y, -direction.x, 0.0f);
|
||||
pVehicle->GetUp() = CVector(0.0f, 0.0f, 1.0f);
|
||||
|
@ -757,12 +757,13 @@ DisplayGameDebugText()
|
||||
{
|
||||
static bool bDisplayPosn = false;
|
||||
static bool bDisplayRate = false;
|
||||
|
||||
#ifndef FINAL
|
||||
{
|
||||
SETTWEAKPATH("GameDebugText");
|
||||
TWEAKBOOL(bDisplayPosn);
|
||||
TWEAKBOOL(bDisplayRate);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
char str[200];
|
||||
@ -1111,6 +1112,7 @@ Idle(void *arg)
|
||||
#endif
|
||||
|
||||
#ifdef FIX_BUGS
|
||||
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); // TODO: temp? this fixes OpenGL render but there should be a better place for this
|
||||
// This has to be done BEFORE RwCameraBeginUpdate
|
||||
RwCameraSetFarClipPlane(Scene.camera, CTimeCycle::GetFarClip());
|
||||
RwCameraSetFogDistance(Scene.camera, CTimeCycle::GetFogStart());
|
||||
|
552
src/math/Matrix.cpp
Normal file
552
src/math/Matrix.cpp
Normal file
@ -0,0 +1,552 @@
|
||||
#include "common.h"
|
||||
|
||||
CMatrix::CMatrix(void)
|
||||
{
|
||||
m_attachment = nil;
|
||||
m_hasRwMatrix = false;
|
||||
}
|
||||
|
||||
CMatrix::CMatrix(CMatrix const &m)
|
||||
{
|
||||
m_attachment = nil;
|
||||
m_hasRwMatrix = false;
|
||||
*this = m;
|
||||
}
|
||||
|
||||
CMatrix::CMatrix(RwMatrix *matrix, bool owner)
|
||||
{
|
||||
m_attachment = nil;
|
||||
Attach(matrix, owner);
|
||||
}
|
||||
|
||||
CMatrix::~CMatrix(void)
|
||||
{
|
||||
if (m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Attach(RwMatrix *matrix, bool owner)
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
if (m_attachment && m_hasRwMatrix)
|
||||
#else
|
||||
if (m_hasRwMatrix && m_attachment)
|
||||
#endif
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = matrix;
|
||||
m_hasRwMatrix = owner;
|
||||
Update();
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::AttachRW(RwMatrix *matrix, bool owner)
|
||||
{
|
||||
if (m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = matrix;
|
||||
m_hasRwMatrix = owner;
|
||||
UpdateRW();
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Detach(void)
|
||||
{
|
||||
if (m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = nil;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Update(void)
|
||||
{
|
||||
m_matrix = *m_attachment;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::UpdateRW(void)
|
||||
{
|
||||
if (m_attachment) {
|
||||
*m_attachment = m_matrix;
|
||||
RwMatrixUpdate(m_attachment);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::operator=(CMatrix const &rhs)
|
||||
{
|
||||
m_matrix = rhs.m_matrix;
|
||||
if (m_attachment)
|
||||
UpdateRW();
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::CopyOnlyMatrix(CMatrix *other)
|
||||
{
|
||||
m_matrix = other->m_matrix;
|
||||
}
|
||||
|
||||
CMatrix &
|
||||
CMatrix::operator+=(CMatrix const &rhs)
|
||||
{
|
||||
m_matrix.right.x += rhs.m_matrix.right.x;
|
||||
m_matrix.up.x += rhs.m_matrix.up.x;
|
||||
m_matrix.at.x += rhs.m_matrix.at.x;
|
||||
m_matrix.right.y += rhs.m_matrix.right.y;
|
||||
m_matrix.up.y += rhs.m_matrix.up.y;
|
||||
m_matrix.at.y += rhs.m_matrix.at.y;
|
||||
m_matrix.right.z += rhs.m_matrix.right.z;
|
||||
m_matrix.up.z += rhs.m_matrix.up.z;
|
||||
m_matrix.at.z += rhs.m_matrix.at.z;
|
||||
m_matrix.pos.x += rhs.m_matrix.pos.x;
|
||||
m_matrix.pos.y += rhs.m_matrix.pos.y;
|
||||
m_matrix.pos.z += rhs.m_matrix.pos.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetUnity(void)
|
||||
{
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::ResetOrientation(void)
|
||||
{
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetScale(float s)
|
||||
{
|
||||
m_matrix.right.x = s;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = s;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = s;
|
||||
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetTranslate(float x, float y, float z)
|
||||
{
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
|
||||
m_matrix.pos.x = x;
|
||||
m_matrix.pos.y = y;
|
||||
m_matrix.pos.z = z;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotateXOnly(float angle)
|
||||
{
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = c;
|
||||
m_matrix.up.z = s;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = -s;
|
||||
m_matrix.at.z = c;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotateYOnly(float angle)
|
||||
{
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = c;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = -s;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = s;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = c;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotateZOnly(float angle)
|
||||
{
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = c;
|
||||
m_matrix.right.y = s;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = -s;
|
||||
m_matrix.up.y = c;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotateX(float angle)
|
||||
{
|
||||
SetRotateXOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CMatrix::SetRotateY(float angle)
|
||||
{
|
||||
SetRotateYOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotateZ(float angle)
|
||||
{
|
||||
SetRotateZOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotate(float xAngle, float yAngle, float zAngle)
|
||||
{
|
||||
float cX = Cos(xAngle);
|
||||
float sX = Sin(xAngle);
|
||||
float cY = Cos(yAngle);
|
||||
float sY = Sin(yAngle);
|
||||
float cZ = Cos(zAngle);
|
||||
float sZ = Sin(zAngle);
|
||||
|
||||
m_matrix.right.x = cZ * cY - (sZ * sX) * sY;
|
||||
m_matrix.right.y = (cZ * sX) * sY + sZ * cY;
|
||||
m_matrix.right.z = -cX * sY;
|
||||
|
||||
m_matrix.up.x = -sZ * cX;
|
||||
m_matrix.up.y = cZ * cX;
|
||||
m_matrix.up.z = sX;
|
||||
|
||||
m_matrix.at.x = (sZ * sX) * cY + cZ * sY;
|
||||
m_matrix.at.y = sZ * sY - (cZ * sX) * cY;
|
||||
m_matrix.at.z = cX * cY;
|
||||
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateX(float x)
|
||||
{
|
||||
float c = Cos(x);
|
||||
float s = Sin(x);
|
||||
|
||||
float ry = m_matrix.right.y;
|
||||
float rz = m_matrix.right.z;
|
||||
float uy = m_matrix.up.y;
|
||||
float uz = m_matrix.up.z;
|
||||
float ay = m_matrix.at.y;
|
||||
float az = m_matrix.at.z;
|
||||
float py = m_matrix.pos.y;
|
||||
float pz = m_matrix.pos.z;
|
||||
|
||||
m_matrix.right.y = c * ry - s * rz;
|
||||
m_matrix.right.z = c * rz + s * ry;
|
||||
m_matrix.up.y = c * uy - s * uz;
|
||||
m_matrix.up.z = c * uz + s * uy;
|
||||
m_matrix.at.y = c * ay - s * az;
|
||||
m_matrix.at.z = c * az + s * ay;
|
||||
m_matrix.pos.y = c * py - s * pz;
|
||||
m_matrix.pos.z = c * pz + s * py;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateY(float y)
|
||||
{
|
||||
float c = Cos(y);
|
||||
float s = Sin(y);
|
||||
|
||||
float rx = m_matrix.right.x;
|
||||
float rz = m_matrix.right.z;
|
||||
float ux = m_matrix.up.x;
|
||||
float uz = m_matrix.up.z;
|
||||
float ax = m_matrix.at.x;
|
||||
float az = m_matrix.at.z;
|
||||
float px = m_matrix.pos.x;
|
||||
float pz = m_matrix.pos.z;
|
||||
|
||||
m_matrix.right.x = c * rx + s * rz;
|
||||
m_matrix.right.z = c * rz - s * rx;
|
||||
m_matrix.up.x = c * ux + s * uz;
|
||||
m_matrix.up.z = c * uz - s * ux;
|
||||
m_matrix.at.x = c * ax + s * az;
|
||||
m_matrix.at.z = c * az - s * ax;
|
||||
m_matrix.pos.x = c * px + s * pz;
|
||||
m_matrix.pos.z = c * pz - s * px;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateZ(float z)
|
||||
{
|
||||
float c = Cos(z);
|
||||
float s = Sin(z);
|
||||
|
||||
float ry = m_matrix.right.y;
|
||||
float rx = m_matrix.right.x;
|
||||
float uy = m_matrix.up.y;
|
||||
float ux = m_matrix.up.x;
|
||||
float ay = m_matrix.at.y;
|
||||
float ax = m_matrix.at.x;
|
||||
float py = m_matrix.pos.y;
|
||||
float px = m_matrix.pos.x;
|
||||
|
||||
m_matrix.right.x = c * rx - s * ry;
|
||||
m_matrix.right.y = c * ry + s * rx;
|
||||
m_matrix.up.x = c * ux - s * uy;
|
||||
m_matrix.up.y = c * uy + s * ux;
|
||||
m_matrix.at.x = c * ax - s * ay;
|
||||
m_matrix.at.y = c * ay + s * ax;
|
||||
m_matrix.pos.x = c * px - s * py;
|
||||
m_matrix.pos.y = c * py + s * px;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Rotate(float x, float y, float z)
|
||||
{
|
||||
float cX = Cos(x);
|
||||
float sX = Sin(x);
|
||||
float cY = Cos(y);
|
||||
float sY = Sin(y);
|
||||
float cZ = Cos(z);
|
||||
float sZ = Sin(z);
|
||||
|
||||
float rx = m_matrix.right.x;
|
||||
float ry = m_matrix.right.y;
|
||||
float rz = m_matrix.right.z;
|
||||
float ux = m_matrix.up.x;
|
||||
float uy = m_matrix.up.y;
|
||||
float uz = m_matrix.up.z;
|
||||
float ax = m_matrix.at.x;
|
||||
float ay = m_matrix.at.y;
|
||||
float az = m_matrix.at.z;
|
||||
float px = m_matrix.pos.x;
|
||||
float py = m_matrix.pos.y;
|
||||
float pz = m_matrix.pos.z;
|
||||
|
||||
float x1 = cZ * cY - (sZ * sX) * sY;
|
||||
float x2 = (cZ * sX) * sY + sZ * cY;
|
||||
float x3 = -cX * sY;
|
||||
float y1 = -sZ * cX;
|
||||
float y2 = cZ * cX;
|
||||
float y3 = sX;
|
||||
float z1 = (sZ * sX) * cY + cZ * sY;
|
||||
float z2 = sZ * sY - (cZ * sX) * cY;
|
||||
float z3 = cX * cY;
|
||||
|
||||
m_matrix.right.x = x1 * rx + y1 * ry + z1 * rz;
|
||||
m_matrix.right.y = x2 * rx + y2 * ry + z2 * rz;
|
||||
m_matrix.right.z = x3 * rx + y3 * ry + z3 * rz;
|
||||
m_matrix.up.x = x1 * ux + y1 * uy + z1 * uz;
|
||||
m_matrix.up.y = x2 * ux + y2 * uy + z2 * uz;
|
||||
m_matrix.up.z = x3 * ux + y3 * uy + z3 * uz;
|
||||
m_matrix.at.x = x1 * ax + y1 * ay + z1 * az;
|
||||
m_matrix.at.y = x2 * ax + y2 * ay + z2 * az;
|
||||
m_matrix.at.z = x3 * ax + y3 * ay + z3 * az;
|
||||
m_matrix.pos.x = x1 * px + y1 * py + z1 * pz;
|
||||
m_matrix.pos.y = x2 * px + y2 * py + z2 * pz;
|
||||
m_matrix.pos.z = x3 * px + y3 * py + z3 * pz;
|
||||
}
|
||||
|
||||
CMatrix &
|
||||
CMatrix::operator*=(CMatrix const &rhs)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
*this = *this * rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Reorthogonalise(void)
|
||||
{
|
||||
CVector &r = GetRight();
|
||||
CVector &f = GetForward();
|
||||
CVector &u = GetUp();
|
||||
u = CrossProduct(r, f);
|
||||
u.Normalise();
|
||||
r = CrossProduct(f, u);
|
||||
r.Normalise();
|
||||
f = CrossProduct(u, r);
|
||||
}
|
||||
|
||||
CMatrix
|
||||
operator*(const CMatrix &m1, const CMatrix &m2)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
CMatrix out;
|
||||
RwMatrix *dst = &out.m_matrix;
|
||||
const RwMatrix *src1 = &m1.m_matrix;
|
||||
const RwMatrix *src2 = &m2.m_matrix;
|
||||
dst->right.x = src1->right.x * src2->right.x + src1->up.x * src2->right.y + src1->at.x * src2->right.z;
|
||||
dst->right.y = src1->right.y * src2->right.x + src1->up.y * src2->right.y + src1->at.y * src2->right.z;
|
||||
dst->right.z = src1->right.z * src2->right.x + src1->up.z * src2->right.y + src1->at.z * src2->right.z;
|
||||
dst->up.x = src1->right.x * src2->up.x + src1->up.x * src2->up.y + src1->at.x * src2->up.z;
|
||||
dst->up.y = src1->right.y * src2->up.x + src1->up.y * src2->up.y + src1->at.y * src2->up.z;
|
||||
dst->up.z = src1->right.z * src2->up.x + src1->up.z * src2->up.y + src1->at.z * src2->up.z;
|
||||
dst->at.x = src1->right.x * src2->at.x + src1->up.x * src2->at.y + src1->at.x * src2->at.z;
|
||||
dst->at.y = src1->right.y * src2->at.x + src1->up.y * src2->at.y + src1->at.y * src2->at.z;
|
||||
dst->at.z = src1->right.z * src2->at.x + src1->up.z * src2->at.y + src1->at.z * src2->at.z;
|
||||
dst->pos.x = src1->right.x * src2->pos.x + src1->up.x * src2->pos.y + src1->at.x * src2->pos.z + src1->pos.x;
|
||||
dst->pos.y = src1->right.y * src2->pos.x + src1->up.y * src2->pos.y + src1->at.y * src2->pos.z + src1->pos.y;
|
||||
dst->pos.z = src1->right.z * src2->pos.x + src1->up.z * src2->pos.y + src1->at.z * src2->pos.z + src1->pos.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
CMatrix &
|
||||
Invert(const CMatrix &src, CMatrix &dst)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
// GTA handles this as a raw 4x4 orthonormal matrix
|
||||
// and trashes the RW flags, let's not do that
|
||||
float (*scr_fm)[4] = (float (*)[4])&src.m_matrix;
|
||||
float (*dst_fm)[4] = (float (*)[4])&dst.m_matrix;
|
||||
|
||||
dst_fm[3][0] = dst_fm[3][1] = dst_fm[3][2] = 0.0f;
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[3][3] = scr_fm[3][3];
|
||||
#endif
|
||||
|
||||
dst_fm[0][0] = scr_fm[0][0];
|
||||
dst_fm[0][1] = scr_fm[1][0];
|
||||
dst_fm[0][2] = scr_fm[2][0];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[0][3] = scr_fm[3][0];
|
||||
#endif
|
||||
dst_fm[1][0] = scr_fm[0][1];
|
||||
dst_fm[1][1] = scr_fm[1][1];
|
||||
dst_fm[1][2] = scr_fm[2][1];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[1][3] = scr_fm[3][1];
|
||||
#endif
|
||||
dst_fm[2][0] = scr_fm[0][2];
|
||||
dst_fm[2][1] = scr_fm[1][2];
|
||||
dst_fm[2][2] = scr_fm[2][2];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[2][3] = scr_fm[3][2];
|
||||
#endif
|
||||
|
||||
dst_fm[3][0] += dst_fm[0][0] * scr_fm[3][0];
|
||||
dst_fm[3][1] += dst_fm[0][1] * scr_fm[3][0];
|
||||
dst_fm[3][2] += dst_fm[0][2] * scr_fm[3][0];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[3][3] += dst_fm[0][3] * scr_fm[3][0];
|
||||
#endif
|
||||
|
||||
dst_fm[3][0] += dst_fm[1][0] * scr_fm[3][1];
|
||||
dst_fm[3][1] += dst_fm[1][1] * scr_fm[3][1];
|
||||
dst_fm[3][2] += dst_fm[1][2] * scr_fm[3][1];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[3][3] += dst_fm[1][3] * scr_fm[3][1];
|
||||
#endif
|
||||
|
||||
dst_fm[3][0] += dst_fm[2][0] * scr_fm[3][2];
|
||||
dst_fm[3][1] += dst_fm[2][1] * scr_fm[3][2];
|
||||
dst_fm[3][2] += dst_fm[2][2] * scr_fm[3][2];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[3][3] += dst_fm[2][3] * scr_fm[3][2];
|
||||
#endif
|
||||
|
||||
dst_fm[3][0] = -dst_fm[3][0];
|
||||
dst_fm[3][1] = -dst_fm[3][1];
|
||||
dst_fm[3][2] = -dst_fm[3][2];
|
||||
#ifndef FIX_BUGS
|
||||
dst_fm[3][3] = scr_fm[3][3] - dst_fm[3][3];
|
||||
#endif
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
CMatrix
|
||||
Invert(const CMatrix &matrix)
|
||||
{
|
||||
CMatrix inv;
|
||||
return Invert(matrix, inv);
|
||||
}
|
||||
|
||||
void
|
||||
CCompressedMatrixNotAligned::CompressFromFullMatrix(CMatrix &other)
|
||||
{
|
||||
m_rightX = 127.0f * other.GetRight().x;
|
||||
m_rightY = 127.0f * other.GetRight().y;
|
||||
m_rightZ = 127.0f * other.GetRight().z;
|
||||
m_upX = 127.0f * other.GetForward().x;
|
||||
m_upY = 127.0f * other.GetForward().y;
|
||||
m_upZ = 127.0f * other.GetForward().z;
|
||||
m_vecPos = other.GetPosition();
|
||||
}
|
||||
|
||||
void
|
||||
CCompressedMatrixNotAligned::DecompressIntoFullMatrix(CMatrix &other)
|
||||
{
|
||||
other.GetRight().x = m_rightX / 127.0f;
|
||||
other.GetRight().y = m_rightY / 127.0f;
|
||||
other.GetRight().z = m_rightZ / 127.0f;
|
||||
other.GetForward().x = m_upX / 127.0f;
|
||||
other.GetForward().y = m_upY / 127.0f;
|
||||
other.GetForward().z = m_upZ / 127.0f;
|
||||
other.GetUp() = CrossProduct(other.GetRight(), other.GetForward());
|
||||
other.GetPosition() = m_vecPos;
|
||||
other.Reorthogonalise();
|
||||
}
|
@ -7,104 +7,30 @@ public:
|
||||
RwMatrix *m_attachment;
|
||||
bool m_hasRwMatrix; // are we the owner?
|
||||
|
||||
CMatrix(void){
|
||||
m_attachment = nil;
|
||||
m_hasRwMatrix = false;
|
||||
}
|
||||
CMatrix(CMatrix const &m){
|
||||
m_attachment = nil;
|
||||
m_hasRwMatrix = false;
|
||||
*this = m;
|
||||
}
|
||||
CMatrix(RwMatrix *matrix, bool owner = false){
|
||||
m_attachment = nil;
|
||||
Attach(matrix, owner);
|
||||
}
|
||||
CMatrix(void);
|
||||
CMatrix(CMatrix const &m);
|
||||
CMatrix(RwMatrix *matrix, bool owner = false);
|
||||
CMatrix(float scale){
|
||||
m_attachment = nil;
|
||||
m_hasRwMatrix = false;
|
||||
SetScale(scale);
|
||||
}
|
||||
~CMatrix(void){
|
||||
if(m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
}
|
||||
void Attach(RwMatrix *matrix, bool owner = false){
|
||||
#ifdef FIX_BUGS
|
||||
if(m_attachment && m_hasRwMatrix)
|
||||
#else
|
||||
if(m_hasRwMatrix && m_attachment)
|
||||
#endif
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = matrix;
|
||||
m_hasRwMatrix = owner;
|
||||
Update();
|
||||
}
|
||||
void AttachRW(RwMatrix *matrix, bool owner = false){
|
||||
if(m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = matrix;
|
||||
m_hasRwMatrix = owner;
|
||||
UpdateRW();
|
||||
}
|
||||
void Detach(void){
|
||||
if(m_hasRwMatrix && m_attachment)
|
||||
RwMatrixDestroy(m_attachment);
|
||||
m_attachment = nil;
|
||||
}
|
||||
void Update(void){
|
||||
m_matrix = *m_attachment;
|
||||
}
|
||||
void UpdateRW(void){
|
||||
if(m_attachment){
|
||||
*m_attachment = m_matrix;
|
||||
RwMatrixUpdate(m_attachment);
|
||||
}
|
||||
}
|
||||
void operator=(CMatrix const &rhs){
|
||||
m_matrix = rhs.m_matrix;
|
||||
if(m_attachment)
|
||||
UpdateRW();
|
||||
}
|
||||
CMatrix& operator+=(CMatrix const &rhs){
|
||||
m_matrix.right.x += rhs.m_matrix.right.x;
|
||||
m_matrix.up.x += rhs.m_matrix.up.x;
|
||||
m_matrix.at.x += rhs.m_matrix.at.x;
|
||||
m_matrix.right.y += rhs.m_matrix.right.y;
|
||||
m_matrix.up.y += rhs.m_matrix.up.y;
|
||||
m_matrix.at.y += rhs.m_matrix.at.y;
|
||||
m_matrix.right.z += rhs.m_matrix.right.z;
|
||||
m_matrix.up.z += rhs.m_matrix.up.z;
|
||||
m_matrix.at.z += rhs.m_matrix.at.z;
|
||||
m_matrix.pos.x += rhs.m_matrix.pos.x;
|
||||
m_matrix.pos.y += rhs.m_matrix.pos.y;
|
||||
m_matrix.pos.z += rhs.m_matrix.pos.z;
|
||||
return *this;
|
||||
}
|
||||
CMatrix& operator*=(CMatrix const &rhs);
|
||||
~CMatrix(void);
|
||||
void Attach(RwMatrix *matrix, bool owner = false);
|
||||
void AttachRW(RwMatrix *matrix, bool owner = false);
|
||||
void Detach(void);
|
||||
void Update(void);
|
||||
void UpdateRW(void);
|
||||
void operator=(CMatrix const &rhs);
|
||||
CMatrix &operator+=(CMatrix const &rhs);
|
||||
CMatrix &operator*=(CMatrix const &rhs);
|
||||
|
||||
CVector &GetPosition(void){ return *(CVector*)&m_matrix.pos; }
|
||||
CVector &GetRight(void) { return *(CVector*)&m_matrix.right; }
|
||||
CVector &GetForward(void) { return *(CVector*)&m_matrix.up; }
|
||||
CVector &GetUp(void) { return *(CVector*)&m_matrix.at; }
|
||||
|
||||
void SetTranslate(float x, float y, float z){
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
|
||||
m_matrix.pos.x = x;
|
||||
m_matrix.pos.y = y;
|
||||
m_matrix.pos.z = z;
|
||||
}
|
||||
void SetTranslate(float x, float y, float z);
|
||||
void SetTranslate(const CVector &trans){ SetTranslate(trans.x, trans.y, trans.z); }
|
||||
void Translate(float x, float y, float z){
|
||||
m_matrix.pos.x += x;
|
||||
@ -113,23 +39,7 @@ public:
|
||||
}
|
||||
void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); }
|
||||
|
||||
void SetScale(float s){
|
||||
m_matrix.right.x = s;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = s;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = s;
|
||||
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
void SetScale(float s);
|
||||
void Scale(float scale)
|
||||
{
|
||||
float *pFloatMatrix = (float*)&m_matrix;
|
||||
@ -143,66 +53,9 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void SetRotateXOnly(float angle){
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = c;
|
||||
m_matrix.up.z = s;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = -s;
|
||||
m_matrix.at.z = c;
|
||||
}
|
||||
void SetRotateX(float angle){
|
||||
SetRotateXOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
void SetRotateYOnly(float angle){
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = c;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = -s;
|
||||
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = s;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = c;
|
||||
}
|
||||
void SetRotateY(float angle){
|
||||
SetRotateYOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
void SetRotateZOnly(float angle){
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
|
||||
m_matrix.right.x = c;
|
||||
m_matrix.right.y = s;
|
||||
m_matrix.right.z = 0.0f;
|
||||
|
||||
m_matrix.up.x = -s;
|
||||
m_matrix.up.y = c;
|
||||
m_matrix.up.z = 0.0f;
|
||||
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
}
|
||||
void SetRotateXOnly(float angle);
|
||||
void SetRotateYOnly(float angle);
|
||||
void SetRotateZOnly(float angle);
|
||||
void SetRotateZOnlyScaled(float angle, float scale) {
|
||||
float c = Cos(angle);
|
||||
float s = Sin(angle);
|
||||
@ -219,12 +72,9 @@ public:
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = scale;
|
||||
}
|
||||
void SetRotateZ(float angle){
|
||||
SetRotateZOnly(angle);
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
void SetRotateX(float angle);
|
||||
void SetRotateY(float angle);
|
||||
void SetRotateZ(float angle);
|
||||
void SetRotate(float xAngle, float yAngle, float zAngle);
|
||||
void Rotate(float x, float y, float z);
|
||||
void RotateX(float x);
|
||||
@ -232,34 +82,9 @@ public:
|
||||
void RotateZ(float z);
|
||||
|
||||
void Reorthogonalise(void);
|
||||
void CopyOnlyMatrix(CMatrix *other){
|
||||
m_matrix = other->m_matrix;
|
||||
}
|
||||
void SetUnity(void) {
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
void ResetOrientation(void) {
|
||||
m_matrix.right.x = 1.0f;
|
||||
m_matrix.right.y = 0.0f;
|
||||
m_matrix.right.z = 0.0f;
|
||||
m_matrix.up.x = 0.0f;
|
||||
m_matrix.up.y = 1.0f;
|
||||
m_matrix.up.z = 0.0f;
|
||||
m_matrix.at.x = 0.0f;
|
||||
m_matrix.at.y = 0.0f;
|
||||
m_matrix.at.z = 1.0f;
|
||||
}
|
||||
void CopyOnlyMatrix(CMatrix *other);
|
||||
void SetUnity(void);
|
||||
void ResetOrientation(void);
|
||||
void SetTranslateOnly(float x, float y, float z) {
|
||||
m_matrix.pos.x = x;
|
||||
m_matrix.pos.y = y;
|
||||
@ -268,11 +93,12 @@ public:
|
||||
void SetTranslateOnly(const CVector& pos) {
|
||||
SetTranslateOnly(pos.x, pos.y, pos.z);
|
||||
}
|
||||
void CheckIntegrity(){}
|
||||
};
|
||||
|
||||
|
||||
CMatrix &Invert(const CMatrix &src, CMatrix &dst);
|
||||
CVector operator*(const CMatrix &mat, const CVector &vec);
|
||||
CMatrix Invert(const CMatrix &matrix);
|
||||
CMatrix operator*(const CMatrix &m1, const CMatrix &m2);
|
||||
inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec)
|
||||
{
|
||||
@ -283,15 +109,6 @@ inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec)
|
||||
mat.m_matrix.at.x * v.x + mat.m_matrix.at.y * v.y + mat.m_matrix.at.z * v.z);
|
||||
}
|
||||
|
||||
const CVector Multiply3x3(const CMatrix &mat, const CVector &vec);
|
||||
const CVector Multiply3x3(const CVector &vec, const CMatrix &mat);
|
||||
|
||||
inline CMatrix
|
||||
Invert(const CMatrix &matrix)
|
||||
{
|
||||
CMatrix inv;
|
||||
return Invert(matrix, inv);
|
||||
}
|
||||
|
||||
|
||||
class CCompressedMatrixNotAligned
|
||||
@ -304,28 +121,8 @@ class CCompressedMatrixNotAligned
|
||||
int8 m_upY;
|
||||
int8 m_upZ;
|
||||
public:
|
||||
void CompressFromFullMatrix(CMatrix &other)
|
||||
{
|
||||
m_rightX = 127.0f * other.GetRight().x;
|
||||
m_rightY = 127.0f * other.GetRight().y;
|
||||
m_rightZ = 127.0f * other.GetRight().z;
|
||||
m_upX = 127.0f * other.GetForward().x;
|
||||
m_upY = 127.0f * other.GetForward().y;
|
||||
m_upZ = 127.0f * other.GetForward().z;
|
||||
m_vecPos = other.GetPosition();
|
||||
}
|
||||
void DecompressIntoFullMatrix(CMatrix &other)
|
||||
{
|
||||
other.GetRight().x = m_rightX / 127.0f;
|
||||
other.GetRight().y = m_rightY / 127.0f;
|
||||
other.GetRight().z = m_rightZ / 127.0f;
|
||||
other.GetForward().x = m_upX / 127.0f;
|
||||
other.GetForward().y = m_upY / 127.0f;
|
||||
other.GetForward().z = m_upZ / 127.0f;
|
||||
other.GetUp() = CrossProduct(other.GetRight(), other.GetForward());
|
||||
other.GetPosition() = m_vecPos;
|
||||
other.Reorthogonalise();
|
||||
}
|
||||
void CompressFromFullMatrix(CMatrix &other);
|
||||
void DecompressIntoFullMatrix(CMatrix &other);
|
||||
};
|
||||
|
||||
class CCompressedMatrix : public CCompressedMatrixNotAligned
|
||||
|
177
src/math/Quaternion.cpp
Normal file
177
src/math/Quaternion.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
#include "common.h"
|
||||
#include "Quaternion.h"
|
||||
|
||||
void
|
||||
CQuaternion::Normalise(void)
|
||||
{
|
||||
float sq = MagnitudeSqr();
|
||||
if (sq == 0.0f)
|
||||
w = 1.0f;
|
||||
else {
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
z *= invsqrt;
|
||||
w *= invsqrt;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, float invSin, float t)
|
||||
{
|
||||
if (theta == 0.0f)
|
||||
*this = q2;
|
||||
else {
|
||||
float w1, w2;
|
||||
if (theta > PI / 2) {
|
||||
theta = PI - theta;
|
||||
w1 = Sin((1.0f - t) * theta) * invSin;
|
||||
w2 = -Sin(t * theta) * invSin;
|
||||
} else {
|
||||
w1 = Sin((1.0f - t) * theta) * invSin;
|
||||
w2 = Sin(t * theta) * invSin;
|
||||
}
|
||||
// TODO: VU0 code
|
||||
*this = w1 * q1 + w2 * q2;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Multiply(const CQuaternion &q1, const CQuaternion &q2)
|
||||
{
|
||||
x = (q2.z * q1.y) - (q1.z * q2.y) + (q1.x * q2.w) + (q2.x * q1.w);
|
||||
y = (q2.x * q1.z) - (q1.x * q2.z) + (q1.y * q2.w) + (q2.y * q1.w);
|
||||
z = (q2.y * q1.x) - (q1.y * q2.x) + (q1.z * q2.w) + (q2.z * q1.w);
|
||||
w = (q2.w * q1.w) - (q2.x * q1.x) - (q2.y * q1.y) - (q2.z * q1.z);
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Get(RwV3d *axis, float *angle)
|
||||
{
|
||||
*angle = Acos(w);
|
||||
float s = Sin(*angle);
|
||||
|
||||
axis->x = x * (1.0f / s);
|
||||
axis->y = y * (1.0f / s);
|
||||
axis->z = z * (1.0f / s);
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Set(RwV3d *axis, float angle)
|
||||
{
|
||||
float halfCos = Cos(angle * 0.5f);
|
||||
float halfSin = Sin(angle * 0.5f);
|
||||
x = axis->x * halfSin;
|
||||
y = axis->y * halfSin;
|
||||
z = axis->z * halfSin;
|
||||
w = halfCos;
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Get(RwMatrix *matrix)
|
||||
{
|
||||
float x2 = x + x;
|
||||
float y2 = y + y;
|
||||
float z2 = z + z;
|
||||
|
||||
float x_2x = x * x2;
|
||||
float x_2y = x * y2;
|
||||
float x_2z = x * z2;
|
||||
float y_2y = y * y2;
|
||||
float y_2z = y * z2;
|
||||
float z_2z = z * z2;
|
||||
float w_2x = w * x2;
|
||||
float w_2y = w * y2;
|
||||
float w_2z = w * z2;
|
||||
|
||||
matrix->right.x = 1.0f - (y_2y + z_2z);
|
||||
matrix->up.x = x_2y - w_2z;
|
||||
matrix->at.x = x_2z + w_2y;
|
||||
matrix->right.y = x_2y + w_2z;
|
||||
matrix->up.y = 1.0f - (x_2x + z_2z);
|
||||
matrix->at.y = y_2z - w_2x;
|
||||
matrix->right.z = x_2z - w_2y;
|
||||
matrix->up.z = y_2z + w_2x;
|
||||
matrix->at.z = 1.0f - (x_2x + y_2y);
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Set(const RwMatrix &matrix)
|
||||
{
|
||||
float f, s, m;
|
||||
|
||||
f = matrix.up.y + matrix.right.x + matrix.at.z;
|
||||
if (f >= 0.0f) {
|
||||
s = Sqrt(f + 1.0f);
|
||||
w = 0.5f * s;
|
||||
m = 0.5f / s;
|
||||
x = (matrix.up.z - matrix.at.y) * m;
|
||||
y = (matrix.at.x - matrix.right.z) * m;
|
||||
z = (matrix.right.y - matrix.up.x) * m;
|
||||
return;
|
||||
}
|
||||
|
||||
f = matrix.right.x - matrix.up.y - matrix.at.z;
|
||||
if (f >= 0.0f) {
|
||||
s = Sqrt(f + 1.0f);
|
||||
x = 0.5f * s;
|
||||
m = 0.5f / s;
|
||||
y = (matrix.up.x + matrix.right.y) * m;
|
||||
z = (matrix.at.x + matrix.right.z) * m;
|
||||
w = (matrix.up.z - matrix.at.y) * m;
|
||||
return;
|
||||
}
|
||||
|
||||
f = matrix.up.y - matrix.right.x - matrix.at.z;
|
||||
if (f >= 0.0f) {
|
||||
s = Sqrt(f + 1.0f);
|
||||
y = 0.5f * s;
|
||||
m = 0.5f / s;
|
||||
w = (matrix.at.x - matrix.right.z) * m;
|
||||
x = (matrix.up.x - matrix.right.y) * m;
|
||||
z = (matrix.at.y + matrix.up.z) * m;
|
||||
return;
|
||||
}
|
||||
|
||||
f = matrix.at.z - (matrix.up.y + matrix.right.x);
|
||||
s = Sqrt(f + 1.0f);
|
||||
z = 0.5f * s;
|
||||
m = 0.5f / s;
|
||||
w = (matrix.right.y - matrix.up.x) * m;
|
||||
x = (matrix.at.x + matrix.right.z) * m;
|
||||
y = (matrix.at.y + matrix.up.z) * m;
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Get(float *f1, float *f2, float *f3)
|
||||
{
|
||||
RwMatrix matrix;
|
||||
|
||||
Get(&matrix);
|
||||
*f3 = Atan2(matrix.right.y, matrix.up.y);
|
||||
if (*f3 < 0.0f)
|
||||
*f3 += TWOPI;
|
||||
float s = Sin(*f3);
|
||||
float c = Cos(*f3);
|
||||
*f1 = Atan2(-matrix.at.y, s * matrix.right.y + c * matrix.up.y);
|
||||
if (*f1 < 0.0f)
|
||||
*f1 += TWOPI;
|
||||
*f2 = Atan2(-(matrix.right.z * c - matrix.up.z * s), matrix.right.x * c - matrix.up.x * s);
|
||||
if (*f2 < 0.0f)
|
||||
*f2 += TWOPI;
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Set(float f1, float f2, float f3)
|
||||
{
|
||||
float c1 = Cos(f1 * 0.5f);
|
||||
float c2 = Cos(f2 * 0.5f);
|
||||
float c3 = Cos(f3 * 0.5f);
|
||||
float s1 = Sin(f1 * 0.5f);
|
||||
float s2 = Sin(f2 * 0.5f);
|
||||
float s3 = Sin(f3 * 0.5f);
|
||||
x = ((c2 * c1) * s3) - ((s2 * s1) * c3);
|
||||
y = ((s1 * c2) * c3) + ((s2 * c1) * s3);
|
||||
z = ((s2 * c1) * c3) - ((s1 * c2) * s3);
|
||||
w = ((c2 * c1) * c3) + ((s2 * s1) * s3);
|
||||
}
|
@ -10,18 +10,8 @@ public:
|
||||
|
||||
float Magnitude(void) const { return Sqrt(x*x + y*y + z*z + w*w); }
|
||||
float MagnitudeSqr(void) const { return x*x + y*y + z*z + w*w; }
|
||||
void Normalise(void) {
|
||||
float sq = MagnitudeSqr();
|
||||
if(sq == 0.0f)
|
||||
w = 1.0f;
|
||||
else{
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
z *= invsqrt;
|
||||
w *= invsqrt;
|
||||
}
|
||||
}
|
||||
void Normalise(void);
|
||||
void Multiply(const CQuaternion &q1, const CQuaternion &q2);
|
||||
|
||||
const CQuaternion &operator+=(CQuaternion const &right) {
|
||||
x += right.x;
|
||||
@ -60,8 +50,12 @@ public:
|
||||
}
|
||||
|
||||
void Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, float invSin, float t);
|
||||
void Get(RwV3d *axis, float *angle);
|
||||
void Set(RwV3d *axis, float angle);
|
||||
void Get(RwMatrix *matrix);
|
||||
void Set(const RwMatrix &matrix);
|
||||
void Set(float f1, float f2, float f3);
|
||||
void Get(float *f1, float *f2, float *f3);
|
||||
};
|
||||
|
||||
inline float
|
||||
|
17
src/math/Rect.cpp
Normal file
17
src/math/Rect.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "common.h"
|
||||
|
||||
CRect::CRect(void)
|
||||
{
|
||||
left = 1000000.0f;
|
||||
top = 1000000.0f;
|
||||
right = -1000000.0f;
|
||||
bottom = -1000000.0f;
|
||||
}
|
||||
|
||||
CRect::CRect(float l, float t, float r, float b)
|
||||
{
|
||||
left = l;
|
||||
top = t;
|
||||
right = r;
|
||||
bottom = b;
|
||||
}
|
@ -8,18 +8,8 @@ public:
|
||||
float right; // x max
|
||||
float top; // y min
|
||||
|
||||
CRect(void){
|
||||
left = 1000000.0f;
|
||||
top = 1000000.0f;
|
||||
right = -1000000.0f;
|
||||
bottom = -1000000.0f;
|
||||
}
|
||||
CRect(float l, float t, float r, float b){
|
||||
left = l;
|
||||
top = t;
|
||||
right = r;
|
||||
bottom = b;
|
||||
}
|
||||
CRect(void);
|
||||
CRect(float l, float t, float r, float b);
|
||||
void ContainPoint(CVector const &v){
|
||||
if(v.x < left) left = v.x;
|
||||
if(v.x > right) right = v.x;
|
||||
|
46
src/math/Vector.cpp
Normal file
46
src/math/Vector.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "common.h"
|
||||
|
||||
void
|
||||
CVector::Normalise(void)
|
||||
{
|
||||
float sq = MagnitudeSqr();
|
||||
if (sq > 0.0f) {
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
z *= invsqrt;
|
||||
} else
|
||||
x = 1.0f;
|
||||
}
|
||||
|
||||
CVector
|
||||
CrossProduct(const CVector &v1, const CVector &v2)
|
||||
{
|
||||
return CVector(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
|
||||
}
|
||||
|
||||
CVector
|
||||
Multiply3x3(const CMatrix &mat, const CVector &vec)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z,
|
||||
mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z,
|
||||
mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z);
|
||||
}
|
||||
|
||||
CVector
|
||||
Multiply3x3(const CVector &vec, const CMatrix &mat)
|
||||
{
|
||||
return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.right.y * vec.y + mat.m_matrix.right.z * vec.z,
|
||||
mat.m_matrix.up.x * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.up.z * vec.z,
|
||||
mat.m_matrix.at.x * vec.x + mat.m_matrix.at.y * vec.y + mat.m_matrix.at.z * vec.z);
|
||||
}
|
||||
|
||||
CVector
|
||||
operator*(const CMatrix &mat, const CVector &vec)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z + mat.m_matrix.pos.x,
|
||||
mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z + mat.m_matrix.pos.y,
|
||||
mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z + mat.m_matrix.pos.z);
|
||||
}
|
@ -24,24 +24,7 @@ public:
|
||||
float MagnitudeSqr(void) const { return x*x + y*y + z*z; }
|
||||
float Magnitude2D(void) const { return Sqrt(x*x + y*y); }
|
||||
float MagnitudeSqr2D(void) const { return x*x + y*y; }
|
||||
void Normalise(void) {
|
||||
float sq = MagnitudeSqr();
|
||||
if(sq > 0.0f){
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
z *= invsqrt;
|
||||
}else
|
||||
x = 1.0f;
|
||||
}
|
||||
|
||||
void Normalise(float norm) {
|
||||
float sq = MagnitudeSqr();
|
||||
float invsqrt = RecipSqrt(norm, sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
z *= invsqrt;
|
||||
}
|
||||
void Normalise(void);
|
||||
|
||||
void Normalise2D(void) {
|
||||
float sq = MagnitudeSqr2D();
|
||||
@ -124,17 +107,16 @@ DotProduct(const CVector &v1, const CVector &v2)
|
||||
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
|
||||
}
|
||||
|
||||
inline const CVector
|
||||
CrossProduct(const CVector &v1, const CVector &v2)
|
||||
{
|
||||
return CVector(
|
||||
v1.y*v2.z - v1.z*v2.y,
|
||||
v1.z*v2.x - v1.x*v2.z,
|
||||
v1.x*v2.y - v1.y*v2.x);
|
||||
}
|
||||
CVector CrossProduct(const CVector &v1, const CVector &v2);
|
||||
|
||||
inline float
|
||||
Distance(const CVector &v1, const CVector &v2)
|
||||
{
|
||||
return (v2 - v1).Magnitude();
|
||||
}
|
||||
|
||||
class CMatrix;
|
||||
|
||||
CVector Multiply3x3(const CMatrix &mat, const CVector &vec);
|
||||
CVector Multiply3x3(const CVector &vec, const CMatrix &mat);
|
||||
CVector operator*(const CMatrix &mat, const CVector &vec);
|
@ -11,7 +11,13 @@ public:
|
||||
float Magnitude(void) const { return Sqrt(x*x + y*y); }
|
||||
float MagnitudeSqr(void) const { return x*x + y*y; }
|
||||
|
||||
void Normalise(void);
|
||||
void Normalise(void) {
|
||||
float sq = MagnitudeSqr();
|
||||
// assert(sq != 0.0f); // just be safe here
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
}
|
||||
|
||||
void NormaliseSafe(void) {
|
||||
float sq = MagnitudeSqr();
|
||||
@ -20,7 +26,7 @@ public:
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
}else
|
||||
y = 1.0f;
|
||||
x = 1.0f;
|
||||
}
|
||||
|
||||
const CVector2D &operator+=(CVector2D const &right) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "common.h"
|
||||
|
||||
#include "Quaternion.h"
|
||||
#include "VuVector.h"
|
||||
|
||||
// TODO: move more stuff into here
|
||||
@ -117,235 +116,3 @@ void TransformPoints(CVuVector *out, int n, const CMatrix &mat, const CVuVector
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CVector2D::Normalise(void)
|
||||
{
|
||||
float sq = MagnitudeSqr();
|
||||
assert(sq != 0.0f); // just be safe here
|
||||
//if(sq > 0.0f){
|
||||
float invsqrt = RecipSqrt(sq);
|
||||
x *= invsqrt;
|
||||
y *= invsqrt;
|
||||
//}else
|
||||
// x = 1.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::SetRotate(float xAngle, float yAngle, float zAngle)
|
||||
{
|
||||
float cX = Cos(xAngle);
|
||||
float sX = Sin(xAngle);
|
||||
float cY = Cos(yAngle);
|
||||
float sY = Sin(yAngle);
|
||||
float cZ = Cos(zAngle);
|
||||
float sZ = Sin(zAngle);
|
||||
|
||||
m_matrix.right.x = cZ * cY - (sZ * sX) * sY;
|
||||
m_matrix.right.y = (cZ * sX) * sY + sZ * cY;
|
||||
m_matrix.right.z = -cX * sY;
|
||||
|
||||
m_matrix.up.x = -sZ * cX;
|
||||
m_matrix.up.y = cZ * cX;
|
||||
m_matrix.up.z = sX;
|
||||
|
||||
m_matrix.at.x = (sZ * sX) * cY + cZ * sY;
|
||||
m_matrix.at.y = sZ * sY - (cZ * sX) * cY;
|
||||
m_matrix.at.z = cX * cY;
|
||||
|
||||
m_matrix.pos.x = 0.0f;
|
||||
m_matrix.pos.y = 0.0f;
|
||||
m_matrix.pos.z = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Rotate(float x, float y, float z)
|
||||
{
|
||||
// TODO? do this directly without creating another matrix
|
||||
CMatrix rot;
|
||||
rot.SetRotate(x, y, z);
|
||||
*this = rot * *this;
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateX(float x)
|
||||
{
|
||||
Rotate(x, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateY(float y)
|
||||
{
|
||||
Rotate(0.0f, y, 0.0f);
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::RotateZ(float z)
|
||||
{
|
||||
Rotate(0.0f, 0.0f, z);
|
||||
}
|
||||
|
||||
void
|
||||
CMatrix::Reorthogonalise(void)
|
||||
{
|
||||
CVector &r = GetRight();
|
||||
CVector &f = GetForward();
|
||||
CVector &u = GetUp();
|
||||
u = CrossProduct(r, f);
|
||||
u.Normalise();
|
||||
r = CrossProduct(f, u);
|
||||
r.Normalise();
|
||||
f = CrossProduct(u, r);
|
||||
}
|
||||
|
||||
CMatrix&
|
||||
Invert(const CMatrix &src, CMatrix &dst)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
// GTA handles this as a raw 4x4 orthonormal matrix
|
||||
// and trashes the RW flags, let's not do that
|
||||
// actual copy of librw code:
|
||||
RwMatrix *d = &dst.m_matrix;
|
||||
const RwMatrix *s = &src.m_matrix;
|
||||
d->right.x = s->right.x;
|
||||
d->right.y = s->up.x;
|
||||
d->right.z = s->at.x;
|
||||
d->up.x = s->right.y;
|
||||
d->up.y = s->up.y;
|
||||
d->up.z = s->at.y;
|
||||
d->at.x = s->right.z;
|
||||
d->at.y = s->up.z;
|
||||
d->at.z = s->at.z;
|
||||
d->pos.x = -(s->pos.x*s->right.x +
|
||||
s->pos.y*s->right.y +
|
||||
s->pos.z*s->right.z);
|
||||
d->pos.y = -(s->pos.x*s->up.x +
|
||||
s->pos.y*s->up.y +
|
||||
s->pos.z*s->up.z);
|
||||
d->pos.z = -(s->pos.x*s->at.x +
|
||||
s->pos.y*s->at.y +
|
||||
s->pos.z*s->at.z);
|
||||
d->flags = rwMATRIXTYPEORTHONORMAL;
|
||||
return dst;
|
||||
}
|
||||
|
||||
CVector
|
||||
operator*(const CMatrix &mat, const CVector &vec)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
return CVector(
|
||||
mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z + mat.m_matrix.pos.x,
|
||||
mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z + mat.m_matrix.pos.y,
|
||||
mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z + mat.m_matrix.pos.z);
|
||||
}
|
||||
|
||||
CMatrix
|
||||
operator*(const CMatrix &m1, const CMatrix &m2)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
CMatrix out;
|
||||
RwMatrix *dst = &out.m_matrix;
|
||||
const RwMatrix *src1 = &m1.m_matrix;
|
||||
const RwMatrix *src2 = &m2.m_matrix;
|
||||
dst->right.x = src1->right.x*src2->right.x + src1->up.x*src2->right.y + src1->at.x*src2->right.z;
|
||||
dst->right.y = src1->right.y*src2->right.x + src1->up.y*src2->right.y + src1->at.y*src2->right.z;
|
||||
dst->right.z = src1->right.z*src2->right.x + src1->up.z*src2->right.y + src1->at.z*src2->right.z;
|
||||
dst->up.x = src1->right.x*src2->up.x + src1->up.x*src2->up.y + src1->at.x*src2->up.z;
|
||||
dst->up.y = src1->right.y*src2->up.x + src1->up.y*src2->up.y + src1->at.y*src2->up.z;
|
||||
dst->up.z = src1->right.z*src2->up.x + src1->up.z*src2->up.y + src1->at.z*src2->up.z;
|
||||
dst->at.x = src1->right.x*src2->at.x + src1->up.x*src2->at.y + src1->at.x*src2->at.z;
|
||||
dst->at.y = src1->right.y*src2->at.x + src1->up.y*src2->at.y + src1->at.y*src2->at.z;
|
||||
dst->at.z = src1->right.z*src2->at.x + src1->up.z*src2->at.y + src1->at.z*src2->at.z;
|
||||
dst->pos.x = src1->right.x*src2->pos.x + src1->up.x*src2->pos.y + src1->at.x*src2->pos.z + src1->pos.x;
|
||||
dst->pos.y = src1->right.y*src2->pos.x + src1->up.y*src2->pos.y + src1->at.y*src2->pos.z + src1->pos.y;
|
||||
dst->pos.z = src1->right.z*src2->pos.x + src1->up.z*src2->pos.y + src1->at.z*src2->pos.z + src1->pos.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
CMatrix&
|
||||
CMatrix::operator*=(CMatrix const &rhs)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
*this = *this * rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CVector
|
||||
Multiply3x3(const CMatrix &mat, const CVector &vec)
|
||||
{
|
||||
// TODO: VU0 code
|
||||
return CVector(
|
||||
mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z,
|
||||
mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z,
|
||||
mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z);
|
||||
}
|
||||
|
||||
const CVector
|
||||
Multiply3x3(const CVector &vec, const CMatrix &mat)
|
||||
{
|
||||
return CVector(
|
||||
mat.m_matrix.right.x * vec.x + mat.m_matrix.right.y * vec.y + mat.m_matrix.right.z * vec.z,
|
||||
mat.m_matrix.up.x * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.up.z * vec.z,
|
||||
mat.m_matrix.at.x * vec.x + mat.m_matrix.at.y * vec.y + mat.m_matrix.at.z * vec.z);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CQuaternion::Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, float invSin, float t)
|
||||
{
|
||||
if(theta == 0.0f)
|
||||
*this = q2;
|
||||
else{
|
||||
float w1, w2;
|
||||
if(theta > PI/2){
|
||||
theta = PI - theta;
|
||||
w1 = Sin((1.0f - t) * theta) * invSin;
|
||||
w2 = -Sin(t * theta) * invSin;
|
||||
}else{
|
||||
w1 = Sin((1.0f - t) * theta) * invSin;
|
||||
w2 = Sin(t * theta) * invSin;
|
||||
}
|
||||
// TODO: VU0 code
|
||||
*this = w1*q1 + w2*q2;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Set(RwV3d *axis, float angle)
|
||||
{
|
||||
float halfCos = Cos(angle*0.5f);
|
||||
float halfSin = Sin(angle*0.5f);
|
||||
x = axis->x*halfSin;
|
||||
y = axis->y*halfSin;
|
||||
z = axis->z*halfSin;
|
||||
w = halfCos;
|
||||
}
|
||||
|
||||
void
|
||||
CQuaternion::Get(RwMatrix *matrix)
|
||||
{
|
||||
float x2 = x+x;
|
||||
float y2 = y+y;
|
||||
float z2 = z+z;
|
||||
|
||||
float x_2x = x * x2;
|
||||
float x_2y = x * y2;
|
||||
float x_2z = x * z2;
|
||||
float y_2y = y * y2;
|
||||
float y_2z = y * z2;
|
||||
float z_2z = z * z2;
|
||||
float w_2x = w * x2;
|
||||
float w_2y = w * y2;
|
||||
float w_2z = w * z2;
|
||||
|
||||
matrix->right.x = 1.0f - (y_2y + z_2z);
|
||||
matrix->up.x = x_2y - w_2z;
|
||||
matrix->at.x = x_2z + w_2y;
|
||||
matrix->right.y = x_2y + w_2z;
|
||||
matrix->up.y = 1.0f - (x_2x + z_2z);
|
||||
matrix->at.y = y_2z - w_2x;
|
||||
matrix->right.z = x_2z - w_2y;
|
||||
matrix->up.z = y_2z + w_2x;
|
||||
matrix->at.z = 1.0f - (x_2x + y_2y);
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ CGlass::WindowRespondsToExplosion(CEntity *entity, CVector point)
|
||||
|
||||
if ( fDistToGlass < 10.0f )
|
||||
{
|
||||
distToGlass.Normalise(0.3f);
|
||||
distToGlass *= (0.3f / fDistToGlass); // normalise
|
||||
WindowRespondsToCollision(object, 10000.0f, distToGlass, object->GetPosition(), true);
|
||||
}
|
||||
else
|
||||
|
@ -222,10 +222,11 @@ CSkidmarks::RegisterOne(uintptr id, CVector pos, float fwdX, float fwdY, bool *i
|
||||
|
||||
aSkidmarks[i].m_pos[aSkidmarks[i].m_last] = pos;
|
||||
|
||||
CVector2D dist = aSkidmarks[i].m_pos[aSkidmarks[i].m_last] - aSkidmarks[i].m_pos[aSkidmarks[i].m_last-1];
|
||||
dist.NormaliseSafe();
|
||||
CVector2D right(aSkidmarks[i].m_pos[aSkidmarks[i].m_last].y - aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].y,
|
||||
aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].x - aSkidmarks[i].m_pos[aSkidmarks[i].m_last].x);
|
||||
|
||||
right.NormaliseSafe();
|
||||
fwd.NormaliseSafe();
|
||||
CVector2D right(dist.y, -dist.x);
|
||||
float turn = DotProduct2D(fwd, right);
|
||||
turn = Abs(turn) + 1.0f;
|
||||
aSkidmarks[i].m_side[aSkidmarks[i].m_last] = CVector(right.x, right.y, 0.0f) * turn * 0.125f;
|
||||
|
@ -140,8 +140,7 @@ void CWaterCannon::Render(void)
|
||||
if ( !bInit )
|
||||
{
|
||||
CVector cp = CrossProduct(m_avecPos[pointB] - m_avecPos[pointA], TheCamera.GetForward());
|
||||
cp.Normalise(0.05f);
|
||||
norm = cp;
|
||||
norm = cp * (0.05f / cp.Magnitude());
|
||||
bInit = true;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,15 @@
|
||||
#if defined RW_GL3 && !defined LIBRW_SDL2
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <shellapi.h>
|
||||
#include <windowsx.h>
|
||||
#include <basetsd.h>
|
||||
#include <regstr.h>
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#define WITHWINDOWS
|
||||
#include "common.h"
|
||||
|
||||
@ -1180,7 +1190,11 @@ void resizeCB(GLFWwindow* window, int width, int height) {
|
||||
* memory things don't work.
|
||||
*/
|
||||
/* redraw window */
|
||||
if (RwInitialised && (gGameState == GS_PLAYING_GAME || gGameState == GS_ANIMVIEWER))
|
||||
if (RwInitialised && (gGameState == GS_PLAYING_GAME
|
||||
#ifndef MASTER
|
||||
|| gGameState == GS_ANIMVIEWER
|
||||
#endif
|
||||
))
|
||||
{
|
||||
RsEventHandler((gGameState == GS_PLAYING_GAME ? rsIDLE : rsANIMVIEWER), (void*)TRUE);
|
||||
}
|
||||
@ -1610,6 +1624,72 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
case GS_INIT_LOGO_MPEG:
|
||||
{
|
||||
//if (!startupDeactivate)
|
||||
// PlayMovieInWindow(cmdShow, "movies\\Logo.mpg");
|
||||
gGameState = GS_LOGO_MPEG;
|
||||
TRACE("gGameState = GS_LOGO_MPEG;");
|
||||
break;
|
||||
}
|
||||
|
||||
case GS_LOGO_MPEG:
|
||||
{
|
||||
// CPad::UpdatePads();
|
||||
|
||||
// if (startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0)
|
||||
++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetLeftMouseJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetEnterJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetCharJustDown(' '))
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetAltJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetTabJustDown())
|
||||
// ++gGameState;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GS_INIT_INTRO_MPEG:
|
||||
{
|
||||
//#ifndef NO_MOVIES
|
||||
// CloseClip();
|
||||
// CoUninitialize();
|
||||
//#endif
|
||||
//
|
||||
// if (CMenuManager::OS_Language == LANG_FRENCH || CMenuManager::OS_Language == LANG_GERMAN)
|
||||
// PlayMovieInWindow(cmdShow, "movies\\GTAtitlesGER.mpg");
|
||||
// else
|
||||
// PlayMovieInWindow(cmdShow, "movies\\GTAtitles.mpg");
|
||||
|
||||
gGameState = GS_INTRO_MPEG;
|
||||
TRACE("gGameState = GS_INTRO_MPEG;");
|
||||
break;
|
||||
}
|
||||
|
||||
case GS_INTRO_MPEG:
|
||||
{
|
||||
// CPad::UpdatePads();
|
||||
//
|
||||
// if (startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0)
|
||||
++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetLeftMouseJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetEnterJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetCharJustDown(' '))
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetAltJustDown())
|
||||
// ++gGameState;
|
||||
// else if (CPad::GetPad(0)->GetTabJustDown())
|
||||
// ++gGameState;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GS_INIT_ONCE:
|
||||
{
|
||||
//CoUninitialize();
|
||||
@ -1818,8 +1898,10 @@ main(int argc, char *argv[])
|
||||
{
|
||||
if ( gGameState == GS_PLAYING_GAME )
|
||||
CGame::ShutDown();
|
||||
#ifndef MASTER
|
||||
else if ( gGameState == GS_ANIMVIEWER )
|
||||
CAnimViewer::Shutdown();
|
||||
#endif
|
||||
|
||||
CTimer::Stop();
|
||||
|
||||
@ -1843,8 +1925,10 @@ main(int argc, char *argv[])
|
||||
|
||||
if ( gGameState == GS_PLAYING_GAME )
|
||||
CGame::ShutDown();
|
||||
#ifndef MASTER
|
||||
else if ( gGameState == GS_ANIMVIEWER )
|
||||
CAnimViewer::Shutdown();
|
||||
#endif
|
||||
|
||||
DMAudio.Terminate();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user