Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmanderin87

Posted 29 November 2012 - 04:34 PM

The polygon rotation method is

public void rotate(float x0, float y0, double angle) {
  Log.i("Polygon", "Degree: " + angle);

  for(int i = 0; i < mPoints.size(); i++) {
   Point point = mPoints.get(i);
  
   float x = (float) (x0 + (point.x - x0) * Math.cos(Utilities.toRadians(angle)) -
				  (point.y - y0) * Math.sin(Utilities.toRadians(angle)));
   float y = (float) (y0 + (point.x - x0) * Math.sin(Utilities.toRadians(angle)) +
			(point.y - y0) * Math.cos(Utilities.toRadians(angle)));

   point.x = x;
   point.y = y;
  }
}

The sprite rotation is done through a libgdx spritebatch and I am certain its correct.

public void draw(SpriteBatch batch, float x, float y, float degree) {
  batch.draw(mImage,  x - width() / 2, y - height() / 2,
	   pivotX(), pivotY(),
	   width(), height(),
	   mScale, mScale,
	   degree,
	   0, 0,
	   (int) width(), (int) height(),
	   false, false);
}

The delta time comes from libgdx and is the time since last frame.

float deltaTime = Gdx.graphics.getDeltaTime();

I am almost certain its something in the polygon rotation code... I was testing it... it would rotate until a certain point and then go the other way.

#2manderin87

Posted 29 November 2012 - 04:34 PM

The polygon rotation method is

public void rotate(float x0, float y0, double angle) {
  Log.i("Polygon", "Degree: " + angle);

  for(int i = 0; i < mPoints.size(); i++) {
   Point point = mPoints.get(i);
  
   float x = (float) (x0 + (point.x - x0) * Math.cos(Utilities.toRadians(angle)) -
				  (point.y - y0) * Math.sin(Utilities.toRadians(angle)));
   float y = (float) (y0 + (point.x - x0) * Math.sin(Utilities.toRadians(angle)) +
			(point.y - y0) * Math.cos(Utilities.toRadians(angle)));

   point.x = x;
   point.y = y;
  }
}

The sprite rotation is done through a libgdx spritebatch and I am certain its correct.

public void draw(SpriteBatch batch, float x, float y, float degree) {
  batch.draw(mImage,  x - width() / 2, y - height() / 2,
	   pivotX(), pivotY(),
	   width(), height(),
	   mScale, mScale,
	   degree,
	   0, 0,
	   (int) width(), (int) height(),
	   false, false);
}

The delta time comes from libgdx and is the time since last frame.

float deltaTime = Gdx.graphics.getDeltaTime();
I

I am almost certain its something in the polygon rotation code... I was testing it... it would rotate until a certain point and then go the other way.

#1manderin87

Posted 29 November 2012 - 04:31 PM

The polygon rotation method is

public void rotate(float x0, float y0, double angle) {
  Log.i("Polygon", "Degree: " + angle);
 
  for(int i = 0; i < mPoints.size(); i++) {
   Point point = mPoints.get(i);
  
   float x = (float) (x0 + (point.x - x0) * Math.cos(Utilities.toRadians(angle)) -
				  (point.y - y0) * Math.sin(Utilities.toRadians(angle)));
   float y = (float) (y0 + (point.x - x0) * Math.sin(Utilities.toRadians(angle)) +
		    (point.y - y0) * Math.cos(Utilities.toRadians(angle)));
 
   point.x = x;
   point.y = y;
  }
}

The sprite rotation is done through a libgdx spritebatch and I am certain its correct.

public void draw(SpriteBatch batch, float x, float y, float degree) {
  batch.draw(mImage,  x - width() / 2, y - height() / 2,
	   pivotX(), pivotY(),
	   width(), height(),
	   mScale, mScale,
	   degree,
	   0, 0,
	   (int) width(), (int) height(),
	   false, false);
}

The delta time comes from libgdx and is the time since last frame.

float deltaTime = Gdx.graphics.getDeltaTime();

PARTNERS