diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index be8325a42c..95a639b943 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -112,6 +112,7 @@ PREP(isModLoaded); PREP(isPlayer); PREP(isTurnedOut); PREP(letterToCode); +PREP(lightIntensityFromObject); PREP(loadPerson); PREP(loadPersonLocal); PREP(loadSettingsFromProfile); diff --git a/addons/common/functions/fnc_getLightProperties.sqf b/addons/common/functions/fnc_getLightProperties.sqf index 3d00314aae..ee1884ac1b 100644 --- a/addons/common/functions/fnc_getLightProperties.sqf +++ b/addons/common/functions/fnc_getLightProperties.sqf @@ -20,18 +20,11 @@ _light = _this select 1; private "_config"; _config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "Reflectors" >> _light; -// world position and direction -private ["_position", "_direction"]; - -_position = _vehicle modelToWorld (_vehicle selectionPosition getText (_config >> "position")); -_direction = _vehicle modelToWorld (_vehicle selectionPosition getText (_config >> "direction")); - -_direction = _position vectorFromTo _direction; - -// Intensity, angles -private ["_intensity", "_innerAngle", "_outerAngle"]; +private ["_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; _intensity = getNumber (_config >> "intensity"); +_position = getText (_config >> "position"); +_direction = getText (_config >> "direction"); _innerAngle = getNumber (_config >> "innerAngle"); _outerAngle = getNumber (_config >> "outerAngle"); diff --git a/addons/common/functions/fnc_lightIntensityFromObject.sqf b/addons/common/functions/fnc_lightIntensityFromObject.sqf new file mode 100644 index 0000000000..cf9e215403 --- /dev/null +++ b/addons/common/functions/fnc_lightIntensityFromObject.sqf @@ -0,0 +1,56 @@ +/* + * Author: commy2 + * Calculate light intensity object 1 recieves from object 2 + * + * Arguments: + * 0: Object that recieves light (Object) + * 1: Object that emits light (Object) + * + * Return Value: + * Brightest light level + * + */ +#include "script_component.hpp" + +private ["_unit", "_lightSource"]; + +_unit = _this select 0; +_lightSource = _this select 1; + +private "_unitPos"; +_unitPos = _unit modelToWorld (_unit selectionPosition "spine3"); + +private ["_lights", "_lightLevel"]; + +_lights = [_lightSource] call FUNC(getTurnedOnLights); + +_lightLevel = 0; + +{ + private ["_properties", "_intensity", "_innerAngle", "_outerAngle", "_position", "_direction", "_directionToUnit", "_distance", "_angle"]; + + _properties = [_lightSource, _x] call FUNC(getLightProperties); + + // @todo intensity affects range? + //_intensity = _properties select 0; + + _innerAngle = (_properties select 3) / 2; + _outerAngle = (_properties select 4) / 2; + + // get world position and direction + _position = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 1)); + _direction = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 2)); + + _direction = _position vectorFromTo _direction; + _directionToUnit = _position vectorFromTo _unitPos; + + _distance = _unitPos distance _position; + _angle = acos (_direction vectorDotProduct _directionToUnit); + + _lightLevel = _lightLevel max ((linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])); + +//systemChat format ["%1 %2", (linearConversion [0, 30, _distance, 1, 0, true]), (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])]; + +} forEach _lights; + +_lightLevel