Author Topic: Simple math problem - finding the center of a tile  (Read 831 times)

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Simple math problem - finding the center of a tile
« on: May 01, 2016, 07:45:08 pm »


               

My math brain is completely out to lunch today.  I need a function that will calculate the tile center from the x,y position of a waypoint. 


 


Edit: I have it now:


FloatToInt((vPosition.x) / 10) * 10 + 5;



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Simple math problem - finding the center of a tile
« Reply #1 on: May 01, 2016, 09:21:30 pm »


               

....you got it



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Simple math problem - finding the center of a tile
« Reply #2 on: May 01, 2016, 09:22:46 pm »


               

Here is something you can look at, not sure it's what you were looking for , but there might be something there for you. I was working on it and finished before I saw you got what you needed.



// Will return the center of the specific tileset tile the OWaypoint object is located
vector TileCenter(object oWaypoint)
{
    vector vWaypoint = GetPosition(oWaypoint);
    float fX,fY;
 
    float fX = vWaypoint.x;
    float  fY= vWaypoint.y;
 
    // Store the decimal value if fX
    float fX1 = fX-FloatToInt(fX);
    // Get the value of the ones column of fX
    int iX1 = FloatToInt(fX)%10;
    // The x coordinate within the specific tile
    float fX2 = fX1+iX1;
    // The x value for the distance to the center of the specific tile from the oWaypoint object
    float fX3 = (((10.0-fX2)-fX2)/2)+fX2;
    // The x value for center of the tile the oWaypoint object is located within the global environment
    float fX4= fX-fX2+fX3;
 
 
    // Store the decimal value if fY
    float fY1 = fY-FloatToInt(fY);
    // Get the value of the ones column of fY
    int iY1 = FloatToInt(fY)%10;
    // The y coordinate within the specific tile
    float fY2 = fY1+iY1;
    // The y value for the distance to the center of the specific tile from the oWaypoint object
    float fY3 = (((10.0-fY2)-fY2)/2)+fY2;
    // The y value for center of the tile the oWaypoint object is located within the global environment
    float fY4= fY-fY2+fY3;
 
    return Vector(fX4, fY4, 0.0);
}


               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Simple math problem - finding the center of a tile
« Reply #3 on: May 01, 2016, 10:36:14 pm »


               

That might be useful enough to post on the vault for anyone who needs such a script after this thread has disappeared 2 or 3 pages down the line.


 


TR



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Simple math problem - finding the center of a tile
« Reply #4 on: May 02, 2016, 12:02:23 am »


               

Hmmm... I might just do that. Thanks.