Page 1 of 1
sdl collision
Posted: Sun Nov 14, 2010 8:36 am
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 (26.32 KiB) Viewed 1689 times
Re: sdl collision
Posted: Sun Nov 14, 2010 10:11 am
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?
Re: sdl collision
Posted: Sun Nov 14, 2010 1:49 pm
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
Re: sdl collision
Posted: Sun Nov 14, 2010 2:37 pm
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.
Re: sdl collision
Posted: Sun Nov 14, 2010 4:19 pm
by DuGaming
thanks for the help, I'll defiantly look into those things
Re: sdl collision
Posted: Sun Nov 14, 2010 10:29 pm
by pritam
Honestly Axis Aligned Bounding Boxes is all you should need for this project, at least on the first go.
Re: sdl collision
Posted: Mon Nov 15, 2010 7:02 am
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.
Re: sdl collision
Posted: Mon Nov 15, 2010 12:53 pm
by dandymcgee
Personally, I'd use rectangles for the walls and a circles to make up the line.
Re: sdl collision
Posted: Mon Nov 15, 2010 5:34 pm
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
, 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.
Re: sdl collision
Posted: Mon Nov 15, 2010 8:39 pm
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.