modelchildren.bb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;
  2. ; MODEL CHILDREN V1.00
  3. ; --------------------
  4. ; Simple example of how to play around with a model's children objects.
  5. ; Here, the flares and backplate are part of the "Models\facia.x" model.
  6. ; The example gets entities from each of the child flare subobjects in
  7. ; the facia model and moves them around on the X and Y axis. Simple.
  8. ;
  9. ; Email: [email protected] / ICQ: 27181384
  10. ;
  11. ; Created with BB3D Beta 1.60
  12. ; Last Modified: 13/08/2001
  13. ;
  14. AppTitle "Model Children V1.00 - By Rob Hutchinson 2001"
  15. ; Randomize from the timer.
  16. SeedRnd MilliSecs()
  17. ; Setup the screen
  18. Include "start.bb"
  19. ; Setup the camera
  20. camera = CreateCamera()
  21. ; Load in our model
  22. mainmesh = LoadAnimMesh("models\facia.x")
  23. MoveEntity mainmesh,7,3,20
  24. TurnEntity mainmesh,180,0,0
  25. ; Some ambient lighting
  26. AmbientLight 200,200,200
  27. ; Flies:
  28. Type fly
  29. Field obj
  30. Field posx#,posy#
  31. Field rotx#,roty#
  32. Field radx#,rady#
  33. Field spdx#,spdy#
  34. End Type
  35. ; Count the number of children in the model. We already know
  36. ; that child 1 is the backface, so we use all other objects (the flares).
  37. Global maxFlies = CountChildren(mainmesh)-1
  38. Global TopSpeed# = 2.5
  39. Dim flies.fly(maxFlies+1)
  40. For a=0 To CountChildren(mainmesh)-2
  41. flies(a) = New fly
  42. ; Get a handle to the child object.
  43. flies(a)\obj = GetChild(mainmesh,a+2)
  44. ; Addition blend the object so it appears as a light rather than a brick.
  45. EntityBlend flies(a)\obj,3
  46. ; Randomize some movement values.
  47. flies(a)\rotx = Rnd(360)
  48. flies(a)\roty = Rnd(360)
  49. flies(a)\radx = Rnd(-15,15)
  50. flies(a)\rady = Rnd(-15,15)
  51. flies(a)\spdx = Rnd(-TopSpeed#,TopSpeed#)
  52. flies(a)\spdy = Rnd(-TopSpeed#,TopSpeed#)
  53. Next
  54. Repeat
  55. ; Allow the user to switch to wireframe mode.
  56. If KeyHit(17) Then wire = Not wire
  57. WireFrame wire
  58. ; Move them all!
  59. For a=0 To CountChildren(mainmesh)-2
  60. flies(a)\posx=Sin(flies(a)\rotx)*flies(a)\radx
  61. flies(a)\posy=Cos(flies(a)\roty)*flies(a)\rady
  62. flies(a)\rotx=flies(a)\rotx+flies(a)\spdx
  63. flies(a)\roty=flies(a)\roty+flies(a)\spdy
  64. flies(a)\rotx=QWrap(flies(a)\rotx,0,360)
  65. flies(a)\roty=QWrap(flies(a)\roty,0,360)
  66. PositionEntity flies(a)\obj,flies(a)\posx,flies(a)\posy,EntityZ(flies(a)\obj)
  67. Next
  68. ; Update the world stuff
  69. UpdateWorld
  70. RenderWorld
  71. ; Flip display
  72. Flip
  73. Until KeyDown(1)
  74. ; Terminate.
  75. End
  76. Function CurveValue#(current#,destination#,curve)
  77. current#=current#+((destination#-current#)/curve)
  78. Return current#
  79. End Function
  80. Function QWrap(Value#,Low#,High#) ; Remember this? where is the Blitz
  81. Return Low#+(Value# Mod High#) ; PC version when you need it? :))
  82. End Function