Advertisement
Guest User

new GetCorrectedCubePosition

a guest
Oct 19th, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. private Vector3 GetCorrectedCubePosition(float Face, float X, float Y)
  2.         {
  3.             Vector3 positionOnCube = new Vector3(X, Y, 0);
  4.             positionOnCube -= new Vector3(planet.BlockMap.FaceWidth / 2, planet.BlockMap.FaceWidth / 2, planet.BlockMap.FaceWidth / 2);
  5.  
  6.             //adjust for positive and negative values
  7.             if (Face == PlanetBlockMap.SOUTH | Face == PlanetBlockMap.BACK | Face == PlanetBlockMap.WEST) //negative Y
  8.             {
  9.                 positionOnCube.Z *= -1;
  10.             }
  11.  
  12.             //rotate the whole vector to suit the direction this face is facing
  13.             Vector3 rotatedPosition = Vector3.Zero;
  14.             if (Face == PlanetBlockMap.NORTH)
  15.             {
  16.                 rotatedPosition.X = positionOnCube.X;
  17.                 rotatedPosition.Y = positionOnCube.Z;
  18.                 rotatedPosition.Z = positionOnCube.Y;
  19.             }
  20.             else if (Face == PlanetBlockMap.SOUTH)
  21.             {
  22.                 rotatedPosition.X = positionOnCube.Y;
  23.                 rotatedPosition.Y = positionOnCube.Z;
  24.                 rotatedPosition.Z = positionOnCube.X;
  25.             }
  26.             else if (Face == PlanetBlockMap.FRONT)
  27.             {
  28.                 rotatedPosition.X = positionOnCube.Y;
  29.                 rotatedPosition.Y = positionOnCube.X;
  30.                 rotatedPosition.Z = positionOnCube.Z;
  31.             }
  32.             else if (Face == PlanetBlockMap.BACK)
  33.             {
  34.                 rotatedPosition = positionOnCube;
  35.             }
  36.             else if (Face == PlanetBlockMap.EAST)
  37.             {
  38.                 rotatedPosition.X = positionOnCube.Z;
  39.                 rotatedPosition.Y = positionOnCube.Y;
  40.                 rotatedPosition.Z = positionOnCube.X;
  41.             }
  42.             else if (Face == PlanetBlockMap.WEST)
  43.             {
  44.                 rotatedPosition.X = positionOnCube.Z;
  45.                 rotatedPosition.Y = positionOnCube.X;
  46.                 rotatedPosition.Z = positionOnCube.Y;
  47.             }
  48.  
  49.             rotatedPosition *= (1f / planet.BlockMap.FaceWidth);
  50.  
  51.  
  52.  
  53.             return rotatedPosition;
  54.         }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement