OSDN Git Service

1cdf71614c658305d6085e5aec5448520deb5cae
[mikumikustudio/MikuMikuStudio.git] / engine / src / mmd / projectkyoto / jme3 / mmd / nativebullet / PhysicsControl.java
1 /*
2  * Copyright (c) 2010-2014, Kazuhiko Kobayashi
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 package projectkyoto.jme3.mmd.nativebullet;
29
30 import com.jme3.animation.Bone;
31 import com.jme3.animation.Skeleton;
32 import com.jme3.renderer.RenderManager;
33 import com.jme3.renderer.ViewPort;
34 import com.jme3.scene.Spatial;
35 import com.jme3.scene.control.AbstractControl;
36 import com.jme3.scene.control.Control;
37 import projectkyoto.jme3.mmd.PMDNode;
38 import projectkyoto.mmd.file.PMDModel;
39
40 /**
41  *
42  * @author kobayasi
43  */
44 public class PhysicsControl extends AbstractControl {
45
46     PMDNode pmdNode;
47     PMDPhysicsWorld world;
48     public PhysicsControl() {
49         world = new PMDPhysicsWorld();
50     }
51     public PhysicsControl(PMDNode pmdNode) {
52         this.pmdNode = pmdNode;
53         world = new PMDPhysicsWorld();
54         world.addPMDNode(pmdNode);
55     }
56
57     @Override
58     protected void controlUpdate(float tpf) {
59 //        pmdNode.getSkeleton().updateWorldVectors();
60 //        world.updateJointPosition(pmdNode);
61         world.stepSimulation(tpf);
62 //        world.applyResultToBone();
63 //        pmdNode.calcOffsetMatrices();
64 //        pmdNode.update();
65     }
66
67     @Override
68     protected void controlRender(RenderManager rm, ViewPort vp) {
69     }
70
71     @Override
72     public Control cloneForSpatial(Spatial spatial) {
73         throw new UnsupportedOperationException("Not supported yet.");
74     }
75     PMDRigidBody rigidBodyArray[];
76
77     void initRigidBodyArray() {
78         Skeleton skeleton = pmdNode.getSkeleton();
79         PMDModel pmdModel = pmdNode.getPmdModel();
80         rigidBodyArray = new PMDRigidBody[pmdModel.getRigidBodyList().getRigidBodyArray().length];
81         for (int i = 0; i < pmdModel.getRigidBodyList().getRigidBodyArray().length; i++) {
82             projectkyoto.mmd.file.PMDRigidBody fileRigidBody =
83                     pmdModel.getRigidBodyList().getRigidBodyArray()[i];
84             Bone bone = skeleton.getBone(fileRigidBody.getRelBoneIndex());
85             PMDRigidBody rb = createRigidBody(fileRigidBody, bone);
86             rigidBodyArray[i] = rb;
87         }
88     }
89
90     PMDRigidBody createRigidBody(projectkyoto.mmd.file.PMDRigidBody fileRigidBody, Bone bone) {
91         return null;
92     }
93
94     void setKinematicPos() {
95     }
96 //    void stepSimulation(float timeStep) {
97 //        setKinematicPos();
98 //        btWorld.stepSimulation(timeStep);
99 //        for(int i=0;i<btWorld.getNumCollisionObjects();i++) {
100 //            CollisionObject obj = btWorld.getCollisionObjectArray().getQuick(i);
101 //            if (obj instanceof PMDRigidBody) {
102 //                PMDRigidBody rb = (PMDRigidBody)obj;
103 //            }
104 //        }
105 //    }
106
107     public PMDPhysicsWorld getWorld() {
108         return world;
109     }
110 }