Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /examples/vr-demo/main.c
ViewVC logotype

Diff of /examples/vr-demo/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2060, Tue Oct 30 19:31:28 2012 UTC revision 2061, Tue Oct 30 21:55:10 2012 UTC
# Line 10  Line 10 
10   * All rights reserved.   * All rights reserved.
11   */   */
12    
 #include <AntTweakBar.h>  
13  #include "GL/glfw.h"  #include "GL/glfw.h"
14  #include "util.h"  #include "util.h"
15  #include "vr-lite.h"  #include "vr-lite.h"
16  #include <unistd.h>  #include <unistd.h>
17    
18    /* minimum and maximum values from */
19    #define MIN_VALUE       0
20    #define MAX_VALUE       2632
21    
22    /* half the width of the opacity range */
23    #define OPAC_HALF_WID   150
24    
25    #define MIN_OPAC_MID    ((float)(MIN_VALUE+OPAC_HALF_WID))
26    #define MAX_OPAC_MID    ((float)(MAX_VALUE-OPAC_HALF_WID))
27    
28  /* pixel dimensions of output */  /* pixel dimensions of output */
29  #define WIDTH   990  #define WIDTH   480
30  #define HEIGHT  990  #define HEIGHT  345
31    
32  /* world bounds */  /* world bounds */
33  #define WRLD_MIN_X      0.0  #define WRLD_MIN_X      0.0
# Line 46  Line 55 
55  unsigned int    Width;          // view window width  unsigned int    Width;          // view window width
56  unsigned int    Height;         // view window height  unsigned int    Height;         // view window height
57  GLuint          ImageTexture;   // Texture ID of background image  GLuint          ImageTexture;   // Texture ID of background image
 float           WrldOrigin[2];  
 float           WrldDim[2];  
58    
59  typedef struct {  
     TwBar       *ctls;  
     unsigned int running;  
 } State_t;  
60    
61  // Callback function called by GLUT to render screen  // Callback function called by GLUT to render screen
62  void Draw (Nrrd *img)  void Draw (Nrrd *img)
# Line 184  Line 188 
188      }      }
189  }  }
190    
191  void GetData (ISO_World_t *wrld, Nrrd *nData)  void GetData (VR_World_t *wrld, Nrrd *nData)
192  {  {
193    // get snapshot of state    // get snapshot of state
194      if (ISO_Snapshot_pos (wrld, nData)) {      if (VR_Snapshot_pos (wrld, nData)) {
195        // error        // error
196          fprintf(stderr, "Error getting nrrd data\n");          fprintf(stderr, "Error getting nrrd data\n");
197          exit(1);          exit(1);
# Line 196  Line 200 
200    
201  int main (int argc, const char **argv)  int main (int argc, const char **argv)
202  {  {
     State_t     state = { .running = 0 };  
   
203    // Initialize GLFW    // Initialize GLFW
204      if (0 == glfwInit()) {      if (0 == glfwInit()) {
205        // An error occured        // An error occured
# Line 213  Line 215 
215          glfwTerminate();          glfwTerminate();
216          return 1;          return 1;
217      }      }
     glfwEnable(GLFW_MOUSE_CURSOR);  
218      glfwEnable(GLFW_KEY_REPEAT);      glfwEnable(GLFW_KEY_REPEAT);
219      glfwSetWindowTitle("Diderot Iso2D Animation");      glfwSetWindowTitle("Diderot VR Demo");
   
   // Initialize AntTweakBar  
     TwInit (TW_OPENGL, 0);  
   
   // create a tweakbar  
     TwBar *tweakBar = TwNewBar("Controls");  
     state.ctls = tweakBar;  
     unsigned int NumSteps = 0;  
     TwAddVarRO (tweakBar, "NumSteps", TW_TYPE_UINT32, &NumSteps, " label='# of steps' ");  
     TwAddButton (tweakBar, "StartButton", StartButtonCB, &state, " label='Start' ");  
220    
221    // Set GLFW event callbacks    // Set GLFW event callbacks
222      glfwSetWindowSizeCallback (WindowSizeCB);      glfwSetWindowSizeCallback (WindowSizeCB);
223      glfwSetMouseButtonCallback ((GLFWmousebuttonfun)TwEventMouseButtonGLFW);  // redirect to AntTweakBar      glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW);
     glfwSetMousePosCallback ((GLFWmouseposfun)TwEventMousePosGLFW);  // redirect to AntTweakBar  
     glfwSetMouseWheelCallback ((GLFWmousewheelfun)TwEventMouseWheelGLFW);  // redirect to AntTweakBar  
     glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW);  // redirect to AntTweakBar  
     glfwSetCharCallback ((GLFWcharfun)TwEventCharGLFW);  // redirect to AntTweakBar  
224    
225    // load Diderot image for background texture    // load Diderot image for background texture
226      InitTexture ();      InitTexture ();
# Line 246  Line 233 
233      WrldDim[1] = 0.013125 * 80.0;      WrldDim[1] = 0.013125 * 80.0;
234    
235    // initialize the Diderot program    // initialize the Diderot program
236      ISO_World_t *wrld = ISO_Init ();      VR_World_t *wrld = VR_Init ();
     ISO_Initially (wrld);  
237    
238    // nrrd for getting computational state    // nrrd for getting computational state
239      Nrrd *nData = nrrdNew();      Nrrd *nRGB = nrrdNew();
240    
241    // get and render initial state    // get and render initial state
242      GetData (wrld, nData);      GetData (wrld, nData);
# Line 258  Line 244 
244    
245    // Main loop (repeated while window is not closed and [ESC] is not pressed)    // Main loop (repeated while window is not closed and [ESC] is not pressed)
246      while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {      while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {
247          if (state.running != 0) {          if (NeedsRecompute) {
248              while ((state.running != 0) && (ISO_NumActive(wrld) > 0)) {            // recompute
249                // step the computation              VR_Initially (wrld);
250                  NumSteps += ISO_Run (wrld, STEP_SIZE);              VR_Run (wrld, 0);
251                // get and render the state            // get output image
252                  GetData (wrld, nData);              if (VR_OutputGet_outRGBA (wrld, nRGB)) {
                 Draw (nData);  
                 usleep (SLEEP_MS * 1000);  // sleep for a bit  
             }  
             if (ISO_NumActive(wrld) == 0) {  
               // get and render final state  
                 if (ISO_OutputGet_pos (wrld, nData)) {  
253                    // error                    // error
254                      fprintf(stderr, "Error getting nrrd data\n");                      fprintf(stderr, "Error getting nrrd data\n");
255                      exit(1);                      exit(1);
256                  }                  }
                 Draw (nData);  
257              }              }
258            if (NeedsRedraw) {
259          }          }
         else {  
260              glfwWaitEvents();              glfwWaitEvents();
             Draw(nData);  
         }  
261      }      }
262    
263    // shutdown the world    // shutdown the world
264      ISO_Shutdown (wrld);      VR_Shutdown (wrld);
265    
266    // Terminate AntTweakBar and GLFW    // Terminate AntTweakBar and GLFW
267      TwTerminate();      TwTerminate();

Legend:
Removed from v.2060  
changed lines
  Added in v.2061

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0