Raised This Month: $ Target: $400
 0% 

Vector to angles, angles to vector [Solved]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-23-2014 , 19:55   Vector to angles, angles to vector [Solved]
Reply With Quote #1

Hello Alliedmodders!

Quote:
Solved: https://forums.alliedmods.net/showth...51#post2090551
Also look those are things what you may looking for
vector.inc
native vector_to_angle(const Float:fVector[3], Float:vReturn[3]);
native angle_vector(const Float:vector[3], FRU, Float:ret[3]);

After some long research ive been able to create this:
PHP Code:
// v - direction, an - angles
stock vector_to_anglesFloat:v[3], Float:an[3] )
{
    
an[0] = floatsqroot((v[0]*v[0]) + (v[1]*v[1])) / v[2]
    
an[1] = floatatan(v[1]/v[0], degrees)
    

Problem is that this wont work.
an[0] wont work at all.
an[1] is correct in 180 degrees.
90 > will turn -90 not 91
-90 < will turn 90 not -91

uh. Some much tries and no solution : /

I dont have code for 'angles to vector' yet. Never tried it because working on this stupid thing what eat all my time.

Also. I know there are functions for this but for where i want, cant use those. There are no amxmodx functions.

Edit:
PHP Code:
static cell AMX_NATIVE_CALL vector_to_angle(AMX *amxcell *params)
{
    
cell *cAddr get_amxaddr(amxparams[1]);

    
REAL fX amx_ctof(cAddr[0]);
    
REAL fY amx_ctof(cAddr[1]);
    
REAL fZ amx_ctof(cAddr[2]);

    
Vector vVector Vector(fXfYfZ);
    
Vector vAngle Vector(000);
    
VEC_TO_ANGLES(vVectorvAngle); // where it came from?

    
cell *vRet get_amxaddr(amxparams[2]);

    
vRet[0] = FloatToCell(vAngle.x);
    
vRet[1] = FloatToCell(vAngle.y);
    
vRet[2] = FloatToCell(vAngle.z);

    return 
1;


Last edited by .Dare Devil.; 01-24-2014 at 20:01. Reason: Solved
.Dare Devil. is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-24-2014 , 04:23   Re: Vector to angles, angles to vector
Reply With Quote #2

Each time your posts are confusing as hell. Not sure why you try always to reinvent the wheel. You should learn to search more before anything.

There are natives for that, like vector_to_angle, why you don't want to use that ?

VEC_TO_ANGLES is an exported engine function, something you can find among EngFunc_* constants.
__________________

Last edited by Arkshine; 01-24-2014 at 04:24.
Arkshine is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-24-2014 , 10:43   Re: Vector to angles, angles to vector
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
Each time your posts are confusing as hell. Not sure why you try always to reinvent the wheel. You should learn to search more before anything.

There are natives for that, like vector_to_angle, why you don't want to use that ?

VEC_TO_ANGLES is an exported engine function, something you can find among EngFunc_* constants.
I need formulas. Those arent for pawn or amxmodx thats why i cant use vector_to_angle.
.Dare Devil. is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-24-2014 , 10:51   Re: Vector to angles, angles to vector
Reply With Quote #4

why the hell are you asking this here if its not for amxx
jimaway is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-24-2014 , 10:54   Re: Vector to angles, angles to vector
Reply With Quote #5

Quote:
Originally Posted by jimaway View Post
why the hell are you asking this here if its not for amxx
Because i want that formula is in pawn code.
This is my excuse.

Just leaving it here in case someone need it:
PHP Code:
void VectorAngles(const vec3_t forwardvec3_t angles) {

   
float   tmpyawpitch;

   if(
forward[1] == && forward[0] == 0) {

      
yaw 0;
      if(
forward[2] > 0) { pitch 90; }
      else { 
pitch 270; }
   }
   else {

      
yaw = (atan2(forward[1], forward[0]) * 180 M_PI);
      if(
yaw 0) { yaw += 360; }

      
tmp sqrt(forward[0]*forward[0] + forward[1]*forward[1]);
      
pitch = (atan2(forward[2], tmp) * 180 M_PI);
      if(
pitch 0) { pitch += 360; }
   }
   
angles[0] = pitch;
   
angles[1] = yaw;
   
angles[2] = 0;


Last edited by .Dare Devil.; 01-24-2014 at 18:33.
.Dare Devil. is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 10:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode