void updateGraphics(void) { ///////////////////////////////////////////////////////////////////// // UPDATE WIDGETS ///////////////////////////////////////////////////////////////////// // update haptic rate label labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]"); // update position of haptic rate label labelHapticRate->setLocalPos((int)(0.5 * (windowW - labelHapticRate->getWidth())), 15); // update position of message label labelMessage->setLocalPos((int)(0.5 * (windowW - labelMessage->getWidth())), 50); ///////////////////////////////////////////////////////////////////// // RENDER SCENE ///////////////////////////////////////////////////////////////////// // render world camera->renderView(windowW, windowH); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err = glGetError(); if (err != GL_NO_ERROR) cout << "Error: " << gluErrorString(err) << endl; }
void updateGraphics(void) { int px, py; // update haptic rate label labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]"); px = (int)(0.5 * (displayW - labelHapticRate->getWidth())); labelHapticRate->setLocalPos(px, 15); // update other widgets py = (int)(0.5 * (displayH - level->getHeight())); level->setLocalPos(50, py); level->setValue(tool->m_lastComputedGlobalForce.length()); px = displayW - 80; py = (int)(0.5 * displayH); dial->setLocalPos(px, py); dial->setValue1(angVel.length()); // render world camera->renderView(displayW, displayH); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err; err = glGetError(); if (err != GL_NO_ERROR) printf("Error: %s\n", gluErrorString(err)); }
void updateGraphics(void) { int px; // update position of label labelHapticDeviceModel->setLocalPos(10, displayH - 30, 0.0); // update position of label and content double posX = 1000 * hapticDevicePosition.x(); double posY = 1000 * hapticDevicePosition.y(); double posZ = 1000 * hapticDevicePosition.z(); labelHapticDevicePosition->setString("position [mm]: " + cStr(posX, 0) + " " + cStr(posY, 0) + " " + cStr(posZ, 0)); labelHapticDevicePosition->setLocalPos(10, displayH - 50, 0.0); // update haptic rate label labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]"); px = (int)(0.5 * (displayW - labelHapticRate->getWidth())); labelHapticRate->setLocalPos(px, 15); // render world camera->renderView(displayW, displayH); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err; err = glGetError(); if (err != GL_NO_ERROR) printf("Error: %s\n", gluErrorString(err)); }
void updateGraphics(void) { ///////////////////////////////////////////////////////////////////// // UPDATE WIDGETS ///////////////////////////////////////////////////////////////////// // display haptic rate data labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]"); // update position of label labelHapticRate->setLocalPos((int)(0.5 * (windowW - labelHapticRate->getWidth())), 15); // update value of level level->setValue( cylinder->getLocalPos().y() ); // update value of scope scope->setSignalValues( tool->m_lastComputedGlobalForce.length() ); ///////////////////////////////////////////////////////////////////// // RENDER SCENE ///////////////////////////////////////////////////////////////////// // render world camera->renderView(windowW, windowH); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err; err = glGetError(); if (err != GL_NO_ERROR) cout << "Error: %s\n" << gluErrorString(err); }
void updateGraphics(void) { // update haptic rate label labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]"); int px = (int)(0.5 * (displayW - labelHapticRate->getWidth())); labelHapticRate->setLocalPos(px, 15); // render world camera->renderView(displayW, displayH); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err; err = glGetError(); if (err != GL_NO_ERROR) printf("Error: %s\n", gluErrorString(err)); }
void updateGraphics( void ) { ///////////////////////////////////////////////////////////////////// // CHECK GAME STATUS ///////////////////////////////////////////////////////////////////// if ( particles_left[ELECTRON] == 0 && particles_left[PROTON] == 0 && particles_left[NEUTRON] == 0 ) { // Display game over screen camera->m_frontLayer->addChild( clear_screen ); // Set timeout timeout_start = clock(); show_clear_screen = true; // Get new random atom getNewAtom( rand() % NUM_ATOMS + 1 ); } // If timeout if ( show_clear_screen && ( ( clock() - timeout_start )/( double )CLOCKS_PER_SEC ) > CLEAR_SCREEN_TIMEOUT ) { // Reset screen resetScreen(); show_clear_screen = false; camera->m_frontLayer->removeChild( clear_screen ); } ///////////////////////////////////////////////////////////////////// // UPDATE WIDGETS ///////////////////////////////////////////////////////////////////// // update haptic rate label labelHapticRate->setString( "haptic rate: "+cStr( frequencyCounter.getFrequency(), 0 ) + " [Hz]" ); // update position of label labelHapticRate->setLocalPos( ( int )( 0.5 * ( windowW - labelHapticRate->getWidth() ) ), 15 ); // Set text and position of atom number label atom_num->setString( to_string( current_atom_num ) ); atom_num->setLocalPos( ( int )( 0.089 * ( windowW - atom_num->getWidth() ) ), ( int )( 0.93 * ( windowH - atom_num->getHeight() ) ) ); // Set text and position of element symbol label atom_label->setString( current_atom_symbol ); atom_label->setLocalPos( ( int )( 0.11 * ( windowW - atom_label->getWidth() ) ), ( int )( 0.91 * ( windowH - atom_label->getHeight() ) ) ); // Set text and position of element name label atom_name->setString( current_atom_name ); atom_name->setLocalPos( ( int )( 0.08 * ( windowW - atom_name->getWidth() ) ), ( int )( 0.81 * ( windowH - atom_name->getHeight() ) ) ); // Set text and posistion of particle labels particle_labels[ELECTRON]->setString( "e-" ); particle_labels[PROTON]->setString( "p+" ); particle_labels[NEUTRON]->setString( "n" ); particle_labels[ELECTRON]->setLocalPos( ( int )( 0.95 * ( windowW - particle_labels[0]->getWidth() ) ), ( int )( 0.835 * ( windowH - particle_labels[0]->getHeight() ) ) ); particle_labels[PROTON]->setLocalPos( ( int )( 0.95 * ( windowW - particle_labels[1]->getWidth() ) ), ( int )( 0.520 * ( windowH - particle_labels[1]->getHeight() ) ) ); particle_labels[NEUTRON]->setLocalPos( ( int )( 0.95 * ( windowW - particle_labels[2]->getWidth() ) ), ( int )( 0.190 * ( windowH - particle_labels[2]->getHeight() ) ) ); // Check if button is pressed bool buttonStatus; hapticDevice->getUserSwitch( 0, buttonStatus ); if ( buttonStatus && !show_clear_screen ) { // If user is holding the button, don't change color if ( !selected_particle->getShowEnabled() ) { // Get cursor position cVector3d tool_pos; tool_pos = tool->getDeviceLocalPos(); for ( int i = 0; i < NUM_PARTICLE_TYPE; i++ ) { // Get box position cVector3d boxPos = particle_boxes[i]->getLocalPos(); double box_x_max = boxPos.x() + PARTICLE_BOX*2; // Let user pick above box double box_x_min = boxPos.x() - PARTICLE_BOX*2; // Let user pick above box double box_y_max = boxPos.y() + PARTICLE_BOX/2; double box_y_min = boxPos.y() - PARTICLE_BOX/2; double box_z_max = boxPos.z() + PARTICLE_BOX/2; double box_z_min = boxPos.z() - PARTICLE_BOX/2; // If collision, set colors if ( tool_pos.x() <= box_x_max && tool_pos.x() >= box_x_min && tool_pos.y() <= box_y_max && tool_pos.y() >= box_y_min && tool_pos.z() <= box_z_max && tool_pos.z() >= box_z_min ) { selected_particle->setMaterial( select_material[i] ); selected_particle->setShowEnabled( true,true ); is_selected = i; } } } } else { // If user released the button with a selected particle if ( ELECTRON == is_selected && ELECTRON == in_ok_position && particles_left[ELECTRON] > 0 ) { // Place it on the screen cShapeSphere* placed_atom = selected_particle->copy(); world->addChild( placed_atom ); placed_atoms.push_back( placed_atom ); particles_left[ELECTRON]--; in_ok_position = -1; } if ( PROTON == is_selected && PROTON == in_ok_position && particles_left[PROTON] > 0 ) { // Place it on the screen cShapeSphere* placed_atom = selected_particle->copy(); world->addChild( placed_atom ); placed_atoms.push_back( placed_atom ); particles_left[PROTON]--; in_ok_position = -1; } if ( NEUTRON == is_selected && PROTON == in_ok_position && particles_left[NEUTRON] > 0 ) { // Place it on the screen cShapeSphere* placed_atom = selected_particle->copy(); world->addChild( placed_atom ); placed_atoms.push_back( placed_atom ); particles_left[NEUTRON]--; in_ok_position = -1; } selected_particle->setShowEnabled( false, false ); is_selected = -1; } ///////////////////////////////////////////////////////////////////// // RENDER SCENE ///////////////////////////////////////////////////////////////////// // render world camera->renderView( windowW, windowH ); // swap buffers glutSwapBuffers(); // check for any OpenGL errors GLenum err = glGetError(); if ( err != GL_NO_ERROR ) cout << "Error: " << gluErrorString( err ) << endl; }