Ragdoll
- setSpatial(null) supported - fixed debug shape git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7336 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
f640e5de21
commit
bb6a8c8062
@ -32,7 +32,6 @@
|
|||||||
package com.jme3.bullet.collision;
|
package com.jme3.bullet.collision;
|
||||||
|
|
||||||
import com.jme3.asset.AssetManager;
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
|
|
||||||
import com.jme3.bullet.collision.shapes.CollisionShape;
|
import com.jme3.bullet.collision.shapes.CollisionShape;
|
||||||
import com.jme3.bullet.util.DebugShapeFactory;
|
import com.jme3.bullet.util.DebugShapeFactory;
|
||||||
import com.jme3.export.InputCapsule;
|
import com.jme3.export.InputCapsule;
|
||||||
@ -167,22 +166,27 @@ public abstract class PhysicsCollisionObject implements Savable {
|
|||||||
protected Spatial attachDebugShape(AssetManager manager) {
|
protected Spatial attachDebugShape(AssetManager manager) {
|
||||||
debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
||||||
debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
|
debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
|
||||||
// debugMaterialBlue.getAdditionalRenderState().setDepthTest(false);
|
|
||||||
debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
||||||
debugMaterialGreen.setColor("Color", ColorRGBA.Green);
|
debugMaterialGreen.setColor("Color", ColorRGBA.Green);
|
||||||
// debugMaterialGreen.getAdditionalRenderState().setDepthTest(false);
|
|
||||||
debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
||||||
debugMaterialRed.setColor("Color", ColorRGBA.Red);
|
debugMaterialRed.setColor("Color", ColorRGBA.Red);
|
||||||
// debugMaterialRed.getAdditionalRenderState().setDepthTest(false);
|
|
||||||
debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
|
||||||
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
|
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
|
||||||
// debugMaterialYellow.getAdditionalRenderState().setDepthTest(false);
|
|
||||||
debugArrow = new Arrow(Vector3f.UNIT_XYZ);
|
debugArrow = new Arrow(Vector3f.UNIT_XYZ);
|
||||||
debugArrowGeom = new Geometry("DebugArrow", debugArrow);
|
debugArrowGeom = new Geometry("DebugArrow", debugArrow);
|
||||||
debugArrowGeom.setMaterial(debugMaterialGreen);
|
debugArrowGeom.setMaterial(debugMaterialGreen);
|
||||||
return attachDebugShape();
|
return attachDebugShape();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a debug shape for this CollisionObject
|
||||||
|
* @param manager
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Spatial createDebugShape(AssetManager manager){
|
||||||
|
return attachDebugShape(manager);
|
||||||
|
}
|
||||||
|
|
||||||
protected Spatial attachDebugShape(Material material) {
|
protected Spatial attachDebugShape(Material material) {
|
||||||
debugMaterialBlue = material;
|
debugMaterialBlue = material;
|
||||||
debugMaterialGreen = material;
|
debugMaterialGreen = material;
|
||||||
|
@ -103,7 +103,8 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
protected Vector3f modelPosition = new Vector3f();
|
protected Vector3f modelPosition = new Vector3f();
|
||||||
protected Quaternion modelRotation = new Quaternion();
|
protected Quaternion modelRotation = new Quaternion();
|
||||||
protected float rootMass = 15;
|
protected float rootMass = 15;
|
||||||
private float totalMass = 0;
|
protected float totalMass = 0;
|
||||||
|
protected boolean added=false;
|
||||||
|
|
||||||
public RagdollControl() {
|
public RagdollControl() {
|
||||||
}
|
}
|
||||||
@ -142,9 +143,9 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
|
|
||||||
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
|
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
|
||||||
|
|
||||||
q2.set(q).multLocal(link.initalWorldRotation).normalize();
|
q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
|
||||||
q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
|
q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
|
||||||
q2.normalize();
|
q2.normalizeLocal();
|
||||||
if (link.bone.getParent() == null) {
|
if (link.bone.getParent() == null) {
|
||||||
modelPosition.set(p).subtractLocal(link.bone.getInitialPos());
|
modelPosition.set(p).subtractLocal(link.bone.getInitialPos());
|
||||||
modelRotation.set(q).multLocal(link.bone.getInitialRot().inverse());
|
modelRotation.set(q).multLocal(link.bone.getInitialRot().inverse());
|
||||||
@ -244,6 +245,11 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSpatial(Spatial model) {
|
public void setSpatial(Spatial model) {
|
||||||
|
if (model == null) {
|
||||||
|
removeFromPhysicsSpace();
|
||||||
|
clearData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
targetModel = model;
|
targetModel = model;
|
||||||
Node parent = model.getParent();
|
Node parent = model.getParent();
|
||||||
|
|
||||||
@ -399,21 +405,26 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addToPhysicsSpace() {
|
private void addToPhysicsSpace() {
|
||||||
|
|
||||||
if (baseRigidBody != null) {
|
if (baseRigidBody != null) {
|
||||||
space.add(baseRigidBody);
|
space.add(baseRigidBody);
|
||||||
|
added=true;
|
||||||
}
|
}
|
||||||
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
||||||
PhysicsBoneLink physicsBoneLink = it.next();
|
PhysicsBoneLink physicsBoneLink = it.next();
|
||||||
if (physicsBoneLink.rigidBody != null) {
|
if (physicsBoneLink.rigidBody != null) {
|
||||||
space.add(physicsBoneLink.rigidBody);
|
space.add(physicsBoneLink.rigidBody);
|
||||||
|
added=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
||||||
PhysicsBoneLink physicsBoneLink = it.next();
|
PhysicsBoneLink physicsBoneLink = it.next();
|
||||||
if (physicsBoneLink.joint != null) {
|
if (physicsBoneLink.joint != null) {
|
||||||
space.add(physicsBoneLink.joint);
|
space.add(physicsBoneLink.joint);
|
||||||
|
added=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HullCollisionShape makeShape(PhysicsBoneLink link, Spatial model) {
|
private HullCollisionShape makeShape(PhysicsBoneLink link, Spatial model) {
|
||||||
@ -506,6 +517,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromPhysicsSpace() {
|
private void removeFromPhysicsSpace() {
|
||||||
|
|
||||||
if (baseRigidBody != null) {
|
if (baseRigidBody != null) {
|
||||||
space.remove(baseRigidBody);
|
space.remove(baseRigidBody);
|
||||||
}
|
}
|
||||||
@ -521,6 +533,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
space.remove(physicsBoneLink.rigidBody);
|
space.remove(physicsBoneLink.rigidBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
added=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
@ -542,7 +555,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
|
|||||||
public void attachDebugShape(AssetManager manager) {
|
public void attachDebugShape(AssetManager manager) {
|
||||||
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
|
||||||
PhysicsBoneLink physicsBoneLink = it.next();
|
PhysicsBoneLink physicsBoneLink = it.next();
|
||||||
physicsBoneLink.rigidBody.attachDebugShape(manager);
|
physicsBoneLink.rigidBody.createDebugShape(manager);
|
||||||
}
|
}
|
||||||
debug = true;
|
debug = true;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi
|
|||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
bulletAppState.setEnabled(true);
|
bulletAppState.setEnabled(true);
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
// bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
||||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||||
setupLight();
|
setupLight();
|
||||||
|
|
||||||
@ -155,7 +155,6 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi
|
|||||||
q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
|
q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
|
||||||
//q.lookAt(model.getLocalRotation().toRotationMatrix().getColumn(2), Vector3f.UNIT_Y);
|
//q.lookAt(model.getLocalRotation().toRotationMatrix().getColumn(2), Vector3f.UNIT_Y);
|
||||||
model.setLocalRotation(q);
|
model.setLocalRotation(q);
|
||||||
System.out.println(angles[0]+ " "+angles[2]);
|
|
||||||
if(angles[0]<0){
|
if(angles[0]<0){
|
||||||
ragdoll.blendControlToAnim("StandUpBack",animChannel);
|
ragdoll.blendControlToAnim("StandUpBack",animChannel);
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user