/*
 * Copyright 2017 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.physics.bullet.shapes;


import com.bulletphysics.collision.shapes.CompoundShape;
import org.terasology.math.geom.Quat4f;
import org.terasology.physics.shapes.CollisionShape;

public class BulletCompoundShape extends BulletCollisionShape implements org.terasology.physics.shapes.CompoundShape {
    private final CompoundShape compoundShape;

    public BulletCompoundShape() {
        compoundShape = new CompoundShape();
    }

    @Override
    public void addChildShape(org.terasology.math.Transform transform, CollisionShape collisionShape) {
        compoundShape.addChildShape(toBulletTransform(transform), ((BulletCollisionShape) collisionShape).underlyingShape);
    }

    @Override
    public CollisionShape rotate(Quat4f rot) {
        return null;
    }
}

@@ -695,16 +695,198 @@
 dShape;%0A
+import com.bulletphysics.collision.shapes.CompoundShapeChild;%0Aimport com.bulletphysics.linearmath.Transform;%0Aimport org.terasology.math.Rotation;%0Aimport org.terasology.math.VecMath;%0A
 import o
@@ -971,16 +971,68 @@
 Shape;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -1193,318 +1193,1481 @@
 pe;%0A
-%0A    public BulletCompoundShape() %7B%0A        compoundShape = new CompoundShape();%0A    %7D%0A%0A    @Override%0A    public void addChildShape(org.terasology.math.Transform transform, CollisionShape collisionShape) %7B%0A        compoundShape.addChildShape(toBulletTransform(transform), ((BulletCollisionShape) collisionShape
+    private List%3CBulletCompoundShapeChild%3E childList;%0A%0A    public BulletCompoundShape() %7B%0A        this(new CompoundShape());%0A    %7D%0A%0A    private BulletCompoundShape(CompoundShape compoundShape) %7B%0A        this.compoundShape = compoundShape;%0A%0A        childList = new ArrayList%3C%3E();%0A    %7D%0A%0A    @Override%0A    public void addChildShape(org.terasology.math.Transform transform, CollisionShape collisionShape) %7B%0A        BulletCollisionShape bulletCollisionShape = (BulletCollisionShape) collisionShape;%0A        Transform bulletTransform = toBulletTransform(transform);%0A        compoundShape.addChildShape(bulletTransform, bulletCollisionShape.underlyingShape);%0A%0A        childList.add(new BulletCompoundShapeChild(bulletTransform, bulletCollisionShape,%0A                compoundShape.getChildList().get(compoundShape.getNumChildShapes() - 1)));%0A    %7D%0A%0A    // TODO: Add removeChildShape if needed%0A%0A    @Override%0A    public CollisionShape rotate(Quat4f rot) %7B%0A        CompoundShape newShape = new CompoundShape();%0A        for (BulletCompoundShapeChild child : childList) %7B%0A            CollisionShape rotatedChild = child.childShape.rotate(rot);%0A            javax.vecmath.Vector3f offset = com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), child.transform.origin, new javax.vecmath.Vector3f());%0A            newShape.addChildShape(new Transform(new javax.vecmath.Matrix4f(VecMath.to(Rotation.none().getQuat4f()), offset, 1.0f)), ((BulletCollisionShape) rotatedChild
 ).un
@@ -2686,96 +2686,552 @@
 e);%0A
+    
     %7D%0A
-%0A    @Override%0A
+        return new BulletCompoundShape(newShape);%0A    %7D%0A%0A    private static class BulletCompoundShapeChild %7B%0A 
     
+   
 public 
-CollisionShape rotate(Quat4f rot) %7B%0A        return null;
+Transform transform;%0A        public BulletCollisionShape childShape;%0A%0A        public CompoundShapeChild compoundShapeChild;%0A%0A        private BulletCompoundShapeChild(Transform transform, BulletCollisionShape childShape, CompoundShapeChild compoundShapeChild) %7B%0A            this.transform = transform;%0A            this.childShape = childShape;%0A            this.compoundShapeChild = compoundShapeChild;%0A        %7D
 %0A   

Complete BulletCompoundShape.rotate definition