Skip to content

Commit b6d2ce0

Browse files
committed
Merge pull request #8 from qaisjp/feature/fov-manipulation
Add set/getCameraFieldOfView with modes
2 parents a862f85 + b97a154 commit b6d2ce0

File tree

14 files changed

+150
-28
lines changed

14 files changed

+150
-28
lines changed

MTA10/core/CCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ void CCore::ApplyGameSettings ( void )
607607
CVARS_GET ( "classic_controls", bval ); pController->SetClassicControls ( bval );
608608
CVARS_GET ( "volumetric_shadows", bval ); m_pGame->GetSettings ()->SetVolumetricShadowsEnabled ( bval );
609609
CVARS_GET ( "aspect_ratio", iVal ); m_pGame->GetSettings ()->SetAspectRatio ( (eAspectRatio)iVal, CVARS_GET_VALUE < bool > ( "hud_match_aspect_ratio" ) );
610-
CVARS_GET ( "fov", iVal ); m_pGame->GetSettings ()->SetFieldOfView ( iVal );
610+
CVARS_GET ( "fov", iVal ); iVal = Clamp ( 70, iVal, 100 ); m_pGame->GetSettings ()->SetFieldOfView ( iVal );
611611
CVARS_GET ( "grass", bval ); m_pGame->GetSettings ()->SetGrassEnabled ( bval );
612612
CVARS_GET ( "heat_haze", bval ); m_pMultiplayer->SetHeatHazeEnabled ( bval );
613613
CVARS_GET ( "fast_clothes_loading", iVal ); m_pMultiplayer->SetFastClothesLoading ( (CMultiplayer::EFastClothesLoading)iVal );

