void Editor::update(float interval) { switch (mState) { case STATE_TESTING: if (wasKeyPressed(KEY_ESC)) { disableTestMode(); } updateBall(mBall, interval); break; case STATE_EDITING: { Vector3 markerPos; if (wasKeyPressed(KEY_ESC)) { Main::pushState(mScreenEditorMain); } if (wasKeyPressed(KEY_ENTER)) { enableTestMode(); } Vector3 min(gCurStart.x + 0.5f, gCurStart.y + 0.5f, 0.0f); Vector3 max(gCurEnd.x + 0.5f, gCurEnd.y + 0.5f, 0.0f); KdRangeTraverse iter(*sgLevel.kdLevelTree, min, max); KdList list(iter); markerPos.x = (gCurStart.x + gCurEnd.x) / 2.0f + 0.5f; markerPos.y = (gCurStart.y + gCurEnd.y) / 2.0f + 0.5f; if (list.next()) { markerPos.z = (float) sgLevel.blocks[*list].z / HEIGHT_STEPS; } else { markerPos.z = (float) 0.0f; } updateEditorCamera(interval, add(markerPos, sgLevel.origin)); animateEditor(interval); break; } default: break; } }
bool Check::updateSelected(float interval) { if (wasKeyPressed(KEY_ENTER)) { set(!this->value); } return true; }
void updateEditorCamera(float interval, Vector3 marker) { static float distance = 5.0f; static float height = 2.0f; static Vector3 dest(0.0f, 0.0f, 0.0f); float angle; /* camera controls for editor */ /* zoom */ if (isKeyPressed('v')) distance += 0.1f; if (isKeyPressed('c') && distance > 0.5) distance -= 0.1f; /* rotation */ if (wasKeyPressed('b')) gCamAngle--; if (wasKeyPressed('n')) gCamAngle++; if (gCamAngle < 0) gCamAngle += 4; if (gCamAngle >= 4) gCamAngle -= 4; /* height */ if (isKeyPressed('x')) height += 0.1f; if (isKeyPressed('y')) height -= 0.1f; angle = gCamAngle * 90.0f; /* new camera position */ dest.x = sin(angle * M_PI / 180.0f) * distance + marker.x; dest.y = -cos(angle * M_PI / 180.0f) * distance + marker.y; dest.z = height + marker.z; moveCamera(interval, dest, marker); }
void Game::update(float interval) { updateEnvironment(interval); switch (mGameState) { case STATE_MENU: break; case STATE_WAITING: updateBall(sgoBall, interval); if ((sgoBall.pos() - sgLookat).len() < 1.0f) { mCounter = 0.0f; mGameState = STATE_COUNTDOWN; } break; case STATE_COUNTDOWN: mCounter += interval; if (mCounter > COUNTDOWN_TIME) { enableBall(); mGameState = STATE_RUNNING; } case STATE_RUNNING: if (wasKeyPressed(KEY_ESC)) { Main::pushState(gScreenMain2); } /* manually switch features */ if (wasFunctionPressed(1)) { setBallShadow(!useBallShadow()); } if (wasFunctionPressed(2)) { setReflection(!useReflection()); } if (wasFunctionPressed(5)) { suspend(); toggleMouseControl(); resume(); } updateBall(sgoBall, interval); break; } updateGameField(sgoBall); }
void animateEditor(float interval) { int markermode = 0; /* editor controls for changing environment */ if (wasKeyPressed('a')) { changeMarkerArea(0, gCos[gCamAngle], gSin[gCamAngle]); } if (wasKeyPressed('d')) { changeMarkerArea(0, -gCos[gCamAngle], -gSin[gCamAngle]); } if (wasKeyPressed('s')) { changeMarkerArea(0, -gSin[gCamAngle], gCos[gCamAngle]); } if (wasKeyPressed('w')) { changeMarkerArea(0, gSin[gCamAngle], -gCos[gCamAngle]); } if (wasKeyPressed('f')) { changeMarkerArea(-1, 0, 0); } if (wasKeyPressed('r')) { changeMarkerArea(1, 0, 0); } if (wasKeyPressed('0')) { flattenMarkerArea(); } if (wasKeyPressed('+')) { populateMarkerArea(); } if (wasKeyPressed('-')) { deleteMarkerArea(); } /* editor controls for current field */ if (wasKeyPressed('1')) { if (gCurStart.x != sgLevel.finish.x || gCurStart.y != sgLevel.finish.y) { sgLevel.start.x = gCurStart.x; sgLevel.start.y = gCurStart.y; } } if (wasKeyPressed('2')) { if (gCurStart.x != sgLevel.start.x || gCurStart.y != sgLevel.start.y) { sgLevel.finish.x = gCurStart.x; sgLevel.finish.y = gCurStart.y; } } markermode = getModifiers() == GLUT_ACTIVE_SHIFT; /* editor controls for moving selection */ if (wasCursorPressed(CURSOR_LEFT)) { moveMarkerLeft(markermode); } if (wasCursorPressed(CURSOR_RIGHT)) { moveMarkerRight(markermode); } if (wasCursorPressed(CURSOR_DOWN)) { moveMarkerDown(markermode); } if (wasCursorPressed(CURSOR_UP)) { moveMarkerUp(markermode); } }
void Ball::animateBall(float interval) { bool collision = false; Vector3 normal(0.0f, 0.0f, 0.0f); Vector3 ball; Vector3 step; mVelocity = add(mVelocity, scale(MOVE_FORCE / mMass * interval, mPushDirection)); mVelocity.z -= GRAVITY * interval; /* collision detection */ step = scale(interval, mVelocity); ball = mPos + step; /* check only fields near by the ball. check field under ball first!!! */ QuadList list = getFieldSphereIntersection(ball, BALL_RADIUS); while (list.next()) { Quad quad = *list; const Vector3* q = quad.mVertices; const Vector3& dir = quad.mNormals[0]; Vector3 a1 = closestPointTriangle(ball, q[0], q[1], q[2]); Vector3 a2 = closestPointTriangle(ball, q[2], q[3], q[0]); float d1 = (ball - a1).len(); float d2 = (ball - a2).len(); Vector3 a = (d1 <= d2) ? a1 : a2; if ((a - ball).len() <= BALL_RADIUS) { /* dist = vector from ball center to quad */ Vector3 dist = a - ball; float l = dist.len(); /* move = vector to move the ball out of quad */ Vector3 move = scale(-((mRadius - l) / l), dist); /* some rotation for a better look */ Vector3 right = norm(cross(dir, step)); Vector3 forward = norm(cross(right, dir)); mAngularRate = scale(dot(sub(ball, mPos), forward) / (2.0f * M_PI * mRadius) * 360.0f / interval, right); ball = add(ball, move); normal = add(normal, move); collision = true; } } mPos = ball; normal = norm(normal); mHasBallHitGoal = false; /* contact to surface? */ if (collision) { float vn = dot(mVelocity, normal); Vector3 rebound = scale(-(1 + ELASTICITY) * vn, normal); if (len(rebound) > 3.0f * JUMP_FORCE * interval) { /* collision was to havy */ explodeBall(); } else { mVelocity = add(mVelocity, rebound); if (mJump) { mVelocity = add(mVelocity, scale(JUMP_FORCE / mMass * interval, normal)); } } int x = (int) floor(ball.x - sgLevel.origin.x); int y = (int) floor(ball.y - sgLevel.origin.y); if (x == sgLevel.finish.x && y == sgLevel.finish.y) { /* hit goal */ mHasBallHitGoal = true; } } /***/ /* damping */ mVelocity = scale(DAMPING, mVelocity); Quaternion rotation = mkQuaternion(len(mAngularRate) * interval, mAngularRate); mOrientation = mulQuaternion(rotation, mOrientation); /* falling to infinity */ if (mPos.z < -1.0f) { explodeBall(); } /* reset through user */ if (wasKeyPressed(KEY_ENTER)) { explodeBall(); } mPushDirection = Vector3(0.0f, 0.0f, 0.0f); mJump = false; }
bool OISSubsystem::wasKeyPressed(String key) { return wasKeyPressed(mKeyNames[key]); }
// Returns true if 'o' or a TBD gamepad button is pressed. bool Input::isOculusButtonPressed() const { return (wasKeyPressed('O')); }
// True if the player hits escape or select button on gamepad. bool Input::isQuitPressed() const { return (wasKeyPressed(VK_ESCAPE) || wasGamepadButtonPressed(BackButton)); }
// True if return or A button on gamepad is pressed. bool Input::wasMenuSelectPressed() const { return (wasKeyPressed(VK_RETURN) || wasGamepadButtonPressed(ButtonA)); }
// True if the player hits the right arrow key or right on the DPad or right on the left thumbstick bool Input::wasMenuRightKeyPressed() const { return (wasKeyPressed(VK_RIGHT) || wasGamepadButtonPressed(DPadRight) || (getGamepadThumbLX(0) > (int)(GAMEPAD_THUMBSTICK_DEADZONE))); }
// True if the player hits the left arrow key or left on the DPad or left on the left thumbstick bool Input::wasMenuLeftKeyPressed() const { return (wasKeyPressed(VK_LEFT) || wasGamepadButtonPressed(DPadLeft) || (getGamepadThumbLX(0) < -(int)(GAMEPAD_THUMBSTICK_DEADZONE))); }
// True if the player hits down arrow key or down on the DPad or down on Left thumbstick. bool Input::wasMenuDownPressed() const { return (wasKeyPressed(VK_DOWN) || wasGamepadButtonPressed(DPadDown) || (getGamepadThumbLY(0) < -(int)(GAMEPAD_THUMBSTICK_DEADZONE))); }
// MENU MOVEMENT // True if the player hits up arrow key or up on the DPad or up on Left thumbstick. bool Input::wasMenuUpPressed() const { return (wasKeyPressed(VK_UP) || wasGamepadButtonPressed(DPadUp) || (getGamepadThumbLY(0) > (int)(GAMEPAD_THUMBSTICK_DEADZONE))); }
// True if the player hits space or start button on gamepad. bool Input::isStartPressed() const { return (wasKeyPressed(VK_SPACE) || wasGamepadButtonPressed(StartButton)); }
bool Input::wasJumpKeyPressed() const { return (wasKeyPressed(VK_SPACE) || wasGamepadButtonPressed(ButtonA)); }
// True if the player hits backspace. bool Input::isBackPressed() const { return (wasKeyPressed(VK_BACK)); }