Hi everyone Im new to this forum, and reallllly need help with my final OpenGL project.
Basically the project is:
Create two robots in OpenGL(with a C++ compiler)using any 3D shapes you want, and get them to move round and round(continuously) in a circle, in opposite directions. Whenever while moving, the robots come very close together, have them both stop moving and “fight”—the fight can even be a small simple punch or kick animation from either robot. Once the 'bots have “fought” for a few seconds, have them start moving in a circle again, and repeat the process.
I have created two(very ugly!) robots, and I have them moving in a small circle(although I somehow cant tell if they’re moving in opposite directions). My biggest problem is—how can I determine when the robots are close enough to start the fight animation? Is there a distance formula to calculate the distance between the robots? And once I have the distance between them, how do I get them to stop moving in a circle and start fighting? Someone pleeease help me!!
P.S.: Are we allowed to attach files to these posts, in case we want to post code or something?
UrbanLegend, I’m moving the robots in a circle with the Rotate() function, rotating them through an angle that increments from 0 to 360, and then back to 0 again. But how do I know the positions of the robots when they are close together?
You will have to get x and y coordinate from angle and radius.
dot is also calculated as:v0.xv1.x+v0.yv1.y+v0.zv1.z
lenght consequently will be:sqrt(v0.xv0.x+v0.yv0.y+v0.zv0.z)
for 2D (plane)
v0.xv1.x+v0.yv1.y
and
sqrt(v0.xv0.x+v0.yv0.y)
If you get length (distance) between 2 robots, divide it by 2 to get number, then compare it with circle that bounds robot, if calculated number is less, then you have collision.
[EDIT]
I ran afay too fast…
v.x=robot1.x-robot2.x
v.y=robot1.y-robot2.y
v.z=robot1.z-robot2.z
and length formulas will be:
sqrt(v.xv.x+v.yv.y+v.zv.z)
sqrt(v.xv.x+v.y*v.y)