Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 28 29 [30] 31 32 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 888001 times)

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #435 on: January 12, 2012, 06:37:06 pm »

Wait, I'm not so sure about this...

return (this.Right > r.Left && this.Left < r.Right && this.Top < r.Bottom && this.Bottom > r.Top);

In the above example, there is clearly an overlap, but assuming the red box is this then it's bottom is less than the green ones top (Remembering that top left is 0,0) and there for not all four conditions are filled.

This only checks for containment, not interception.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #436 on: January 12, 2012, 06:39:09 pm »

Screw me, I didn't take into account that you can't just negate the comparison operators if you're dealing with something that isn't a point. Forget what I said please.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #437 on: January 12, 2012, 06:43:03 pm »

See that is why I needed to bust out a pencil in the first place... Finding if things overlap is a bitch to do! Much easier to find if they don't, and reverse it.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #438 on: January 12, 2012, 06:54:38 pm »

Wait, I'm not so sure about this...

return (this.Right > r.Left && this.Left < r.Right && this.Top < r.Bottom && this.Bottom > r.Top);

In the above example, there is clearly an overlap, but assuming the red box is this then it's bottom is less than the green ones top (Remembering that top left is 0,0) and there for not all four conditions are filled.

This only checks for containment, not interception.

Wait, all four conditions are actually fulfilled. Or am I seeing something wrong?
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #439 on: January 12, 2012, 07:01:04 pm »

I think you might be reading it upside down.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #440 on: January 12, 2012, 07:01:27 pm »

Last one isn't (assuming topleft = 0,0).
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #441 on: January 12, 2012, 07:03:42 pm »

If topleft = 0.0 then bottomleft = n.0 > 0.0. So if A is below B, then A > B, which corresponds to the given situation, no? You would have been right if bottomleft = 0.0, but down is higher, not lower in this case. Unless top is actually bottom in your image (that is, top has the highest Y coordinate, not the lowest)
« Last Edit: January 12, 2012, 07:06:44 pm by Virex »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #442 on: January 12, 2012, 07:03:48 pm »

The intersection of two grid aligned squares in pseudocode:

(((B.maxX > A.maxX > B.minX) OR (B.maxX > A.minX > B.minX)) AND ((B.maxY > A.maxY > B.minY) OR (B.maxY > A.minY > B.minY))) OR (((A.maxX > B.maxX > A.minX) OR (A.maxX > B.minX > A.minX)) AND ((A.maxY > B.maxY > A.minY) OR (A.maxY > B.minY > A.minY)))

You can trade some efficiency for readability assuming a method that determines if a point is in a square and methods that return the corners of a square:

B.containsPoint(A.topleft) | B.containsPoint(A.topright) | B.containsPoint(A.bottomleft) | B.containsPoint(A.bottomright) | A.containsPoint(B.topleft) | A.containsPoint(B.topright) | A.containsPoint(B.bottomleft) | A.containsPoint(B.bottomright)
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #443 on: January 12, 2012, 07:07:58 pm »

Anything math related like that I just steal from elsewhere.  I stole mine from the libtcod python tutorial:

Code: [Select]
def intersect(self, other):
        #returns true if this rectangle intersects with another one
        return (self.x1 <= other.x2 and self.x2 >= other.x1 and
                self.y1 <= other.y2 and self.y2 >= other.y1)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #444 on: January 12, 2012, 07:09:52 pm »

Ok, well I'm wiling to go with that.
Libtcod has been pretty well worked over.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #445 on: January 12, 2012, 07:10:38 pm »

You guys are giving me nightmares of CS projects past...

...do you still need help with collision detection or do you collectively have it down now...?

Also, that didn't look like nearly as much snow until I started shoveling it...that took forever and I'm still thawing...
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #446 on: January 12, 2012, 07:15:44 pm »

Well while your offering...
Knowing if there is a collision is nice, but how would you go about finding firstly the depth of the collision, and secondly given an x and y speed, the place and time of collision?

And you can have it on my desk by Monday.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #447 on: January 12, 2012, 07:17:11 pm »

After 1.5 minutes of watching 30 rock on comedy central, my method is longer than necessary as there are dead paths.

(((B.maxX > A.maxX > B.minX) OR (B.maxX > A.minX > B.minX)) AND ((B.maxY > A.maxY > B.minY) OR (B.maxY > A.minY > B.minY))) OR ((A.maxX > B.maxX > A.minX) AND (A.maxY > B.maxY > A.minY))

You can trade some efficiency for readability assuming a method that determines if a point is in a square and methods that return the corners of a square:

B.containsPoint(A.topleft) | B.containsPoint(A.topright) | B.containsPoint(A.bottomleft) | B.containsPoint(A.bottomright) | A.containsPoint(B.topleft)

The reason for this is that if no corners of square A are inside square B, then either all or no corners of B will be inside A.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #448 on: January 12, 2012, 07:21:37 pm »

You... Ok there Nadaka?
I mean the entire reason we are going over this is because it is simpler than having a negator, so lets make sure it stays simpler than having a negator.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #449 on: January 12, 2012, 07:28:30 pm »

Calling 1 method 4 times on 1 object and once on another isn't simple enough?
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.
Pages: 1 ... 28 29 [30] 31 32 ... 796