home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch17 / pi / bspline / b_spline.pi < prev   
Encoding:
Text File  |  1994-08-05  |  3.4 KB  |  125 lines

  1. // Scene File: B-SPLINE.PI
  2. // Author: Rob McGregor
  3.  
  4. // Uses B-Spline interpolation influenced by key frame 
  5. // points to calculate an object's path... 
  6.  
  7. include "..\..\..\colors.inc"
  8. include "..\..\..\texture.inc"
  9. include "..\..\..\stones.inc"
  10.  
  11. // Set up the camera
  12. viewpoint {
  13.   from       <0, 0, -10>
  14.   at         <0, 0, 0>
  15.   up         <0, 1, 0>
  16.   angle      45
  17.   resolution 320,200
  18.   aspect     1.6
  19. }
  20.  
  21. // Define the range of the animation
  22. start_frame 0
  23. end_frame   50
  24. outfile     "bspln"
  25.  
  26. /******************************************************** 
  27.    The control points are:
  28.    
  29.    <0, 0, 0>, <1.6, 2.8, 0>, <3.6, 0, 0>, 
  30.    <0.4, -3.2, 0>, <-3.2, -0.4, 0>, <0, 0, 0>
  31.    
  32.    The first and last points are doubled to include them 
  33.    in the interpolation and create a smoother loop.
  34.  
  35.    x-axis: 0, 0, 1.6, 3.6,  0.4, -3.2, 0, 0 
  36.    y-axis: 0, 0, 2.8, 0.0, -3.2, -0.4, 0, 0
  37. *********************************************************/
  38.  
  39. // Define the 4 local 3-D control points as arrays
  40. define n1x [0, 0, 1.6, 3.6,  0.4]
  41. define n1y [0, 0, 2.8, 0.0, -3.2]
  42.  
  43. define n2x [0, 1.6, 3.6,  0.4, -3.2]
  44. define n2y [0, 2.8, 0.0, -3.2, -0.4]
  45.  
  46. define n3x [1.6, 3.6,  0.4, -3.2, -0.4]
  47. define n3y [2.8, 0.0, -3.2, -0.4,  0.0]
  48.  
  49. define n4x [3.6,  0.4, -3.2, 0, 0]
  50. define n4y [0.0, -3.2, -0.4, 0, 0]
  51.  
  52. // Set up the key frames in another array
  53. define KF [0, 9, 19, 29, 39, 49]
  54.  
  55. // Assign the value of "frame" to variable "F"
  56. define F frame
  57.  
  58. // Determine what key frame sequence we're in
  59. if (F <= KF[1])               // <= 9 
  60.   define key 0
  61. if (F > KF[1] && F <= KF[2])  // > 9 && <= 19
  62.   define key 1
  63. if (F > KF[2] && F <= KF[3])  // > 19 && <= 29
  64.   define key 2
  65. if (F > KF[3] && F <= KF[4])  // > 29 && <= 39
  66.   define key 3
  67. if (F > KF[4])                // > 39 
  68.   define key 4
  69.  
  70. // Calculate the value of "t" from the 
  71. // current frame and key frame sequence
  72. define F1 KF[key]
  73. define F2 KF[key + 1]
  74. define t  (F - F1) / (F2 - F1)
  75.  
  76. /****************************************************************
  77.   Calculate the values of the object's location vector using the 
  78.   B-Spline equation:
  79.  
  80.     P = ((-P1 * t^3 + 3 * P2 * t^3 - 3 * P3 * t^3 + P4 * t^3) +
  81.         (3 * P1 * t^2 - 6 * P2 * t^2 + 3 * P3 * t^2) +
  82.         (-3 * P1 * t +3 * P3 *t) + (P1 + 4 * P2 + P3)) * (1 / 6)
  83. ****************************************************************/
  84.  
  85. define t2 t * t
  86. define t3 t2 * t
  87.  
  88. define Px ((-n1x[key] * t3 + 3 * n2x[key] * t3 - 3 * n3x[key] * 
  89.           t3 + n4x[key] * t3) + (3 * n1x[key] * t2 - 6 * 
  90.           n2x[key] * t2 + 3 * n3x[key] * t2) + (-3 * n1x[key] * 
  91.           t +3 * n3x[key] *t) + (n1x[key] + 4 * n2x[key] + 
  92.           n3x[key])) * (1 / 6)
  93.  
  94. define Py ((-n1y[key] * t3 + 3 * n2y[key] * t3 - 3 * n3y[key] * 
  95.           t3 + n4y[key] * t3) + (3 * n1y[key] * t2 - 6 * 
  96.           n2y[key] * t2 + 3 * n3y[key] * t2) + (-3 * n1y[key] * 
  97.           t +3 * n3y[key] *t) + (n1y[key] + 4 * n2y[key] + 
  98.           n3y[key])) * (1 / 6)
  99.  
  100. // Now move the sphere to the new location
  101. object {
  102.   sphere <0, 0, 0>, 0.5
  103.   reflective_red
  104.   translate <Px, Py, 0>
  105. }
  106.  
  107. // Set the sky color and add a little haze
  108. background Grey
  109. haze 0.98, 25, Grey
  110.  
  111. // Lights
  112. light <-5, 30, -100>
  113. light <5, 30, -100>
  114.  
  115. // The floor...
  116. object {
  117.   disc <0, 0, 0>, <0, 1, 0>, 10000
  118.   texture { 
  119.     checker steely_blue, 
  120.     texture { shiny { color white }}
  121.   }
  122.   rotate <0, 25, 0>
  123.   translate <0, -4.5, 0>
  124. }
  125.