BirdDemo.bb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. Global info1$="Birds Demo, by Adam Gore"
  2. Global info2$="A small Blitz3D compatibility test"
  3. Global info3$="Spline data imported from Lightwave"
  4. Include "../start.bb"
  5. Include "KBSplines.bb"
  6. Global gwidth = 640;800
  7. Global gheight = 480;600
  8. Const FPS = 30
  9. Global fstep
  10. ;Graphics3D gwidth,gheight
  11. period=1000/FPS
  12. time=MilliSecs()-period
  13. cmot.Motion = New motion
  14. b2mot.Motion = New Motion
  15. b1mot.Motion = New Motion
  16. If Load_Motion( "Cam.bbm", cmot ) = False Then RuntimeError "Error loading file" : End
  17. If Load_Motion( "Bird1.bbm", b1mot ) = False Then RuntimeError "Error loading file" : End
  18. If Load_Motion( "Bird2.bbm", b2mot ) = False Then RuntimeError "Error loading file" : End
  19. camera=CreateCamera()
  20. CameraRange camera,1,3000
  21. AmbientLight 90,90,90
  22. light_sun = CreateLight(1)
  23. LightColor light_sun,200,200,100
  24. RotateEntity light_sun,60,-90,0
  25. mesh_canyon = LoadMesh( "Canyon.x" )
  26. mesh_skybox = MakeSkyBox("Textures\sky")
  27. mesh_bird = LoadMD2("Bird.md2")
  28. tex1 = LoadTexture( "Textures\Bird.bmp" )
  29. EntityTexture mesh_bird,tex1
  30. mesh_bird2 = CopyEntity( mesh_bird )
  31. AnimateMD2 mesh_bird,1,2.5,0,31
  32. AnimateMD2 mesh_bird2,1,2.5,0,31
  33. Apply_Motion(cmot,0,camera)
  34. Apply_Motion(b1mot,0,mesh_bird)
  35. Apply_Motion(b2mot,0,mesh_bird2)
  36. fstep = 1
  37. While KeyHit(1)<>True
  38. Repeat
  39. elapsed=MilliSecs()-time
  40. Until elapsed
  41. ticks=elapsed/period
  42. tween#=Float(elapsed Mod period)/Float(period)
  43. For k=1 To ticks
  44. time=time+period
  45. If k=ticks Then CaptureWorld
  46. Apply_Motion(cmot,fstep,camera)
  47. Apply_Motion(b1mot,fstep,mesh_bird)
  48. Apply_Motion(b2mot,fstep,mesh_bird2)
  49. fstep = fstep + 1
  50. If fstep > cmot\nsteps Then fstep = 1
  51. PositionEntity mesh_skybox,EntityX(camera,1),EntityY(camera,1),EntityZ(camera,1)
  52. UpdateWorld
  53. Next
  54. RenderWorld tween
  55. Flip
  56. Wend
  57. End
  58. Function MakeSkyBox( file$ )
  59. m=CreateMesh()
  60. ;front face
  61. b=LoadBrush( file$+"_FR.bmp",49 )
  62. s=CreateSurface( m,b )
  63. AddVertex s,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0
  64. AddVertex s,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1
  65. AddTriangle s,0,1,2:AddTriangle s,0,2,3
  66. FreeBrush b
  67. ;right face
  68. b=LoadBrush( file$+"_LF.bmp",49 )
  69. s=CreateSurface( m,b )
  70. AddVertex s,+1,+1,-1,0,0:AddVertex s,+1,+1,+1,1,0
  71. AddVertex s,+1,-1,+1,1,1:AddVertex s,+1,-1,-1,0,1
  72. AddTriangle s,0,1,2:AddTriangle s,0,2,3
  73. FreeBrush b
  74. ;back face
  75. b=LoadBrush( file$+"_BK.bmp",49 )
  76. s=CreateSurface( m,b )
  77. AddVertex s,+1,+1,+1,0,0:AddVertex s,-1,+1,+1,1,0
  78. AddVertex s,-1,-1,+1,1,1:AddVertex s,+1,-1,+1,0,1
  79. AddTriangle s,0,1,2:AddTriangle s,0,2,3
  80. FreeBrush b
  81. ;left face
  82. b=LoadBrush( file$+"_RT.bmp",49 )
  83. s=CreateSurface( m,b )
  84. AddVertex s,-1,+1,+1,0,0:AddVertex s,-1,+1,-1,1,0
  85. AddVertex s,-1,-1,-1,1,1:AddVertex s,-1,-1,+1,0,1
  86. AddTriangle s,0,1,2:AddTriangle s,0,2,3
  87. FreeBrush b
  88. ;top face
  89. b=LoadBrush( file$+"_UP.bmp",49 )
  90. s=CreateSurface( m,b )
  91. AddVertex s,-1,+1,+1,0,1:AddVertex s,+1,+1,+1,0,0
  92. AddVertex s,+1,+1,-1,1,0:AddVertex s,-1,+1,-1,1,1
  93. AddTriangle s,0,1,2:AddTriangle s,0,2,3
  94. FreeBrush b
  95. ScaleMesh m,1700,1700,1700
  96. FlipMesh m
  97. EntityFX m,1
  98. Return m
  99. End Function