Efficient building collision/validation
by SimU Group · in RTS Starter Kit · 10/09/2007 (1:04 am) · 3 replies
I'm trying to set the texture of the building marker being placed to RED if it is in an invalid position, GREEN otherwise. I've invoked a Con::executef function when On3DMouseDown is invoked in the GUIRTSTSCtrl and I named it 'OnMouseMove' and I passed the position parameters to it.
Here are the 3 rules of validation and how I currently implement them:
1-) Building should not be on water (Check if Z is < 255)
2-) Building should be on flat terrain (Loop over some points between the X and Y limits of the worldBox of the object and store the maximum and minimum terrain height. Invalid if the difference is more than 3)
Of course this is tooooooooo slow. I can do some box intersection when testing collision with other bulidings which would be more efficient, but I'm sure that torque provide a method to check for buildings collision.
Any suggestions are highly appreciated....
Here are the 3 rules of validation and how I currently implement them:
1-) Building should not be on water (Check if Z is < 255)
2-) Building should be on flat terrain (Loop over some points between the X and Y limits of the worldBox of the object and store the maximum and minimum terrain height. Invalid if the difference is more than 3)
%worldBox = %b.getWorldBox();
%minH = 1000000;
%maxH = 0;
for (%x = getWord(%worldBox, 0) ; %x < getWord(%worldBox, 3) ; %x += 2)
for (%y = getWord(%worldBox, 1) ; %y < getWord(%worldBox, 4) ; %y += 2)
{
%z = getTerrainHeight(%x SPC %y);
if (%z < %minH) %minH = %z;
if (%z > %maxH) %maxH = %z;
}
if (%maxH - %minH > 5) return 2;3-) Building shouldn't intersect any other building. (I do the same with the terrain with some point in all the other buildings)%worldBox = %b.getWorldBox();
for (%i = 0 ; %i < Buildings.getCount() ; %i++)
{
%t = Buildings.getObject(%i);
%box = %t.getWorldBox();
for (%x = getWord(%worldBox, 0) ; %x < getWord(%worldBox, 3) ; %x += 2)
if (getWord(%Box, 0) <= %x && %x <= getWord(%box, 3))
for (%y = getWord(%worldBox, 1) ; %y < getWord(%worldBox, 4) ; %y += 2)
if (getWord(%Box, 1) <= %y && %y <= getWord(%box, 4))
{
%coll = %t;
return 3;
}
}Of course this is tooooooooo slow. I can do some box intersection when testing collision with other bulidings which would be more efficient, but I'm sure that torque provide a method to check for buildings collision.
Any suggestions are highly appreciated....
#2
any ideas ??
10/10/2007 (6:49 am)
Thanks... the ray casts works perfectly when checking the buildings collision.. but how about the terrain hieght checking?? Maybe I can implement a Range Minimum(Maximum) Query (RMQ) algorithm which requires some sort of precomputation... but I'll have to redo the calculations each time the terrain changes...any ideas ??
#3
That was a little debate about RTSUnits running on slopes, the system would be too much for units, but you should give it a try for placing buildings.
Edit: Typo
10/10/2007 (8:38 am)
Quoting Johnathan Moore on other thread:Quote:
"...you could put in a method containing two raycasts onto the terrain in front and behind the unit, then get the angle between the two contact points. Although it would work better with 4(2 to the sides aswell)."
That was a little debate about RTSUnits running on slopes, the system would be too much for units, but you should give it a try for placing buildings.
Edit: Typo
Torque 3D Owner Novack
CyberianSoftware
And, you should check this thread: Building placement validation
Although I dont know the final status as a "formal" resource, its a valuable work.