home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / graphics / 3d / icoons / source / rotate_p.c < prev    next >
C/C++ Source or Header  |  1992-10-06  |  7KB  |  208 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6.  
  7. #include "general.h"
  8. #include "globals.h"
  9. #include "intui.h"
  10. #include "timer.h"
  11. #include "spl_math.h"
  12. #include "spl_util.h"
  13. #include "spl_gfx.h"
  14. #include "rotate_p.h"
  15. /************************************************************************/
  16. /*                                                                      */
  17. /* This file contains code to handle the ROTATE P. command.        */
  18. /*                                                                      */
  19. /************************************************************************/
  20.  
  21. static Boolean_T    Rotate_P_Active;
  22. static short        Old_Rot_X;
  23. static short        Old_Rot_Y;
  24. static Vector_T        Old_Rotation_Vector;
  25. static Vector_T        Box_Min, Box_Max;
  26.  
  27. static 
  28. void Rotate_P_Timeout()
  29. /************************************************************************/
  30. /*                                                                      */
  31. /* Function called when timer expires: Draw splines in persp window.    */
  32. /*                                                                      */
  33. /************************************************************************/
  34. {
  35.     Compute_Splines();
  36.  
  37.     Clear_All(What_P);
  38.     Draw_All(What_P);
  39.  
  40.     Redraw_Mask = 0;
  41.  
  42.     Stop_Timer();
  43.  
  44. } /* Rotate_P_Timeout */
  45.  
  46. static 
  47. void Rotate_P_Redraw(long What)
  48. /************************************************************************/
  49. /*                                                                      */
  50. /* Function called to redraw screen while rotating persp window.    */
  51. /*                                                                      */
  52. /************************************************************************/
  53. {
  54.     Compute_Rotation_Matrix(M_Rotation, Rotation_Vector);
  55.  
  56.     Clear_All(What_P);
  57.     Draw_Box(Box_Min, Box_Max, NULL, DM_Plane, What_P);
  58.     Draw_Origin(DM_Normal, What_P);
  59.  
  60.     Start_Timer(Delay_Draw_Seconds, Delay_Draw_Micros);
  61.     Redraw_Mask |= What_P;
  62.  
  63. } /* Rotate_P_Redraw */
  64.  
  65. static
  66. void Rotate_P_Select_Up(short X, short Y)
  67. /************************************************************************/
  68. /*                                                                      */
  69. /* Function called when mouse button is released.            */
  70. /* X, Y are the actual coordinates in the active window.        */
  71. /*                                                                      */
  72. /************************************************************************/
  73. {
  74.     /* If the timer hasn't expired, then call the timeout handler to*/
  75.     /* compute and draw the splines.                */
  76.  
  77.     if (!Check_Timer()) Rotate_P_Timeout();
  78.  
  79.     Set_Mode_Normal();
  80.  
  81. } /* Rotate_P_Select_Up */
  82.  
  83. static 
  84. void Rotate_P_Select_Down(short X, short Y)
  85. /************************************************************************/
  86. /*                                                                      */
  87. /* Function called when mouse button is pressed.            */
  88. /* X, Y are the actual coordinates in the active window.        */
  89. /*                                                                      */
  90. /************************************************************************/
  91. {
  92.  
  93.     if (X < 0) return;
  94.     if (Get_Bounding_Box(Box_Min, Box_Max)) {
  95.  
  96.     /* If we couldn't create a bbox, then just make a box.    */
  97.     Vec3Scalar(Box_Min, =, -Grid_Size, -Grid_Size, -Grid_Size);
  98.     Vec3Scalar(Box_Max, =,  Grid_Size,  Grid_Size,  Grid_Size);
  99.     }
  100.     Rotate_P_Active = TRUE;
  101.  
  102.     Old_Rot_X = X;
  103.     Old_Rot_Y = Y;
  104.  
  105.     Old_Rotation_Vector[0] = Rotation_Vector[0];
  106.     Old_Rotation_Vector[1] = Rotation_Vector[1];
  107.     Old_Rotation_Vector[2] = Rotation_Vector[2];
  108.  
  109.     if (MQ_Size_Rotate_P > 0) {
  110.     SetMouseQueue(Windows[Id_Active_Window].Window, MQ_Size_Rotate_P); 
  111.     Redraw_Always = TRUE;
  112.     } else Redraw_Always = FALSE;
  113.  
  114. } /* Rotate_P_Select_Down */
  115.  
  116. static 
  117. void  Rotate_P_Move(short X, short Y)
  118. /************************************************************************/
  119. /*                                                                      */
  120. /* Function called when mouse is moved to rotate persp. window.        */
  121. /* X, Y are the actual coordinates in the active window.        */
  122. /*                                                                      */
  123. /************************************************************************/
  124. {
  125.     if (X < 0) return;
  126.  
  127.     if (!Rotate_P_Active) return;
  128.  
  129.     X = (X - Old_Rot_X) / 2;
  130.     Y = (Y - Old_Rot_Y) / 2;
  131.  
  132.     X += Old_Rotation_Vector[2];
  133.     Y += Old_Rotation_Vector[0];
  134.     X %= 360;
  135.     Y %= 360;
  136.     Rotation_Vector[2] = X;
  137.     Rotation_Vector[0] = Y;
  138.  
  139.     sprintf(Error_Msg, "Rotate P.(%3.0f,%3.0f,%3.0f)", 
  140.         Rotation_Vector[0],
  141.         Rotation_Vector[1],
  142.         Rotation_Vector[2]);
  143.     Display_Status(Error_Msg);
  144.  
  145.     if (Redraw_Always) Rotate_P_Redraw(What_P);
  146.     else               Redraw_Mask = What_P;
  147.  
  148. } /* Rotate_P_Move */
  149.  
  150.  
  151. Boolean_T Rotate_P_Handle_Event(struct IntuiMessage *Msg)
  152. /************************************************************************/
  153. /*                                                                      */
  154. /* Event handler routine for the 'ROTATE P' mode.            */
  155. /* Events handled:                            */
  156. /*    Select down: Start rotating.                    */
  157. /*    Select up  : Stop rotating.                    */
  158. /*    Mouse move : Rotate persp.                    */
  159. /*                                                                      */
  160. /************************************************************************/
  161. {
  162.  
  163.     switch (Msg->Class) {
  164.  
  165.  
  166.     case IDCMP_MOUSEBUTTONS:
  167.         /* Msg->Code contain id of button pressed         */
  168.         /* Msg->MouseX and Msg->MouseY contain mouse position             */
  169.  
  170.     switch (Msg->Code) {
  171.  
  172.     case SELECTDOWN:
  173.         Rotate_P_Select_Down(Msg->MouseX, Msg->MouseY);
  174.         return(TRUE);
  175.  
  176.     case SELECTUP:
  177.         Rotate_P_Select_Up(Msg->MouseX, Msg->MouseY);
  178.         return(TRUE);
  179.  
  180.     } /* switch (Msg->Code) */
  181.     break;
  182.  
  183.     case IDCMP_MOUSEMOVE:
  184.     Rotate_P_Move(Msg->MouseX, Msg->MouseY);
  185.     return(TRUE);
  186.  
  187.     } /* switch (Msg->Class) */
  188.  
  189.     return(FALSE);
  190.  
  191. } /* Rotate_P_Handle_Event */
  192.  
  193. void Set_Mode_Rotate_P()
  194. /************************************************************************/
  195. /*                                                                      */
  196. /* Change to ROTATE P mode.                        */
  197. /*                                                                      */
  198. /************************************************************************/
  199. {
  200.     Rotate_P_Active        = FALSE;
  201.     State.Handle_Event        = Rotate_P_Handle_Event;
  202.     State.Timeout        = Rotate_P_Timeout;
  203.     State.Redraw        = Rotate_P_Redraw;
  204.  
  205.     Display_Status("Rotate P.");
  206.  
  207. } /* Set_Mode_Rotate_P */
  208.