Scaling

We've almost performed all of the transformations we can apply to models. The last one described in this book is the scaling a model. LibGDX luckily contains all the required functions and methods for this. Let's extend our previous example and make our box grow and shrink over time.

We will first create a function that increments and subtracts from a scale variable:

boolean increment; 
float scale = 1; 
void scale(){
      if(increment) {
         scale = (scale + Gdx.graphics.getDeltaTime()/5);           
         if (scale >= 1.5f)  {
             increment = false;
         } else {
             scale = (scale - Gdx.graphics.getDeltaTime()/5);          
             if(scale <= 0.5f)
                 increment = true;
       }
} 

To apply this scaling, we can adjust our updateTransformation function to include it:

private void updateTransformation(){ instance.transform.setFromEulerAngles(0, ...

Get Building a 3D Game with LibGDX 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.