home *** CD-ROM | disk | FTP | other *** search
/ Dream 41 / Amiga_Dream_41.iso / Amiga / Pro / 3d / ICoons1_0.lzh / icoons / source / rotate_g.c < prev    next >
C/C++ Source or Header  |  1992-10-05  |  8KB  |  263 lines

  1. /* :ts=8 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <math.h>
  7.  
  8. #include "general.h"
  9. #include "globals.h"
  10. #include "intui.h"
  11. #include "timer.h"
  12. #include "spl_math.h"
  13. #include "spl_util.h"
  14. #include "spl_gfx.h"
  15. #include "rotate_g.h"
  16.  
  17. /* Get Stringinfo buffer for the Rotate gadget with id 'G':    */
  18. #define Get_Gadget_String(G) (((struct StringInfo *) \
  19.                 (Rotate_GroupGadgets[G]->SpecialInfo))->Buffer)
  20.  
  21.     /* Set string to 'S' in string gadget 'G':    */
  22. #define Set_Gadget_String(G, S) \
  23.         GT_SetGadgetAttrs(Rotate_GroupGadgets[G], \
  24.             Windows[W_Rotate_Group].Window, NULL, \
  25.             GTST_String, S)
  26.  
  27. static Boolean_T    Rotate_Group_Active;
  28. static short        Rotate_Group_Axis = 0; /* 0 = X, 1 = Y, 2 = Z */
  29. static short        Orig_Rotate_Group_X;
  30. static short        Prev_Rotate_Group_X;
  31. static double        Rotate_Group_Angle;
  32. static Vector_T        Box_Min, Box_Max;
  33.  
  34. static
  35. void Set_Rotate_Group_Angle_Value(double Angle)
  36. /************************************************************************/
  37. /*                                                                      */
  38. /* Set rotate angle value gadget to 'Angle'.                */
  39. /*                                                                      */
  40. /************************************************************************/
  41. {
  42.     char Buffer[Buffer_Length+1];
  43.  
  44.     if (Windows[W_Rotate_Group].Window == NULL) return;
  45.  
  46.     sprintf(Buffer, " %.0lf", Angle);
  47.     Set_Gadget_String(GDX_Rotate_Group_Angle_Value, Buffer);
  48.  
  49. } /* Set_Rotate_Group_Angle_Value */
  50.  
  51. static
  52. void Rotate_Group_Timeout()
  53. /************************************************************************/
  54. /*                                                                      */
  55. /* Function called when timer expires: Draw all splines.        */
  56. /*                                                                      */
  57. /************************************************************************/
  58. {    
  59.     Points_Rotate(Rotate_Group_Angle, Rotate_Group_Axis);
  60.     Compute_Splines();
  61.     Clear_All(What_All);
  62.     Draw_All(What_All);
  63.  
  64.     Redraw_Mask = 0;
  65.  
  66.     Stop_Timer();
  67.  
  68. } /* Rotate_Group_Timeout */
  69.  
  70. static 
  71. void Rotate_Group_Redraw(long Mask)
  72. /************************************************************************/
  73. /*                                                                      */
  74. /* Function called to redraw screen while rotating points.        */
  75. /*                                                                      */
  76. /************************************************************************/
  77. {    
  78.     Vector_T R_Vector;
  79.  
  80.     if (Windows[W_Rotate_Group].Window == NULL) return;
  81.  
  82.     R_Vector[0] = R_Vector[1] = R_Vector[2] = 0.0;
  83.     R_Vector[Rotate_Group_Axis] = Rotate_Group_Angle;
  84.  
  85.     Set_Rotate_Group_Angle_Value(Rotate_Group_Angle);
  86.  
  87.     Clear_Plane(3, What_All);
  88.     Draw_Box(Box_Min, Box_Max, R_Vector, DM_Plane, What_All);
  89.  
  90.     Start_Timer(Delay_Draw_Seconds, Delay_Draw_Micros);
  91.  
  92.     Redraw_Mask = 0;
  93.  
  94. } /* Rotate_Group_Redraw */
  95.  
  96. static
  97. void Rotate_Group_Select_Up(short X, short Y)
  98. /************************************************************************/
  99. /*                                                                      */
  100. /* X, Y are the actual coordinates in the active window.        */
  101. /*                                                                      */
  102. /************************************************************************/
  103. {
  104.     /* If the timer hasn't expired, then call the timeout handler to*/
  105.     /* compute and draw the splines.                 */
  106.  
  107.     if (!Check_Timer()) Rotate_Group_Timeout();
  108.  
  109.     Set_Rotate_Group_Angle_Value(0.0);
  110.     Set_Mode_Normal();
  111.  
  112. } /* Rotate_Group_Select_Up */
  113.  
  114. static 
  115. void Rotate_Group_Select_Down(short X, short Y)
  116. /************************************************************************/
  117. /*                                                                      */
  118. /* X, Y are the actual coordinates in the active window.        */
  119. /*                                                                      */
  120. /************************************************************************/
  121. {
  122.  
  123.     if (X < 0) return;
  124.  
  125.     if (Get_Select_Bounding_Box(Box_Min, Box_Max)) {
  126.     Display_Message("No points selected");
  127.     return;
  128.     }
  129.     Draw_Box(Box_Min, Box_Max, NULL, DM_Plane, What_All);
  130.  
  131.     Rotate_Group_Active = TRUE;
  132.  
  133.     Orig_Rotate_Group_X = X;
  134.     Prev_Rotate_Group_X = X;
  135.  
  136.     Rotate_Group_Angle = 0.0;
  137.  
  138.     if (MQ_Size_Rotate_G > 0) {
  139.     SetMouseQueue(Windows[Id_Active_Window].Window, MQ_Size_Rotate_G); 
  140.     Redraw_Always = TRUE;
  141.     } else Redraw_Always = FALSE;
  142.  
  143. } /* Rotate_Group_Select_Down */
  144.  
  145. static 
  146. void  Rotate_Group_Move(short X, short Y)
  147. /************************************************************************/
  148. /*                                                                      */
  149. /* Function called when mouse is moved to rotate points.        */
  150. /* X, Y are the actual coordinates in the active window.        */
  151. /*                                                                      */
  152. /************************************************************************/
  153. {
  154.     if (X < 0) return;
  155.  
  156.     if (!Rotate_Group_Active) return;
  157.     if (ABS(X - Prev_Rotate_Group_X) < 5) return;
  158.  
  159.     Rotate_Group_Angle = (X - Orig_Rotate_Group_X);
  160.     Rotate_Group_Angle = 1.0 + (Rotate_Group_Angle/4.0);
  161.  
  162.     Prev_Rotate_Group_X = X;
  163.  
  164.     if (Redraw_Always) Rotate_Group_Redraw(What_All);
  165.     else               Redraw_Mask = What_All;
  166.  
  167. } /* Rotate_Group_Move */
  168.  
  169. static
  170. Boolean_T Rotate_Group_Handle_Event(struct IntuiMessage *Msg)
  171. /************************************************************************/
  172. /*                                                                      */
  173. /* Event handler routine for the 'ROTATE GROUP' mode.            */
  174. /* Events handled:                            */
  175. /*    Select down: Start rotation.                    */
  176. /*    Select up: Stop rotation.                    */
  177. /*    Mouse move: Change rotation angle.                */
  178. /*                                                                      */
  179. /************************************************************************/
  180. {
  181.  
  182.     switch (Msg->Class) {
  183.  
  184.  
  185.     case IDCMP_MOUSEBUTTONS:
  186.         /* Msg->Code contain id of button pressed         */
  187.         /* Msg->MouseX and Msg->MouseY contain mouse position             */
  188.  
  189.     switch (Msg->Code) {
  190.  
  191.     case SELECTDOWN:
  192.         Rotate_Group_Select_Down(Msg->MouseX, Msg->MouseY);
  193.         return(TRUE);
  194.  
  195.     case SELECTUP:
  196.         Rotate_Group_Select_Up(Msg->MouseX, Msg->MouseY);
  197.         return(TRUE);
  198.  
  199.     } /* switch (Msg->Code) */
  200.     break;
  201.  
  202.     case IDCMP_MOUSEMOVE:
  203.     Rotate_Group_Move(Msg->MouseX, Msg->MouseY);
  204.     return(TRUE);
  205.  
  206.     } /* switch (Msg->Class) */
  207.  
  208.     return(FALSE);
  209.  
  210. } /* Rotate_Group_Handle_Event */
  211.  
  212. void Handle_Rotate_Group_Angle()
  213. /************************************************************************/
  214. /*                                                                      */
  215. /* Change to ROTATE GROUP mode.                        */
  216. /*                                                                      */
  217. /************************************************************************/
  218. {
  219.     if (Windows[W_Rotate_Group].Window == NULL) return;
  220.  
  221.     Rotate_Group_Active        = FALSE;
  222.     State.Handle_Event        = Rotate_Group_Handle_Event;
  223.     State.Timeout        = Rotate_Group_Timeout;
  224.     State.Redraw        = Rotate_Group_Redraw;
  225.  
  226.     sprintf(Error_Msg, "Rotate group");
  227.     Display_Status(Error_Msg);
  228.  
  229.     Points_Save();
  230.  
  231. } /* Handle_Rotate_Group_Angle */
  232.  
  233. void Handle_Rotate_Group_Angle_Value()
  234. /************************************************************************/
  235. /*                                                                      */
  236. /* Handle a Rotate_Group_Angle_Value gadget event.                */
  237. /*                                                                      */
  238. /************************************************************************/
  239. {
  240.     if (Windows[W_Rotate_Group].Window == NULL) return;
  241.  
  242.     Points_Save();
  243.     Rotate_Group_Angle = atof(Get_Gadget_String(GDX_Rotate_Group_Angle_Value));
  244.  
  245.     Rotate_Group_Timeout(); /* Compute and draw splines */
  246.  
  247.     Set_Rotate_Group_Angle_Value(0.0);
  248.  
  249. } /* Handle_Rotate_Group_Angle_Value */
  250.  
  251.  
  252. void Handle_Rotate_Group_Axis(short Axis)
  253. /************************************************************************/
  254. /*                                                                      */
  255. /* Handle a Rotate_Group_Axis gadget event.                */
  256. /*                                                                      */
  257. /************************************************************************/
  258. {
  259.     Rotate_Group_Axis = Axis;
  260.  
  261. } /* Handle_Rotate_Group_Axis */
  262.  
  263.