Collection of usefull Trig. expressions.

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Collection of usefull Trig. expressions.

Post by jph_wacheski »

I am collecting some usefull trig. implementations here. (Mostly so I can find them easily!) I suppose many ppl know this stuff, however some of us had wandering minds in highshool,. . or just could not then imagine an use for it! They should be using game dev. to teach math.
I will post the ones I come across and can explain a use for, so far I got;

Code: Select all

 // find a Point using Direction and Distance from a Given Point
find_x=given_x+(sin(-1*direction*2*PI)*distance);
find_y=given_y+(cos(-1*direction*2*PI)*distance);
also very common and usefull;

Code: Select all

 // set X and Y Componets of Velocity using Direction and Speed
set_velocity_x=speed*sin(-1*direction*2*PI);
set_velocity_y=speed*cos(-1*direction*2*PI);
this one I just hacked out,. not sure this is the best way but it is working for me,.

Code: Select all

// set an objects velocity based on a mouse pointer position (shots in a top down game) currentModel.rotation.Z=atan2((currentModel.position.y-mouse_pointer.position.y),
(currentModel.position.x-mouse_pointer.position.x))+PI/2;
  
currentModel.velocity.x=11*sin(-1*currentModel.rotation.Z);
currentModel.velocity.y=11*cos(-1*currentModel.rotation.Z);

peace
iterationGAMES.com
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

since it was not immediately obvious to me, i guess i should chip this in for other newbies:

Code: Select all

// get a direction or an angle from a position
rotation = atan2( positionX, positionY )/( -2 * PI );
Post Reply