2 * Copyright (c) 2010-2014, Kazuhiko Kobayashi
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
28 package projectkyoto.jme3.mmd.nativebullet;
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;
44 public class PhysicsControl extends AbstractControl {
47 PMDPhysicsWorld world;
48 public PhysicsControl() {
49 world = new PMDPhysicsWorld();
51 public PhysicsControl(PMDNode pmdNode) {
52 this.pmdNode = pmdNode;
53 world = new PMDPhysicsWorld();
54 world.addPMDNode(pmdNode);
58 protected void controlUpdate(float tpf) {
59 // pmdNode.getSkeleton().updateWorldVectors();
60 // world.updateJointPosition(pmdNode);
61 world.stepSimulation(tpf);
62 // world.applyResultToBone();
63 // pmdNode.calcOffsetMatrices();
68 protected void controlRender(RenderManager rm, ViewPort vp) {
72 public Control cloneForSpatial(Spatial spatial) {
73 throw new UnsupportedOperationException("Not supported yet.");
75 PMDRigidBody rigidBodyArray[];
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;
90 PMDRigidBody createRigidBody(projectkyoto.mmd.file.PMDRigidBody fileRigidBody, Bone bone) {
94 void setKinematicPos() {
96 // void stepSimulation(float timeStep) {
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;
107 public PMDPhysicsWorld getWorld() {