sdl collision

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
DuGaming
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sat Oct 16, 2010 8:01 am

sdl collision

Post by DuGaming »

I'm thinking of making a maze game, where you draw a line threw a maze and points are deducted when you go outside the line, I'm unsure of how the collision would work though any ideas?

here is a picture of my idea, black lines = walls, red line = mouse movement.
maze.png
maze.png (26.32 KiB) Viewed 1191 times
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: sdl collision

Post by N64vSNES »

You don't know what method of collision detection to use or you don't know how to check collision between to rectangles all together?
DuGaming
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sat Oct 16, 2010 8:01 am

Re: sdl collision

Post by DuGaming »

I don't know what method to use, my first idea was bounding box, but it doesn't work well with rotated rectangles
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: sdl collision

Post by N64vSNES »

If you want pixel perfect collision detection for oriented bounding boxes then you would have to write your own trig for the rotation, look into vectors, and then look into the seperating axis algorythm

Although you should bare in mind this route is complicated and also a fairly expensive method of collison detection.
DuGaming
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sat Oct 16, 2010 8:01 am

Re: sdl collision

Post by DuGaming »

thanks for the help, I'll defiantly look into those things
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: sdl collision

Post by pritam »

Honestly Axis Aligned Bounding Boxes is all you should need for this project, at least on the first go.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: sdl collision

Post by N64vSNES »

pritam wrote:Honestly Axis Aligned Bounding Boxes is all you should need for this project, at least on the first go.
I agree, I don't really see why you would want to use oriented bounding boxes for a project like this in the first place.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: sdl collision

Post by dandymcgee »

Personally, I'd use rectangles for the walls and a circles to make up the line.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
wearymemory
Chaos Rift Junior
Chaos Rift Junior
Posts: 209
Joined: Thu Feb 12, 2009 8:46 pm

Re: sdl collision

Post by wearymemory »

Assuming that mazes could be created separately via an image editing program and loaded by the program, or created using a formatted data file to produce an SDL_Suface; and assuming that both images use an arbitrary alpha value (probably 0xfe) to represent invalid pixels in the maze: The simplest solution, in my opinion :lol: , would be to retrieve the color of the pixel where the mouse is located relative to the SDL_Surface that contains the maze. One could acquire this by utilizing the SDL_GetRGBA function, and comparing the modified alpha value with the arbitrary value that could be used to represent all invalid pixels in the maze. If the alpha value of the pixel located at the coordinates of the mouse were equal to said arbitrary value, then it would be safe to assume that the user is currently outside the bounds of the maze. As a precaution, one should keep track of the last position of the user's mouse, and perform this check for each unique point between the last mouse location, and the current mouse location. Doing so would alleviate some issues that might arise due to the user's swift mouse movements. It is possible to calculate approximately each point between two others with the help of Bresenham's line algorithm.
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

Re: sdl collision

Post by PaperDuckyFTW »

I would suggest checking collision between the mouse and the rectangles, or having the circle test collision with the rectangles (like dandymcgee sugested). This is because I don't know these fancy mathecrapical rules and systems.
Post Reply