Skip to content

Commit

Permalink
Updating remove view camera logic, allowing use of map while in remot…
Browse files Browse the repository at this point in the history
…e view
  • Loading branch information
sethduda committed Jan 16, 2017
1 parent 9e6f95f commit 7e4c6a1
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 72 deletions.
2 changes: 1 addition & 1 deletion AICommand/cfgnotifications.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RemoteControl
{
title = "Remote Control";
title = "Remote";
iconPicture = "AICommand\images\warning.jpg";
description = "%2";
priority = 0;
Expand Down
116 changes: 63 additions & 53 deletions AICommand/functions/actions/fn_commandMenuActionsInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,75 @@ 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"];
private ["_group"];
_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;
Expand Down Expand Up @@ -271,7 +333,6 @@ AIC_fnc_remoteControlActionHandler = {
openMap false;

["RemoteControl",["","Press DELETE to Exit Remote Control"]] call BIS_fnc_showNotification;

};

AIC_fnc_terminateRemoteControl = {
Expand All @@ -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;
Expand All @@ -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"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 16 additions & 3 deletions AICommand/functions/remoteCamera/fn_cameraUpdatePosition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
39 changes: 27 additions & 12 deletions AICommand/functions/remoteCamera/fn_enable3rdPersonCamera.sqf
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions AICommand/functions/remoteCamera/functions.h
Original file line number Diff line number Diff line change
@@ -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)
#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)]

0 comments on commit 7e4c6a1

Please sign in to comment.