Author Topic: Scale around a center point?  (Read 8352 times)

Offline sticksen

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Scale around a center point?
« Reply #15 on: October 26, 2011, 06:50:32 pm »
Finally I got it working...first the code:
Code: [Select]
/**
* Scales whole scene via scaleDelta. Note that scale value is handled as
* accumulative, not absolute. Scene is scaled around scaleMidpoint
*
* @param scaleDelta
*            accumulative scale value
* @param scaleMidpoint
*            midpoint in screen coordinates
*/
public void scale(float scaleDelta, Vector3f scaleMidpoint) {

//obtain world coordinates of scaleMidpoint
backgroundMap.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
SimpleVector worldCoord = getCollisionCoordinates(backgroundName, scaleMidpoint);
backgroundMap.setCollisionMode(Object3D.COLLISION_CHECK_NONE);

SimpleVector translation = rootNode.getTranslation();
Matrix mat = rootNode.getRotationMatrix();
mat.translate(-(worldCoord.x - translation.x), -(worldCoord.y - translation.y), 0);
Matrix scale = getScaleMatrix(scaleDelta);
mat.matMul(scale);
mat.translate(worldCoord.x - translation.x, worldCoord.y - translation.y, 0);
}

private Matrix getScaleMatrix(float scale) {
Matrix scaleMat = new Matrix();
scaleMat.setDump(new float[] { scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, 1 });
return scaleMat;
}
Ok, this is kind of a hack, because there's no rootNode.getMatrix() or setMatrix, only getTranslationMatrix and getRotationMatrix. getScaleMatrix also isn't present, so I had to use the rotation matrix and add scale values to it, which don't seem to be stripped afterwards.
The Matrix class itself features .translate, .rotate, but also no .scale, which is another inconsistency.

All other tips mentioned here didn't work for me.

This seems to be the only way things are happening like I want it to, but now another problem arises: Billboarded objects seem to be scaled double. I'm opening a new thread on this.

Thanks for all your help!
« Last Edit: October 26, 2011, 06:55:15 pm by sticksen »