PDA

View Full Version : Desperately need help with final OpenGL project



GLRookie
05-14-2005, 05:59 AM
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?

M/\dm/\n
05-14-2005, 06:24 AM
Use vector algebra, distance between robots will be lenght of vector (robot1pos-robot2pos)
Lenght is sqrt(dot(v, v));

GLRookie
05-14-2005, 06:51 AM
How do I calculate robot1pos and robot2pos? Also, what is the dot() function?

GLRookie
05-14-2005, 07:57 AM
Come on, how do I calculate the positions of the two robots? I need help!! :(

UrbanLegend
05-14-2005, 08:15 AM
Uhm

Well you have stated that You are creating the robots and moving them,

if your actually doing that then you have to know their positions to move them

UrbanLegend
05-14-2005, 08:19 AM
Dot is short for the DOT product, see any graphics bookor vector math tutorial, a quick Google will find this in straight away

Baically:

The dot product is the product of the lengths of the vectors and the cosine of the angle between them.

GLRookie
05-14-2005, 09:24 AM
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?

M/\dm/\n
05-14-2005, 10:21 AM
You will have to get x and y coordinate from angle and radius.

dot is also calculated as:v0.x*v1.x+v0.y*v1.y+v0.z*v1.z
lenght consequently will be:sqrt(v0.x*v0.x+v0.y*v0.y+v0.z*v0.z)

for 2D (plane)
v0.x*v1.x+v0.y*v1.y
and
sqrt(v0.x*v0.x+v0.y*v0.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.x*v.x+v.y*v.y+v.z*v.z)
sqrt(v.x*v.x+v.y*v.y)