uint32_t tick(uint32_t interval, void *param){ cout<<':'<<flush; ScrollingDispItem *item=(ScrollingDispItem*)param; if (item->scrollState == freeScrolling) { adjustVelocity(item->veloX); adjustVelocity(item->veloY); item->setOffset(item->veloX*item->scale); if(item->veloX==0 && item->veloY==0) { item->scrollState = still; return 0; // stop ticker } } else {return 0;} // stop ticker return interval; }
void player_inputReleased(u16 released, u16 state) { //no move while dying or launching if (currentStep != STEP_PLAY) return; //if (released & (PORT_A_KEY_LEFT|PORT_B_KEY_LEFT|PORT_A_KEY_RIGHT|PORT_B_KEY_RIGHT) ) //{ adjustVelocity(state); //} }
void player_inputPressed(u16 pressed, u16 state) { //no move while dying or launching if (currentStep != STEP_PLAY) return; if (pressed & (PORT_A_KEY_1|PORT_B_KEY_1) ) { bullet_fire( shipPosition.x ); } adjustVelocity(state); }
void ADynamicCarController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (play) { float deltaSec = GWorld->GetWorld()->GetDeltaSeconds(); updateTarget(); if (first) { first = false; FRotator rotation = agent->GetActorRotation(); rotation.Yaw = getRotation(agent->GetActorLocation(), target); agent->SetActorRotation(rotation); if (followPath) { waypoints = DubinsPath::getPath(waypoints, to2D(agent->GetActorLocation()), rotation.Yaw, maxAngle, L, graph, errorTolerance); writeWaypointsToFile("Waypoints2.txt"); if (waypoints.Num() > 0) { target = waypoints[0]; } } } if (waypointReached()) { bool t35 = followPath && waypointsIndex >= waypoints.Num(); bool t4 = avoidAgents && !followPath; if (t35 || t4) { play = false; GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Green, FString::Printf(TEXT("Time: %f\r\n"), totalTime)); } return; } float a = getAcceleration(deltaSec); v += a; v = UKismetMathLibrary::FClamp(v, -vMax, vMax); float rotation = rotate(deltaSec); FVector vPref = FVector(v * UKismetMathLibrary::DegCos(rotation) * deltaSec, v * UKismetMathLibrary::DegSin(rotation) * deltaSec, 0); vPref = vPref.GetClampedToMaxSize2D(UKismetMathLibrary::FMin(v * deltaSec, FVector2D::Distance(to2D(agent->GetActorLocation()), target))); FVector oldVel = velocity; if (avoidAgents) { adjustVelocity(to2D(vPref), deltaSec); //velocity = vPref; } else { velocity = vPref; } FVector2D q = to2D(velocity - oldVel); float dv = FMath::Sqrt(FVector2D::DotProduct(q, q)); if (dv > aMax * deltaSec) { float f = aMax * deltaSec / dv; velocity = (1 - f) * oldVel + f * velocity; } float rot = agent->GetActorRotation().Yaw; if (velocity.Size2D() != 0) { if (angleDiff(rot, velocity.Rotation().Yaw) > 90) { velocity = -velocity; setRotation(); velocity = -velocity; } else { setRotation(); } } /* if (UKismetMathLibrary::Abs(angleDiff(rot, agent->GetActorRotation().Yaw)) / deltaSec > maxAngle * (v / L) + 5) { GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, FString::Printf(TEXT("rot: %f yaw: %f -> %f (%f) %d %s -> %s"), rot, agent->GetActorRotation().Yaw, angleDiff(rot, agent->GetActorRotation().Yaw), UKismetMathLibrary::Abs(angleDiff(rot, agent->GetActorRotation().Yaw)) / deltaSec, vPref.Equals(velocity), *to2D(vPref).ToString(), *to2D(velocity).ToString())); DrawDebugLine(GWorld->GetWorld(), FVector(to2D(agent->GetActorLocation()), 20), FVector(to2D(agent->GetActorLocation()), 30), FColor::Red, false, 0.5, 0, 1); GEngine->DeferredCommands.Add(TEXT("pause")); }*/ agent->SetActorLocation(agent->GetActorLocation() + velocity); /* DrawDebugLine(GWorld->GetWorld(), to3D(target), to3D(target) + collisionSize, collisionColor, false, 0.1, 0, 1); float a = getAcceleration(deltaSec); v += a; v = UKismetMathLibrary::FClamp(v, -vMax, vMax); float rotation = rotate(deltaSec); acceleration.X = a * UKismetMathLibrary::DegCos(rotation); acceleration.Y = a * UKismetMathLibrary::DegSin(rotation); drawLine(2 * acceleration / deltaSec, accelerationColor); velocity = FVector(v * UKismetMathLibrary::DegCos(rotation) * deltaSec, v * UKismetMathLibrary::DegSin(rotation) * deltaSec, 0); float rot = agent->GetActorRotation().Yaw; setRotation(); GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, FString::Printf(TEXT("%f"), UKismetMathLibrary::Abs(rot - agent->GetActorRotation().Yaw) / deltaSec)); agent->SetActorLocation(agent->GetActorLocation() + velocity); DrawDebugLine(GWorld->GetWorld(), agent->GetActorLocation(), agent->GetActorLocation() + collisionSize, FColor::Green, false, 0.1, 0, 1); */ } }
void RotateScreen::preparePaint (int msSinceLastPaint) { float oldXrot = mXrot + mBaseXrot; if (mGrabIndex || mMoving) { float amount = msSinceLastPaint * 0.05f * optionGetSpeed (); int steps = amount / (0.5f * optionGetTimestep ()); if (!steps) steps = 1; float chunk = amount / (float) steps; while (steps--) { mXrot += mXVelocity * chunk; mYrot += mYVelocity * chunk; if (mXrot > 360.0f / screen->vpSize ().width ()) { mBaseXrot += 360.0f / screen->vpSize ().width (); mXrot -= 360.0f / screen->vpSize ().width (); } else if (mXrot < 0.0f) { mBaseXrot -= 360.0f / screen->vpSize ().width (); mXrot += 360.0f / screen->vpSize ().width (); } if (cubeScreen->invert () == -1) { if (mYrot > 45.0f) { mYVelocity = 0.0f; mYrot = 45.0f; } else if (mYrot < -45.0f) { mYVelocity = 0.0f; mYrot = -45.0f; } } else { if (mYrot > 100.0f) { mYVelocity = 0.0f; mYrot = 100.0f; } else if (mYrot < -100.0f) { mYVelocity = 0.0f; mYrot = -100.0f; } } if (mGrabbed) { mXVelocity /= 1.25f; mYVelocity /= 1.25f; if (fabs (mXVelocity) < 0.01f) mXVelocity = 0.0f; if (fabs (mYVelocity) < 0.01f) mYVelocity = 0.0f; } else if (adjustVelocity (screen->vpSize ().width (), cubeScreen->invert ())) { mXVelocity = 0.0f; mYVelocity = 0.0f; if (fabs (mYrot) < 0.1f) { CompOption::Vector o (0); int tx; float xrot = mBaseXrot + mXrot; if (xrot < 0.0f) tx = (screen->vpSize ().width () * xrot / 360.0f) - 0.5f; else tx = (screen->vpSize ().width () * xrot / 360.0f) + 0.5f; /* flag end of rotation */ cubeScreen->rotationState (CubeScreen::RotationNone); screen->moveViewport (tx, 0, true); mBaseXrot = mMoveTo = mXrot = mYrot = 0.0f; mMoving = false; if (mGrabIndex) { screen->removeGrab (mGrabIndex, &mSavedPointer); mGrabIndex = 0; } if (mMoveWindow) { CompWindow *w = screen->findWindow (mMoveWindow); if (w) w->move (mMoveWindowX - w->x (), 0); } /* only focus default window if switcher isn't active */ else if (!screen->grabExist ("switcher")) screen->focusDefaultWindow (); mMoveWindow = 0; screen->handleCompizEvent ("rotate", "end_viewport_switch", o); } break; } } if (mMoveWindow) { CompWindow *w = screen->findWindow (mMoveWindow); if (w) { float xrot = (screen->vpSize ().width () * (mBaseXrot + mXrot)) / 360.0f; w->moveToViewportPosition (mMoveWindowX - xrot * screen->width (), w->y (), false); } } } if (mMoving) { if (fabs (mXrot + mBaseXrot + mMoveTo) <= 180 / screen->vpSize ().width ()) mProgress = fabs (mXrot + mBaseXrot + mMoveTo) / 180 / screen->vpSize ().width (); else if (fabs (mXrot + mBaseXrot) <= 180 / screen->vpSize ().width ()) mProgress = fabs (mXrot + mBaseXrot) / 180 / screen->vpSize ().width (); else { mProgress += fabs (mXrot + mBaseXrot - oldXrot) / 180 / (screen->vpSize ().width ()); mProgress = MIN (mProgress, 1.0); } } else if (mProgress != 0.0f || mGrabbed) { float amount = msSinceLastPaint * 0.05f * optionGetSpeed (); int steps = amount / (0.5f * optionGetTimestep ()); if (!steps) steps = 1; float chunk = amount / (float) steps; while (steps--) { float dt; if (mGrabbed) dt = 1.0 - mProgress; else dt = 0.0f - mProgress; float adjust = dt * 0.15f; float tamount = fabs (dt) * 1.5f; if (tamount < 0.2f) tamount = 0.2f; else if (tamount > 2.0f) tamount = 2.0f; mProgressVelocity = (tamount * mProgressVelocity + adjust) / (tamount + 1.0f); mProgress += mProgressVelocity * chunk; if (fabs (dt) < 0.01f && fabs (mProgressVelocity) < 0.0001f) { if (mGrabbed) mProgress = 1.0f; else mProgress = 0.0f; break; } } } if (cubeScreen->invert () == 1 && !cubeScreen->unfolded ()) mZoomTranslate = optionGetZoom () * mProgress; else mZoomTranslate = 0.0; cScreen->preparePaint (msSinceLastPaint); }
void Entity::update(const sf::Time& dt){ //moving in Cartesian coordinate system velocity_ += acceleration_*dt.asSeconds(); adjustVelocity(); move(velocity_*dt.asSeconds()); }
void PrivateCubeScreen::preparePaint (int msSinceLastPaint) { int opt; float x, progress; unsigned short *topColor, *bottomColor; if (mGrabIndex) { int steps; float amount, chunk; amount = msSinceLastPaint * 0.2f * optionGetSpeed (); steps = amount / (0.5f * optionGetTimestep ()); if (!steps) steps = 1; chunk = amount / (float) steps; while (steps--) { mUnfold += mUnfoldVelocity * chunk; if (mUnfold > 1.0f) mUnfold = 1.0f; if (adjustVelocity ()) { if (mUnfold < 0.5f) { if (mGrabIndex) { screen->removeGrab (mGrabIndex, NULL); mGrabIndex = 0; } mUnfold = 0.0f; } break; } } } memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size ()); memset (mCapsPainted, 0, sizeof (Bool) * screen->outputDevs ().size ()); /* Transparency handling */ if (mRotationState == CubeScreen::RotationManual || (mRotationState == CubeScreen::RotationChange && !optionGetTransparentManualOnly ())) { opt = mLastOpacityIndex = CubeOptions::ActiveOpacity; } else if (mRotationState == CubeScreen::RotationChange) { opt = mLastOpacityIndex = CubeOptions::InactiveOpacity; } else { opt = CubeOptions::InactiveOpacity; } mToOpacity = (mOptions[opt].value ().f () / 100.0f) * OPAQUE; cubeScreen->cubeGetRotation (x, x, progress); if (mDesktopOpacity != mToOpacity || (progress > 0.0 && progress < 1.0)) { mDesktopOpacity = (optionGetInactiveOpacity () - ((optionGetInactiveOpacity () - mOptions[mLastOpacityIndex].value ().f ()) * progress)) / 100.0f * OPAQUE; } topColor = optionGetTopColor (); bottomColor = optionGetBottomColor (); mPaintAllViewports = (mDesktopOpacity != OPAQUE || topColor[3] != OPAQUE || bottomColor[3] != OPAQUE); cScreen->preparePaint (msSinceLastPaint); }
void Manager::setLevel(int l) { level = l; adjustVelocity(); }