MTA10/core/CSettings.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void CSettings::CreateGUI ( void )
104104
}
105105
else
106106
{
107-
// Otherwise use black background image
107+
// Otherwise use black background image
108108
CGUIStaticImage* pFiller = reinterpret_cast < CGUIStaticImage* > ( pManager->CreateStaticImage () );
109109
pFiller->LoadFromFile ( CORE_MTA_FILLER );
110110
pFiller->SetVisible ( false );
@@ -1771,7 +1771,7 @@ void CSettings::UpdateVideoTab ( void )
17711771

17721772
// Customized sa files
17731773
m_pCheckBoxCustomizedSAFiles->SetSelected ( GetApplicationSettingInt ( "customized-sa-files-request" ) != 0 );
1774-
m_pCheckBoxCustomizedSAFiles->SetVisible ( GetApplicationSettingInt ( "customized-sa-files-show" ) != 0 );
1774+
m_pCheckBoxCustomizedSAFiles->SetVisible ( GetApplicationSettingInt ( "customized-sa-files-show" ) != 0 );
17751775

17761776
// Grass
17771777
bool bGrassEnabled;
@@ -3057,13 +3057,12 @@ void CSettings::SaveData ( void )
30573057
gameSettings->SetDrawDistance ( ( m_pDrawDistance->GetScrollPosition () * 0.875f ) + 0.925f );
30583058
gameSettings->SetBrightness ( m_pBrightness->GetScrollPosition () * 384 );
30593059
gameSettings->SetMouseSensitivity ( m_pMouseSensitivity->GetScrollPosition () );
3060-
gameSettings->SetMipMappingEnabled ( m_pCheckBoxMipMapping->GetSelected () );
3060+
gameSettings->SetMipMappingEnabled ( m_pCheckBoxMipMapping->GetSelected () );
30613061
SetApplicationSettingInt ( "customized-sa-files-request", bCustomizedSAFilesEnabled ? 1 : 0 );
30623062

30633063
// iFieldOfView
30643064
int iFieldOfView = Min < int > ( 4, ( m_pFieldOfView->GetScrollPosition () ) * ( 4 + 1 ) ) * 5 + 70;
30653065
CVARS_SET ( "fov", iFieldOfView );
3066-
gameSettings->SetFieldOfView ( iFieldOfView );
30673066

30683067
// Anisotropic filtering
30693068
int iAnisotropic = Min < int > ( m_iMaxAnisotropic, ( m_pAnisotropic->GetScrollPosition () ) * ( m_iMaxAnisotropic + 1 ) );
@@ -3090,7 +3089,7 @@ void CSettings::SaveData ( void )
30903089
// Volumetric shadows
30913090
bool bVolumetricShadowsEnabled = m_pCheckBoxVolumetricShadows->GetSelected ();
30923091
CVARS_SET ( "volumetric_shadows", bVolumetricShadowsEnabled );
3093-
gameSettings->SetVolumetricShadowsEnabled ( bVolumetricShadowsEnabled );
3092+
gameSettings->SetVolumetricShadowsEnabled ( bVolumetricShadowsEnabled );
30943093

30953094
// Device selection dialog
30963095
bool bDeviceSelectionDialogEnabled = m_pCheckBoxDeviceSelectionDialog->GetSelected ();

MTA10/game_sa/CSettingsSA.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,34 +485,55 @@ void CSettingsSA::SetRadarMode ( eRadarMode hudMode )
485485
////////////////////////////////////////////////
486486
float ms_fFOV = 70;
487487
float ms_fFOVCar = 70;
488-
float ms_fFOVCarMax = 100; // When car go fast
488+
float ms_fFOVCarMax = 100; // at high vehicle velocity
489489

490-
float CSettingsSA::GetFieldOfView ( void )
490+
// consider moving this to the camera class - qaisjp
491+
float CSettingsSA::GetFieldOfViewPlayer ( void )
491492
{
492493
return ms_fFOV;
493494
}
494495

496+
float CSettingsSA::GetFieldOfViewVehicle ( void )
497+
{
498+
return ms_fFOVCar;
499+
}
500+
501+
float CSettingsSA::GetFieldOfViewVehicleMax ( void )
502+
{
503+
return ms_fFOVCarMax;
504+
}
505+
495506
void CSettingsSA::SetFieldOfView ( float fAngle )
496507
{
497-
fAngle = Clamp( 70.f, fAngle, 100.f );
508+
SetFieldOfViewPlayer ( fAngle );
509+
SetFieldOfViewVehicle ( fAngle );
510+
}
511+
512+
void CSettingsSA::SetFieldOfViewPlayer ( float fAngle )
513+
{
498514
ms_fFOV = fAngle;
499-
ms_fFOVCar = fAngle;
500-
501-
// Player follow
502515
MemPut < void* > ( 0x0522F3A, &ms_fFOV );
503516
MemPut < void* > ( 0x0522F5D, &ms_fFOV );
504517
MemPut < float > ( 0x0522F7A, ms_fFOV );
518+
}
505519

506-
// Car follow
520+
void CSettingsSA::SetFieldOfViewVehicle ( float fAngle )
521+
{
522+
ms_fFOVCar = fAngle;
507523
MemPut < void* > ( 0x0524B76, &ms_fFOVCar );
508524
MemPut < void* > ( 0x0524B9A, &ms_fFOVCar );
509525
MemPut < void* > ( 0x0524BA2, &ms_fFOVCar );
510-
MemPut < void* > ( 0x0524BB4, &ms_fFOVCarMax );
511-
MemPut < float > ( 0x0524BC5, ms_fFOVCarMax );
512526
MemPut < void* > ( 0x0524BD3, &ms_fFOVCar );
513527
MemPut < float > ( 0x0524BE4, ms_fFOVCar );
514528
}
515529

530+
void CSettingsSA::SetFieldOfViewVehicleMax ( float fAngle )
531+
{
532+
ms_fFOVCarMax = fAngle;
533+
MemPut < void* > ( 0x0524BB4, &ms_fFOVCarMax );
534+
MemPut < float > ( 0x0524BC5, ms_fFOVCarMax );
535+
}
536+
516537

517538
////////////////////////////////////////////////
518539
//

MTA10/game_sa/CSettingsSA.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ class CSettingsSA : public CGameSettings
146146
void SetRadarMode ( eRadarMode hudMode );
147147

148148
void SetFieldOfView ( float fAngle );
149-
float GetFieldOfView ( void );
149+
void SetFieldOfViewPlayer ( float fAngle );
150+
void SetFieldOfViewVehicle ( float fAngle );
151+
void SetFieldOfViewVehicleMax ( float fAngle );
152+
float GetFieldOfViewPlayer ( void );
153+
float GetFieldOfViewVehicle ( void );
154+
float GetFieldOfViewVehicleMax ( void );
150155

151156
void Save ( void );
152157

MTA10/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,9 +2781,9 @@ void CClientGame::AddBuiltInEvents ( void )
27812781
m_Events.AddEvent ( "onClientPlayerStealthKill", "target", NULL, false );
27822782
m_Events.AddEvent ( "onClientPlayerHitByWaterCannon", "vehicle", NULL, false );
27832783
m_Events.AddEvent ( "onClientPlayerHeliKilled", "heli", NULL, false );
2784-
m_Events.AddEvent ( "onClientPlayerPickupHit", "pickup, matchingDimension", NULL, false );
2785-
m_Events.AddEvent ( "onClientPlayerPickupLeave", "pickup, matchingDimension", NULL, false );
2786-
m_Events.AddEvent ( "onClientPlayerNetworkStatus", "type, ticks", NULL, false );
2784+
m_Events.AddEvent ( "onClientPlayerPickupHit", "pickup, matchingDimension", NULL, false );
2785+
m_Events.AddEvent ( "onClientPlayerPickupLeave", "pickup, matchingDimension", NULL, false );
2786+
m_Events.AddEvent ( "onClientPlayerNetworkStatus", "type, ticks", NULL, false );
27872787

27882788
// Ped events
27892789
m_Events.AddEvent ( "onClientPedDamage", "attacker, weapon, bodypart", NULL, false );
@@ -5465,6 +5465,11 @@ void CClientGame::ResetMapInfo ( void )
54655465
g_pGame->GetWorld ()->SetCurrentArea ( 0 );
54665466
m_pCamera->SetFocusToLocalPlayer ();
54675467

5468+
float fFOV;
5469+
g_pCore->GetCVars ()->Get ( "fov", fFOV );
5470+
g_pGame->GetSettings ()->SetFieldOfView ( Clamp ( 70.f, fFOV, 100.f ) );
5471+
g_pGame->GetSettings ()->SetFieldOfViewVehicleMax ( 100 );
5472+
54685473
// Dimension
54695474
SetAllDimensions ( 0 );
54705475

@@ -5526,7 +5531,7 @@ void CClientGame::ResetMapInfo ( void )
55265531
// Water-colour
55275532
g_pMultiplayer->ResetWater ( );
55285533

5529-
// Water
5534+
// Water
55305535
GetManager ()->GetWaterManager ()->ResetWorldWaterLevel ();
55315536

55325537
// Re-enable interior sounds and furniture

MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4443,7 +4443,6 @@ bool CStaticFunctionDefinitions::SetCameraMatrix ( const CVector& vecPosition, C
44434443
return true;
44444444
}
44454445

4446-
44474446
bool CStaticFunctionDefinitions::SetCameraTarget ( CClientEntity * pEntity )
44484447
{
44494448
assert ( pEntity );

MTA10/mods/shared_logic/CClientCamera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void CClientCamera::SetFocus ( CClientPlayer* pPlayer, eCamMode eMode, bool bSmo
378378
// Should we attach to a player, or set the camera to free?
379379
if ( pPlayer )
380380
{
381-
// Attach the camera to the player vehicle if in a vehicle. To the player model otherwize
381+
// Attach the camera to the player vehicle if in a vehicle. To the player model otherwise
382382
CClientVehicle* pVehicle = pPlayer->GetOccupiedVehicle ();
383383
if ( pVehicle )
384384
{

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Camera.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,73 @@ int CLuaFunctionDefs::SetCameraMatrix ( lua_State* luaVM )
164164
return 1;
165165
}
166166

167+
// Only when onfoot/invehicle
168+
int CLuaFunctionDefs::SetCameraFieldOfView ( lua_State* luaVM )
169+
{
170+
float fFOV; eFieldOfViewMode eMode;
171+
CScriptArgReader argStream ( luaVM );
172+
173+
argStream.ReadEnumString ( eMode );
174+
argStream.ReadNumber ( fFOV );
175+
176+
if ( fFOV < 0 || fFOV > 179 )
177+
argStream.SetCustomError ( "Outside 0-179 boundaries" );
178+
179+
if ( !argStream.HasErrors () )
180+
{
181+
if (eMode == FOV_MODE_PLAYER)
182+
g_pGame->GetSettings ()->SetFieldOfViewPlayer ( fFOV );
183+
else if ( eMode == FOV_MODE_VEHICLE )
184+
g_pGame->GetSettings ()->SetFieldOfViewVehicle ( fFOV );
185+
else if ( eMode == FOV_MODE_VEHICLE_MAX )
186+
g_pGame->GetSettings ()->SetFieldOfViewVehicleMax ( fFOV );
187+
else {
188+
argStream.m_iIndex = 1;
189+
m_pScriptDebugging->LogCustom ( luaVM, SString("Enum not yet implemented: " + EnumToString ( eMode )) );
190+
lua_pushboolean ( luaVM, false );
191+
return 1;
192+
}
193+
lua_pushboolean ( luaVM, true );
194+
return 1;
195+
}
196+
else
197+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
198+
199+
lua_pushboolean ( luaVM, false );
200+
return 1;
201+
}
202+
203+
// Only when onfoot/invehicle
204+
int CLuaFunctionDefs::GetCameraFieldOfView ( lua_State* luaVM )
205+
{
206+
eFieldOfViewMode eMode;
207+
CScriptArgReader argStream ( luaVM );
208+
209+
argStream.ReadEnumString ( eMode );
210+
211+
if ( !argStream.HasErrors() )
212+
{
213+
float fFOV;
214+
if ( eMode == FOV_MODE_PLAYER )
215+
fFOV = g_pGame->GetSettings ()->GetFieldOfViewPlayer ();
216+
else if ( eMode == FOV_MODE_VEHICLE )
217+
fFOV = g_pGame->GetSettings ()->GetFieldOfViewVehicle ();
218+
else if ( eMode == FOV_MODE_VEHICLE_MAX )
219+
fFOV = g_pGame->GetSettings ()->GetFieldOfViewVehicleMax ();
220+
else {
221+
argStream.m_iIndex = 1;
222+
m_pScriptDebugging->LogCustom ( luaVM, SString ( "Enum not yet implemented: " + EnumToString ( eMode ) ) );
223+
lua_pushboolean ( luaVM, false );
224+
return 1;
225+
}
226+
227+
lua_pushnumber ( luaVM, fFOV );
228+
return 1;
229+
}
230+
231+
lua_pushboolean ( luaVM, false );
232+
return 1;
233+
}
167234

168235
int CLuaFunctionDefs::SetCameraTarget ( lua_State* luaVM )
169236
{

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,15 @@ class CLuaFunctionDefs
518518
LUA_DECLARE ( GetCameraMatrix );
519519
LUA_DECLARE ( GetCameraTarget );
520520
LUA_DECLARE ( GetCameraInterior );
521-
LUA_DECLARE ( GetCameraGoggleEffect );
522-
LUA_DECLARE ( GetCameraShakeLevel );
521+
LUA_DECLARE ( GetCameraGoggleEffect );
522+
LUA_DECLARE ( GetCameraShakeLevel );
523+
LUA_DECLARE ( GetCameraFieldOfView );
523524

524525
// Cam set funcs
525526
LUA_DECLARE ( SetCameraMatrix );
526527
LUA_DECLARE ( SetCameraTarget );
527528
LUA_DECLARE ( SetCameraInterior );
529+
LUA_DECLARE ( SetCameraFieldOfView );
528530
LUA_DECLARE ( FadeCamera );
529531
LUA_DECLARE ( SetCameraClip );
530532
LUA_DECLARE ( GetCameraClip );

MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ IMPLEMENT_ENUM_BEGIN(eWebBrowserMouseButton)
459459
ADD_ENUM(BROWSER_MOUSEBUTTON_RIGHT, "right")
460460
IMPLEMENT_ENUM_END("webbrowser-mouse-button")
461461

462+
IMPLEMENT_ENUM_BEGIN(eFieldOfViewMode)
463+
ADD_ENUM(FOV_MODE_PLAYER, "player")
464+
ADD_ENUM(FOV_MODE_VEHICLE, "vehicle")
465+
ADD_ENUM(FOV_MODE_VEHICLE_MAX, "vehicle_max")
466+
ADD_ENUM(FOV_MODE_AIMING, "aiming")
467+
IMPLEMENT_ENUM_END("fieldofview-mode")
468+
462469
//
463470
// Get best guess at name of userdata type
464471
//

0 commit comments

Comments
 (0)