Better method of updating camera view

This commit is contained in:
SilentSpike 2015-07-15 14:33:11 +01:00
parent 784865d634
commit 147571c76f
4 changed files with 92 additions and 85 deletions

View File

@ -9,5 +9,6 @@ PREP(handleMouse);
PREP(handleRespawn);
PREP(moduleSpectator);
PREP(setSpectator);
PREP(updateView);
ADDON = true;

View File

@ -1,30 +1,7 @@
#include "script_component.hpp"
// Update camera values
GVAR(camera) camSetFov GVAR(camFOV);
// Commit changes
GVAR(camera) camCommit 0;
showCinemaBorder false;
cameraEffectEnableHUD true;
// If valid unit then apply camera view as appropriate
if ((GVAR(camUnit) in GVAR(unitList)) && !isNull GVAR(camUnit)) then {
if (camMode == 1) then {
GVAR(camUnit) switchCamera "internal";
} else {
GVAR(camera) camSetTarget GVAR(camUnit);
};
};
// Don't recreate the PFH
if !(isNil QGVAR(camPFH)) exitWith {};
// Constantly handle camera manipulation
GVAR(camPFH) = [
{
// Kill PFH when display is closed
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; GVAR(camPFH) = nil; };
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Different behaviour based on camera mode
switch (GVAR(camMode)) do {
@ -66,7 +43,8 @@ GVAR(camPFH) = [
[GVAR(camera), GVAR(camTilt), GVAR(camBank)] call BIS_fnc_setPitchBank;
};
case 1: { // Internal
if !(alive GVAR(camUnit)) then {
call FUNC(updateView);
};
};
};
}, 0] call CBA_fnc_addPerFrameHandler;

View File

@ -46,6 +46,7 @@ switch (toLower _mode) do {
GVAR(camSpeed) = 0.8;
GVAR(camTilt) = -60;
GVAR(camZoom) = 3;
GVAR(gunCam) = false;
// Initalize display variables
GVAR(ctrlKey) = false;
@ -58,8 +59,14 @@ switch (toLower _mode) do {
// Initalize the camera view
GVAR(camera) = "Camera" camCreate GVAR(camPos);
GVAR(camera) setDir GVAR(camPan);
GVAR(camera) cameraEffect ["internal", "back"];
call FUNC(handleCamera);
call FUNC(updateView);
// HUD stuff
showCinemaBorder false;
cameraEffectEnableHUD true;
// Handle camera movement
[FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler;
// Create the dialog
createDialog QGVAR(overlay);
@ -95,12 +102,14 @@ switch (toLower _mode) do {
GVAR(camSpeed) = nil;
GVAR(camTilt) = nil;
GVAR(camZoom) = nil;
GVAR(gunCam) = nil;
// Cleanup display variables
GVAR(mouse) = nil;
GVAR(mouseDelta) = nil;
GVAR(mousePos) = nil;
GVAR(mousePosOld) = nil;
GVAR(unitList) = nil;
// Reset nametag settings
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
@ -128,7 +137,7 @@ switch (toLower _mode) do {
(_display displayCtrl IDC_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode));
// Populate unit tree
//["onload",_display displayCtrl IDC_TREE] call FUNC(handleTree);
//["onload",_display displayCtrl IDC_TREE] call FUNC(updateUnits);
// Hacky way to enable keybindings
//_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}];
@ -147,9 +156,9 @@ switch (toLower _mode) do {
// Detect right click
if ((_button == 1) && (GVAR(camMode) == 1)) then {
// In first person aim down sight toggle
GVAR(ads) = false;
GVAR(camUnit) switchCamera "internal";
// In first person toggle sights mode
GVAR(gunCam) = !GVAR(gunCam);
call FUNC(updateView);
};
};
case "onmousebuttonup": {
@ -229,20 +238,9 @@ switch (toLower _mode) do {
};
case 57: { // Spacebar
GVAR(camMode) = [1,2,0] select GVAR(camMode);
GVAR(gunCam) = false;
switch (GVAR(camMode)) do {
case 0: {
GVAR(camera) cameraEffect ["internal", "back"];
GVAR(camUnit) = objNull;
};
case 1: {
GVAR(camUnit) = ;
};
case 2: {
};
};
call FUNC(handleCamera);
call FUNC(updateView);
};
};

View File

@ -0,0 +1,30 @@
#include "script_component.hpp"
GVAR(camera) camSetFOV GVAR(camFOV);
if (GVAR(camMode) == 0) then { // Free
GVAR(camera) cameraEffect ["internal", "back"];
} else {
// When no units available to spectate, exit to freecam
if (unitList isEqualTo []) exitWith {
GVAR(camMode) = 0;
call FUNC(updateView);
};
// First ensure valid unit is selected
if !(GVAR(camUnit) in GVAR(unitList)) then {
GVAR(camUnit) = GVAR(unitList) select floor(random(count GVAR(unitList)));
};
if (GVAR(camMode) == 1) then { // Internal
// Handle gun cam
if (GVAR(gunCam)) then {
GVAR(camUnit) switchCamera "gunner";
} else {
GVAR(camUnit) switchCamera "internal";
};
} else { // External
GVAR(camUnit) switchCamera "external";
};
};