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!