Data Realms Fan Forums
http://45.55.195.193/

ATTN: Boxes
http://45.55.195.193/viewtopic.php?f=73&t=15748
Page 1 of 2

Author:  Grif [ Tue Jul 07, 2009 8:09 am ]
Post subject:  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

Author:  mail2345 [ Tue Jul 07, 2009 8:17 am ]
Post subject:  Re: ATTN: Boxes

Grif wrote:
self.box1 = Box(topleftcorner,bottomrightcorner);

Don't you mean bottomrightcorner?

Author:  Grif [ Tue Jul 07, 2009 8:20 am ]
Post subject:  Re: ATTN: Boxes

Who are you quoting I would obviously never say something that foolish

Author:  Geti [ Tue Jul 07, 2009 11:22 am ]
Post subject:  Re: ATTN: Boxes

whoa, kickawesome. that should be fairly handy.

Author:  piipu [ Tue Jul 07, 2009 11:47 am ]
Post subject:  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.

Author:  Grif [ Tue Jul 07, 2009 4:42 pm ]
Post subject:  Re: ATTN: Boxes

Um?

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

Seems more optimized to me?

Author:  numgun [ Tue Jul 07, 2009 5:42 pm ]
Post subject:  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?

Author:  Mind [ Tue Jul 07, 2009 7:17 pm ]
Post subject:  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.

Author:  Roon3 [ Tue Jul 07, 2009 7:34 pm ]
Post subject:  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).

Author:  mail2345 [ Tue Jul 07, 2009 7:52 pm ]
Post subject:  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.

Author:  Asatruer [ Tue Jul 07, 2009 10:41 pm ]
Post subject:  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?

Author:  Mind [ Tue Jul 07, 2009 10:43 pm ]
Post subject:  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.

Author:  mail2345 [ Tue Jul 07, 2009 10:44 pm ]
Post subject:  Re: ATTN: Boxes

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

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

Author:  TheLastBanana [ Tue Jul 07, 2009 10:51 pm ]
Post subject:  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.

Author:  Asatruer [ Tue Jul 07, 2009 11:39 pm ]
Post subject:  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.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/