Advertisement

Please Help - Simple collision detection problem

Started by September 30, 2002 04:18 AM
29 comments, last by LostBoy 22 years, 4 months ago
I'm not really sure (I'm somewhat of a beginner too), but to my understanding, using glReadPixels(x,y,1,1,...) would only give you the pixel at the centre of the sphere.
So basically, wouldn't it be possible that within an update of ballX/Y, that one pixel that you are checking could overstep the line, thus, passing the collision detection area.
Would it be possible (definitely slower) to perhaps use glReadPixels using a larger area (i.e. glReadPixels(ballX-(radius/2), ballY+(radius/2), ballX+(radius/2)..) then looping through to check all of those pixels?

Also, would this 'color-collision' technique work at all under certain rotations of the scene? (i.e. when objects cover one another on the z-axis)

Personally, I think the maths technique is the way to go. I know you want to avoid it, but its not THAT hard. I was definitely no genius at linear algebra, but even I managed to create basic collision detection systems for 3D models. Believe me, if you pick up an old math textbook, its all there.

quote:

1. I'm not sure as to what was vincoof talking about.-
(my_integer = (int)my_float_value



All he's saying is that its basic C/C++ practice to cast values when assigning them to a different data type. It will get rid of all those annoying error messages.

[edited by - tuita on October 3, 2002 11:12:31 AM]
Thanks. I can usually pick up on math just by looking at it. When I get lost is when that math is combined with opengl standard practices that I am not used to seeing. It''s when someone covers some code, but leaves out something vital, because they think that I am already aware of certain details.
So far my experience has been good with opengl. Just reading some tuts and looking at code, I have been able to figure out what is going on. But I must say that this collision detection has stoped me in my tracks. I can grasp the concepts, but those concepts are not useful for someone like me that does not yet know how to implement his ideas with opengl.

I know that I have much to learn, and I thank everyone for their patience.

vincoof : what I meant by #3 is, I need to know how to store the entire line as a single variable so that I can use it in my math. That way I would not have to rely on pixel color detection, in the event that I get more fancy with my game as it evolves.

JC
Advertisement
Oops.

[edited by - LostBoy on October 3, 2002 11:36:34 AM]
Oops again.

[edited by - LostBoy on October 3, 2002 11:37:04 AM]
#3 Do you want to know how to convert a couple of points (x,y) into a line equation ax+by+c=0 ?
Yes, exactly. I don''t quite know how to condense that into one variable. I think that if I could at least get that far, I''ll be half way there.

I am also reading the opengl super bible. I am learning much from it. I think that with the bible, and the generous help that I am getting from you kind people, that I will conquer this problem.

JC
Advertisement
What you need is sphere polygon collision detection. Don't fight it, learn it. It is the best way. Just make your walls all out of polygons (triangle strips) like the Nehe tut on loading in a 3d scene, and combine it with this here tut:

http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg3.htm

hey how do you linkify a URL here?


I read the faq and it doth not say.

[edited by - element2001 on October 3, 2002 7:02:05 PM]
Much obliged. I''ll check it out.

JC
I sent you an email about your project. by the way I was the one that sent you the post about the color collision stuff(glReadPixels)

[edited by - tylerbingham on October 4, 2002 1:00:02 AM]
The equation is rather simple :
- your point P1(x1,y1) belongs to the line
- your point P2(x2,y2) belongs to the line
- your line equation is ax+by+c=0

Because P1 belongs to the line, you can write :
ax1+by1+c=0

Idem with P2 :
ax2+by2+c=0

There you have 3 variables (a,b,c) and 2 equations, that means there is an infinite number of solutions. You have to use another constraint. I recommend a²+b²=1 because the vector (a,b) is in fact the normal of the line (I won''t explain it here, and anyway you can choose another constraint, but I just choose this one since it already solves later problems).

So, you have 3 variables a, b, c and you have 3 equations :
(1) : ax1+by1+c=0
(2) : ax2+by2+c=0
(3) : a²+b²=1

change your equation (1) to (1'') : ax1+by1=-c
change your equation (2) to (2'') : ax2+by2=-c

you can then compare (1'') with (2'') :
ax1+by1=ax2+by2
which is equivalent to :
ax1-ax2=by1-by2
which is nothing else than (let''s call it (4)) :
(4) : a*(x1-x2)=b*(y1-y2)

change your equation (3) to (3'') : a=sqrt(1-b²)

Then you can insert this ''a'' variable into equation (4), and you get ''b''.
Use the result of ''b'' into either (3) or (4) to compute ''a''.
And use the result of ''a'' and ''b'' in either (1'') or (2'') to compute ''c''.

Pretty simple in fact, when you know all the 3D math that is behind the OpenGL !

This topic is closed to new replies.

Advertisement