void MyWindow::keyboard(unsigned char _key, int _x, int _y) { switch (_key) { case ' ': // use space key to play or stop the motion mSimulating = !mSimulating; if (mSimulating) { mPlay = false; glutTimerFunc(mDisplayTimeout, refreshTimer, 0); } break; case 'q': // Spawn a cube case 'Q': { // Spawn a cube Eigen::Vector3d position = Eigen::Vector3d(dart::math::random(-1.0, 1.0), dart::math::random( 0.5, 1.0), dart::math::random(-1.0, 1.0)); Eigen::Vector3d size = Eigen::Vector3d(dart::math::random(0.1, 0.5), dart::math::random(0.1, 0.5), dart::math::random(0.1, 0.5)); spawnCube(position, size); break; } case 'w': // Spawn a cube case 'W': { // Spawn a cube if (mWorld->getNumSkeletons() > 1) mWorld->removeSkeleton(mWorld->getSkeleton(mWorld->getNumSkeletons() - 1)); break; } default: Win3D::keyboard(_key, _x, _y); } glutPostRedisplay(); }
void WidgetAugmentedView::createActions(QToolBar* menu) { QAction* action; ACTION_ICON("Spawn Object", spawnObject(), ":/add.png"); ACTION_ICON("Spawn Ball Small", spawnBallSmall(), ":/sport_golf.png"); ACTION_ICON("Spawn Ball Big", spawnBallBig(), ":/sport_soccer.png"); ACTION_ICON("Spawn Cube", spawnCube(), ":/package.png"); menu->addSeparator(); ACTION_ICON("Delete all objects", clearObjects(), ":/bin_closed.png"); menu->addSeparator(); ACTION_ICON("Change depth correction method", changeDepthCorrectionMethod(), ":/layers.png"); }
void spawnAllCubes() { _evilCubes.clear(); _colorIndex = (_colorIndex + 1) % environment_colors_N; for(int i = 0; i < MAX_CUBES; ++i) spawnCube(); }
void MyWindow::keyboard(unsigned char _key, int _x, int _y) { switch (_key) { case ' ': // use space key to play or stop the motion mSimulating = !mSimulating; if (mSimulating) { mPlay = false; glutTimerFunc(mDisplayTimeout, refreshTimer, 0); } break; case 'p': // playBack mPlay = !mPlay; if (mPlay) { mSimulating = false; glutTimerFunc(mDisplayTimeout, refreshTimer, 0); } break; case '[': // step backward if (!mSimulating) { mPlayFrame--; if (mPlayFrame < 0) mPlayFrame = 0; glutPostRedisplay(); } break; case ']': // step forwardward if (!mSimulating) { mPlayFrame++; if (mPlayFrame >= mWorld->getRecording()->getNumFrames()) mPlayFrame = 0; glutPostRedisplay(); } break; case 'v': // show or hide markers mShowMarkers = !mShowMarkers; break; case '1': // upper right force mForce[0] = -500; break; case '2': // upper right force mForce[0] = 500; break; case '3': // upper right force mForce[2] = -500; break; case '4': // upper right force mForce[2] = 500; break; case 'q': // Spawn a cube case 'Q': { // Spawn a cube Eigen::Vector3d position = Eigen::Vector3d(dart::math::random(-1.0, 1.0), dart::math::random(-1.0, 1.0), dart::math::random(0.5, 1.0)); Eigen::Vector3d size = Eigen::Vector3d(dart::math::random(0.01, 0.2), dart::math::random(0.01, 0.2), dart::math::random(0.01, 0.2)); spawnCube(position, size); break; } case 'w': // Spawn a cube case 'W': { // Spawn a cube if (mWorld->getNumSkeletons() > 4) mWorld->removeSkeleton(mWorld->getSkeleton(4)); break; } default: Win3D::keyboard(_key, _x, _y); } glutPostRedisplay(); }
void Game::update(float timeStep, const Input& input) { m_explosionTime -= timeStep; if(!m_isDead) { Input worldInput; worldInput.x = input.x; worldInput.y = input.y + m_cameraY; worldInput.pressed = input.pressed; m_aimX = worldInput.x; m_aimY = worldInput.y; for(LevelCube* pCube = m_pFirstCube; pCube != 0;) { pCube->update(timeStep, m_pPlayer->m_pAttachedCube == pCube); if(pCube->canBeDeleted(m_cameraY)) { if(pCube == m_pPlayer->m_pAttachedCube) { m_pPlayer->m_pAttachedCube = 0; m_pPlayer->m_speedX += m_pPlayer->m_normalX * 4; m_pPlayer->m_speedY += m_pPlayer->m_normalY * 4; } pCube = remove(pCube); } else pCube = pCube->m_pNext; } spawnCube(); if(m_pPlayer->m_pAttachedCube == 0) { m_pPlayer->updateFree(timeStep, worldInput); for(LevelCube* pCube = m_pFirstCube; pCube != 0; pCube = pCube->m_pNext) { float dx = m_pPlayer->m_posX - pCube->m_posX; float dy = m_pPlayer->m_posY - pCube->m_posY; float minDist = m_pPlayer->m_size + pCube->m_size; if(abs(dx) < minDist && abs(dy) < minDist) { m_pPlayer->m_pAttachedCube = pCube; if(abs(dx) > abs(dy)) { m_attachX = dx < 0 ? -1 : 1; m_attachY = dy / pCube->m_size; m_pPlayer->m_normalX = dx < 0 ? -1 : 1; m_pPlayer->m_normalY = 0; } else { m_attachX = dx / pCube->m_size; m_attachY = dy < 0 ? -1 : 1; m_pPlayer->m_normalX = 0; m_pPlayer->m_normalY = dy < 0 ? -1 : 1; } } } } if(m_pPlayer->m_pAttachedCube != 0) { LevelCube& cube = *m_pPlayer->m_pAttachedCube; m_pPlayer->m_posX = cube.m_posX + m_attachX * cube.m_size + m_pPlayer->m_normalX * (m_pPlayer->m_size + 0.01f); m_pPlayer->m_posY = cube.m_posY + m_attachY * cube.m_size + m_pPlayer->m_normalY * (m_pPlayer->m_size + 0.01f); if(cube.m_type == CubeType_Bouncy || cube.m_type == CubeType_Harmful) { float dot = (m_pPlayer->m_speedX - cube.m_speedX) * m_pPlayer->m_normalX + m_pPlayer->m_speedY * m_pPlayer->m_normalY; if(dot < 0) { m_pPlayer->m_speedX -= 2 * m_pPlayer->m_normalX * dot; m_pPlayer->m_speedY -= 2 * m_pPlayer->m_normalY * dot; m_pPlayer->m_pAttachedCube = 0; if(cube.m_type == CubeType_Harmful) { m_explosionX = cube.m_posX; m_explosionY = cube.m_posY; m_explosionTime = 1; remove(&cube); m_pPlayer->m_stamina -= 0.25f; } } } else m_pPlayer->updateAttached(timeStep, cube.m_speedX, worldInput); } m_maxY = max(m_maxY, m_pPlayer->m_posY); m_cameraY = m_maxY - atanf((m_maxY - m_pPlayer->m_posY) / 20) * 20 + 2; if(abs(m_pPlayer->m_posX) > 7.0f || m_pPlayer->m_posY - m_cameraY < -5.25f || m_pPlayer->m_stamina < 0) { m_isDead = true; m_explosionX = m_pPlayer->m_posX; m_explosionY = m_pPlayer->m_posY; m_explosionTime = 1; } } else if(m_explosionTime < 0) reset(); }