Jump to content

[SOLVED] (Warp command in all directions) This damn math caclulations


Guest lillecarl

Recommended Posts

I need some help with math, i'm thinking about to implent a "warp" command to my mangos one (https://bitbucket.org/celtus/oc-patch/src/401a8dcab846/WarpCommand/warpcommand.patch)

But i want to add 2 additions to the patch, at the moment you can go forward, backward, up and down.

But i would want to add left and right aswell but i dont really know how to do the math for that, i would really appreciate if someone could help me.

Here is the forward/backward code'

   case 'f':
       {
           float fx = x + cosf(o)*value;
           float fy = y + sinf(o)*value; 
           float fz = std::max(warpmap->GetHeight(fx, fy, MAX_HEIGHT), warpmap->GetWaterLevel(fx, fy));
           _player->TeleportTo(mapid, fx, fy, fz, o);
       }
       break;
   case 'b':
       {
           float bx = x - cosf(o)*value;
           float by = y - sinf(o)*value;
           float bz = std::max(warpmap->GetHeight(bx, by, MAX_HEIGHT), warpmap->GetWaterLevel(bx, by));
           _player->TeleportTo(mapid, bx, by, bz, o);
       }
       break;

Thanks in advance

- LilleCarl

Link to comment
Share on other sites

This is what I got at AI of ormorok in Nexus

He casts spikes in b, f, l, r directions

SpikeXY[0][0] = BaseX+(SPIKE_DISTANCE*CrystalSpikes_Count*cos(BaseO));
               SpikeXY[0][1] = BaseY+(SPIKE_DISTANCE*CrystalSpikes_Count*sin(BaseO));
               SpikeXY[1][0] = BaseX-(SPIKE_DISTANCE*CrystalSpikes_Count*cos(BaseO));
               SpikeXY[1][1] = BaseY-(SPIKE_DISTANCE*CrystalSpikes_Count*sin(BaseO));
               SpikeXY[2][0] = BaseX+(SPIKE_DISTANCE*CrystalSpikes_Count*cos(BaseO-(M_PI/2)));
               SpikeXY[2][1] = BaseY+(SPIKE_DISTANCE*CrystalSpikes_Count*sin(BaseO-(M_PI/2)));
               SpikeXY[3][0] = BaseX-(SPIKE_DISTANCE*CrystalSpikes_Count*cos(BaseO-(M_PI/2)));
               SpikeXY[3][1] = BaseY-(SPIKE_DISTANCE*CrystalSpikes_Count*sin(BaseO-(M_PI/2)));

I guess you can use it to evaluate it for your use

Link to comment
Share on other sites

Solved this is how it looks atm:

   case 'u':
       {
           _player->TeleportTo(mapid, x, y, z + value, o);
       }
       break;
   case 'd':
       {
           _player->TeleportTo(mapid, x, y, z - value, o);
       }
       break;
   case 'f':
       {
           float fx = x + cosf(o)*value;
           float fy = y + sinf(o)*value; 
           _player->TeleportTo(mapid, fx, fy, z, o);
       }
       break;
   case 'b':
       {
           float bx = x - cosf(o)*value;
           float by = y - sinf(o)*value;
           _player->TeleportTo(mapid, bx, by, z, o);
       }
       break;
   case 'r':
       {
           float lx = x + cos(o-(M_PI/2))*value;
           float ly = y + sin(o-(M_PI/2))*value;
           _player->TeleportTo(mapid, lx, ly, z, o);
       }
       break;
   case 'l':
       {
           float rx = x - cos(o-(M_PI/2))*value;
           float ry = y - sin(o-(M_PI/2))*value;
           _player->TeleportTo(mapid, rx, ry, z, o);
       }
       break;

Next step is how the actual orientation is working, as i see it the max value of the orientation is somewhere around 6,2 and that makes me clueless when i wanna write a command to turn around exaxtly, lets say 30 degrees (is degrees the correct word?)

- LilleCarl

Link to comment
Share on other sites

All orientation in Mangos is done in radians, 1 radian = 180 degrees

Max value of orientation is 2M_PI (3.14*2 = ~6.28) witch alseo equals 0 (2 radians are full cycle)

To turn right you need to substract 'value' from current orientation.

30 degrees = M_PI / 6

So the new orientation would be 'o - value' (if the value is given in radians)

Also this rule should be followed:

0 < orientation < 2M_PI

This should work:

if (orientation < 0.0f)
 orientation += 2.0f * M_PI;
else if (orientation > 2* M_PI)
 orientation -= 2.0f * M_PI;

Turning around would be 'o - M_PI'

Degrees to radians can be converted with 'radians = degrees * M_PI / 180.0f'

Link to comment
Share on other sites

  • 9 months later...

Working now! 100%

bool ChatHandler::HandleWarpCommand(char* args)
{
   // Based on a concept by Pwntzyou
   if (!*args)
       return false;

   Player* _player = m_session->GetPlayer();

   char* arg1 = strtok((char*)args, " ");
   char* arg2 = strtok(NULL, " ");

   if (! arg1)
       return false;

   if (! arg2)
       return false;

   char dir = arg1[0];
   int value = (int)atoi(arg2);
   float x = _player->GetPositionX();
   float y = _player->GetPositionY();
   float z = _player->GetPositionZ();
   float o = _player->GetOrientation();
   uint32 mapid = _player->GetMapId();
   PSendSysMessage("Value is: %i",value);

   switch (dir)
   {
   case 'x':
       {
           float xx = x + cosf(o)*value;
           float xy = y + sinf(o)*value; 
           _player->TeleportTo(mapid, xx, xy, z, o);
       }
       break;
   case 'y':
       {
           float yx = x + cos(o-(M_PI/2))*value;
           float yy = y + sin(o-(M_PI/2))*value;
           _player->TeleportTo(mapid, yx, yy, z, o);
       }
       break;
   case 'z':
       {
           _player->TeleportTo(mapid, x, y, z + value, o);
       }
       break;
   case 'o':
       {
           o = o - (value * M_PI / 180.0f);

           if (o < 0.0f) o += value * M_PI;
           else if (o > 2* M_PI) o -= value * M_PI;
           _player->TeleportTo(mapid,x,y,z,o);
       }
       break;
   }
   return true;
}

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use