Advertisement

Can anyone figure this out ?

Started by January 14, 2003 02:04 PM
2 comments, last by LostBoy 22 years, 1 month ago
This may be easy for some of you, but I am no ace in opengl. So please explain it to me in a way that a beginner can understand. I am trying to do collision in a mini golf game. I have beat my brains out trying to look at code examples and work them into my program. I always get errors. The two ideas that I have concentrated most on are pixel collision or closest point on a line collision. Pixel collision seems that it would be simple to use (though not for me because I can''t get the glReadPixels command right). I am using floating point values for my ball travel, and have only seen examples using integers for coordinates. Those won''t work for me as I don''t want to resort to using integers for my ball travel. It would not be nearly as smooth looking to use integers. So any examples that I have seen are worthless to me, as I cannot convert them to work with floating numbers. As far as the closest point on a line method, how could I do that ? If I had an invisible point that moved along with my ball, and this invisible point followed the bounding lines for my course shape, then I could just measure the distance between my ball and the bounding line. Obviously, when the distance is equal to zero, I would have a collision and I could just invert my balls travel to look like a deflection. I think that I have te right ideas, I just can''t make them happen. Please help if you can. Thanks,
The best thing to do is use line line collision. just check if the line between the current position of the ball and the new position crosses the boundry lines (well segments). This is incredibly easy and if you cant figure out how to do it on your own, just search for "math segment intersection".
Advertisement
How do I refference my bounding line ? I understand the concept that you have introduced, however I need a code example. I am using GL_LINE_STRIP to make the bounding lines. I need to know how I can compare my X,Y ball coordinates with any given point on the bounding line. Keep in mind that the bounding area can be a straight line, or an angle, or circular. It follows the edges of the particular hole that I am playing on.
do multiple tests on each segment of your line.


I''ve never actually needed to ues this code in a very long time, so I forget if it works or not


  bool Vector2::lineToLine(Vector2 & line1Start, Vector2 & line1End, Vector2 & line2Start, Vector2 & line2End, Vector2 & impactPoint)	{		float denom=			(line1End.x-line1Start.x)*			(line2End.y-line2Start.y)			-			(line1End.y-line1Start.y)*			(line2End.x-line2Start.x);		if (denom==0)//parallel			return false;		float r=			(			(line1Start.y-line2Start.y)*			(line2End.x-line2Start.x)			-			(line1Start.x-line2Start.x)*			(line2End.y-line2Start.y)			)			/denom;		if (r<0 || r>=1)			return false;		impactPoint.x=line1Start.x+r*(line1End.x-line1Start.x);		impactPoint.y=line1Start.y+r*(line1End.y-line1Start.y);		return true;	};  


| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

This topic is closed to new replies.

Advertisement