home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch3_6 / axd.c next >
Encoding:
C/C++ Source or Header  |  1995-04-25  |  4.2 KB  |  164 lines

  1. /* ------------------------------------------------------------------------- *\
  2.    AXD.C :
  3.  
  4.    This package provides an implementation of 6 different algorithms
  5.    for doing procedural axial deformations.
  6.  
  7.    by Carole Blanc (4 June 1994)
  8.  
  9.    "A Generic Implementation of Axial Deformation Techniques"
  10.    in Graphics Gems V (edited by A. Paeth), Academic Press
  11. \* ------------------------------------------------------------------------- */
  12.  
  13. /*
  14. ** This package uses the "Toolbox of Macros Functions for Computer Graphics"
  15. ** which provides files : tool.h, real.h, uint.h, sint.h, vec?.h and mat?.h
  16. */
  17.  
  18. #include "axd.h"
  19. #include "../ch7-7/mactbox/mat3.h"
  20.  
  21. /*
  22. ** Each "local_*" routines inputs/outputs the following arguments
  23. **
  24. ** Input:  Point = coordinates of the point in the local frame
  25. **         Shape = shape function of the deformation
  26. **         Ampli = amplitude of the deformation
  27. ** Output: Point = coordinates of the deformed point in the local frame
  28. **
  29. ** Each "world_*" routines inputs/outputs the following arguments
  30. **
  31. ** Input:  Point = coordinates of the point in the world frame
  32. **         Frame = local frame in which the deformation is applied
  33. **         Shape = shape function of the deformation
  34. **         Ampli = amplitude of the deformation
  35. ** Output: Point = coordinates of the deformed point in the world frame
  36. **
  37. ** Note: The "Frame" argument must be initialized by MAKE_FRAME3 (see "mat3.h")
  38. */
  39.  
  40. /*
  41. ** pinch : Scale the x coordinate of the object according to z
  42. */
  43.  
  44. void local_pinch (realvec3 *Point, shape Shape, real Ampli)
  45. {
  46.   Point->x *= 1.0 - Ampli * Shape (Point->z); 
  47. }
  48.  
  49. void world_pinch (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  50. {
  51.   realvec3 Tmp;
  52.  
  53.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  54.   local_pinch  (&Tmp, Shape, Ampli);
  55.   WORLD_FRAME3 (*Point, Frame, Tmp);
  56. }
  57.  
  58. /*
  59. ** taper : Scale the polar radius of the object according to z
  60. */
  61.  
  62. void local_taper (realvec3 *Point, shape Shape, real Ampli)
  63. {
  64.   register real Tmp;
  65.  
  66.   Tmp = 1.0 - Ampli * Shape (Point->z); Point->x *= Tmp; Point->y *= Tmp;
  67. }
  68.  
  69. void world_taper (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  70. {
  71.   realvec3 Tmp;
  72.  
  73.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  74.   local_taper  (&Tmp, Shape, Ampli);
  75.   WORLD_FRAME3 (*Point, Frame, Tmp);
  76. }
  77.  
  78. /*
  79. ** mould : Scale the polar radius of the object according to the polar angle
  80. */
  81.  
  82. void local_mould (realvec3 *Point, shape Shape, real Ampli)
  83. {
  84.   register real Tmp;
  85.  
  86.   Tmp = atan2 (Point->y, Point->x) / PI;
  87.   Tmp = 1.0 - Ampli * Shape (Tmp); Point->x *= Tmp; Point->y *= Tmp;
  88. }
  89.  
  90. void world_mould (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  91. {
  92.   realvec3 Tmp;
  93.  
  94.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  95.   local_mould  (&Tmp, Shape, Ampli);
  96.   WORLD_FRAME3 (*Point, Frame, Tmp);
  97. }
  98.  
  99. /*
  100. ** twist : Scale the polar angle of the object according to z
  101. */
  102.  
  103. void local_twist (realvec3 *Point, shape Shape, real Ampli)
  104. {
  105.   register real Tmp, Cos, Sin;
  106.  
  107.   Tmp = PI * Ampli * Shape (Point->z);
  108.   Cos = cos (Tmp); Sin = sin (Tmp); Tmp = Point->x;
  109.   Point->x = Cos * Tmp - Sin * Point->y;
  110.   Point->y = Sin * Tmp + Cos * Point->y;
  111. }
  112.  
  113. void world_twist (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  114. {
  115.   realvec3 Tmp;
  116.  
  117.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  118.   local_twist  (&Tmp, Shape, Ampli);
  119.   WORLD_FRAME3 (*Point, Frame, Tmp);
  120. }
  121.  
  122. /*
  123. ** shear : Translate the z axis of the object along x according to z
  124. */
  125.  
  126. void local_shear (realvec3 *Point, shape Shape, real Ampli)
  127. {
  128.   Point->x += Ampli * Shape (Point->z);
  129. }
  130.  
  131. void world_shear (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  132. {
  133.   realvec3 Tmp;
  134.  
  135.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  136.   local_shear  (&Tmp, Shape, Ampli);
  137.   WORLD_FRAME3 (*Point, Frame, Tmp);
  138. }
  139.  
  140. /*
  141. ** bend : Rotate the z axis of the object around y according to z
  142. */
  143.  
  144. void local_bend (realvec3 *Point, shape Shape, real Ampli)
  145. {
  146.   register real Tmp, Cos, Sin;
  147.  
  148.   Tmp = PI * Ampli * Shape (Point->z);
  149.   Cos = cos (Tmp); Sin = sin (Tmp); Tmp = Point->z;
  150.   Point->z = Cos * Tmp - Sin * Point->x;
  151.   Point->x = Sin * Tmp + Cos * Point->x;
  152. }
  153.  
  154. void world_bend (realvec3 *Point, frame3 Frame, shape Shape, real Ampli)
  155. {
  156.   realvec3 Tmp;
  157.  
  158.   LOCAL_FRAME3 (Tmp, Frame, *Point);
  159.   local_bend   (&Tmp, Shape, Ampli);
  160.   WORLD_FRAME3 (*Point, Frame, Tmp);
  161. }
  162.  
  163. /* ------------------------------------------------------------------------- */
  164.