Java Code Examples for org.andengine.opengl.util.GLState#translateModelViewGLMatrixf()

The following examples show how to use org.andengine.opengl.util.GLState#translateModelViewGLMatrixf() . 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: ParallaxBackground.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue) {
	pGLState.pushModelViewGLMatrix();
	{
		final float cameraWidth = pCamera.getWidth();
		final float entityWidthScaled = this.mEntity.getWidth() * this.mEntity.getScaleX();
		float baseOffset = (pParallaxValue * this.mParallaxFactor) % entityWidthScaled;

		while (baseOffset > 0) {
			baseOffset -= entityWidthScaled;
		}
		pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);

		float currentMaxX = baseOffset;

		do {
			this.mEntity.onDraw(pGLState, pCamera);
			pGLState.translateModelViewGLMatrixf(entityWidthScaled, 0, 0);
			currentMaxX += entityWidthScaled;
		} while (currentMaxX < cameraWidth);
	}
	pGLState.popModelViewGLMatrix();
}
 
Example 2
Source File: Entity.java    From tilt-game-android with MIT License 6 votes vote down vote up
protected void applyRotation(final GLState pGLState) {
	final float rotation = this.mRotation;

	if (rotation != 0) {
		final float localRotationCenterX = this.mLocalRotationCenterX;
		final float localRotationCenterY = this.mLocalRotationCenterY;

		pGLState.translateModelViewGLMatrixf(localRotationCenterX, localRotationCenterY, 0);
		pGLState.rotateModelViewGLMatrixf(-rotation, 0, 0, 1);
		pGLState.translateModelViewGLMatrixf(-localRotationCenterX, -localRotationCenterY, 0);

		/* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same.
		 * In that case the last glTranslatef of the rotation and the first glTranslatef of the scale is superfluous.
		 * The problem is that applyRotation and applyScale would need to be "merged" in order to efficiently check for that condition.  */
	}
}
 
Example 3
Source File: TextureWarmUpVertexBufferObject.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void warmup(final GLState pGLState, final ITexture pTexture) {
	pTexture.bind(pGLState);
	this.bind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());

	pGLState.pushModelViewGLMatrix();
	{
		/* Far far away and really small. */
		pGLState.loadModelViewGLMatrixIdentity();
		pGLState.translateModelViewGLMatrixf(1000000, 1000000, 0);
		pGLState.scaleModelViewGLMatrixf(0.0001f, 0.0001f, 0);

		this.draw(GLES20.GL_TRIANGLES, TextureWarmUpVertexBufferObject.VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
	}
	pGLState.popModelViewGLMatrix();

	this.unbind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
}
 
Example 4
Source File: ParallaxBackground.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue) {
	pGLState.pushModelViewGLMatrix();
	{
		final float cameraWidth = pCamera.getWidth();
		final float shapeWidthScaled = this.mAreaShape.getWidthScaled();
		float baseOffset = (pParallaxValue * this.mParallaxFactor) % shapeWidthScaled;

		while(baseOffset > 0) {
			baseOffset -= shapeWidthScaled;
		}
		pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);

		float currentMaxX = baseOffset;
		
		do {
			this.mAreaShape.onDraw(pGLState, pCamera);
			pGLState.translateModelViewGLMatrixf(shapeWidthScaled, 0, 0);
			currentMaxX += shapeWidthScaled;
		} while(currentMaxX < cameraWidth);
	}
	pGLState.popModelViewGLMatrix();
}
 
Example 5
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
protected void applyRotation(final GLState pGLState) {
	final float rotation = this.mRotation;

	if(rotation != 0) {
		final float rotationCenterX = this.mRotationCenterX;
		final float rotationCenterY = this.mRotationCenterY;

		pGLState.translateModelViewGLMatrixf(rotationCenterX, rotationCenterY, 0);
		pGLState.rotateModelViewGLMatrixf(rotation, 0, 0, 1);
		pGLState.translateModelViewGLMatrixf(-rotationCenterX, -rotationCenterY, 0);

		/* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same.
		 * In that case the last glTranslatef of the rotation and the first glTranslatef of the scale is superfluous.
		 * The problem is that applyRotation and applyScale would need to be "merged" in order to efficiently check for that condition.  */
	}
}
 
