| Blockland Forums > Modification Help |
| Doing a container search in a rectangular prism with two given points. |
| << < (2/2) |
| Port:
--- Quote from: otto-san on February 10, 2012, 07:32:43 PM ---Didn't exactly work. --- End quote --- --- Quote from: Port on February 10, 2012, 07:30:49 PM ---There is probably a more efficient way, but this should work. Also, this code assumes that the first point is on the negative axis (e.g. 2 2 2 and 4 4 4, not 4 4 4 and 2 2 2, but that's an easy fix anyway). --- End quote --- --- Quote from: otto-san on February 10, 2012, 07:32:43 PM ---Just realised you did this: initContainerRadiusSearch( %center, vectorDist( %vec0, %vec1 ) * 4, %mask ); The second argument has to be a vector, doesn't it? --- End quote --- ::initContainerRadiusSearch usage: (Point3F pos, float radius, bitset mask)Start a search for items within radius of pos, filtering by bitset mask. --- Code: ---function getRectCenter( %vec0, %vec1 ) { if ( vectorLen( %vec0 ) >= vectorLen( %vec1 ) ) { return vectorAdd( %vec0, vectorScale( vectorSub( %vec1, %vec0 ), 0.5 ) ); } else { return vectorAdd( %vec1, vectorScale( vectorSub( %vec0, %vec1 ), 0.5 ) ); } } function doStuff( %vec0, %vec1, %mask ) { %val = ( vectorLen( %vec0 ) >= vectorLen( %vec1 ) ); %center = getRectCenter( %vec0, %vec1 ); initContainerRadiusSearch( %center, vectorDist( %vec0, %vec1 ) * 4, %mask ); while ( isObject( %obj = containerSearchNext() ) { %pos = %obj.getPosition(); %dif0 = vectorSub( %pos, %vec0 ); %dif1 = vectorSub( %vec1, %pos ); if ( getWord( %dif0, 0 ) < 0 || getWord( %dif0, 1 ) < 0 || getWord( %dif1, 2 ) < 0 ) { continue; } if ( getWord( %dif1, 0 ) < 0 || getWord( %dif1, 1 ) < 0 || getWord( %dif1, 2 ) < 0 ) { continue; } // do stuff with %obj } } --- End code --- |
| otto-san:
OH that was radius search. I was thinking box search. Maybe I should have read it more carefully, haha. I'll try that, thanks. |
| Port:
The reason I'm using a radius search instead of box search is because the mathematical formulas that Torque uses for comparing intersections between the search box and object world boxes are really weird. |
| Slicksilver:
--- Quote from: Port on February 10, 2012, 08:38:40 PM ---The reason I'm using a radius search instead of box search is because the mathematical formulas that Torque uses for comparing intersections between the search box and object world boxes are really weird. --- End quote --- I can honestly say I've never had an issue with initContainerBoxSearch. It's always fit my needs, especially with simple things like bricks. |
| Navigation |
| Message Index |
| Previous page |