-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update fnc_headDir #390
Update fnc_headDir #390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,49 +54,37 @@ Author: | |
#include "script_component.hpp" | ||
SCRIPT(headDir); | ||
|
||
private["_azimuth", "_angle", "_dif", "_infov", "_object", "_threed", "_do"]; | ||
|
||
params ["_unit"]; | ||
_object = param [1,_unit]; | ||
_threed = false; | ||
|
||
_do = (typeName _object != typeName _unit); | ||
if (!_do) then { | ||
_do = (_object != _unit); | ||
}; | ||
|
||
if (_do) then { | ||
_angle = [(_unit call CBA_fnc_getPos),(_object call CBA_fnc_getPos)] call BIS_fnc_dirTo; | ||
} else { | ||
_angle = 0; | ||
}; | ||
if (_unit != player) then | ||
{ | ||
_azimuth = getdir _unit; | ||
params [ | ||
["_unit", objNull, [objNull]], | ||
["_offset", ""] | ||
]; | ||
|
||
private _azimuth = 0; | ||
private _isExternalCam = false; | ||
if (_unit != call CBA_fnc_currentUnit) then { | ||
_azimuth = getDir _unit; | ||
} else { | ||
private ["_position","_viewPos","_vector","_magnitude"]; | ||
_position = positionCameraToWorld [0, 0, 0]; | ||
_threed = if ((_position distance _unit)>2) then {true} else {false}; | ||
_viewPos = positionCameraToWorld [0, 0, 99999999]; | ||
_vector = [ | ||
(_viewPos select 0) - (_position select 0), | ||
(_viewPos select 1) - (_position select 1), | ||
(_viewPos select 2) - (_position select 2) | ||
]; | ||
_magnitude = [0, 0, 0] distance _vector; | ||
_vector = [ | ||
(_vector select 0) / _magnitude, | ||
(_vector select 1) / _magnitude, | ||
(_vector select 2) / _magnitude | ||
]; | ||
private _camPos = AGLToASL positionCameraToWorld [0, 0, 0]; | ||
_isExternalCam = (_camPos vectorDistance getPosASL _unit) > 2; | ||
private _viewPos = AGLToASL positionCameraToWorld [0, 0, 99999999]; | ||
private _vector = _viewPos vectorDiff _camPos; | ||
_vector = _vector vectorMultiply (1 / vectorMagnitude _vector); | ||
_azimuth = (_vector select 0) atan2 (_vector select 1); | ||
_azimuth = [_azimuth] call CBA_fnc_simplifyAngle; | ||
}; | ||
|
||
_dif = _angle - _azimuth; | ||
private _diff = -_azimuth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks much cleaner, but what happened to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the relative angle code to lines 76-78: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. roger |
||
|
||
if !(_offset isEqualTo "") then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but now it no longer works for markers at all, or am I wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you supply any other string than an empty string, it will return true: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. I read it as |
||
ADD(_diff,_unit getDir ([_offset] call CBA_fnc_getPos)); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this error if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could work: ["_offsetObject", ""]
later on:
if !(_offsetObject isEqualTo "") then { Update: It does work. |
||
if (_diff < 0) then { | ||
ADD(_diff,360); | ||
}; | ||
if (_diff > 180) then { | ||
SUB(_diff,360); | ||
}; | ||
|
||
if (_dif < 0) then { _dif = 360 + _dif;}; | ||
if (_dif > 180) then { _dif = _dif - 360;}; | ||
_infov = if (abs(_dif) < 43) then {true} else {false}; | ||
private _inFOV = abs _diff < 43; | ||
|
||
[_azimuth,_dif,_infov,_threed] | ||
[_azimuth, _diff, _inFOV, _isExternalCam] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit strange that we use this here, but then have L81-86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need this. The angle is "simplified" with ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
81-86 are for after the offset is applied. Could move the simplify after the offset and remove 81-86.
Plus they're for 2 different vars.