Example 6
Source File: TextureWarmUpVertexBufferObject.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void warmup(final GLState pGLState, final ITexture pTexture) {
	pTexture.bind(pGLState);
	this.bind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());

	pGLState.pushModelViewGLMatrix();
	{
		/* Far far away and really small. */
		pGLState.loadModelViewGLMatrixIdentity();
		pGLState.translateModelViewGLMatrixf(1000000, 1000000, 0);
		pGLState.scaleModelViewGLMatrixf(0.0001f, 0.0001f, 0);

		this.draw(GLES20.GL_TRIANGLES, VERTICES_PER_VERTEXBUFFEROBJECT_SIZE);
	}
	pGLState.popModelViewGLMatrix();

	this.unbind(pGLState, PositionTextureCoordinatesShaderProgram.getInstance());
}
 
Example 7
Source File: Entity.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void applySkew(final GLState pGLState) {
	final float skewX = this.mSkewX;
	final float skewY = this.mSkewY;

	if ((skewX != 0) || (skewY != 0)) {
		final float localSkewCenterX = this.mLocalSkewCenterX;
		final float localSkewCenterY = this.mLocalSkewCenterY;

		pGLState.translateModelViewGLMatrixf(localSkewCenterX, localSkewCenterY, 0);
		pGLState.skewModelViewGLMatrixf(skewX, skewY);
		pGLState.translateModelViewGLMatrixf(-localSkewCenterX, -localSkewCenterY, 0);
	}
}
 
Example 8
Source File: Entity.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void applyScale(final GLState pGLState) {
	final float scaleX = this.mScaleX;
	final float scaleY = this.mScaleY;

	if ((scaleX != 1) || (scaleY != 1)) {
		final float localScaleCenterX = this.mLocalScaleCenterX;
		final float localScaleCenterY = this.mLocalScaleCenterY;

		pGLState.translateModelViewGLMatrixf(localScaleCenterX, localScaleCenterY, 0);
		pGLState.scaleModelViewGLMatrixf(scaleX, scaleY, 1);
		pGLState.translateModelViewGLMatrixf(-localScaleCenterX, -localScaleCenterY, 0);
	}
}
 
Example 9
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected void applySkew(final GLState pGLState) {
	final float skewX = this.mSkewX;
	final float skewY = this.mSkewY;

	if((skewX != 0) || (skewY != 0)) {
		final float skewCenterX = this.mSkewCenterX;
		final float skewCenterY = this.mSkewCenterY;

		pGLState.translateModelViewGLMatrixf(skewCenterX, skewCenterY, 0);
		pGLState.skewModelViewGLMatrixf(skewX, skewY);
		pGLState.translateModelViewGLMatrixf(-skewCenterX, -skewCenterY, 0);
	}
}
 
Example 10
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected void applyScale(final GLState pGLState) {
	final float scaleX = this.mScaleX;
	final float scaleY = this.mScaleY;

	if((scaleX != 1) || (scaleY != 1)) {
		final float scaleCenterX = this.mScaleCenterX;
		final float scaleCenterY = this.mScaleCenterY;

		pGLState.translateModelViewGLMatrixf(scaleCenterX, scaleCenterY, 0);
		pGLState.scaleModelViewGLMatrixf(scaleX, scaleY, 1);
		pGLState.translateModelViewGLMatrixf(-scaleCenterX, -scaleCenterY, 0);
	}
}
 
Example 11
Source File: Entity.java    From tilt-game-android with MIT License 4 votes vote down vote up
protected void applyOffset(final GLState pGLState) {
	pGLState.translateModelViewGLMatrixf(-this.mLocalOffsetCenterX, -this.mLocalOffsetCenterY, 0);
}
 
Example 12
Source File: Entity.java    From tilt-game-android with MIT License 4 votes vote down vote up
protected void applyTranslation(final GLState pGLState) {
	pGLState.translateModelViewGLMatrixf(this.mX, this.mY, 0);
}
 
Example 13
Source File: Entity.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
protected void applyTranslation(final GLState pGLState) {
	pGLState.translateModelViewGLMatrixf(this.mX, this.mY, 0);
}