SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 02/04/2010, 02:37 AM   #1
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 669
Reputation: 380
Default Rotation between two points

Hi guys,

I have two 3D points (X, Y, Z) and wondered how I would get X, Y, Z rotation angles between these points.
I've searched these forums, the interwebs, and asked for help, yet nobody seems to know how to do something like this.

To be more specific, I'm trying to create an object at point 1 which will face point 2, so I need the rotation values which will make it face point 2.
I'm assuming it'd use some complex (or not) math functions, but all of my attempts with just about every function failed. :<

Hopefully there are some math geeks out there who can help.
__________________
ev0lution is offline  
Old 02/04/2010, 04:15 AM   #2
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default Re: Rotation between two points

I've figured it out for 2D coordinates (X,Y) but not yet for 3D coordinates (X,Y,Z)

pawn Code:
Float:GetAngleBetweenPoints(Float:X1,Float:Y1,Float:X2,Float:Y2)
{
  new Float:angle=atan2(X2-X1,Y2-Y1);
  if(angle>360)angle-=360;
  if(angle<0)angle+=360;
  return angle;
}

I once used it to make an in-game compass that pointed out nearby players and the user's objective.


looked like this (if player was looking straight North)
|||||||||N|||||||||
|=player
|=objective
Joe Staff is offline  
Old 02/04/2010, 04:17 AM   #3
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 669
Reputation: 380
Default Re: Rotation between two points

Quote:
Originally Posted by Joe Staff
I've figured it out for 2D coordinates (X,Y) but not yet for 3D coordinates (X,Y,Z)

pawn Code:
Float:GetAngleBetweenPoints(Float:X1,Float:Y1,Float:X2,Float:Y2)
{
  new Float:angle=atan2(X2-X1,Y2-Y1);
  if(angle>360)angle-=360;
  if(angle<0)angle+=360;
  return angle;
}
Thanks for trying, but I think I had already stumbled across something similar in my attempts to find what I wanted.
The problem is, not only is it for two 2D points, it also only returns one angle, I'd need three.
__________________
ev0lution is offline  
Old 02/04/2010, 04:19 AM   #4
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default Re: Rotation between two points

I spent a WHOLE lotta time trying to figure that out.

The only results I could find were some formulas that require a DOT algorithm, which isn't possible (as far as I know) in the pawn version for SA-MP.
Joe Staff is offline  
Old 02/04/2010, 04:24 AM   #5
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 669
Reputation: 380
Default Re: Rotation between two points

Quote:
Originally Posted by Joe Staff
I spent a WHOLE lotta time trying to figure that out.

The only results I could find were some formulas that require a DOT algorithm, which isn't possible (as far as I know) in the pawn version for SA-MP.
Sigh.. well thanks anyway.
Hopefully somebody knows a way of doing this in pawn.
__________________
ev0lution is offline  
Old 02/04/2010, 10:01 PM   #6
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 669
Reputation: 380
Default Re: Rotation between two points

Bump. :\
__________________
ev0lution is offline  
Old 04/04/2010, 12:15 AM   #7
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 669
Reputation: 380
Default Re: Rotation between two points

Quote:
Originally Posted by ev0lutionnn
Bump. :\
__________________
ev0lution is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SA-MP Server Log Rotation KingJ Server Support 41 16/10/2012 02:37 PM
Adding Points, /points and Hitman into a Roleplay Script Despare Help Archive 2 27/12/2009 01:35 PM
Rotation Problem Puzi Help Archive 5 06/09/2009 09:06 AM
Rotation little help RyDeR` Help Archive 0 03/08/2009 06:10 PM
Rotation Hot Help Archive 6 19/05/2009 01:40 AM


All times are GMT. The time now is 05:57 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.