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); ...

Get Cardboard VR Projects for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.