1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.graphics.g3d.utils.shapebuilders; 18 19 import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder; 20 21 import com.badlogic.gdx.utils.GdxRuntimeException; 22 /** Helper class with static methods to build capsule shapes using {@link MeshPartBuilder}. 23 * @author xoppa */ 24 public class CapsuleShapeBuilder extends BaseShapeBuilder { build(MeshPartBuilder builder, float radius, float height, int divisions)25 public static void build (MeshPartBuilder builder, float radius, float height, int divisions) { 26 if (height < 2f * radius) throw new GdxRuntimeException("Height must be at least twice the radius"); 27 final float d = 2f * radius; 28 CylinderShapeBuilder.build(builder, d, height - d, d, divisions, 0, 360, false); 29 SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, .5f * (height - d), 0), d, d, d, divisions, divisions, 0, 30 360, 0, 90); 31 SphereShapeBuilder.build(builder, matTmp1.setToTranslation(0, -.5f * (height - d), 0), d, d, d, divisions, divisions, 0, 32 360, 90, 180); 33 } 34 } 35