Java Code Examples for org.andengine.input.touch.TouchEvent#set()

The following examples show how to use org.andengine.input.touch.TouchEvent#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void convertSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	this.convertAxisAlignedSceneToSurfaceTouchEvent(pSceneTouchEvent, pSurfaceWidth, pSurfaceHeight);

	final float rotation = this.mRotation;
	if(rotation == 0) {
		/* Nothing to do. */
	} else if(rotation == 180) {
		pSceneTouchEvent.set(pSurfaceWidth - pSceneTouchEvent.getX(), pSurfaceHeight - pSceneTouchEvent.getY());
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1);

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 2
Source File: Camera.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void convertSceneTouchEventToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	this.convertAxisAlignedSceneToSurfaceTouchEvent(pSceneTouchEvent, pSurfaceWidth, pSurfaceHeight);

	final float rotation = this.mRotation;
	if (rotation == 0) {
		/* Nothing. */
	} else if (rotation == 180) {
		pSceneTouchEvent.setY(pSurfaceHeight - pSceneTouchEvent.getY());
		pSceneTouchEvent.setX(pSurfaceWidth - pSceneTouchEvent.getX());
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, -rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 3
Source File: ZoomCamera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent) {
	final float zoomFactor = this.mZoomFactor;
	if(zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.scaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}

	super.applySceneToCameraSceneOffset(pSceneTouchEvent);
}
 
Example 4
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float relativeX = (pSceneTouchEvent.getX() - xMin) / (xMax - xMin);
	final float relativeY = (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);

	pSceneTouchEvent.set(relativeX * pSurfaceWidth, relativeY * pSurfaceHeight);
}
 
Example 5
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void convertAxisAlignedSurfaceToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final float pRelativeX, final float pRelativeY) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float x = xMin + pRelativeX * (xMax - xMin);
	final float y = yMin + pRelativeY * (yMax - yMin);

	pSurfaceTouchEvent.set(x, y);
}
 
Example 6
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void unapplyCameraSceneRotation(final TouchEvent pCameraSceneTouchEvent) {
	final float cameraSceneRotation = -this.mCameraSceneRotation;

	if(cameraSceneRotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 7
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void applyCameraSceneRotation(final TouchEvent pSceneTouchEvent) {
	final float cameraSceneRotation = -this.mCameraSceneRotation;

	if(cameraSceneRotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 8
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void unapplySceneRotation(final TouchEvent pSceneTouchEvent) {
	final float rotation = this.mRotation;

	if(rotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY());

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 9
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void applySceneRotation(final TouchEvent pCameraSceneTouchEvent) {
	final float rotation = this.mRotation;
	if(rotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, -rotation, this.getCenterX(), this.getCenterY());

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 10
Source File: ZoomCamera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void unapplySceneToCameraSceneOffset(final TouchEvent pCameraSceneTouchEvent) {
	super.unapplySceneToCameraSceneOffset(pCameraSceneTouchEvent);

	final float zoomFactor = this.mZoomFactor;
	if(zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.revertScaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 11
Source File: ZoomCamera.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent) {
	final float zoomFactor = this.mZoomFactor;
	if (zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.scaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}

	super.applySceneToCameraSceneOffset(pSceneTouchEvent);
}
 
Example 12
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float relativeX = (pSceneTouchEvent.getX() - xMin) / (xMax - xMin);
	final float relativeY = 1 - (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);

	final float x = relativeX * pSurfaceWidth;
	final float y = relativeY * pSurfaceHeight;

	pSceneTouchEvent.set(x, y);
}
 
Example 13
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void convertAxisAlignedSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final float pRelativeX, final float pRelativeY) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float x = xMin + pRelativeX * (xMax - xMin);
	final float y = yMin + pRelativeY * (yMax - yMin);

	pSurfaceTouchEvent.set(x, y);
}
 
Example 14
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void unapplyCameraSceneRotation(final TouchEvent pCameraSceneTouchEvent) {
	final float cameraSceneRotation = this.mCameraSceneRotation;

	if (cameraSceneRotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 15
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void applyCameraSceneRotation(final TouchEvent pSceneTouchEvent) {
	final float cameraSceneRotation = this.mCameraSceneRotation;

	if (cameraSceneRotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 16
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void unapplySceneRotation(final TouchEvent pSceneTouchEvent) {
	final float rotation = this.mRotation;

	if (rotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 17
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void applySceneRotation(final TouchEvent pCameraSceneTouchEvent) {
	final float rotation = this.mRotation;

	if (rotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example 18
Source File: ZoomCamera.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void unapplySceneToCameraSceneOffset(final TouchEvent pCameraSceneTouchEvent) {
	super.unapplySceneToCameraSceneOffset(pCameraSceneTouchEvent);

	final float zoomFactor = this.mZoomFactor;
	if (zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.revertScaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}