function to return light intensity recieved from another object

This commit is contained in:
commy2 2015-04-07 18:54:53 +02:00
parent deabbcd840
commit 98f7125171
3 changed files with 60 additions and 10 deletions

View File

@ -112,6 +112,7 @@ PREP(isModLoaded);
PREP(isPlayer); PREP(isPlayer);
PREP(isTurnedOut); PREP(isTurnedOut);
PREP(letterToCode); PREP(letterToCode);
PREP(lightIntensityFromObject);
PREP(loadPerson); PREP(loadPerson);
PREP(loadPersonLocal); PREP(loadPersonLocal);
PREP(loadSettingsFromProfile); PREP(loadSettingsFromProfile);

View File

@ -20,18 +20,11 @@ _light = _this select 1;
private "_config"; private "_config";
_config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "Reflectors" >> _light; _config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "Reflectors" >> _light;
// world position and direction private ["_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"];
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"];
_intensity = getNumber (_config >> "intensity"); _intensity = getNumber (_config >> "intensity");
_position = getText (_config >> "position");
_direction = getText (_config >> "direction");
_innerAngle = getNumber (_config >> "innerAngle"); _innerAngle = getNumber (_config >> "innerAngle");
_outerAngle = getNumber (_config >> "outerAngle"); _outerAngle = getNumber (_config >> "outerAngle");

View File

@ -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