Improve freecam handling

This commit is contained in:
SilentSpike 2015-07-18 16:59:05 +01:00
parent 60b3c6c0f8
commit fb2b2bc9e5
4 changed files with 46 additions and 59 deletions

View File

@ -1,6 +1,6 @@
/*
* Author: F3 Project, Head, SilentSpike
* Handles camera manipulation according to input
* Handles free camera manipulation according to input
*
* Arguments:
* None <NIL>
@ -16,12 +16,9 @@
#include "script_component.hpp"
// Kill PFH when display is closed
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Kill PFH when not in free cam (or display is closed)
if ((GVAR(camMode) != 0) || isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Different behaviour based on camera mode
switch (GVAR(camMode)) do {
case 0: { // Free
_oldPos = getPosASL GVAR(camera);
_mX = 0;
_mY = 0;
@ -57,7 +54,3 @@ switch (GVAR(camMode)) do {
GVAR(camera) setPosASL GVAR(camPos);
GVAR(camera) setDir GVAR(camPan);
[GVAR(camera), GVAR(camTilt), GVAR(camBank)] call BIS_fnc_setPitchBank;
};
case 1: { // Internal
};
};

View File

@ -43,9 +43,7 @@ switch (toLower _mode) do {
// Initalize display variables
GVAR(ctrlKey) = false;
GVAR(mouse) = [false,false];
GVAR(mouseDelta) = [0.5,0.5];
GVAR(mousePos) = [0.5,0.5];
GVAR(mousePosOld) = [0.5,0.5];
// Initalize the camera view
GVAR(camera) = "Camera" camCreate GVAR(camPos);
@ -54,9 +52,6 @@ switch (toLower _mode) do {
GVAR(camera) camSetFOV GVAR(camFOV);
// Handle camera movement
[FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler;
// Populate the unit list
[] call FUNC(updateUnits);
@ -169,15 +164,13 @@ switch (toLower _mode) do {
} else {
GVAR(camZoom) = (GVAR(camZoom) - (_zChange * GVAR(camZoom) * 0.2)) max 0.1;
};
[] call FUNC(handleCamera);
};
case "onmousemoving": {
private ["_x","_y"];
_x = _args select 1;
_y = _args select 2;
GVAR(mousePos) = [_x,_y];
[] call FUNC(handleMouse);
[_x,_y] call FUNC(handleMouse);
};
// Keyboard events
case "onkeydown": {

View File

@ -16,24 +16,22 @@
#include "script_component.hpp"
private ["_x","_y","_leftButton","_rightButton","_oldX","_oldY","_deltaX","_deltaY"];
params ["_x","_y"];
private ["_leftButton","_rightButton","_oldX","_oldY","_deltaX","_deltaY"];
_x = GVAR(mousePos) select 0;
_y = GVAR(mousePos) select 1;
_leftButton = GVAR(mouse) select 0;
_rightButton = GVAR(mouse) select 1;
_oldX = GVAR(mousePosOld) select 0;
_oldY = GVAR(mousePosOld) select 1;
_oldX = GVAR(mousePos) select 0;
_oldY = GVAR(mousePos) select 1;
// Get change in pos
_deltaX = _oldX - _x;
_deltaY = _oldY - _y;
GVAR(mouseDelta) = [_deltaX, _deltaY];
if (_rightButton && !_leftButton) then {
GVAR(camPan) = GVAR(camPan) - (_deltaX * 360);
GVAR(camTilt) = ((GVAR(camTilt) + (_deltaY * 180)) min 89) max -89;
};
GVAR(mousePosOld) = [_x,_y];
GVAR(mousePos) = [_x,_y];

View File

@ -21,6 +21,9 @@ if (GVAR(camMode) == 0) then { // Free
// HUD stuff
showCinemaBorder false;
cameraEffectEnableHUD false;
// Handle camera movement
[FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler;
} else {
// When null unit is given choose random
if (isNull _newUnit) then {