Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. ;TRACK_SMOOTH TRACK_YR TRACK_SMOOTH_YR SAMPLE DEMO
  2. ;WRITTEN By Bitmaniak
  3. ;Tracking Functions idea and specs By DoctorZ
  4. ;Tracking Functions code by Bitmaniak
  5. ;*********************************************************************************
  6. ;*** Thi is a real shared pivot...
  7. ;*********************************************************************************
  8. Global gPivot1,gPivot2,gCube
  9.  
  10. ;*********************************************************************************
  11. ;*** Slow PointEntity on xz axe
  12. ;*********************************************************************************
  13. Function track_YR_Smooth(e1,e2,smothness#=1.0)
  14. PositionEntity gPivot1,EntityX(e1),EntityY(e1),EntityZ(e1)
  15. PointEntity gPivot1,e2
  16. RotateEntity e1, 0,curveAngle#(EntityYaw(gPivot1),EntityYaw(e1),smothness#),0
  17. End Function
  18.  
  19. ;*********************************************************************************
  20. ;*** Fast PointEntity on xz axe
  21. ;*********************************************************************************
  22. Function track_YR(e1,e2)
  23. PositionEntity gPivot1,EntityX(e1),EntityY(e1),EntityZ(e1)
  24. PointEntity gPivot1,e2
  25. RotateEntity e1, 0,EntityYaw(gPivot1),0
  26. End Function
  27.  
  28. ;*********************************************************************************
  29. ;*** Slow PointEntity on all axes
  30. ;*********************************************************************************
  31. Function track_Smooth(e1,e2,smothness#)
  32. PositionEntity gPivot1,EntityX(e1),EntityY(e1),EntityZ(e1)
  33. PointEntity gPivot1,e2
  34. RotateEntity e1, curveAngle#(EntityPitch(gPivot1),EntityPitch(e1),smothness#),curveAngle#(EntityYaw(gPivot1),EntityYaw(e1),smothness#),0
  35. End Function
  36. ;*********************************************************************************
  37. ;*** Fast PointEntity on all axes...so...pointEntity...just for fun!
  38. ;*********************************************************************************
  39. Function track(e1,e2)
  40. PointEntity e1,e2
  41. End Function
  42.  
  43. ;*********************************************************************************
  44. ;*** This calculate the 2d distance*distance on y axes
  45. ;*** The exact distance is the sqr( EntityDistance_YR_Power2(e1,e2))
  46. ;*********************************************************************************
  47. Function EntityDistance_YR_Power2(e1,e2)
  48. p#=EntityX(e2)-EntityX(e1)
  49. q#=EntityZ(e2)-EntityZ(e1)
  50. Return (p*p)+(q*q)
  51. End Function
  52.  
  53. ;*********************************************************************************
  54. ;*** Anyone knows this! Calculate the incremental steps
  55. ;*********************************************************************************
  56. Function curveangle#( newangle#,oldangle#,increments#)
  57. If increments>1
  58. If (oldangle+360)-newangle<newangle-oldangle
  59. oldangle=360+oldangle
  60. End If
  61. If (newangle+360)-oldangle<oldangle-newangle
  62. newangle=360+newangle
  63. End If
  64. oldangle=oldangle-(oldangle-newangle)/increments
  65. End If
  66. If increments<=1
  67. Return newangle
  68. End If
  69. Return oldangle
  70.  
  71. End Function
  72.  
  73. ;*********************************************************************************
  74. ;*** Same of above but with points
  75. ;*********************************************************************************
  76. ;Global gPivot2
  77. Function track_SmoothPoint(entity, x#,y#,z#, turnspeed#=1.0, useRoll%=0)
  78. PositionEntity gPivot2,x,y,z
  79. PositionEntity gPivot1,EntityX(entity),EntityY(entity),EntityZ(entity)
  80. PointEntity gPivot1,gPivot2
  81. temp_pitch# = curveAngle#(EntityPitch(gPivot1),EntityPitch(entity),turnspeed#*2)
  82. temp_yaw# = curveAngle#(EntityYaw(gPivot1),EntityYaw(entity),turnspeed#)
  83. If useRoll
  84. temp_roll# = curveAngle#(EntityRoll(gPivot1),EntityRoll(entity),turnspeed#)
  85. RotateEntity entity, temp_pitch, temp_yaw, temp_roll
  86. Else
  87. RotateEntity entity, temp_pitch, temp_yaw, 0
  88. End If
  89. End Function
  90.  
  91. ;*********************************************************************************
  92. ;*** Create a squared texure
  93. ;*********************************************************************************
  94. Function defaultTextureEntity(mesh, colr1=32,colg1=128,colb1=192, colr2=255,colg2=255,colb2=160)
  95. tex=CreateTexture( 64,64 )
  96. ScaleTexture tex,.125,.125
  97. SetBuffer TextureBuffer( tex )
  98. Color colr1,colg1,colb1:Rect 32,0,32,32:Rect 0,32,32,32
  99. Color colr2,colg2,colb2:Rect 0,0,32,32:Rect 32,32,32,32
  100. SetBuffer BackBuffer()
  101. Color 255,255,255
  102.  
  103. brush=CreateBrush()
  104. BrushTexture brush,tex
  105. EntityTexture mesh,tex
  106.  
  107. FreeBrush brush
  108. FreeTexture tex
  109. End Function
  110.  
  111. ;*********************************************************************************
  112. ;*** Draws Lines
  113. ;*********************************************************************************
  114. Function drawpivot(e,camera,length)
  115. ;Get initial position
  116. CameraProject camera,EntityX(e,1),EntityY(e,1),EntityZ(e,1)
  117. x=ProjectedX()
  118. y=ProjectedY()
  119.  
  120. ;Draw X axis
  121. Color 255,0,0
  122. MoveEntity e,length,0,0
  123. CameraProject camera,EntityX(e,1),EntityY(e,1),EntityZ(e,1)
  124. Line x,y,ProjectedX(),ProjectedY()
  125. MoveEntity e,-length,0,0
  126.  
  127. ;Draw Y axis
  128. Color 0,255,0
  129. MoveEntity e,0,length,0
  130. CameraProject camera,EntityX(e,1),EntityY(e,1),EntityZ(e,1)
  131. Line x,y,ProjectedX(),ProjectedY()
  132. MoveEntity e,0,-length,0
  133.  
  134. ;Draw Z axis
  135. Color 0,0,255
  136. MoveEntity e,0,0,length
  137. CameraProject camera,EntityX(e,1),EntityY(e,1),EntityZ(e,1)
  138. Line x,y,ProjectedX(),ProjectedY()
  139. MoveEntity e,0,0,-length
  140. End Function
  141.  
  142.  
  143. ;*********************************************************************************
  144. ;*** The test!
  145. ;*********************************************************************************
  146.  
  147. Graphics3D 800,600
  148. SetBuffer BackBuffer()
  149.  
  150. camera=CreateCamera()
  151. light=CreateLight()
  152.  
  153. PositionEntity camera,0,0,-10
  154.  
  155. ;*** create some entities
  156. cone=CreateCone()
  157. PositionEntity cone,-2,0,-5
  158. RotateMesh cone,90,0,0
  159. defaultTextureEntity(cone)
  160.  
  161.  
  162. cone1=CopyEntity(cone)
  163. PositionEntity cone1,-1,0,0
  164. EntityColor cone1,255,0,0
  165.  
  166. cone2=CopyEntity(cone)
  167. PositionEntity cone2,1,2,0
  168. EntityColor cone2,0,255,0
  169.  
  170. cone3=CopyEntity(cone)
  171. PositionEntity cone3,0,0,0
  172. EntityColor cone3,0,255,255
  173.  
  174. cone4=CopyEntity(cone)
  175. PositionEntity cone4,0,0,0
  176. EntityColor cone4,255,255,0
  177.  
  178. cube=CreateCube()
  179. PositionEntity cube,0,0,8
  180. defaultTextureEntity(cube)
  181.  
  182.  
  183. plane = CreatePlane()
  184. defaultTextureEntity(plane)
  185. PositionEntity plane,0,-.5,0
  186. EntityAlpha plane,.5
  187.  
  188. gPivot1 = CreatePivot()
  189. gPivot2 = CreatePivot()
  190. gCube = CreatePivot()
  191.  
  192. gfxMiddleWidth = GraphicsWidth()/2
  193. gfxMiddleHeight = GraphicsHeight()/2
  194.  
  195. ;*********************************************************************************
  196.  
  197. While Not KeyDown( 1 )
  198. ;*** Cube rotation
  199. my = -MouseYSpeed()/5
  200. mx = MouseXSpeed()/5
  201.  
  202. MoveMouse gfxMiddleWidth,gfxMiddleHeight
  203. ; PositionEntity gPivot1,EntityX(cone),EntityY(cone),EntityZ(cone)
  204. PositionEntity gPivot1,0,0,0
  205.  
  206.  
  207. EntityParent cube,gCube
  208. TurnEntity gCube,my,mx,0
  209. EntityParent cube,0
  210.  
  211. ;*** The routines
  212. ;*** Before you used to call a pointEntity(e1,e2)...now you'll call a track_Smooth(e1,e2,smooth)
  213.  
  214. track_Smooth(cone,cube,20.0)
  215. track_Smooth(cone1,cube,100.0)
  216. track(cone2,cube)
  217.  
  218. d#=EntityDistance_YR_Power2(cone3,cube)
  219. If d>1
  220. track_YR_Smooth(cone3,cube,10.0)
  221. MoveEntity cone3,0,0,.1
  222. End If
  223.  
  224. track_Smooth(cone4,cube,EntityDistance(cone4,cube)*2)
  225. MoveEntity cone4,0,0,EntityDistance(cone4,cube)/200.0
  226.  
  227. RenderWorld
  228.  
  229. drawpivot(cone,camera,1)
  230. drawpivot(cone1,camera,1)
  231. drawpivot(cone2,camera,1)
  232. drawpivot(cone3,camera,1)
  233. drawpivot(cone4,camera,1)
  234.  
  235. Text 0,0,d
  236. Flip
  237. Wend
  238.  
  239. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement