o5_ 7 Posted April 6, 2017 Need a little help... What I hope to achieve with my script is to furnish structures passed to it. The plan is to profile the building based on its type so we dont outfit a mud-hut with big screen TV and such. I need help with placement. I think the best way is to get the boundingboxreal of an object or furniture and then check it for collision/intersection (of structure walls and such) based on one of the randomly selected building positions. Every time I run lineIntersectsSurface it returns null objects. What's the best way to accomplish this? Thanks guys! This community is the best! Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
Savage_Donkey 243 Posted April 6, 2017 Have you taken a look at the TPW furniture script? It's part of TPW mods and does what you're looking for. Share this post Link to post Share on other sites
o5_ 7 Posted April 6, 2017 No... I'll check it out tonight. Thanks. Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
Midnighters 152 Posted April 6, 2017 use configClasses in combo with the base class name: "ThingX" it'll pull all of those out as a config entry so: "(configName (_x)) isKindOf['ThingX',configFile >> 'CfgVehicles']" configClasses(configFile >> "CfgVehicles"); and to extract the classname (getText(_x >> "_generalMacro")); Share this post Link to post Share on other sites
o5_ 7 Posted April 6, 2017 Thanks midnighters. I wasn't familiar with _generalMacro. Do you have any suggestions for finding a suitable location inside a structure? Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
Midnighters 152 Posted April 6, 2017 1 hour ago, o5_ said: Thanks midnighters. I wasn't familiar with _generalMacro. Do you have any suggestions for finding a suitable location inside a structure? Sent from my LG-H811 using Tapatalk These two commands are great for this very thing: buildingPos and buildingExit _generalMacro is what the game uses to reference the config entry. So for weapons like "SMG_04" that'd refer to the Protector 9MM I Believe. Take a look at the buildingPos command specifically, Quote Since Arma 3 v.155.133934 if index -1 is supplied, the command will return array with all available positions. that'll allow you to either select a random building position or select a specific one. Share this post Link to post Share on other sites
o5_ 7 Posted April 6, 2017 Again I appreciate your help. I already use this command. I guess i didn't add enough info. I have selected the structure and even selected a random position in the building but sometime when I spawn a piece of furniture it clips walls and bugs out. I need a pre-check to see if the object will spawn without touching walls. I imagine lineIntersectsSurface could work but I cant make sense of the return. Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
Midnighters 152 Posted April 6, 2017 2 hours ago, o5_ said: Again I appreciate your help. I already use this command. I guess i didn't add enough info. I have selected the structure and even selected a random position in the building but sometime when I spawn a piece of furniture it clips walls and bugs out. I need a pre-check to see if the object will spawn without touching walls. I imagine lineIntersectsSurface could work but I cant make sense of the return. Sent from my LG-H811 using Tapatalk Oh. Awesome, sounds like you've got it covered then. Share this post Link to post Share on other sites
o5_ 7 Posted April 6, 2017 SMH.... No, no I don't. I need an intersection/collision/proximity check to ensure my furniture doesn't bug out from clipping on walls or anything for that matter. Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
o5_ 7 Posted April 7, 2017 So I looked at the TPW mods script and it's far simpler than I imagined, which is a good thing, but not dynamic. They use prearranged templates based on the structure. My idea is to PREDETERMINE what furniture to use based on the structure, BUT the placement would be completely random and/or dynamic. Sent from my LG-H811 using Tapatalk Share this post Link to post Share on other sites
Midnighters 152 Posted April 7, 2017 2 hours ago, o5_ said: So I looked at the TPW mods script and it's far simpler than I imagined, which is a good thing, but not dynamic. They use prearranged templates based on the structure. My idea is to PREDETERMINE what furniture to use based on the structure, BUT the placement would be completely random and/or dynamic. Sent from my LG-H811 using Tapatalk I think the idea is great, but it may be beyond anybody's ability right now to do so :( Share this post Link to post Share on other sites
o5_ 7 Posted April 8, 2017 Making progress... here is what I have so far.r. fnc_furniture_placement = { _position = (_this param [0, [], [[]]]); _object = (_this param [1]); _bbr = (boundingBoxReal _object); _house = 0; { _pos1ATL = (_position vectorAdd (_x select 0)); _pos2ATL = (_position vectorAdd (_x select 1)); _pos1ASL = (ATLtoASL _pos1ATL); _pos2ASL = (ATLtoASL _pos2ATL); lineIntersectsSurfaces [ _pos1ASL, _pos2ASL, objNull, objNull, true, 1, "GEOM", "NONE" ] select 0 params ["","","","_house"]; _color = [1,1,1,1]; if (not ([_house,0] call BIS_fnc_areEqual)) then { hint str _house; _color = [1,0,0,1]; }; [[_pos1ATL,_pos2ATL],_color] call fnc_line; } forEach [_bbr]; }; fnc_line = { [(_this select 0), (_this select 1)] spawn { _pos = (_this select 0); _pos1 = (_pos select 0); _pos2 = (_pos select 1); waitUntil { drawLine3d [_pos1, _pos2, (_this select 1)]; }; }; }; _building = (nearestBuilding (getMarkerPos "house")); _buildingPositions = ([_building] call BIS_fnc_buildingPositions); _numberOfPositions = (count _buildingPositions); _table = ("OfficeTable_01_new_F" createVehicle [0,0,0]); _house_pos = 0; while {true} do { _house_pos = (_building buildingPos (floor (random (_numberOfPositions)))); _house_pos set [2,((_house_pos select 2) + .5)]; [_house_pos, _table] call fnc_furniture_placement; sleep 6; }; the issue is this only checks along a line from 1 boundingBox corner to the other. I think I should run 4 lineIntersectsSurface check for every boundingBox corner. Does anyone know how I can do this? Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 8, 2017 The following thoughts are very simple and it might be that they are not fitting your problem correct. It might be that you have to use some more complex math to get ur desired points to intersect. What I can say is that the following is correct if the bounding box is not rotated away from x, y and z axis of the grid. What you are intersect upto now is from x1,y1,z1 to x2,y2,z2 these are the checks that u want additionally: from x1, y2, z1 to x2, y1, z2 from x2, y1, z1 to x1, y2, z2 from x2, y2, z1 to x1,y1, z2 Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted April 8, 2017 Could be an easier approach: Place furniture inside a building Get the building object via cursortarget Make an array containing furniture type, direction and position (_building worldToModel (ASLtoAGL (getPosATL _furniture))) Repeat step 1-3 until you have a few furniture variations for that building Spawn random furniture template based on building type using modelToWorld and the previously stored position If there's interest I could try to work out something like this. Cheers Share this post Link to post Share on other sites
o5_ 7 Posted April 8, 2017 Thanks sarogahtyp! One more question... how can i simulate the rotation of the object as all my tests show the boundingBox vectors as if the object was at 0*. like _object setDir 0; ? Thanks for the help. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 8, 2017 Man! A friend of mine who is mathematician would say: "This is NOT superficial!" but I ll look if I can find some math u could use. but it ll take a while. maybe u r faster if u look urself which math is needed to rotate things in space. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 8, 2017 (edited) I did find all things you could need. if I understood all of this again and can tell u how u can use it then then I ll post it :-) Info you need: https://www.youtube.com/watch?v=gj6TJEyazO8 tensor_build.sqf /* File tensor_build.sqf Description: builds a rotation tensor which is needed to rotate a vector in space Arguments: 0 - desired rotation angle for x-axis 1 - desired rotation angle for y-axis 2 - desired rotation angle for z-axis Return value: rotation tensor */ private [ "_ct", "_cr", "_cp", "_st", "_sr", "_sp", "_rotation" ]; _ct = cos(_this select 0); _cr = cos(_this select 1); _cp = cos(_this select 2); _st = sin(_this select 0); _sr = sin(_this select 1); _sp = sin(_this select 2); _rotation = [ [_cp*_cr, -1*_sp*_ct + _cp*_sr*_st, _sp*_st + _cp*_sr*_ct], [_sp*_cr, _cp*_ct + _sp*_sr*_st, -1*_cp*_st + _sp*_sr*_ct], [-1*_sr, _cr*_st, _cr*_ct] ]; _rotation tensor_apply.sqf /* File tensor_apply.sqf Description: rotates a vector with usage of the prior build rotation tensor Arguments: 0 - vector which should be rotated 1 - rotation tensor Return value: rotated vector */ private[ "_v", "_r", "_r0", "_r1", "_r2", "_newVector" ]; _v = _this select 0; _r = _this select 1; _r0 = _r select 0; _r1 = _r select 1; _r2 = _r select 2; _newVector = [ (_v select 0)*(_r0 select 0) + (_v select 1)*(_r1 select 0) + (_v select 2)*(_r2 select 0), (_v select 0)*(_r0 select 1) + (_v select 1)*(_r1 select 1) + (_v select 2)*(_r2 select 1), (_v select 0)*(_r0 select 2) + (_v select 1)*(_r1 select 2) + (_v select 2)*(_r2 select 2) ]; _newVector Edited April 8, 2017 by sarogahtyp Added headers to scripts Share this post Link to post Share on other sites
o5_ 7 Posted April 8, 2017 You're a great help and I appreciate it! I'm testing now. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 8, 2017 these are arma 2 scripts. u should use params in it instead of those "_this select x" lines. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 8, 2017 how it works: tensor_build.sqf has 3 input parameters. these are the angles a vector should be rotated with. so you have to pass ur desired rotation angles for x, y and z axis. the script returns a rotation tensor which is used in tensor_apply.sqf tensor_apply. sqf has 2 input parameters. the vector which should be rotated and the rotation tensor which was returned by tensor_build. sqf It just returns the rotated vector. EDIT: I updated the scripts with a clarifying header Share this post Link to post Share on other sites
Larrow 2822 Posted April 8, 2017 Just get the bound position relative to the _object in its model space. This will give you the correct position. _object modelToWorld _boundVector; OR As per Saro you can calculate the rotation. [ _boundVector, getDir _object ] call BIS_fnc_rotateVector2D First would be faster as your dealing with modelSpace (bounds) coordinates already. Share this post Link to post Share on other sites
Tankbuster 1747 Posted April 8, 2017 I did something similar ages ago. I shoved the objects up against a wall, then faced them towards the centre of the building in script. Most of the time, it looked decent and was pretty quick and cpu cheap. Share this post Link to post Share on other sites
o5_ 7 Posted April 9, 2017 Thanks everyone for the pointers, especially you @ sarogahtyp. The functions you've given me work. I was afraid the lineIntersectsSurface and vector rotating functions would be heavy but they're surprisingly fast. My next task is to map out the walls of the structure. Again, thanks for the help Gents. Share this post Link to post Share on other sites