Skip to content

Commit

Permalink
getSceneToLocalMatrix seems to be working.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGramlich committed Dec 21, 2010
1 parent bad1f07 commit 814330c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="lib/libProgressMonitor.jar"/> <classpathentry kind="lib" path="lib/libProgressMonitor.jar"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public static boolean checkCollision(final RectangularShape pRectangularShapeA,
} }


public static void fillVertices(final RectangularShape pRectangularShape, final float[] pVertices) { public static void fillVertices(final RectangularShape pRectangularShape, final float[] pVertices) {
final float left = pRectangularShape.getX(); final float left = 0;
final float top = pRectangularShape.getY(); final float top = 0;
final float right = pRectangularShape.getWidth() + left; final float right = pRectangularShape.getWidth();
final float bottom = pRectangularShape.getHeight() + top; final float bottom = pRectangularShape.getHeight();


pVertices[0 + VERTEX_INDEX_X] = left; pVertices[0 + VERTEX_INDEX_X] = left;
pVertices[0 + VERTEX_INDEX_Y] = top; pVertices[0 + VERTEX_INDEX_Y] = top;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -136,33 +136,6 @@ protected void onHandleControlKnobReleased() {
this.onUpdateControlKnob(0, 0); this.onUpdateControlKnob(0, 0);
} }


private void updateControlKnob(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final Sprite controlBase = this.mControlBase;

final float relativeX = MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth() - 0.5f;
final float relativeY = MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight() - 0.5f;

this.onUpdateControlKnob(relativeX, relativeY);
}

/**
* @param pRelativeX from <code>-0.5</code> (left) to <code>0.5</code> (right).
* @param pRelativeY from <code>-0.5</code> (top) to <code>0.5</code> (bottom).
*/
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
final Sprite controlBase = this.mControlBase;
final Sprite controlKnob = this.mControlKnob;

this.mControlValueX = 2 * pRelativeX;
this.mControlValueY = 2 * pRelativeY;

final float[] controlBaseSceneCenterCoordinates = controlBase.getSceneCenterCoordinates();
final float x = controlBaseSceneCenterCoordinates[VERTEX_INDEX_X] - controlKnob.getWidth() * 0.5f + pRelativeX * controlBase.getWidthScaled();
final float y = controlBaseSceneCenterCoordinates[VERTEX_INDEX_Y] - controlKnob.getHeight() * 0.5f + pRelativeY * controlBase.getHeightScaled();

controlKnob.setPosition(x, y);
}

protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final int pointerID = pSceneTouchEvent.getPointerID(); final int pointerID = pSceneTouchEvent.getPointerID();


Expand Down Expand Up @@ -192,6 +165,33 @@ protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent,
return true; return true;
} }


private void updateControlKnob(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final Sprite controlBase = this.mControlBase;

final float relativeX = MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth() - 0.5f;
final float relativeY = MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight() - 0.5f;

this.onUpdateControlKnob(relativeX, relativeY);
}

/**
* @param pRelativeX from <code>-0.5</code> (left) to <code>0.5</code> (right).
* @param pRelativeY from <code>-0.5</code> (top) to <code>0.5</code> (bottom).
*/
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
final Sprite controlBase = this.mControlBase;
final Sprite controlKnob = this.mControlKnob;

this.mControlValueX = 2 * pRelativeX;
this.mControlValueY = 2 * pRelativeY;

final float[] controlBaseSceneCenterCoordinates = controlBase.getSceneCenterCoordinates();
final float x = controlBaseSceneCenterCoordinates[VERTEX_INDEX_X] - controlKnob.getWidth() * 0.5f + pRelativeX * controlBase.getWidthScaled();
final float y = controlBaseSceneCenterCoordinates[VERTEX_INDEX_Y] - controlKnob.getHeight() * 0.5f + pRelativeY * controlBase.getHeightScaled();

controlKnob.setPosition(x, y);
}

// =========================================================== // ===========================================================
// Inner and Anonymous Classes // Inner and Anonymous Classes
// =========================================================== // ===========================================================
Expand Down
63 changes: 51 additions & 12 deletions src/org/anddev/andengine/entity/Entity.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -436,9 +436,11 @@ public void reset() {


this.mEntityModifiers.reset(); this.mEntityModifiers.reset();


final ArrayList<IEntity> entities = this.mChildren; if(this.mChildren != null) {
for(int i = entities.size() - 1; i >= 0; i--) { final ArrayList<IEntity> entities = this.mChildren;
entities.get(i).reset(); for(int i = entities.size() - 1; i >= 0; i--) {
entities.get(i).reset();
}
} }
} }


Expand Down Expand Up @@ -607,19 +609,12 @@ private void allocateChildren() {
this.mChildren = new ArrayList<IEntity>(Entity.CHILDREN_CAPACITY_DEFAULT); this.mChildren = new ArrayList<IEntity>(Entity.CHILDREN_CAPACITY_DEFAULT);
} }


