SHARE
TWEET

Code :)

a guest Apr 30th, 2013 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Connect the accelerometer to port one and start the program.
  2. // It will render, as a 3D box, the angle of the accelerometer.
  3.  
  4. task main(){ // Overall program.
  5.  
  6.   SetSensorLowspeed(S1); // Initialise the HiTechnic Accelerometer
  7.  
  8.   int x, foobar, z // Create the variables for the values from the accelerometer
  9.  
  10.   int x1, foo, z1 // Create two sets of 'dump' values to dump the raw data into,
  11.   int x2, bar, z2 // for the sake of a little smoothing.
  12.  
  13.   glInit(); // Initialise OpenGL (boot up the library for rendering our box)
  14.  
  15.   glBox(GL_POLYGON, 30, 50, 30); // Create a 30x50x30-pixel box. Since it's
  16.                                  // the first box, it's ID is 0.
  17.  
  18.   while(true){ // Program that runs once everything's been set up
  19.  
  20.     ReadSensorHTAccel(S1, x1, foo, z1); // Read the Accelerometer, dump the data
  21.     ReadSensorHTAccel(S1, x2, bar, z2); // Read the Accelerometer, dump the data
  22.  
  23.     x = ((x1 + x2)/4.444); // Convert the raw data into usable angle data
  24.     z = ((z1 + z2)/4.444);
  25.  
  26.     glSetAngleX(x); // This sets the camera angle. Technically, we're changing
  27.     glSetAngleY(y); // the viewing angle, not the actual box's angle.
  28.  
  29.     glBeginRender(); // Setup rendering
  30.  
  31.     glSet(GL_CULL_MODE, GL_CULL_NONE); //Don't hide any lines (i.e., make everything transparent)
  32.  
  33.     glCallObject(0); // Call the first object, ID 0. (The only object, actually)
  34.  
  35.     glFinishRender(); //Finish everything, clear the screen, and render the cube
  36.   }
  37. }
RAW Paste Data
Top