www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: ned flanders on July 19, 2013, 07:09:08 pm

Title: Non-uniform scaling
Post by: ned flanders on July 19, 2013, 07:09:08 pm
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?
Title: Re: Non-uniform scaling
Post by: ned flanders on July 19, 2013, 08:25:07 pm
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:

Code: [Select]
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.
Title: Re: Non-uniform scaling
Post by: EgonOlsen on July 19, 2013, 09:14:47 pm
That's ok, but it might screw up your normals so that lighting can become strange. You might want to add

Code: [Select]
plane.rotateMesh();
plane.clearRotation();

at the end to make the change permanent to the mesh.
Title: Re: Non-uniform scaling
Post by: ned flanders on July 19, 2013, 09:51:50 pm
Thanks, makes perfect sense, I forgot about the normals.