AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Vector to angles, angles to vector [Solved] (https://forums.alliedmods.net/showthread.php?t=234018)

.Dare Devil. 01-23-2014 19:55

Vector to angles, angles to vector [Solved]
 
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;



Arkshine 01-24-2014 04:23

Re: Vector to angles, angles to vector
 
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.

.Dare Devil. 01-24-2014 10:43

Re: Vector to angles, angles to vector
 
Quote:

Originally Posted by Arkshine (Post 2090240)
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.

jimaway 01-24-2014 10:51

Re: Vector to angles, angles to vector
 
why the hell are you asking this here if its not for amxx

.Dare Devil. 01-24-2014 10:54

Re: Vector to angles, angles to vector
 
Quote:

Originally Posted by jimaway (Post 2090378)
why the hell are you asking this here if its not for amxx

Because i want that formula is in pawn code. :bee:
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;




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

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