Code example for PointF

Methods: lengthset

0
		mCurrentCenterOfParticle.set(x,y);
	} 
 
	public void propagate(PointF positionForce) {
		// Get Friction 
		Vec2D.scalerMult(-1.0, mVelocityVector, mTotalForce);
		Vec2D.unitVector(mTotalForce.x, mTotalForce.y, mTotalForce);
		Vec2D.scalerMult(mFrictionMagnitude, mTotalForce, mTotalForce);
		// Add in positional Force 
		 
		Vec2D.add(positionForce, mTotalForce, mTotalForce); // since m=1, this is also the acceleration!
 
		if (continuePropagation(positionForce)){
 
			if ((mVelocityVector.length() < mTotalForce.length()) && 
					(positionForce.length() < EPSILON)){
						Vec2D.scalerMult(mVelocityVector.length()/mTotalForce.length(), mTotalForce, mTotalForce);
					} 
 
			mAnimationFinished = false;
			long now = System.currentTimeMillis(); 
			long deltaMillis = now - mLastTime;
			 
			//TODO FIX JUMPY PLAY ON THE DROID 
			if (deltaMillis < MILLIS_MIN_RATE) return;
			 
			// Calculate velocity 
			float vx = mVelocityVector.x + mTotalForce.x * deltaMillis/1000;
			float vy = mVelocityVector.y + mTotalForce.y * deltaMillis/1000;
 
			// calculate position traveled in this timestep: v^2 = v0^2 + 2*a*deltaX 
			float dx = 0;
			float dy = 0;
			if (mTotalForce.x != 0.0) {
				dx =  (float) ((Math.pow(vx, 2.0) - Math.pow(mVelocityVector.x, 2.0)) / (2.0 * mTotalForce.x));
			} 
			if (mTotalForce.y != 0.0) {
				dy = (float) ((Math.pow(vy, 2.0) - Math.pow(mVelocityVector.y, 2.0)) / (2.0 * mTotalForce.y));
			} 
			 
			float x = (float) (mCurrentCenterOfParticle.x + dx);
			float y = (float) (mCurrentCenterOfParticle.y + dy);
			mPreviousCenterOfParticle.set(mCurrentCenterOfParticle);
			mCurrentCenterOfParticle.set(x,y);
			mVelocityVector.set(vx, vy);
			mLastTime = now;
		} 
	} 
 
	private boolean continuePropagation(PointF positionForce){
		if ((Math.abs(mVelocityVector.length()) < EPSILON_MAGNITUDE) && 
			(Math.abs(positionForce.length()) < EPSILON)){
			mVelocityVector.set(0,0);
			mPreviousCenterOfParticle.set(mCurrentCenterOfParticle);
			mPreviousLaunchLocation.set(mCurrentCenterOfParticle);
			mAnimationFinished = true;
			GameNotifier.Instance().notifyShotFinished(); 
			return false; 
Stop searching for code, let great code find you!  Add Codota to your java IDE