From 7e4c6a1a10dff027e4b664786b0f4e0fb1452dbf Mon Sep 17 00:00:00 2001 From: sethduda Date: Mon, 16 Jan 2017 12:50:43 -0500 Subject: [PATCH] Updating remove view camera logic, allowing use of map while in remote view --- AICommand/cfgnotifications.hpp | 2 +- .../actions/fn_commandMenuActionsInit.sqf | 116 ++++++++++-------- .../fn_cameraMouseZoomHandler.sqf | 2 +- .../remoteCamera/fn_cameraUpdatePosition.sqf | 19 ++- .../fn_disable3rdPersonCamera.sqf | 4 + .../remoteCamera/fn_enable3rdPersonCamera.sqf | 39 ++++-- AICommand/functions/remoteCamera/functions.h | 4 +- 7 files changed, 114 insertions(+), 72 deletions(-) diff --git a/AICommand/cfgnotifications.hpp b/AICommand/cfgnotifications.hpp index 891a037..f38b8f3 100644 --- a/AICommand/cfgnotifications.hpp +++ b/AICommand/cfgnotifications.hpp @@ -1,6 +1,6 @@ class RemoteControl { - title = "Remote Control"; + title = "Remote"; iconPicture = "AICommand\images\warning.jpg"; description = "%2"; priority = 0; diff --git a/AICommand/functions/actions/fn_commandMenuActionsInit.sqf b/AICommand/functions/actions/fn_commandMenuActionsInit.sqf index 8861a48..3063b15 100644 --- a/AICommand/functions/actions/fn_commandMenuActionsInit.sqf +++ b/AICommand/functions/actions/fn_commandMenuActionsInit.sqf @@ -237,6 +237,63 @@ AIC_fnc_clearAllWaypointsActionHandler = { ["GROUP","Confirm Cancel All",["Clear All Waypoints"],AIC_fnc_clearAllWaypointsActionHandler] call AIC_fnc_addCommandMenuAction; +AIC_fnc_remoteViewActionHandler = { + params ["_menuParams","_actionParams"]; + _menuParams params ["_groupControlId"]; + private ["_group"]; + _group = AIC_fnc_getGroupControlGroup(_groupControlId); + private ["_fromUnit","_rcUnit","_exitingRcUnit"]; + + private _remoteControlActive = !isNull (missionNamespace getVariable ["AIC_Remote_Control_From_Unit",objNull]); + if(_remoteControlActive) then { + [] call AIC_fnc_terminateRemoteControl; + }; + + _fromUnit = missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]; + if(isNull _fromUnit || !alive _fromUnit) then { + _fromUnit = player; + missionNamespace setVariable ["AIC_Remote_View_From_Unit",_fromUnit]; + }; + + _rcUnit = leader _group; + _exitingRcUnit = missionNamespace getVariable ["AIC_Remote_View_To_Unit",objNull]; + if(!isNull _exitingRcUnit) then { + ["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler; + }; + missionNamespace setVariable ["AIC_Remote_View_To_Unit",_rcUnit]; + + AIC_Remote_View_From_Unit_Event_Handler = _fromUnit addEventHandler ["HandleDamage", "[] call AIC_fnc_terminateRemoteView; _this select 2;"]; + AIC_Remote_View_Delete_Handler = ["MAIN_DISPLAY","KeyDown", "if(_this select 1 == 211) then { [] call AIC_fnc_terminateRemoteView; }"] call AIC_fnc_addEventHandler; + + openMap false; + + [_rcUnit] call AIC_fnc_enable3rdPersonCamera; + + ["RemoteControl",["","Press DELETE to Exit Remote View"]] call BIS_fnc_showNotification; + +}; + +AIC_fnc_terminateRemoteView = { + ["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler; + (missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_View_From_Unit_Event_Handler",-1])]; + missionNamespace setVariable ["AIC_Remote_View_To_Unit",nil]; + missionNamespace setVariable ["AIC_Remote_View_From_Unit",nil]; + [] call AIC_fnc_disable3rdPersonCamera; + ["RemoteControl",["","Remote View Terminated"]] call BIS_fnc_showNotification; +}; + +["GROUP","Remote View",["Remote"],AIC_fnc_remoteViewActionHandler,[],{ + params ["_groupControlId"]; + private ["_group"]; + _group = AIC_fnc_getGroupControlGroup(_groupControlId); + private ["_canControl"]; + _canControl = false; + if(player != leader _group) then { + _canControl = true; + }; + _canControl; +}] call AIC_fnc_addCommandMenuAction; + AIC_fnc_remoteControlActionHandler = { params ["_menuParams","_actionParams"]; _menuParams params ["_groupControlId"]; @@ -244,6 +301,11 @@ AIC_fnc_remoteControlActionHandler = { _group = AIC_fnc_getGroupControlGroup(_groupControlId); private ["_fromUnit","_rcUnit","_exitingRcUnit"]; + private _remoteViewActive = !isNull (missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]); + if(_remoteViewActive) then { + [] call AIC_fnc_terminateRemoteView; + }; + _fromUnit = missionNamespace getVariable ["AIC_Remote_Control_From_Unit",objNull]; if(isNull _fromUnit || !alive _fromUnit) then { _fromUnit = player; @@ -271,7 +333,6 @@ AIC_fnc_remoteControlActionHandler = { openMap false; ["RemoteControl",["","Press DELETE to Exit Remote Control"]] call BIS_fnc_showNotification; - }; AIC_fnc_terminateRemoteControl = { @@ -280,6 +341,7 @@ AIC_fnc_terminateRemoteControl = { (missionNamespace getVariable ["AIC_Remote_Control_To_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_Control_To_Unit_Event_Handler",-1])]; missionNamespace setVariable ["AIC_Remote_Control_To_Unit",nil]; selectPlayer (missionNamespace getVariable ["AIC_Remote_Control_From_Unit",player]); + missionNamespace setVariable ["AIC_Remote_Control_From_Unit",nil]; (vehicle player) switchCamera cameraView; BIS_fnc_feedback_allowPP = true; ["RemoteControl",["","Remote Control Terminated"]] call BIS_fnc_showNotification; @@ -300,58 +362,6 @@ AIC_fnc_terminateRemoteControl = { _canControl; }] call AIC_fnc_addCommandMenuAction; -AIC_fnc_remoteViewActionHandler = { - params ["_menuParams","_actionParams"]; - _menuParams params ["_groupControlId"]; - private ["_group"]; - _group = AIC_fnc_getGroupControlGroup(_groupControlId); - private ["_fromUnit","_rcUnit","_exitingRcUnit"]; - - _fromUnit = missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]; - if(isNull _fromUnit || !alive _fromUnit) then { - _fromUnit = player; - missionNamespace setVariable ["AIC_Remote_View_From_Unit",_fromUnit]; - }; - - _rcUnit = leader _group; - _exitingRcUnit = missionNamespace getVariable ["AIC_Remote_View_To_Unit",objNull]; - if(!isNull _exitingRcUnit) then { - ["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler; - }; - missionNamespace setVariable ["AIC_Remote_View_To_Unit",_rcUnit]; - - AIC_Remote_View_From_Unit_Event_Handler = _fromUnit addEventHandler ["HandleDamage", "[] call AIC_fnc_terminateRemoteView; _this select 2;"]; - AIC_Remote_View_Delete_Handler = ["MAIN_DISPLAY","KeyDown", "if(_this select 1 == 211) then { [] call AIC_fnc_terminateRemoteView; }"] call AIC_fnc_addEventHandler; - - openMap false; - - [_rcUnit] call AIC_fnc_enable3rdPersonCamera; - - ["RemoteControl",["","Press DELETE to Exit Remote View"]] call BIS_fnc_showNotification; - -}; - -AIC_fnc_terminateRemoteView = { - ["MAIN_DISPLAY","KeyDown",(missionNamespace getVariable ["AIC_Remote_View_Delete_Handler",-1])] call AIC_fnc_removeEventHandler; - (missionNamespace getVariable ["AIC_Remote_View_From_Unit",objNull]) removeEventHandler ["HandleDamage", (missionNamespace getVariable ["AIC_Remote_View_From_Unit_Event_Handler",-1])]; - missionNamespace setVariable ["AIC_Remote_View_To_Unit",nil]; - selectPlayer (missionNamespace getVariable ["AIC_Remote_View_From_Unit",player]); - [] call AIC_fnc_disable3rdPersonCamera; - ["RemoteControl",["","Remote View Terminated"]] call BIS_fnc_showNotification; -}; - -["GROUP","Remote View",["Remote"],AIC_fnc_remoteViewActionHandler,[],{ - params ["_groupControlId"]; - private ["_group"]; - _group = AIC_fnc_getGroupControlGroup(_groupControlId); - private ["_canControl"]; - _canControl = false; - if(player != leader _group) then { - _canControl = true; - }; - _canControl; -}] call AIC_fnc_addCommandMenuAction; - AIC_fnc_assignVehicleActionHandler = { params ["_menuParams","_actionParams"]; _menuParams params ["_groupControlId"]; diff --git a/AICommand/functions/remoteCamera/fn_cameraMouseZoomHandler.sqf b/AICommand/functions/remoteCamera/fn_cameraMouseZoomHandler.sqf index d483854..1f4ece2 100644 --- a/AICommand/functions/remoteCamera/fn_cameraMouseZoomHandler.sqf +++ b/AICommand/functions/remoteCamera/fn_cameraMouseZoomHandler.sqf @@ -7,5 +7,5 @@ if(_mouseZoom > 0) then { _mouseZoom = -1; }; _distance = AIC_FNC_CAMERA_DISTANCE; -AIC_3rd_Person_Camera_Distance = (_distance - _mouseZoom) max 3 min 50; +AIC_3rd_Person_Camera_Distance = (_distance - _mouseZoom) max 3 min 60; [] spawn AIC_fnc_cameraUpdatePosition; \ No newline at end of file diff --git a/AICommand/functions/remoteCamera/fn_cameraUpdatePosition.sqf b/AICommand/functions/remoteCamera/fn_cameraUpdatePosition.sqf index 136707e..3c2998c 100644 --- a/AICommand/functions/remoteCamera/fn_cameraUpdatePosition.sqf +++ b/AICommand/functions/remoteCamera/fn_cameraUpdatePosition.sqf @@ -2,10 +2,23 @@ private ["_cam"]; _cam = AIC_FNC_CAMERA; if(!isNil "_cam") then { - if(AIC_FNC_CAMERA_WORLD_POSITION select 2 < 0) then { + + private _targetObject = vehicle AIC_FNC_CAMERA_TARGET; + private _targetPosition = getPosASLVisual _targetObject; + private _bbr = boundingBoxReal _targetObject; + private _p1 = _bbr select 0; + private _p2 = _bbr select 1; + private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + _targetPosition = _targetPosition vectorAdd [0,0,_maxHeight * 0.5]; + private _cameraPosition = AIC_FNC_CAMERA_REL_POSITION vectorAdd _targetPosition; + if((ASLToATL _cameraPosition) select 2 < 0) then { AIC_3rd_Person_Camera_Y_Move_Total = AIC_FNC_CAMERA_Y_TOTAL min AIC_FNC_CAMERA_Y_TOTAL_PRIOR; + _cameraPosition = AIC_FNC_CAMERA_REL_POSITION vectorAdd _targetPosition; }; - _cam camSetRelPos AIC_FNC_CAMERA_REL_POSITION; - _cam camCommit 0.01; + private _lookVector = _cameraPosition vectorFromTo _targetPosition; + private _cameraUpVector = (_lookVector vectorCrossProduct [0,0,1]) vectorCrossProduct _lookVector; + _cam setPosASL _cameraPosition; + _cam setVectorDirAndUp [_lookVector,_cameraUpVector]; AIC_3rd_Person_Camera_Y_Move_Total_Prior = AIC_FNC_CAMERA_Y_TOTAL; + AIC_3rd_Person_Camera_Last_Position = _cameraPosition; }; \ No newline at end of file diff --git a/AICommand/functions/remoteCamera/fn_disable3rdPersonCamera.sqf b/AICommand/functions/remoteCamera/fn_disable3rdPersonCamera.sqf index 9754c35..52121f1 100644 --- a/AICommand/functions/remoteCamera/fn_disable3rdPersonCamera.sqf +++ b/AICommand/functions/remoteCamera/fn_disable3rdPersonCamera.sqf @@ -7,6 +7,10 @@ if(!isNull AIC_FNC_CAMERA) then { missionNamespace setVariable ["AIC_3rd_Person_Camera_X_Move_Total",nil]; missionNamespace setVariable ["AIC_3rd_Person_Camera_Y_Move_Total",nil]; missionNamespace setVariable ["AIC_3rd_Person_Camera_Y_Move_Total_Prior",nil]; + missionNamespace setVariable ["AIC_3rd_Person_Camera_Last_Position",nil]; + removeMissionEventHandler ["EachFrame", AIC_3rd_Person_Camera_Frame_Handler]; ["MAIN_DISPLAY","MouseMoving", AIC_Mouse_Move_Handler] call AIC_fnc_removeEventHandler; ["MAIN_DISPLAY","MouseZChanged", AIC_Mouse_Zoom_Handler] call AIC_fnc_removeEventHandler; + ["MAIN_DISPLAY","KeyDown", AIC_3rd_Person_Camera_Map_Handler1] call AIC_fnc_removeEventHandler; + ["MAIN_DISPLAY","MouseButtonDown", AIC_3rd_Person_Camera_Map_Handler2] call AIC_fnc_removeEventHandler; } \ No newline at end of file diff --git a/AICommand/functions/remoteCamera/fn_enable3rdPersonCamera.sqf b/AICommand/functions/remoteCamera/fn_enable3rdPersonCamera.sqf index 64cb9b7..bff46b8 100644 --- a/AICommand/functions/remoteCamera/fn_enable3rdPersonCamera.sqf +++ b/AICommand/functions/remoteCamera/fn_enable3rdPersonCamera.sqf @@ -1,23 +1,38 @@ #include "..\functions.h" _this spawn { - params ["_object"]; - private ["_lastPosition"]; + params ["_object",["_followDirection",false]]; waitUntil {time > 0}; showCinemaBorder false; + AIC_3rd_Person_Camera_Target = _object; AIC_3rd_Person_Camera = "camera" camCreate (_object modelToWorld [0,0,0]); - AIC_3rd_Person_Camera camSetTarget _object; AIC_3rd_Person_Camera cameraEffect ["internal", "BACK"]; - [] call AIC_fnc_cameraUpdatePosition; AIC_Mouse_Move_Handler = ["MAIN_DISPLAY","MouseMoving", "_this call AIC_fnc_cameraMouseMoveHandler"] call AIC_fnc_addEventHandler; AIC_Mouse_Zoom_Handler = ["MAIN_DISPLAY","MouseZChanged", "_this call AIC_fnc_cameraMouseZoomHandler"] call AIC_fnc_addEventHandler; - _lastPosition = getPos _object; - _lastVectorDir = vectorDir _object; - while {!isNull AIC_FNC_CAMERA && !isNull _object && alive _object} do { - if(_lastPosition distance _object > 0.01 || vectorMagnitude (_lastVectorDir vectorDiff (vectorDir _object)) > 0.01 ) then { - [] call AIC_fnc_cameraUpdatePosition; - _lastPosition = getPos _object; + AIC_3rd_Person_Camera_Frame_Handler = addMissionEventHandler ["EachFrame", {[] call AIC_fnc_cameraUpdatePosition; false}]; + + AIC_fnc_remoteCameraMapHandler = { + private ["_event","_eventParams","_actionKeys"]; + _event = param [0]; + _eventParams = param [1]; + _actionKeys = actionKeys "ShowMap"; + if(_event == "KeyDown" || _event == "MouseButtonDown") then { + if( (_eventParams select 1) in _actionKeys || (65536 + (_eventParams select 1)) in _actionKeys ) then { + [] spawn { + AIC_FNC_CAMERA cameraEffect ["Terminate", "Back"]; + openMap true; + waitUntil {!visibleMap}; + if(!isNil "AIC_3rd_Person_Camera") then { + AIC_3rd_Person_Camera cameraEffect ["internal", "BACK"]; + }; + }; + }; }; - sleep 0.01; - }; + + }; + + AIC_3rd_Person_Camera_Map_Handler1 = ["MAIN_DISPLAY","KeyDown", "[""KeyDown"",_this] call AIC_fnc_remoteCameraMapHandler"] call AIC_fnc_addEventHandler; + AIC_3rd_Person_Camera_Map_Handler2 = ["MAIN_DISPLAY","MouseButtonDown", "[""MouseButtonDown"",_this] call AIC_fnc_remoteCameraMapHandler"] call AIC_fnc_addEventHandler; + + waitUntil {isNull AIC_FNC_CAMERA || isNull _object}; [] call AIC_fnc_disable3rdPersonCamera; }; \ No newline at end of file diff --git a/AICommand/functions/remoteCamera/functions.h b/AICommand/functions/remoteCamera/functions.h index 464c820..3daefea 100644 --- a/AICommand/functions/remoteCamera/functions.h +++ b/AICommand/functions/remoteCamera/functions.h @@ -1,7 +1,7 @@ #define AIC_FNC_CAMERA_DISTANCE (missionNamespace getVariable ["AIC_3rd_Person_Camera_Distance",8]) #define AIC_FNC_CAMERA (missionNamespace getVariable ["AIC_3rd_Person_Camera",objNull]) +#define AIC_FNC_CAMERA_TARGET (missionNamespace getVariable ["AIC_3rd_Person_Camera_Target",objNull]) #define AIC_FNC_CAMERA_X_TOTAL (missionNamespace getVariable ["AIC_3rd_Person_Camera_X_Move_Total",-90]) #define AIC_FNC_CAMERA_Y_TOTAL (missionNamespace getVariable ["AIC_3rd_Person_Camera_Y_Move_Total",60]) #define AIC_FNC_CAMERA_Y_TOTAL_PRIOR (missionNamespace getVariable ["AIC_3rd_Person_Camera_Y_Move_Total_Prior",AIC_FNC_CAMERA_Y_TOTAL]) -#define AIC_FNC_CAMERA_REL_POSITION [AIC_FNC_CAMERA_DISTANCE * (cos AIC_FNC_CAMERA_X_TOTAL) * (sin AIC_FNC_CAMERA_Y_TOTAL), AIC_FNC_CAMERA_DISTANCE * (sin AIC_FNC_CAMERA_X_TOTAL) * (sin AIC_FNC_CAMERA_Y_TOTAL), AIC_FNC_CAMERA_DISTANCE * (cos AIC_FNC_CAMERA_Y_TOTAL)] -#define AIC_FNC_CAMERA_WORLD_POSITION ((camTarget AIC_FNC_CAMERA) modelToWorld AIC_FNC_CAMERA_REL_POSITION) \ No newline at end of file +#define AIC_FNC_CAMERA_REL_POSITION [AIC_FNC_CAMERA_DISTANCE * (cos AIC_FNC_CAMERA_X_TOTAL) * (sin AIC_FNC_CAMERA_Y_TOTAL), AIC_FNC_CAMERA_DISTANCE * (sin AIC_FNC_CAMERA_X_TOTAL) * (sin AIC_FNC_CAMERA_Y_TOTAL), AIC_FNC_CAMERA_DISTANCE * (cos AIC_FNC_CAMERA_Y_TOTAL)] \ No newline at end of file