Book Image

Learning LibGDX Game Development- Second Edition

Book Image

Learning LibGDX Game Development- Second Edition

Overview of this book

Table of Contents (21 chapters)
Learning LibGDX Game Development Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding some rigid bodies


Now, we will create individual bodies and set their properties and put them into our dynamics world, as follows:

   modelbuilder.begin();
MeshPartBuilder mpb = modelbuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.Color, new Material(ColorAttribute.createDiffuse(Color.WHITE)));
   mpb.setColor(1f, 1f, 1f, 1f);
   mpb.box(0, 0, 0, 40, 1, 40);
   Model model = modelbuilder.end();
groundInstance = new ModelInstance(model);


   btCollisionShape groundshape = new btBoxShape(new Vector3(20, 1 / 2f, 20));
   btRigidBodyConstructionInfo bodyInfo = new btRigidBodyConstructionInfo(0, null, groundshape, Vector3.Zero);
   btRigidBody body = new btRigidBody(bodyInfo);
   world.addRigidBody(body);

The preceding steps are to create the ground. In our program, the ground is simply a box with very low height. Using the mesh builder, we create a box with width, height, and depth as 40, 1, and 40 units respectively. Remember, this is simply a visual model...