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 * Author: F3 Project, Head, SilentSpike
* Handles camera manipulation according to input * Handles free camera manipulation according to input
* *
* Arguments: * Arguments:
* None <NIL> * None <NIL>
@ -16,48 +16,41 @@
#include "script_component.hpp" #include "script_component.hpp"
// Kill PFH when display is closed // Kill PFH when not in free cam (or display is closed)
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; if ((GVAR(camMode) != 0) || isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Different behaviour based on camera mode _oldPos = getPosASL GVAR(camera);
switch (GVAR(camMode)) do { _mX = 0;
case 0: { // Free _mY = 0;
_oldPos = getPosASL GVAR(camera); _mZ = 0;
_mX = 0; if (GVAR(camDolly) select 0) then { // Forward
_mY = 0; _mY = _mY + GVAR(camSpeed);
_mZ = 0;
if (GVAR(camDolly) select 0) then { // Forward
_mY = _mY + GVAR(camSpeed);
};
if (GVAR(camDolly) select 1) then { // Backward
_mY = _mY - GVAR(camSpeed);
};
if (GVAR(camDolly) select 2) then { // Left
_mX = _mX - GVAR(camSpeed);
};
if (GVAR(camDolly) select 3) then { // Right
_mX = _mX + GVAR(camSpeed);
};
if (GVAR(camBoom) select 0) then { // Up
_mZ = _mZ + 0.5;
};
if (GVAR(camBoom) select 1) then { // Down
_mZ = _mZ - 0.5;
};
_pan = (GVAR(camPan) + 360) % 360;
_x = (_oldPos select 0) + (_mX * cos(_pan)) + (_mY * sin(_pan));
_y = (_oldPos select 1) - (_mX * sin(_pan)) + (_mY * cos(_pan));
_z = (_oldPos select 2) + _mZ;
// Prevent camera going under terrain
GVAR(camPos) = [_x,_y,_z max (getTerrainHeightASL [_x,_y])];
// Update camera position and rotation
GVAR(camera) setPosASL GVAR(camPos);
GVAR(camera) setDir GVAR(camPan);
[GVAR(camera), GVAR(camTilt), GVAR(camBank)] call BIS_fnc_setPitchBank;
};
case 1: { // Internal
};
}; };
if (GVAR(camDolly) select 1) then { // Backward
_mY = _mY - GVAR(camSpeed);
};
if (GVAR(camDolly) select 2) then { // Left
_mX = _mX - GVAR(camSpeed);
};
if (GVAR(camDolly) select 3) then { // Right
_mX = _mX + GVAR(camSpeed);
};
if (GVAR(camBoom) select 0) then { // Up
_mZ = _mZ + 0.5;
};
if (GVAR(camBoom) select 1) then { // Down
_mZ = _mZ - 0.5;
};
_pan = (GVAR(camPan) + 360) % 360;
_x = (_oldPos select 0) + (_mX * cos(_pan)) + (_mY * sin(_pan));
_y = (_oldPos select 1) - (_mX * sin(_pan)) + (_mY * cos(_pan));
_z = (_oldPos select 2) + _mZ;
// Prevent camera going under terrain
GVAR(camPos) = [_x,_y,_z max (getTerrainHeightASL [_x,_y])];
// Update camera position and rotation
GVAR(camera) setPosASL GVAR(camPos);
GVAR(camera) setDir GVAR(camPan);
[GVAR(camera), GVAR(camTilt), GVAR(camBank)] call BIS_fnc_setPitchBank;

View File

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

View File

@ -16,24 +16,22 @@
#include "script_component.hpp" #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; _leftButton = GVAR(mouse) select 0;
_rightButton = GVAR(mouse) select 1; _rightButton = GVAR(mouse) select 1;
_oldX = GVAR(mousePosOld) select 0; _oldX = GVAR(mousePos) select 0;
_oldY = GVAR(mousePosOld) select 1; _oldY = GVAR(mousePos) select 1;
// Get change in pos // Get change in pos
_deltaX = _oldX - _x; _deltaX = _oldX - _x;
_deltaY = _oldY - _y; _deltaY = _oldY - _y;
GVAR(mouseDelta) = [_deltaX, _deltaY];
if (_rightButton && !_leftButton) then { if (_rightButton && !_leftButton) then {
GVAR(camPan) = GVAR(camPan) - (_deltaX * 360); GVAR(camPan) = GVAR(camPan) - (_deltaX * 360);
GVAR(camTilt) = ((GVAR(camTilt) + (_deltaY * 180)) min 89) max -89; 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 // HUD stuff
showCinemaBorder false; showCinemaBorder false;
cameraEffectEnableHUD false; cameraEffectEnableHUD false;
// Handle camera movement
[FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler;
} else { } else {
// When null unit is given choose random // When null unit is given choose random
if (isNull _newUnit) then { if (isNull _newUnit) then {