TacMap.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #define TACMAP_CPP
  2. /*************************************************************************************************\
  3. TacMap.cpp : Implementation of the TacMap component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "TacMap.h"
  9. #include "TGAInfo.h"
  10. #include "gameOS.hpp"
  11. extern unsigned char godMode;
  12. TacMap::TacMap()
  13. {
  14. }
  15. void TacMap::worldToTacMap( Stuff::Vector3D& world, int xOffset, int yOffset, int xSize, int ySize, gos_VERTEX& tac )
  16. {
  17. long tacX;
  18. long tacY;
  19. land->worldToCell( world, tacY, tacX );
  20. if ( tacX < 0 )
  21. tacX = 0;
  22. if ( tacY < 0 )
  23. tacY = 0;
  24. if ( tacX > land->realVerticesMapSide * MAPCELL_DIM )
  25. tacX = land->realVerticesMapSide * MAPCELL_DIM;
  26. if ( tacY > land->realVerticesMapSide * MAPCELL_DIM )
  27. tacY = land->realVerticesMapSide * MAPCELL_DIM;
  28. tac.x = (float)tacX * (float)xSize /((float)land->realVerticesMapSide * MAPCELL_DIM);
  29. tac.y = (float)tacY * (float)ySize/((float)land->realVerticesMapSide * MAPCELL_DIM);
  30. tac.x += xOffset;
  31. tac.y += yOffset;
  32. }
  33. void TacMap::tacMapToWorld( const Stuff::Vector2DOf<long>& screen, int xSize, int ySize, Stuff::Vector3D& world )
  34. {
  35. // turn screen into cells
  36. long cellX = screen.x /(float)xSize * ((float)land->realVerticesMapSide * MAPCELL_DIM);
  37. long cellY = screen.y /(float)ySize * ((float)land->realVerticesMapSide * MAPCELL_DIM);
  38. if ((cellX < 0) || (cellX >= land->realVerticesMapSide * MAPCELL_DIM) ||
  39. (cellY < 0) || (cellY >= land->realVerticesMapSide * MAPCELL_DIM))
  40. {
  41. world = eye->getPosition();
  42. }
  43. else
  44. {
  45. world.x = land->cellColToWorldCoord[cellX];
  46. world.y = land->cellRowToWorldCoord[cellY];
  47. world.z = land->getTerrainElevation( world );
  48. }
  49. }