Author |
Message |
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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/BoxBoxes 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 |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: ATTN: Boxes
Grif wrote: self.box1 = Box(topleftcorner,bottomrightcorner);
Don't you mean bottomrightcorner?
|
Tue Jul 07, 2009 8:17 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ATTN: Boxes
Who are you quoting I would obviously never say something that foolish
|
Tue Jul 07, 2009 8:20 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: ATTN: Boxes
whoa, kickawesome. that should be fairly handy.
|
Tue Jul 07, 2009 11:22 am |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: ATTN: Boxes
Um?
if self.box:GetWithinBox(actor.pos) then
Seems more optimized to me?
|
Tue Jul 07, 2009 4:42 pm |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
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 |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
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 |
|
|
Roon3
Joined: Sun May 11, 2008 12:50 pm Posts: 899
|
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 |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
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 |
|
|
Asatruer
Joined: Thu May 28, 2009 3:59 pm Posts: 209
|
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 |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
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 |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
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 |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: ATTN: Boxes
I didn't have any documentation when I coded most of the vanilla content 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 |
|
|
Asatruer
Joined: Thu May 28, 2009 3:59 pm Posts: 209
|
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 |
|
|
|