Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Connect the accelerometer to port one and start the program.
- // It will render, as a 3D box, the angle of the accelerometer.
- task main(){ // Overall program.
- SetSensorLowspeed(S1); // Initialise the HiTechnic Accelerometer
- int x, foobar, z // Create the variables for the values from the accelerometer
- int x1, foo, z1 // Create two sets of 'dump' values to dump the raw data into,
- int x2, bar, z2 // for the sake of a little smoothing.
- glInit(); // Initialise OpenGL (boot up the library for rendering our box)
- glBox(GL_POLYGON, 30, 50, 30); // Create a 30x50x30-pixel box. Since it's
- // the first box, it's ID is 0.
- while(true){ // Program that runs once everything's been set up
- ReadSensorHTAccel(S1, x1, foo, z1); // Read the Accelerometer, dump the data
- ReadSensorHTAccel(S1, x2, bar, z2); // Read the Accelerometer, dump the data
- x = ((x1 + x2)/4.444); // Convert the raw data into usable angle data
- z = ((z1 + z2)/4.444);
- glSetAngleX(x); // This sets the camera angle. Technically, we're changing
- glSetAngleY(y); // the viewing angle, not the actual box's angle.
- glBeginRender(); // Setup rendering
- glSet(GL_CULL_MODE, GL_CULL_NONE); //Don't hide any lines (i.e., make everything transparent)
- glCallObject(0); // Call the first object, ID 0. (The only object, actually)
- glFinishRender(); //Finish everything, clear the screen, and render the cube
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement