Scale along a particular axis of an 3D object in JPCT

160 Views Asked by At

I have gone through the 3D object documentation in JPCT but i couldn't find a way to scale an 3D object[a Cylinder] along y axis only. My world have multiple objects and I goal is to scale one particular object. Appreciate any leads. Thank you!!

Something like this openGL function glScalef(1,10,1).

1

There are 1 best solutions below

0
On

The user AGP lists a method of achieving this here: JPCT Forums

It basically uses the following vertex controller class, and I've used it successfully as well:

class VertexController extends GenericVertexController 
{
   public VertexController(Object3D toCheck) {
       super.init(toCheck.getMesh(), true);
   }

   protected void scale(SimpleVector scale) 
   {
      SimpleVector[] vertices = getSourceMesh();
      SimpleVector[] destination = getDestinationMesh();

      for (int i = 0; i < vertices.length; i++) 
      {
         vertices[i].x *= scale.x;
         vertices[i].y *= scale.y;
         vertices[i].z *= scale.z;
         destination[i].x = vertices[i].x;
         destination[i].y = vertices[i].y;
         destination[i].z = vertices[i].z;
      }

      this.updateMesh();
   }

   public void apply() {}
}

And you can call it like this:

vertexController = new VertexController(object);

Then in your onDrawFrame, or whereever required:

vertexController.scale(new SimpleVector(1,1.5f,1));