Skip to content
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

Merged
merged 3 commits into from
Jun 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 27 additions & 39 deletions addons/common/fnc_headDir.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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

Copy link
Contributor

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 ^

Copy link
Contributor Author

@654wak654 654wak654 Jun 22, 2016

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.

};

_dif = _angle - _azimuth;
private _diff = -_azimuth;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much cleaner, but what happened to _angle ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roger


if !(_offset isEqualTo "") then {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
!("base_marker" isEqualTo "") will return true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I read it as isEqualType

ADD(_diff,_unit getDir ([_offset] call CBA_fnc_getPos));
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this error if _offsetobject is a marker (STRING)?

Copy link
Contributor Author

@654wak654 654wak654 Jun 22, 2016

Choose a reason for hiding this comment

The 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]