home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / vopengl / spinbox / sboxcnv.cpp < prev    next >
C/C++ Source or Header  |  1998-06-22  |  6KB  |  232 lines

  1. //=======================================================================
  2. //@V@:Note: This file generated by vgen V1.04 (12:03:15 22 Jun 1998).
  3. //    sboxcnv.cpp:    Source for sboxOGLCanvasPane class
  4. //=======================================================================
  5. /*
  6.  * Spinning box.  This program is in the public domain.
  7.  *
  8.  * Brian Paul
  9.  */
  10.  
  11. #include "sboxcnv.h"
  12.  
  13. #include <math.h>
  14. #include <stdlib.h>
  15.  
  16. static GLfloat Xrot, Xstep;
  17. static GLfloat Yrot, Ystep;
  18. static GLfloat Zrot, Zstep;
  19. static GLfloat Step = 5.0;
  20. static GLfloat Scale = 1.0;
  21. static GLuint Object;
  22.  
  23. static GLuint 
  24. make_object(void)
  25. {
  26.   GLuint list;
  27.  
  28.   list = glGenLists(1);
  29.  
  30.   glNewList(list, GL_COMPILE);
  31.  
  32.   glBegin(GL_LINE_LOOP);
  33.   glVertex3f(1.0, 0.5, -0.4);
  34.   glVertex3f(1.0, -0.5, -0.4);
  35.   glVertex3f(-1.0, -0.5, -0.4);
  36.   glVertex3f(-1.0, 0.5, -0.4);
  37.   glEnd();
  38.  
  39.   glBegin(GL_LINE_LOOP);
  40.   glVertex3f(1.0, 0.5, 0.4);
  41.   glVertex3f(1.0, -0.5, 0.4);
  42.   glVertex3f(-1.0, -0.5, 0.4);
  43.   glVertex3f(-1.0, 0.5, 0.4);
  44.   glEnd();
  45.  
  46.   glBegin(GL_LINES);
  47.   glVertex3f(1.0, 0.5, -0.4);
  48.   glVertex3f(1.0, 0.5, 0.4);
  49.   glVertex3f(1.0, -0.5, -0.4);
  50.   glVertex3f(1.0, -0.5, 0.4);
  51.   glVertex3f(-1.0, -0.5, -0.4);
  52.   glVertex3f(-1.0, -0.5, 0.4);
  53.   glVertex3f(-1.0, 0.5, -0.4);
  54.   glVertex3f(-1.0, 0.5, 0.4);
  55.   glEnd();
  56.  
  57.   glEndList();
  58.  
  59.   return list;
  60. }
  61.  
  62. static void 
  63. reshape(int width, int height)
  64. {
  65.   glViewport(0, 0, (GLint) width, (GLint) height);
  66.   glMatrixMode(GL_PROJECTION);
  67.   glLoadIdentity();
  68.   glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
  69.   glMatrixMode(GL_MODELVIEW);
  70. }
  71. static void 
  72. draw(void)
  73. {
  74.   glClear(GL_COLOR_BUFFER_BIT);
  75.  
  76.   glPushMatrix();
  77.  
  78.   glTranslatef(0.0, 0.0, -10.0);
  79.   glScalef(Scale, Scale, Scale);
  80.   if (Xstep) {
  81.     glRotatef(Xrot, 1.0, 0.0, 0.0);
  82.   } else if (Ystep) {
  83.     glRotatef(Yrot, 0.0, 1.0, 0.0);
  84.   } else {
  85.     glRotatef(Zrot, 0.0, 0.0, 1.0);
  86.   }
  87.  
  88.   glCallList(Object);
  89.  
  90.   glPopMatrix();
  91.  
  92. }
  93.  
  94. static void 
  95. idle(void)
  96. {
  97.   Xrot += Xstep;
  98.   Yrot += Ystep;
  99.   Zrot += Zstep;
  100.  
  101.   if (Xrot >= 360.0) {
  102.     Xrot = Xstep = 0.0;
  103.     Ystep = Step;
  104.   } else if (Yrot >= 360.0) {
  105.     Yrot = Ystep = 0.0;
  106.     Zstep = Step;
  107.   } else if (Zrot >= 360.0) {
  108.     Zrot = Zstep = 0.0;
  109.     Xstep = Step;
  110.   }
  111.   draw();
  112.   
  113. }
  114.  
  115.  
  116.  
  117. //===================>>> sboxOGLCanvasPane::sboxOGLCanvasPane <<<====================
  118.   sboxOGLCanvasPane::sboxOGLCanvasPane(unsigned int vGLmode, PaneType pt)
  119.   {
  120.     initDone = 0;
  121.   }
  122.  
  123. //===================>>> sboxOGLCanvasPane::~sboxOGLCanvasPane <<<====================
  124.   sboxOGLCanvasPane::~sboxOGLCanvasPane()
  125.   {
  126.   }
  127.  
  128. //======================>>> sboxOGLCanvasPane::TimerAnimate <<<========================
  129.   void sboxOGLCanvasPane::TimerAnimate(void)
  130.   {
  131.     // **** Called by CmdWindow AuxTimer for animation.
  132.  
  133.     vglMakeCurrent();  // Typically done here
  134.     idle();
  135.     vglFlush();  // After you draw, typically flush
  136.     
  137.  
  138.   }
  139. //======================>>> sboxOGLCanvasPane::graphicsInit <<<========================
  140.   void sboxOGLCanvasPane::graphicsInit(void)
  141.   {
  142.     vBaseGLCanvasPane::graphicsInit();    // Always call the superclass first!
  143.  
  144.     // **** Your OpenGL initialization code goes here!
  145.   Object = make_object();
  146.   glCullFace(GL_BACK);
  147.   glDisable(GL_DITHER);
  148.   glShadeModel(GL_FLAT);
  149.  
  150.   glColor3f(1.0, 1.0, 1.0);
  151.  
  152.   Xrot = Yrot = Zrot = 0.0;
  153.   Xstep = Step;
  154.   Ystep = Zstep = 0.0;
  155.   reshape(300,300);
  156.  
  157.  
  158.  
  159.     initDone = 1;
  160.   }
  161. //======================>>> sboxOGLCanvasPane::HPage <<<========================
  162.   void sboxOGLCanvasPane::HPage(int shown, int top)
  163.   {
  164.     vBaseGLCanvasPane::HPage(shown, top);
  165.   }
  166.  
  167. //======================>>> sboxOGLCanvasPane::VPage <<<========================
  168.   void sboxOGLCanvasPane::VPage(int shown, int top)
  169.   {
  170.     vBaseGLCanvasPane::VPage(shown, top);
  171.   }
  172.  
  173. //=======================>>> sboxOGLCanvasPane::HScroll <<<======================
  174.   void sboxOGLCanvasPane::HScroll(int step)
  175.   {
  176.     vBaseGLCanvasPane::HScroll(step);
  177.   }
  178.  
  179. //======================>>> sboxOGLCanvasPane::VScroll <<<======================
  180.   void sboxOGLCanvasPane::VScroll(int step)
  181.   {
  182.     vBaseGLCanvasPane::VScroll(step);
  183.   }
  184.  
  185. //======================>>> sboxOGLCanvasPane::MouseDown <<<======================
  186.   void sboxOGLCanvasPane::MouseDown(int X, int Y, int button)
  187.   {
  188.     vBaseGLCanvasPane::MouseDown(X,Y,button);
  189.   }
  190.  
  191. //========================>>> sboxOGLCanvasPane::MouseUp <<<======================
  192.   void sboxOGLCanvasPane::MouseUp(int X, int Y, int button)
  193.   {
  194.     vBaseGLCanvasPane::MouseUp(X,Y,button);
  195.   }
  196.  
  197. //======================>>> sboxCanvasPane::MouseMove <<<======================
  198.   void sboxOGLCanvasPane::MouseMove(int x, int y, int button)
  199.   {
  200.     vBaseGLCanvasPane::MouseMove(x,y,button);
  201.   }
  202.  
  203. //=========================>>> sboxOGLCanvasPane::Redraw <<<======================
  204.   void sboxOGLCanvasPane::Redraw(int x, int y, int w, int h)
  205.   {
  206.     static int inRedraw = 0;
  207.  
  208.     if (inRedraw || !initDone)  // Don't draw until initialized
  209.         return;
  210.  
  211.     inRedraw = 1;  // Don't allow recursive redraws.
  212.  
  213.     vglMakeCurrent();  // Typically done here
  214.  
  215.     // *** Your drawing code typically goes here. You may
  216.     // insert it here, or just call a drawing routine.
  217.  
  218.     draw();
  219.     vglFlush();  // After you draw, typically flush
  220.  
  221.     inRedraw = 0;  // Out of Redraw
  222.  
  223.   }
  224.  
  225. //======================>>> sboxOGLCanvasPane::Resize <<<======================
  226.   void sboxOGLCanvasPane::Resize(int w, int h)
  227.   {
  228.     vBaseGLCanvasPane::Resize(w,h);
  229.     reshape(w,h);
  230.   }
  231.  
  232.