Switch to full style
Libraries, utilities, bootloaders...
Post a reply

Re: Basic Collision Detection help

Tue Aug 05, 2014 10:56 pm

inversesandwich wrote:I love sublime text and the stino plugin! MariaMole (http://dalpix.com/mariamole) is a great IDE though, and I've only just realised that they've released a Ubuntu version of it. Yay!


Is there any trick to getting Sublime + Stino to work with the Gamebuino? I haven't tried it yet but I'm hoping it's not to hard to set up.

Re: Basic Collision Detection help

Wed Aug 06, 2014 12:08 pm

It's really easy to set up, don't worry: https://github.com/Robot-Will/Stino

Re: Basic Collision Detection help

Sun Aug 17, 2014 6:05 pm

Was about to write a post that the collideRectRect function doesn't work if the second rectangle is completely within the first when I found this thread. I guess I should update the library.

Re: Basic Collision Detection help

Sun Aug 17, 2014 7:23 pm

Vraister wrote:Was about to write a post that the collideRectRect function doesn't work if the second rectangle is completely within the first when I found this thread. I guess I should update the library.

It's already fixed in the library ;)

Re: Basic Collision Detection help

Sun Aug 17, 2014 8:50 pm

I updated my library and the collideRectRect function is working correctly now ;-) thanks!

However, I noticed an inconsistency between the two collide functions. collidePointRect returns true only if the point overlaps the rectangle while collideRectRect returns true for an overlap as well as for touching rectangles. I updated the wiki to document this.

Re: Basic Collision Detection help

Sun Aug 17, 2014 8:59 pm

Yep this is not really consistent, what I think it should only return true when they overlap, not when they just touch. What do you think about that?

Re: Basic Collision Detection help

Sun Aug 17, 2014 9:24 pm

The name suggests that it will return true when they collide or in other words as soon as they touch. So I think the behaviour of the collideRectRect function is the correct one.

However, there might be a case for a second function to check for overlap.

Re: Basic Collision Detection help

Sun Aug 17, 2014 9:54 pm

I thought a bit more about it and the collidePointRect function has the correct behaviour. For example, you could move along the edge of a rectangle and that shouldn't count as a collision.

Sorry for my own confusion ;-)

Re: Basic Collision Detection help

Mon Aug 18, 2014 1:36 pm

It would be useful to have an additional collission-detection function for detecting pixel-perfect collission between bitmaps.

bitmapcollide(bitmap1,x1,y1,bitmap2,x1,y1)

This function would have to check pixel-by-pixel based on the two bitmaps and their positions on screen.

How about that?

Re: Basic Collision Detection help

Mon Aug 18, 2014 3:40 pm

yodasvideoarcade wrote:It would be useful to have an additional collission-detection function for detecting pixel-perfect collission between bitmaps.

bitmapcollide(bitmap1,x1,y1,bitmap2,x1,y1)

This function would have to check pixel-by-pixel based on the two bitmaps and their positions on screen.

How about that?



Does this do what you want it to do?
Code:
boolean collideBitmap(const uint8_t *bitmap1, int8_t x1, int8_t y1, const uint8_t *bitmap2, int8_t x2, int8_t y2) {
    int8_t w1 = pgm_read_byte(bitmap1);
    int8_t h1 = pgm_read_byte(bitmap1 + 1);

    int8_t w2 = pgm_read_byte(bitmap2);
    int8_t h2 = pgm_read_byte(bitmap2 + 1);

    return gb.collideRectRect(x1, y1, w1, h1, x2, y2, w2, h2);
}
Attachments
bitmap.zip
Example for collision (hold B to move other box)
(664 Bytes) Downloaded 286 times
Post a reply