Model extents, scaling, and center
3D models come in all shapes and sizes. To view them in our app, we need to know the minimum and maximum boundaries of the model and its geometric center to scale and position it properly. Let's add this to ModelObject
now.
At the top of the ModelObject
class, add the following variables:
public Vector3 extentsMin, extentsMax;
Initialize the extents in the parser, before we parse the model data. The minimum extents are initialized to the maximum possible values; the maximum extents are initialized to the minimum possible values:
public ModelObject(int objFile) { super(); extentsMin = new Vector3(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); extentsMax = new Vector3(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE); . . .
Rather than calculating the extents after the model is loaded, we'll do it during the import process. As we add a new vertex to the vertex list, we'll calculate the current extents...