Advertisement
Guest User

Untitled

a guest
Sep 29th, 2010
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. setupMiniMap(material)
  2. {
  3. // use 0 for no required map aspect ratio.
  4. requiredMapAspectRatio = level.requiredMapAspectRatio;
  5.  
  6. corners = getentarray("minimap_corner", "targetname");
  7. if (corners.size != 2)
  8. {
  9. println("^1Error: There are not exactly two \"minimap_corner\" entities in the map. Could not set up minimap.");
  10. return;
  11. }
  12.  
  13. corner0 = (corners[0].origin[0], corners[0].origin[1], 0);
  14. corner1 = (corners[1].origin[0], corners[1].origin[1], 0);
  15.  
  16. cornerdiff = corner1 - corner0;
  17.  
  18. north = (cos(getnorthyaw()), sin(getnorthyaw()), 0);
  19. west = (0 - north[1], north[0], 0);
  20.  
  21. // we need the northwest and southeast corners. all we know is that corner0 is opposite of corner1.
  22. if (vectordot(cornerdiff, west) > 0) {
  23. // corner1 is further west than corner0
  24. if (vectordot(cornerdiff, north) > 0) {
  25. // corner1 is northwest, corner0 is southeast
  26. northwest = corner1;
  27. southeast = corner0;
  28. }
  29. else {
  30. // corner1 is southwest, corner0 is northeast
  31. side = vecscale(north, vectordot(cornerdiff, north));
  32. northwest = corner1 - side;
  33. southeast = corner0 + side;
  34. }
  35. }
  36. else {
  37. // corner1 is further east than corner0
  38. if (vectordot(cornerdiff, north) > 0) {
  39. // corner1 is northeast, corner0 is southwest
  40. side = vecscale(north, vectordot(cornerdiff, north));
  41. northwest = corner0 + side;
  42. southeast = corner1 - side;
  43. }
  44. else {
  45. // corner1 is southeast, corner0 is northwest
  46. northwest = corner0;
  47. southeast = corner1;
  48. }
  49. }
  50.  
  51. // expand map area to fit required aspect ratio
  52. if ( requiredMapAspectRatio > 0 )
  53. {
  54. northportion = vectordot(northwest - southeast, north);
  55. westportion = vectordot(northwest - southeast, west);
  56. mapAspectRatio = westportion / northportion;
  57. if ( mapAspectRatio < requiredMapAspectRatio )
  58. {
  59. incr = requiredMapAspectRatio / mapAspectRatio;
  60. addvec = vecscale( west, westportion * (incr - 1) * 0.5 );
  61. }
  62. else
  63. {
  64. incr = mapAspectRatio / requiredMapAspectRatio;
  65. addvec = vecscale( north, northportion * (incr - 1) * 0.5 );
  66. }
  67. northwest += addvec;
  68. southeast -= addvec;
  69. }
  70.  
  71. level.mapSize = vectordot(northwest - southeast, north);
  72.  
  73. setMiniMap(material, northwest[0], northwest[1], southeast[0], southeast[1]);
  74. }
  75.  
  76. vecscale(vec, scalar)
  77. {
  78. return (vec[0]*scalar, vec[1]*scalar, vec[2]*scalar);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement