Rube Goldberg Machine 1.0
This is the base code for Rube Goldberg designed for the CS296 Software Systems Lab
Namespaces | Functions
src/maingui.cpp File Reference
#include <iostream>
#include "render.hpp"
#include "cs296_base.hpp"
#include "callbacks.hpp"
#include <sys/time.h>
#include "GL/glui.h"
#include <cstdio>
Include dependency graph for maingui.cpp:

Go to the source code of this file.

Namespaces

namespace  cs296
 

These are user defined include files Included in double quotes - the path to find these has to be given at compile time.


Functions

void create_glui_ui (void)
 This function creates all the GLUI gui elements.
void average_time (int32 no_of_steps)
 Function to compute the average time for 100 iterations.
int main (int argc, char **argv)
 This is the main function.

Function Documentation

void average_time ( int32  no_of_steps)

Function to compute the average time for 100 iterations.

Used to determine duration of function calls.

Definition at line 116 of file maingui.cpp.

                                    { 
    // settings_hz from callbacks.cpp  
    float32 step_size=1/settings_hz; 
   
    b2World* world = test->get_world(); 
    
    const b2Profile& world_profile = world->GetProfile(); 
    int32 step_Count=0; 
    
    float32 time_taken_for_step=0.0000;
    float32 time_taken_for_velocity_update=0.0000;
    float32 time_taken_for_collisions=0.0000;
    float32 time_taken_for_position_update=0.0000;
    
    struct timeval start, end;
    gettimeofday(&start,NULL);
    double t1 = 1000*(start.tv_sec) + start.tv_usec/1000.0;
    
    while (step_Count<no_of_steps)
    { 
        // Step function for Simulation in Box2D world.
        world->Step(step_size, settings.velocity_iterations, settings.position_iterations);     
        time_taken_for_step +=world_profile.step;
        time_taken_for_velocity_update += world_profile.solveVelocity;
        time_taken_for_collisions += world_profile.collide;
        time_taken_for_position_update += world_profile.solvePosition;
        step_Count++;
    }
    
    gettimeofday(&end, NULL); 
    double t2 = 1000*(end.tv_sec) + end.tv_usec/1000.0;
    double t= t2 - t1;
    //[Lab07]
    std::cout<<"Total Iterations: "<< no_of_steps<<"\n";
    std::cout<<"Average time per step is "<< time_taken_for_step/no_of_steps<<" ms\n";
    std::cout<<"Average time for collisions is "<<time_taken_for_collisions/no_of_steps<<" ms\n";
    std::cout<<"Average time for velocity updates is "<<time_taken_for_velocity_update/no_of_steps<<" ms\n";
    std::cout<<"Average time for position updates is "<<time_taken_for_position_update/no_of_steps<<" ms\n\n";
    std::cout<<"Total time for loop is "<<t<<" ms"<<std::endl;
    //std::cout <<t/1000
    //<<std::endl;
}
void create_glui_ui ( void  )

This function creates all the GLUI gui elements.

Definition at line 70 of file maingui.cpp.

{
  GLUI *glui = GLUI_Master.create_glui_subwindow( main_window, GLUI_SUBWINDOW_BOTTOM );
  
  glui->add_statictext("Simulation Timesteps"); 
  GLUI_Spinner* velocityIterationSpinner =
    glui->add_spinner("Velocity Iterations", GLUI_SPINNER_INT, &settings.velocity_iterations);
  velocityIterationSpinner->set_int_limits(1, 500);
  
  GLUI_Spinner* positionIterationSpinner =
    glui->add_spinner("Position Iterations", GLUI_SPINNER_INT, &settings.position_iterations);
  positionIterationSpinner->set_int_limits(0, 100);
  
  GLUI_Spinner* hertzSpinner =
    glui->add_spinner("Sim steps per frame", GLUI_SPINNER_FLOAT, &settings_hz);
  hertzSpinner->set_float_limits(5.0f, 200.0f);


  
  new GLUI_Column( glui, false );
  glui->add_statictext("Simulation Parameters"); 
  glui->add_checkbox("Warm Starting", &settings.enable_warm_starting);
  glui->add_checkbox("Time of Impact", &settings.enable_continuous);
  glui->add_checkbox("Sub-Stepping", &settings.enable_sub_stepping);


  
  new GLUI_Column( glui, false );
  glui->add_statictext("Display Options"); 
  GLUI_Panel* drawPanel =   glui->add_panel("Draw");
  glui->add_checkbox_to_panel(drawPanel, "Shapes", &settings.draw_shapes);
  glui->add_checkbox_to_panel(drawPanel, "Joints", &settings.draw_joints);
  glui->add_checkbox_to_panel(drawPanel, "AABBs", &settings.draw_AABBs);
  glui->add_checkbox_to_panel(drawPanel, "Statistics", &settings.draw_stats);
  glui->add_checkbox_to_panel(drawPanel, "Profile", &settings.draw_profile);
  
  new GLUI_Column( glui, false );
  glui->add_button("Pause", 0, callbacks_t::pause_cb);
  glui->add_button("Single Step", 0, callbacks_t::single_step_cb);
  glui->add_button("Restart", 0, callbacks_t::restart_cb);
  
  glui->add_button("Quit", 0,(GLUI_Update_CB)callbacks_t::exit_cb);
  glui->set_main_gfx_window( main_window );
}
int main ( int  argc,
char **  argv 
)

This is the main function.

This initializes GLUT

Here we setup all the callbacks we need Some are set via GLUI

Others are set directly

We create the GLUI user interface

Enter the infinite GLUT event loop

Definition at line 162 of file maingui.cpp.

{
  test_count = 1;
  test_index = 0;
  test_selection = test_index;
  
  entry = sim;
  test = entry->create_fcn();

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  glutInitWindowSize(800, 500);

  char title[50];
  sprintf(title, "CS296 Base Code. Running on Box2D %d.%d.%d", b2_version.major, b2_version.minor, b2_version.revision);
  main_window = glutCreateWindow(title);

  GLUI_Master.set_glutReshapeFunc(callbacks_t::resize_cb);  
  GLUI_Master.set_glutKeyboardFunc(callbacks_t::keyboard_cb);
  GLUI_Master.set_glutSpecialFunc(callbacks_t::keyboard_special_cb);
  GLUI_Master.set_glutMouseFunc(callbacks_t::mouse_cb);
  glutDisplayFunc(callbacks_t::display_cb);
  glutMotionFunc(callbacks_t::mouse_motion_cb);
  glutKeyboardUpFunc(callbacks_t::keyboard_up_cb); 
  glutTimerFunc(frame_period, callbacks_t::timer_cb, 0);

  /*
  // Command Line argument for number of iterations
  int no_of_steps = 0;
  if(argc == 1) no_of_steps = 100;   //Default Value
  else no_of_steps = atoi(argv[1]);
  average_time(no_of_steps);
  */
  create_glui_ui();

  glutMainLoop();
  
  return 0;
}
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines