sdl collision
Moderator: Coders of Rage
sdl collision
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.
here is a picture of my idea, black lines = walls, red line = mouse movement.
Re: sdl collision
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
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
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.
Although you should bare in mind this route is complicated and also a fairly expensive method of collison detection.
Re: sdl collision
thanks for the help, I'll defiantly look into those things
-
- 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
Honestly Axis Aligned Bounding Boxes is all you should need for this project, at least on the first go.
Re: sdl collision
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.pritam wrote:Honestly Axis Aligned Bounding Boxes is all you should need for this project, at least on the first go.
- dandymcgee
- 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
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!
-
- Chaos Rift Junior
- Posts: 209
- Joined: Thu Feb 12, 2009 8:46 pm
Re: sdl collision
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.
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Re: sdl collision
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.
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project