@Override
public Matrix getSceneToLocalMatrix() {
final Matrix sceneToLocalMatrix = this.mSceneToLocalMatrix;
sceneToLocalMatrix.reset();
this.getLocalToSceneMatrix().invert(sceneToLocalMatrix);
return sceneToLocalMatrix;
}

@Override @Override
public Matrix getLocalToSceneMatrix() { public Matrix getLocalToSceneMatrix() {
final Matrix localToSceneMatrix = this.mLocalToSceneMatrix; final Matrix localToSceneMatrix = this.mLocalToSceneMatrix;
localToSceneMatrix.reset(); localToSceneMatrix.reset();


/* Scale. */
final float scaleX = this.mScaleX; final float scaleX = this.mScaleX;
final float scaleY = this.mScaleY; final float scaleY = this.mScaleY;
if(scaleX != 1 || scaleY != 1) { if(scaleX != 1 || scaleY != 1) {
Expand All @@ -631,8 +626,9 @@ public Matrix getLocalToSceneMatrix() {
} }


/* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same. /* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same.
* In that case the last postTranslate of the rotation and the first postTranslate of the scale is superfluous. */ * In that case the last postTranslate of the scale and the first postTranslate of the rotation is superfluous. */


/* Rotation. */
final float rotation = this.mRotation; final float rotation = this.mRotation;
if(rotation != 0) { if(rotation != 0) {
final float rotationCenterX = this.mRotationCenterX; final float rotationCenterX = this.mRotationCenterX;
Expand All @@ -643,6 +639,7 @@ public Matrix getLocalToSceneMatrix() {
localToSceneMatrix.postTranslate(rotationCenterX, rotationCenterY); localToSceneMatrix.postTranslate(rotationCenterX, rotationCenterY);
} }


/* Translation. */
localToSceneMatrix.postTranslate(this.mX, this.mY); localToSceneMatrix.postTranslate(this.mX, this.mY);


final IEntity parent = this.mParent; final IEntity parent = this.mParent;
Expand All @@ -653,6 +650,48 @@ public Matrix getLocalToSceneMatrix() {
return localToSceneMatrix; return localToSceneMatrix;
} }


@Override
public Matrix getSceneToLocalMatrix() {
final Matrix sceneToLocalMatrix = this.mSceneToLocalMatrix;
sceneToLocalMatrix.reset();

final IEntity parent = this.mParent;
if(parent != null) {
sceneToLocalMatrix.postConcat(parent.getSceneToLocalMatrix());
}

/* Translation. */
sceneToLocalMatrix.postTranslate(-this.mX, -this.mY);

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

sceneToLocalMatrix.postTranslate(-rotationCenterX, -rotationCenterY);
sceneToLocalMatrix.postRotate(-rotation);
sceneToLocalMatrix.postTranslate(rotationCenterX, rotationCenterY);
}

/* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same.
* In that case the last postTranslate of the rotation and the first postTranslate of the scale is superfluous. */

/* Scale. */
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;

sceneToLocalMatrix.postTranslate(-scaleCenterX, -scaleCenterY);
sceneToLocalMatrix.postScale(1 / scaleX, 1 / scaleY);
sceneToLocalMatrix.postTranslate(scaleCenterX, scaleCenterY);
}

return sceneToLocalMatrix;
}

protected void onApplyTransformations(final GL10 pGL) { protected void onApplyTransformations(final GL10 pGL) {
/* Translation. */ /* Translation. */
this.applyTranslation(pGL); this.applyTranslation(pGL);
Expand Down
6 changes: 6 additions & 0 deletions src/org/anddev/andengine/entity/scene/Scene.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.anddev.andengine.engine.handler.UpdateHandlerList; import org.anddev.andengine.engine.handler.UpdateHandlerList;
import org.anddev.andengine.engine.handler.runnable.RunnableHandler; import org.anddev.andengine.engine.handler.runnable.RunnableHandler;
import org.anddev.andengine.entity.Entity; import org.anddev.andengine.entity.Entity;
import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.layer.Layer; import org.anddev.andengine.entity.layer.Layer;
import org.anddev.andengine.entity.layer.ZIndexSorter; import org.anddev.andengine.entity.layer.ZIndexSorter;
import org.anddev.andengine.entity.scene.background.ColorBackground; import org.anddev.andengine.entity.scene.background.ColorBackground;
Expand Down Expand Up @@ -479,6 +480,11 @@ public void reset() {


this.clearChildScene(); this.clearChildScene();
} }

@Override
public void setParent(IEntity pEntity) {
// super.setParent(pEntity);
}


// =========================================================== // ===========================================================
// Methods // Methods
Expand Down

0 comments on commit 814330c

Please sign in to comment.