Advertisement
Guest User

Untitled

a guest
May 17th, 2014
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. [code]
  2. loat Vec3DistanceSq(const float *p1, const float *p2)
  3. {
  4. return ((p2[0] - p1[0]) * (p2[0] - p1[0]) +
  5. ((p2[2] - p1[2]) * (p2[2] - p1[2]) +
  6. ((p2[1] - p1[1]) * (p2[1] - p1[1]))));
  7. }
  8. void LinkTo(int Entity, int parent)
  9. {
  10. if(G_EntLinkTo(Entity, parent, 0))
  11. *(byte *)(*(int *)(Entity + 0x218) + 0xA) = 0;
  12. }
  13. int roundUp(float floatVal)
  14. {
  15. if (int(floatVal) != floatVal)
  16. return int(floatVal+1);
  17. else
  18. return int(floatVal);
  19. }
  20. float Distance(float* p1, float* p2)
  21. {
  22. return sqrt(Vec3DistanceSq(p1, p2));
  23. }
  24. float Distance(float p1X, float p1Y, float p1Z, float p2X, float p2Y, float p2Z)
  25. {
  26. float p1[] = {p1X,p1Y,p1Z},
  27. p2[] = {p2X,p2Y,p2Z};
  28. return sqrt(Vec3DistanceSq(p1, p2));
  29. }
  30. void vectoangles(const float * Vec, float * angles)
  31. {
  32. float forward, yaw, pitch, PiDiv = (180.0f / XM_PI);
  33. if(Vec[1] == 0 && Vec[0] == 0)
  34. {
  35. yaw = 0;
  36. if (Vec[2] > 0)
  37. pitch = 90;
  38. else
  39. pitch = 270;
  40. }
  41. else
  42. {
  43. if (Vec[0])
  44. yaw = (atan2(Vec[1], Vec[0]) * PiDiv);
  45. else if (Vec[1] > 0)
  46. yaw = 90.0f;
  47. else
  48. yaw = 270.0f;
  49. if (yaw < 0.0f)
  50. yaw += 360.0f;
  51. forward = sqrt((Vec[0] * Vec[0]) + (Vec[1] * Vec[1]));
  52. pitch = (atan2(Vec[2], forward) * PiDiv);
  53. if (pitch < 0.0f)
  54. pitch += 360;
  55. }
  56. angles[0] = 360.0f - pitch;
  57. angles[1] = yaw;
  58. angles[2] = 0;
  59. for(int i = 0; i < 3; i++) {
  60. if(angles[i] > 360.0f)
  61. angles[i] -= 360.0f;
  62. if(angles[i] < 0.0f)
  63. angles[i] += 360.0f;
  64. }
  65. }
  66. [/code]
  67. [code]
  68. void CreateRamp(float* top, float* bottom)
  69. {
  70. float D = Distance(top, bottom);
  71. int blocks = roundUp(D/32);
  72. float CX = top[0] - bottom[0],
  73. CY = top[1] - bottom[1],
  74. CZ = top[2] - bottom[2];
  75. int XA = CX/blocks,
  76. YA = CY/blocks,
  77. ZA = CZ/blocks;
  78. float Temp[3] = {top[0], top[1], 0},
  79. Temp2[3] = {bottom[0], bottom[1], 0},
  80. CXY = Distance(Temp, Temp2);
  81. for(int i = 0; i < 3; i++)
  82. Temp2[i] = top[i] - bottom[i];
  83. vectoangles(Temp2, Temp);
  84. for(int b = 0; b < blocks; b++)
  85. spawnEntity(true, "carepackage_friendly_iw6", bottom[0] + (XA * b), bottom[1] + (YA * b), bottom[2] + (ZA * b), Temp[2], Temp[1] + 90, Temp[0]);
  86. spawnEntity(true, "carepackage_friendly_iw6", bottom[0] + (XA * blocks), bottom[1] + (YA * blocks), bottom[2] + (ZA * blocks) - 8, Temp[2], Temp[1] + 90, 0);
  87. }
  88. void CreateGrid(float* corner1, float* corner2, float* angle)
  89. {
  90. float W = Distance(corner1[0], 0, 0, corner2[0], 0, 0),
  91. L = Distance(0, corner1[1], 0, 0, corner2[1], 0),
  92. H = Distance(0, 0, corner1[2], 0, 0, corner2[2]),
  93. CX = corner2[0] - corner1[0],
  94. CY = corner2[1] - corner1[1],
  95. CZ = corner2[2] - corner1[2];
  96. int ROWS = roundUp(W/60),
  97. COLUMNS = roundUp(L/32),
  98. HEIGHT = roundUp(H/20);
  99. float XA = (!ROWS ? 0 : CX/ROWS),
  100. YA = (!COLUMNS ? 0 : CY/COLUMNS),
  101. ZA = (!HEIGHT ? 0 : CZ/HEIGHT);
  102. int center = spawnEntity(true, "carepackage_friendly_iw6", corner1[0], corner1[1], corner1[2], 0,0,0);
  103. for(int r = 0; r <= ROWS; r++) {
  104. for(int c = 0; c <= COLUMNS; c++) {
  105. for(int h = 0; h <= HEIGHT; h++) {
  106. int block = spawnEntity(true, "carepackage_friendly_iw6", corner1[0] + (XA * r), corner1[1] + (YA * c),
  107. corner1[2] + (ZA * h), 0, 0, 0);
  108. LinkTo(block, center);
  109. }
  110. }
  111. }
  112. G_SetAngle(center, angle);
  113. SV_LinkEntity(center);
  114. }
  115. void CreateWall(float* start, float *end)
  116. {
  117. float D = Distance(start[0], start[1], 0, end[0], end[1], 0),
  118. H = Distance(0, 0, start[2], 0, 0, end[2]);
  119. int blocks = roundUp(D/60),
  120. height = roundUp(H/32);
  121. float CX = end[0] - start[0],
  122. CY = end[1] - start[1],
  123. CZ = end[2] - start[2],
  124. XA = (CX/blocks),
  125. YA = (CY/blocks),
  126. ZA = (CZ/height),
  127. TXA = (XA/4),
  128. TYA = (YA/4),
  129. Temp[3], Temp2[3];
  130. for(int i = 0; i < 3; i ++)
  131. Temp2[i] = end[i] - start[i];
  132. vectoangles(Temp2, Temp);
  133. for(int h = 0; h < height; h++){
  134. spawnEntity(true, "carepackage_friendly_iw6", start[0] + TXA, start[1] + TYA,
  135. start[2] + 10 + (ZA*h), 0, Temp[1], 90);
  136. for(int i = 1; i < blocks; i++){
  137. spawnEntity(true, "carepackage_friendly_iw6", start[0] + (XA*i), start[1] + (YA*i),
  138. start[2] + 10 + (ZA*h), 0, Temp[1], 90);
  139. }
  140. spawnEntity(true, "carepackage_friendly_iw6",end[0] + (TXA*-1), end[1] + (TYA*-1),
  141. start[2] + 10 + (ZA*h), 0, Temp[1], 90);
  142. }
  143. }
  144. void CreateBridge(float* point1, float* point2, float* point3)//See the function below to understand
  145. {
  146. float *points[3] = {point1, point2, point3};
  147. for(int i = 0; i < 3; i++) {
  148. if(i+1 >= ((point3[0]==-1234543.3f&&point3[1]==0) ? 2 : 3))
  149. return;
  150. int blocks = roundUp(Distance(points[i], points[i+1])/32);
  151. float CX = points[i][0] - points[i+1][0],
  152. CY = points[i][1] - points[i+1][1],
  153. CZ = points[i][2] - points[i+1][2],
  154. XA = CX/blocks,
  155. YA = CY/blocks,
  156. ZA = CZ/blocks,
  157. CXY = Distance((points[i][0], points[i][1], 0), (points[i+1][0], points[i+1][1], 0)),
  158. Temp[3], Temp2[3] = {points[i][0] - points[i+1][0], points[i][1] - points[i+1][1],
  159. points[i][2] - points[i+1][2]};
  160. vectoangles(Temp2, Temp);
  161. for(int b = 0; b <= blocks; b++){
  162. spawnEntity(true, "carepackage_friendly_iw6", points[i+1][0] + (XA*b), points[i+1][1] + (YA*b), points[i+1][2] + (ZA*b),
  163. Temp[2], Temp[1] + 90, Temp[0]);
  164. }
  165. }
  166. }
  167. void CreateBridge(float point1X, float point1Y, float point1Z, float point2X, float point2Y,
  168. float point2Z, float point3X = -1234543.3f, float point3Y = 0, float point3Z = 0)//the point3 isn't needed unless you want to make a 3rd point
  169. {
  170. float point1[] = {point1X,point1Y,point1Z},
  171. point2[] = {point2X,point2Y,point2Z},
  172. point3[] = {point3X,point3Y,point3Z};
  173. CreateBridge(point1, point2, point3);
  174. }
  175. [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement