FitMesh.bb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ; FitMesh Example
  2. ; ---------------
  3. ; In this example we will demonstrate the use of the FitMesh command.
  4. ; First we will use FitMesh on a semi-transparent blue box. This will represent the dimensions we will
  5. ; be using with FitMesh.
  6. ; Then we will use these dimensions on a red cone, so that it appears to fit inside the box when the
  7. ; space bar is pressed.
  8. ; The first time the space bar is pressed a uniform FitMesh will be performed, which means the cone
  9. ; will be scaled equally along all axis so that at least one axis fits the dimensions specified.
  10. ; The second time the space bar is pressed a non-unifrom FitMesh will be performed, meaning the cone
  11. ; will be scaled non-equally along all axes so that all axes fit the dimensions specified.
  12. Graphics3D 640,480
  13. SetBuffer BackBuffer()
  14. camera=CreateCamera()
  15. light=CreateLight()
  16. ; Create cube
  17. cube=CreateCube()
  18. ; Set cube colour to blue
  19. EntityColor cube,0,0,255
  20. ; Make cube semi-transparent so we will be able to see cone inside it later
  21. EntityAlpha cube,0.5
  22. ; Use FitMesh on cube to make it a cuboid
  23. FitMesh cube,-1,-.5,-1,2,1,2
  24. ; Position cube in front of camera so we can see it
  25. PositionEntity cube,0,-1,5
  26. ; Create cone
  27. cone=CreateCone()
  28. ; Set cone color to red
  29. EntityColor cone,255,0,0
  30. ; Position cone in front of camera so we can see it
  31. PositionEntity cone,0,-1,5
  32. ; Set uniform value to 1 so when space is first pressed, FitMesh will be uniform
  33. uniform=1
  34. While Not KeyDown(1)
  35. ; If space bar pressed....
  36. If KeyHit(57)=True
  37. ; Set syntax string to show syntax useage
  38. syntax$="FitMesh cone,-1,-.5,-1,2,1,2,"+uniform
  39. ; Use FitMesh with cone, using same values as used with cube earlier. Cone should now fit in cube.
  40. FitMesh cone,-1,-.5,-1,2,1,2,uniform
  41. ; Change uniform value from 1 to 0 so when space bar is pressed again FitMesh will be non-uniform
  42. uniform=0
  43. EndIf
  44. RenderWorld
  45. Text 0,0,"Press space to use uniform FitMesh with cone"
  46. Text 0,20,"Press space again to use non-uniform FitMesh with cone"
  47. Text 0,40,syntax$
  48. Flip
  49. Wend
  50. End