Basic Collision Detection help

Libraries, utilities, bootloaders...

Re: Basic Collision Detection help

Postby lime » 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.
lime
 
Posts: 1
Joined: Mon Apr 07, 2014 3:36 pm

Re: Basic Collision Detection help

Postby Jolly » Wed Aug 06, 2014 12:08 pm

It's really easy to set up, don't worry: https://github.com/Robot-Will/Stino
Jolly
 
Posts: 40
Joined: Fri Jul 25, 2014 9:07 pm
Location: Germany

Re: Basic Collision Detection help

Postby Vraister » 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.
Vraister
 
Posts: 5
Joined: Sat Aug 16, 2014 9:25 pm
Location: Scotland

Re: Basic Collision Detection help

Postby rodot » 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 ;)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Basic Collision Detection help

Postby Vraister » 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.
Vraister
 
Posts: 5
Joined: Sat Aug 16, 2014 9:25 pm
Location: Scotland

Re: Basic Collision Detection help

Postby rodot » 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?
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Basic Collision Detection help

Postby Vraister » 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.
Vraister
 
Posts: 5
Joined: Sat Aug 16, 2014 9:25 pm
Location: Scotland

Re: Basic Collision Detection help

Postby Vraister » 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 ;-)
Vraister
 
Posts: 5
Joined: Sat Aug 16, 2014 9:25 pm
Location: Scotland

Re: Basic Collision Detection help

Postby yodasvideoarcade » 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?
User avatar
yodasvideoarcade
 
Posts: 102
Joined: Sat Apr 19, 2014 10:48 am
Location: Frankfurt/Germany

Re: Basic Collision Detection help

Postby Matrix828 » 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: Select all
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 279 times
Matrix828
 
Posts: 43
Joined: Tue Jul 22, 2014 7:44 pm

PreviousNext

Return to Software Development

Who is online

Users browsing this forum: No registered users and 16 guests

cron