/// Advance the simulation time to t+dt using a leap frog method /// (equivalent to velocity verlet). /// /// Forces must be computed before calling the integrator the first time. /// /// - Advance velocities half time step using forces /// - Advance positions full time step using velocities /// - Update link cells and exchange remote particles /// - Compute forces /// - Update velocities half time step using forces /// /// This leaves positions, velocities, and forces at t+dt, with the /// forces ready to perform the half step velocity update at the top of /// the next call. /// /// After nSteps the kinetic energy is computed for diagnostic output. double timestep(SimFlat* s, int nSteps, real_t dt) { for (int ii=0; ii<nSteps; ++ii) { startTimer(velocityTimer); advanceVelocity(s, s->boxes->nLocalBoxes, 0.5*dt); stopTimer(velocityTimer); startTimer(positionTimer); advancePosition(s, s->boxes->nLocalBoxes, dt); stopTimer(positionTimer); startTimer(redistributeTimer); redistributeAtoms(s); stopTimer(redistributeTimer); startTimer(computeForceTimer); computeForce(s); stopTimer(computeForceTimer); startTimer(velocityTimer); advanceVelocity(s, s->boxes->nLocalBoxes, 0.5*dt); stopTimer(velocityTimer); } kineticEnergy(s); return s->ePotential; }
void Editor::moveCurser() { assert(curser); //place/choose/ delete if (hold_place && !Fl::event_key(' ')) { hold_place = false; } else if (hold_place) { handleSpace(); } else if (hold_del && !Fl::event_key(FL_Shift_L) && !Fl::event_key(FL_Shift_R)) { hold_del = false; } else if (hold_del) removeThing(); // skip some frames if (frame < 0) frame = FRAME_SKIP; else { frame--; return; } bool up, down, left, right; up = down = left = right = false; // move in x-dir if (hold_left && !Fl::event_key(FL_Left)) { hold_left = false; } else if (hold_left){ left = true; } else if (hold_right && !Fl::event_key(FL_Right)) { hold_right = false; } else if (hold_right) { right = true; } // move in y-dir if (hold_up && !Fl::event_key(FL_Up)) { hold_up = false; } else if (hold_up) { up = true; } else if (hold_down && !Fl::event_key(FL_Down)) hold_down = false; else if (hold_down) down = true; // set positions advancePosition(up, down, left, right); }
void PathCamera::processTick(const Move* move) { // client and server Parent::processTick(move); // Move to new time advancePosition(TickMs); // Set new position MatrixF mat; interpolateMat(mPosition,&mat); Parent::setTransform(mat); updateContainer(); }
int beatboxmain() { int vol=0; numberOfSamples=44100/10; synthbuf(); rb->pcm_play_data(&get_more, NULL, 0); rb->lcd_set_background(0x000000); rb->lcd_clear_display(); resetPosition(); int i, j; /* Start at 16 cells/loop for now. User can un-loop if more are needed */ for(i=0; i<V_NUMCELLS; i++) trackData[16][i] = VAL_LOOP; /* Very very rough beat to 'Goodbye Horses' trackData[16][3] = VAL_LOOP; trackData[16][2] = VAL_LOOP; trackData[0][3] = 1; trackData[4][3] = 1; trackData[8][3] = 1; trackData[9][3] = 1; trackData[12][3] = 1; trackData[13][3] = 1; trackData[2][2] = 1; trackData[6][2] = 1; trackData[10][2] = 1; trackData[14][2] = 1; */ drawGrid(); showDrumName(yCursor); updateDisplay(); redrawScreen(1); while(!quit) { #ifndef SYNC synthbuf(); #endif rb->yield(); if(stepFlag) { advancePosition(); sendEvents(); updateDisplay(); redrawScreen(0); stepFlag=0; } /* Prevent idle poweroff */ rb->reset_poweroff_timer(); /* Code taken from Oscilloscope plugin */ switch(rb->button_get(false)) { /* case BTN_UP: case BTN_UP | BUTTON_REPEAT: vol = rb->global_settings->volume; if (vol < rb->sound_max(SOUND_VOLUME)) { vol++; rb->sound_set(SOUND_VOLUME, vol); rb->global_settings->volume = vol; } break; case BTN_DOWN: case BTN_DOWN | BUTTON_REPEAT: vol = rb->global_settings->volume; if (vol > rb->sound_min(SOUND_VOLUME)) { vol--; rb->sound_set(SOUND_VOLUME, vol); rb->global_settings->volume = vol; } break; case BTN_RIGHT: { //pressNote(9, 40, 127); // resetPosition(); advancePosition(); sendEvents(); updateDisplay(); redrawScreen(0); break; } case BUTTON_LEFT: { // isPlaying=1; resetPosition(); updateDisplay(); redrawScreen(0); //pressNote(9, 39, 127); break; } */ case BEATBOX_UP: case BEATBOX_UP | BUTTON_REPEAT: { if(editState == EDITSTATE_PATTERN) { if(yCursor > 0) { yCursor--; showDrumName(yCursor); updateDisplay(); redrawScreen(0); } } break; } case BEATBOX_DOWN: case BEATBOX_DOWN | BUTTON_REPEAT: { if(editState == EDITSTATE_PATTERN) { if(yCursor < V_NUMCELLS-1) { yCursor++; showDrumName(yCursor); updateDisplay(); redrawScreen(0); } } break; } case BEATBOX_LEFT: case BEATBOX_LEFT | BUTTON_REPEAT: { if(editState == EDITSTATE_PATTERN) { if(xCursor > 0) { xCursor--; updateDisplay(); redrawScreen(0); } } break; } case BEATBOX_RIGHT: case BEATBOX_RIGHT | BUTTON_REPEAT: { if(editState == EDITSTATE_PATTERN) { if(xCursor < H_NUMCELLS-1) { xCursor++; updateDisplay(); redrawScreen(0); } } break; } case BEATBOX_SELECT: { if(editState == EDITSTATE_PATTERN) { int cv = trackData[xCursor][yCursor]; cv++; if(cv > VAL_LOOP) cv = VAL_NONE; trackData[xCursor][yCursor] = cv; updateDisplay(); redrawScreen(0); } break; } case BEATBOX_PLAY: { if(playState == STATE_PLAYING) playState = STATE_PAUSED; else { updateDisplay(); redrawScreen(0); sendEvents(); playState = STATE_PLAYING; } break; } case BEATBOX_STOP: { if(playState == STATE_STOPPED) { quit=1; } else { playState =STATE_STOPPED; resetPosition(); updateDisplay(); redrawScreen(0); } break; } } } return 0; }
int Editor::handle(int event) { if (Fl_Gl_Window::handle(event) != 0) return 1; int key = Fl::event_key(); switch(event) { case FL_SHORTCUT: case FL_KEYBOARD: switch(key) { case 'j': placeHero(); break; case 'd': placeDoor(); break; case ' ': hold_place = true; hold_del = false; break; case FL_Enter: switchContext(); break; case FL_Left: advancePosition(false, false, true, false); frame = 20; hold_left = true; hold_right = false; break; case FL_Right: advancePosition(false, false, false, true); frame = 20; hold_right= true; hold_left = false; break; case FL_Up: advancePosition(true, false, false, false); frame = 20; hold_up = true; hold_down = false; break; case FL_Down: advancePosition(false, true, false, false); frame = 20; hold_down = true; hold_up = false; break; case 'a': m_UI->startAnimating(); break; case 's': m_UI->stopAnimating(); break; case FL_Shift_L: case FL_Shift_R: hold_del = true; hold_place = false; break; } break; case FL_KEYUP: switch(key) { case ' ': hold_place = false; if (Fl::event_key(FL_Shift_L) || Fl::event_key(FL_Shift_R)) hold_del = true; break; case FL_Left: hold_left = false; if (Fl::event_key(FL_Right)) hold_right = true; break; case FL_Right: hold_right = false; if (Fl::event_key(FL_Left)) hold_left = true; break; case FL_Up: hold_up = false; if (Fl::event_key(FL_Down)) hold_down = true; break; case FL_Down: hold_down = false; if (Fl::event_key(FL_Up)) hold_up = true; break; case FL_Shift_L: case FL_Shift_R: hold_del = false; if (Fl::event_key(' ')) hold_place = true; break; } break; case FL_ENTER: case FL_MOVE: case FL_FOCUS: case FL_UNFOCUS: break; default: return 0; break; } return 1; }