Update to lineIntersectsSurfaces and params

This commit is contained in:
BaerMitUmlaut 2015-09-02 19:43:13 +02:00
parent c532d893c3
commit 93ea0c5654
4 changed files with 30 additions and 61 deletions

View File

@ -25,7 +25,7 @@ _objectsLeft = lineIntersectsWith [eyePos ACE_player, _posCheck, ACE_player, obj
_intersectsLeft = false; _intersectsLeft = false;
{ {
if (_x isKindOf "Static") exitWith {_intersectsLeft = true}; if (_x isKindOf "Static") exitWith {_intersectsLeft = true};
} foreach _objectsLeft; } count _objectsLeft;
if (!_intersectsLeft) exitWith {false}; if (!_intersectsLeft) exitWith {false};
@ -37,7 +37,7 @@ _objectsRight = lineIntersectsWith [eyePos ACE_player, _posCheck, ACE_player, ob
_intersectsRight = false; _intersectsRight = false;
{ {
if (_x isKindOf "Static") exitWith {_intersectsRight = true}; if (_x isKindOf "Static") exitWith {_intersectsRight = true};
} foreach _objectsRight; } count _objectsRight;
//for readability... //for readability...

View File

@ -3,11 +3,11 @@
* Handles tag destruction when the object they are attached to gets destroyed. * Handles tag destruction when the object they are attached to gets destroyed.
* *
* Arguments: * Arguments:
* None
*
* Return Value:
* 0: The tag that should get destroyed <OBJECT> * 0: The tag that should get destroyed <OBJECT>
* 1: The object the tag is attached to <OBJECT> * 1: The object the tag is attached to <OBJECT>
*
* Return Value:
* None
* *
* Example: * Example:
* [tag, object] call ace_tagging_fnc_handleTagDestruction * [tag, object] call ace_tagging_fnc_handleTagDestruction
@ -19,7 +19,7 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_tag", "_attachedTags", "_object"]; private ["_tag", "_attachedTags", "_object"];
PARAMS_2(_tag,_object); params ["_tag", "_object"];
if (count (_object getVariable [QGVAR(attachedTags), []]) == 0) then { if (count (_object getVariable [QGVAR(attachedTags), []]) == 0) then {
_object setVariable [QGVAR(attachedTags), [_tag]]; _object setVariable [QGVAR(attachedTags), [_tag]];

View File

@ -16,9 +16,9 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_color", "_tagPos", "_groundPos", "_vectorDirAndUp"]; private ["_tagPos", "_groundPos", "_vectorDirAndUp"];
PARAMS_1(_color); params ["_color"];
if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith { if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith {
["%1 is not a valid tag colour.", _color] call BIS_fnc_error; ["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
}; };
@ -42,9 +42,12 @@ ACE_player playActionNow "PutDown";
[{ [{
private ["_tag"]; private ["_tag"];
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15]; params ["_tagPos", "_vectorDirAndUp", "_color"];
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (eyePos ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0]; _tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 2) + '\' + str (floor (random 3)) + '.paa']; _tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + _color + '\' + str (floor (random 3)) + '.paa'];
_tag setPosATL (_this select 0); _tag setPosATL _tagPos;
_tag setVectorDirAndUp (_this select 1); _tag setVectorDirAndUp _vectorDirAndUp;
}, [_tagPos, _vectorDirAndUp, _color], 0.6] call EFUNC(common,waitAndExecute); }, [_tagPos, _vectorDirAndUp, _color], 0.6] call EFUNC(common,waitAndExecute);

View File

@ -1,6 +1,6 @@
/* /*
* Author: BaerMitUmlaut * Author: BaerMitUmlaut
* Creates a tag on a wall that is within 2m on front of the player. * Creates a tag on a wall that is on the closest surface within 2m on front of the player.
* *
* Arguments: * Arguments:
* 0: The colour of the tag (valid colours are black, red, green and blue) <STRING> * 0: The colour of the tag (valid colours are black, red, green and blue) <STRING>
@ -16,65 +16,31 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_color", "_eyepos", "_touchingPoints", "_pointCloser", "_pointFurther", "_posCheckCloser", "_posCheckFurther", "_touchingPoint"]; private ["_posIntersect"];
PARAMS_1(_color); params ["_color"];
if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith { if !((toLower _color) in ["black", "red", "green", "blue"]) exitWith {
["%1 is not a valid tag colour.", _color] call BIS_fnc_error; ["%1 is not a valid tag colour.", _color] call BIS_fnc_error;
}; };
//Cache eyepos in case player moves _posIntersect = ACE_player modelToWorldVisual [0, 2, 0];
_eyepos = eyePos ACE_player; _posIntersect set [2, (eyepos ACE_player) select 2];
_touchingPoints = []; ((lineIntersectsSurfaces [eyepos ACE_player, _posIntersect, ACE_player, objNull, true, 1, "FIRE", "NONE"]) select 0) params ["_touchingPoint", "_surfaceNormal", "", "_object"];
{
//When tagWall is called, we already know there is an object within 2m in front of us.
//We define two points (or rather distances from the player) where the wall is always in between.
_pointCloser = 0;
_pointFurther = 2;
for "_i" from 0 to 6 do {
//We need to reduce the distance between those points until we get a very precise position.
//This is done by checking if it is between the closer point and the point in between the two.
_posCheckCloser = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_posCheckCloser set [2, _eyepos select 2];
_posCheckFurther = ACE_player modelToWorldVisual [_x, (_pointCloser + ((_pointFurther - _pointCloser) / 2)), 0];
_posCheckFurther set [2, _eyepos select 2];
if (lineIntersects [_posCheckCloser, _posCheckFurther, ACE_player, objNull]) then {
//If it is, we move the further point to be closer to the closer point.
_pointFurther = _pointCloser + ((_pointFurther - _pointCloser) / 2);
} else {
//If it isn't, we move the closer point towards the further point.
_pointCloser = _pointCloser + ((_pointFurther - _pointCloser) / 2);
};
};
//We do this 7 times each a bit to the left and right of the player - that's definitely precise enough.
_touchingPoint = ACE_player modelToWorldVisual [_x, _pointCloser, 0];
_touchingPoint set [2, _eyepos select 2];
_touchingPoints pushBack (_touchingPoint);
} foreach [-0.5, 0.5];
ACE_player playActionNow "PutDown"; ACE_player playActionNow "PutDown";
[{ [{
private ["_tag", "_object", "_posCheck"]; private ["_tag"];
params ["_touchingPoint", "_surfaceNormal", "_color", "_object"];
_posCheck = ACE_player modelToWorldVisual [0, 2, 0]; playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (eyePos ACE_player), 10, 1, 15];
_posCheck set [2, (eyePos ACE_player) select 2];
_object = (lineIntersectsWith [_posCheck, eyePos player, ACE_player, objNull, true]) select 0;
playSound3D [QUOTE(PATHTO_R(sounds\spray.ogg)), ACE_player, false, (getPosASL ACE_player), 10, 1, 15];
_tag = "UserTexture1m_F" createVehicle [0,0,0]; _tag = "UserTexture1m_F" createVehicle [0,0,0];
_tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + (_this select 1) + '\' + str (floor (random 3)) + '.paa']; _tag setObjectTextureGlobal [0, '\z\ace\addons\tagging\UI\tags\' + _color + '\' + str (floor (random 3)) + '.paa'];
_tag setPosASL (((_this select 0 select 0) vectorAdd (_this select 0 select 1)) vectorMultiply 0.5); //Add 6cm so it doesn't get placed "into" the wall.
_tag setDir (((_this select 0) call BIS_fnc_dirTo) - 90); //6cm works with most building surfaces, but not with all of them. The LODs precision varies between 1cm and around 8cm+.
_tag setPosASL (_touchingPoint vectorAdd (_surfaceNormal vectorMultiply 0.06));
_tag setVectorDirAndUp [(_surfaceNormal vectorMultiply -1), [0,0,1]];
[[_tag, _object], QUOTE(FUNC(handleTagDestruction)), 1] call EFUNC(common,execRemoteFnc); [[_tag, _object], QUOTE(FUNC(handleTagDestruction)), 1] call EFUNC(common,execRemoteFnc);
}, [_touchingPoints, _color], 0.6] call EFUNC(common,waitAndExecute); }, [_touchingPoint, _surfaceNormal, _color, _object], 0.6] call EFUNC(common,waitAndExecute);