Non-uniform scaling

Started by ned flanders, July 19, 2013, 07:09:08 PM

Previous topic - Next topic

ned flanders

Hi, noob question, wondering if there's an easy way to do non-uniform scaling, ie, where x,y,z, scaling factors are different.

My immediate need is simply to create a Primitive.Plane, which is of unit size, then scale as needed in the x,y directions.  For example, maybe I'd like a plane twice as wide as high.

Wait...just occurred to me...should I use the rotation matrix, and pass in values on the diagonal?

ned flanders

Well, I got it to work with the following code, in which I need not only non-uniform x-y scaling, but rotation baked in as well:


plane = Primitives.getPlane(1,1);

Matrix scalingMat = new Matrix();
scalingMat.set(0, 0, width);
scalingMat.set(1, 1, height);

Matrix rotMat = plane.getRotationMatrix();
rotMat.rotateX((float)(Math.PI/2f));

scalingMat.matMul(rotMat);

plane.setRotationMatrix(scalingMat);


Let me know if there's an easier/better way for this.

EgonOlsen

That's ok, but it might screw up your normals so that lighting can become strange. You might want to add


plane.rotateMesh();
plane.clearRotation();


at the end to make the change permanent to the mesh.

ned flanders

Thanks, makes perfect sense, I forgot about the normals.