Advertisement

How to best handle angles and curved areas in collision?

Started by January 15, 2003 03:25 PM
2 comments, last by LostBoy 22 years, 1 month ago
I am having some trouble with this. I am thinking that pixel color detection and a bounding area may be the way to do it. However, I'm having problems geting glReadPixels to work with my floating point values for X and Y coordinates. It is definitely something that I am doing wrong with the syntax as I am new to opengl. Could somone show me how to properly write this statement, but have it use floating point numbers instead of integers ? glReadPixels((int)ballX,((int)ballY),1,1,GL_RGB, GL_UNSIGNED_BYTE, (void *)pixels); Then, how do I use the value it returns? IE - what statement is used to use this return value? I don't need the whole idea explained, I'm just trying to find the syntax for the statements, and I can figure out what to actually do after a contact between the ball and the edge of the course (it's a golf game)has occured. If anyone knows a simpler approach, by all means tell me about it. The part that is giving me the most trouble is dealing with the angled parts of the course. BTW, I'm only dealing with 2D right now. Trying to keep it simple. And I'm using openGl and MSVC++ on Windows 98. [edited by - LostBoy on January 15, 2003 4:26:11 PM]
Since your using float for drawing, I assume you are not drawing by pixels, so your ball x,y wont be at the same position on the screen as pixel x,y. Anyway, this isn''t a good method for collision detection because your graphics will be very simple. If you still want to use it, I suggest using a matrix with all the values.
Advertisement
I assume you are looking top down to your golf course in 2D... What you could do for some simple collision testing is just to treat the edges of your golf course (which are lines) as planes which are raising up toward you and extending down away from you (into your screen). Imagine they extend into infinity.

Now you can:

1. Solve normals to the planes (A, B, C) and store them when initializing, this need only be done once per hole, since I''m guessing that the course is stationary.
2. Eqn of plane is Ax + By + Cz -D = 0. Anything in the negatives are on one side of the plane, positives are on the opposite side. Eqn = 0 means that the ball is exactly on the plane. Note: Once A, B, C is solved, sub a point on the line in to solve for D. Also, since you are looking down on edge to the plane, C will always be zero in your case. That leaves you with Ax + By -D = 0. [1]
3. Test every frame! if ball (x, y) substituted into [1] gives positives while the ball in in legal play, then becomes negative, you know you''ve crossed the threshold of that plane.
4. Hate to make things more complicated... but one unfortunate property of planes is that they extend to infinity in ALL direction. For a dog-legged course with angles, it is possible that some lines will extend into legal playing areas, in which case you will have to give each plane valid x, y areas. So then the passting collision condition becomes a) changing sign of eqn [1] and b) that the collision happened withing a valid 2D ''space''.

Hope this helps.
Hey thanks. I''m new to this angle calculation stuff, so could you tell me what A,B,C,D and Eqn are ? I like the simplicity of your approach here, I just need to know what those variables are.

This topic is closed to new replies.

Advertisement