* fix issue #901 (collision margins initialized to 0) * add a getter for the default collision margin
This commit is contained in:
parent
f60ff58ef0
commit
1ad324aa57
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2018 jMonkeyEngine
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -49,6 +49,11 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public abstract class CollisionShape implements Savable {
|
||||
|
||||
/**
|
||||
* default margin for new non-sphere/non-capsule shapes (in physics-space
|
||||
* units, >0, default=0.04)
|
||||
*/
|
||||
private static float defaultMargin = 0.04f;
|
||||
/**
|
||||
* unique identifier of the btCollisionShape
|
||||
* <p>
|
||||
@ -63,7 +68,7 @@ public abstract class CollisionShape implements Savable {
|
||||
/**
|
||||
* copy of collision margin (in physics-space units, >0, default=0)
|
||||
*/
|
||||
protected float margin = 0.0f;
|
||||
protected float margin = defaultMargin;
|
||||
|
||||
public CollisionShape() {
|
||||
}
|
||||
@ -135,6 +140,27 @@ public abstract class CollisionShape implements Savable {
|
||||
|
||||
private native float getMargin(long objectId);
|
||||
|
||||
/**
|
||||
* Alter the default margin for new shapes that are neither capsules nor
|
||||
* spheres.
|
||||
*
|
||||
* @param margin the desired margin distance (in physics-space units, >0,
|
||||
* default=0.04)
|
||||
*/
|
||||
public static void setDefaultMargin(float margin) {
|
||||
defaultMargin = margin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the default margin for new shapes.
|
||||
*
|
||||
* @return margin the default margin distance (in physics-space units,
|
||||
* >0)
|
||||
*/
|
||||
public static float getDefaultMargin() {
|
||||
return defaultMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the collision margin of this shape. CAUTION: Margin is applied
|
||||
* differently, depending on the type of shape. Generally the collision
|
||||
@ -145,7 +171,7 @@ public abstract class CollisionShape implements Savable {
|
||||
* compound shapes) changes can have unintended consequences.
|
||||
*
|
||||
* @param margin the desired margin distance (in physics-space units, >0,
|
||||
* default=0)
|
||||
* default=0.04)
|
||||
*/
|
||||
public void setMargin(float margin) {
|
||||
setMargin(objectId, margin);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -44,9 +44,17 @@ import java.io.IOException;
|
||||
*/
|
||||
public abstract class CollisionShape implements Savable {
|
||||
|
||||
/**
|
||||
* default margin for new shapes (in physics-space units, >0,
|
||||
* default=0.04)
|
||||
*/
|
||||
private static float defaultMargin = 0.04f;
|
||||
protected com.bulletphysics.collision.shapes.CollisionShape cShape;
|
||||
protected Vector3f scale = new Vector3f(1, 1, 1);
|
||||
protected float margin = 0.0f;
|
||||
/**
|
||||
* copy of collision margin (in physics-space units, >0, default=0)
|
||||
*/
|
||||
protected float margin = defaultMargin;
|
||||
|
||||
public CollisionShape() {
|
||||
}
|
||||
@ -88,6 +96,26 @@ public abstract class CollisionShape implements Savable {
|
||||
return cShape.getMargin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the default margin for new shapes.
|
||||
*
|
||||
* @param margin the desired margin distance (in physics-space units, >0,
|
||||
* default=0.04)
|
||||
*/
|
||||
public static void setDefaultMargin(float margin) {
|
||||
defaultMargin = margin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the default margin for new shapes.
|
||||
*
|
||||
* @return margin the default margin distance (in physics-space units,
|
||||
* >0)
|
||||
*/
|
||||
public static float getDefaultMargin() {
|
||||
return defaultMargin;
|
||||
}
|
||||
|
||||
public void setMargin(float margin) {
|
||||
cShape.setMargin(margin);
|
||||
this.margin = margin;
|
||||
|
Loading…
x
Reference in New Issue
Block a user