View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:10 pm



Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
 ATTN: Boxes 
Author Message
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post ATTN: Boxes
Boxes are your friend. Need rectangular area checking? Use boxes. Need a simple, non-exact proximity check? Use a box!

http://datarealms.com/wiki/index.php/LuaDocs/Box

Boxes are your friend.

And remember kids, boxes are real simple to define: just two vectors!

self.box1 = Box(topleftcorner,bottomrightcorner);

the more you know!

Anyways, since boxes can be updated dynamically (!!!), drawn with bunkermodules, and are faster (in-engine area functions) they're a grate way to get things done. And aren't even used in official content! Shame on you, TLB. :D


Last edited by Grif on Tue Jul 07, 2009 8:20 am, edited 1 time in total.



Tue Jul 07, 2009 8:09 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: ATTN: Boxes
Grif wrote:
self.box1 = Box(topleftcorner,bottomrightcorner);

Don't you mean bottomrightcorner?


Tue Jul 07, 2009 8:17 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: ATTN: Boxes
Who are you quoting I would obviously never say something that foolish


Tue Jul 07, 2009 8:20 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: ATTN: Boxes
whoa, kickawesome. that should be fairly handy.


Tue Jul 07, 2009 11:22 am
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: ATTN: Boxes
I think
Code:
if (topleftcornerofbox.X - thing.Pos.X) < widthofbox and (topleftcornerofbox.Y - thing.Pos.Y) < heigthofbox then
is still faster because boxes have all sorts of useless stuff if you only want to check if something is inside the box.
Edit: As for proximity checks, you can use
Code:
if (thing1.Pos - thing2.Pos).Magnitude < desiredproximity then
for quick and exact results.


Tue Jul 07, 2009 11:47 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: ATTN: Boxes
Um?

if self.box:GetWithinBox(actor.pos) then

Seems more optimized to me?


Tue Jul 07, 2009 4:42 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: ATTN: Boxes
Grif wrote:
Um?

if self.box:GetWithinBox(actor.pos) then

Seems more optimized to me?


What about defining the box? How would one do that?
Also another thing has been bothering me with the proximity checks is what is the difference between all these proximity checks?

TLB's conveyor area check:
Code:
if (item.Pos.X >= self.Pos.X - 15) and (item.Pos.X <= self.Pos.X + 15) and (item.Pos.Y >= self.Pos.Y - 16) and (item.Pos.Y <= self.Pos.Y + 16) then


Another big proximity check:
Code:
local curdist = 600;
for actor in MovableMan.Actors do
      local avgx = actor.Pos.X - self.Pos.X;
      local avgy = actor.Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if dist < curdist then
          curdist = dist;


Kyred's proximity check:
Code:
if math.abs(actor.Pos.X - self.Pos.X) < 40 and math.abs(actor.Pos.Y - self.Pos.Y) < 40 then


The Magnitude() thing:
Code:
if (thing1.Pos - thing2.Pos).Magnitude < desiredproximity then



What are the difference between these(+ this box thing) and which is the most best/efficient method for checking if something is within proximity? And do any of these check for the nearest object if there are more than one within the proximity?


Tue Jul 07, 2009 5:42 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: ATTN: Boxes
Okay.

TLB's: Box

"Big proximity check": Circle.

Magnitude "thing": Circle

Box check: Box.

That's the "shape" each of these make, in essence.


Tue Jul 07, 2009 7:17 pm
Profile
User avatar

Joined: Sun May 11, 2008 12:50 pm
Posts: 899
Reply with quote
Post Re: ATTN: Boxes
I was looking at these functions a few days ago, they seem preatty awesome (I'll definitely be using them in the future).


Tue Jul 07, 2009 7:34 pm
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: ATTN: Boxes
Boxes vs circles:
Circles - More accurate for finding distance, but slower. With SceneMan:ShortestDistance, it can handle X warp.
Boxes - Less accurate for distance, but faster.


Tue Jul 07, 2009 7:52 pm
Profile
User avatar

Joined: Thu May 28, 2009 3:59 pm
Posts: 209
Reply with quote
Post Re: ATTN: Boxes
All of my attempts to kludge something together have been failing. Currently with a "attempt to call method 'GetWithinBox' (a nil value)"
Code:
function Update(self)
   self.boxTL = Vector(self.Pos.X - 24 , self.Pos.Y + 24) --hopefully up and to the left 24 pixels
   self.boxBR = Vector(self.Pos.X + 24 , self.Pos.Y - 24) --hopefully down and to the right 24 pixels
   self.boxboundary = Box(self.boxTL , self.boxBR)
   for p in MovableMan.Particles do
      if p.PresetName == "cube edge glow" then
         if p.Pos:GetWithinBox(self.boxboundary) then  -- line 9
         else
--            p.Lifetime = 1
            p.ToDelete = True;
         end
      end
   end
end

Could someone post a clearer bit of code for how to actually check if something is or is not within a defined box?


Last edited by Asatruer on Tue Jul 07, 2009 10:45 pm, edited 1 time in total.



Tue Jul 07, 2009 10:41 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: ATTN: Boxes
First of all, why is reversed. You need - instead of plus. So you're top left corner is your bottom left corner and your bottom right corner is your bottom right corner.


Tue Jul 07, 2009 10:43 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: ATTN: Boxes
Grif wrote:
if self.box:GetWithinBox(actor.pos) then

I think you meant:
Code:
if self.box:WithinBox(actor.pos) then


Tue Jul 07, 2009 10:44 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: ATTN: Boxes
I didn't have any documentation when I coded most of the vanilla content :P
Anyway, I'll probably end up using these, but the speed increase will be marginal at best. The part that lags is cycling through all actors, which this still has to do.


Tue Jul 07, 2009 10:51 pm
Profile WWW
User avatar

Joined: Thu May 28, 2009 3:59 pm
Posts: 209
Reply with quote
Post Re: ATTN: Boxes
Mind wrote:
First of all, why is reversed. You need - instead of plus.
by "why" you meant Y, right?
Code:
   self.boxTL = Vector(self.Pos.X - 24 , self.Pos.Y - 24)
   self.boxBR = Vector(self.Pos.X + 24 , self.Pos.Y + 24)
didn't help.
mail2345 wrote:
I think you meant:
Code:
if self.box:WithinBox(actor.pos) then

changing from GetWithinBox to WithinBox did not help, and neither did doing both.


Tue Jul 07, 2009 11:39 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.083s | 13 Queries | GZIP : Off ]