1

I'm working on something in Java3D and I know TransformGroups are how you would usually apply scaling...

However, I am trying to create a way of defining cuboids based on a scaling vector.

So I have a unit cube 1,1,1 -> -1,-1,-1 and I want to manually apply a scaling transformation.

 private static void scaleCoordinates(IndexedQuadArray indexedQuadArray, Vector3d scaleVector) {
    //Create scalar transform
    Transform3D scalarTransform = new Transform3D();
    scalarTransform.setScale(scaleVector);

    // retrieve the vertex coordinates
    GeometryInfo indexedQuadArrayGeometryInfo = new GeometryInfo(indexedQuadArray);
    Point3f coordinatesToScaleArray [] = indexedQuadArrayGeometryInfo.getCoordinates();

    // scale each 3d coordinate 
    for(Point3f coordinate: coordinatesToScaleArray){
        scalarTransform.transform(coordinate);
    }

    // update the indexed quad array with scaled-coordinates.
    indexedQuadArray.setCoordinates(0, coordinatesToScaleArray);
}

Now it works when the scaling is positive whole numbers, but if I scale by 0.5 or a negative number the vertices get messed up.

Anyone any idea what's wrong? I should be able to scale by less than 1 I think, maybe something is happinening with Transform3D.transform(Point3f) that I'm not aware of.

Thanks a lot for reading!

1 Answers1

0

I wouldn't expect negative numbers to work. The scaling transformation is really just a multiplcation when you think about it. Thus scaling the point (1,1,1) with the vector (.5,.6,.7) should give you the new point (.5,.6,.7)

If you "scale" by a negative number, you'd be turning your cube inside out, and all sorts of normals and edges would be wrong.

Can you provide a list of the vertices of in your quadArray and the scaleVector you are using?

JohnnyO
  • 3,018
  • 18
  • 30