本文整理汇总了Java中org.jbox2d.collision.shapes.MassData类的典型用法代码示例。如果您正苦于以下问题:Java MassData类的具体用法?Java MassData怎么用?Java MassData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MassData类属于org.jbox2d.collision.shapes包,在下文中一共展示了MassData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFixtures
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
protected void createFixtures(Body body, PhysicsBodyShape shape, boolean sensor, float friction, float restitution, float density, Float fixedWeight) {
FixtureDef fd = new FixtureDef();
fd.shape = createShape(shape, width, height);
fd.isSensor = sensor || CollisionHandlerType.CLIMBABLE == type;
fd.friction = friction;
fd.restitution = restitution;
// calculate the required density to reach the fixed mass
if( fixedWeight!=null ) {
MassData md = new MassData();
fd.shape.computeMass(md, 1.0f);
density = fixedWeight/md.mass;
}
fd.density = density;
fd.userData = null;
body.createFixture(fd);
}
示例2: getMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Get the mass data of the body. The rotational inertia is relative to the center of mass.
*
* @return a struct containing the mass, inertia and center of the body.
*/
public final void getMassData(MassData data) {
// data.mass = m_mass;
// data.I = m_I + m_mass * Vec2.dot(m_sweep.localCenter, m_sweep.localCenter);
// data.center.set(m_sweep.localCenter);
data.mass = m_mass;
data.I =
m_I
+ m_mass
* (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y
* m_sweep.localCenter.y);
data.center.x = m_sweep.localCenter.x;
data.center.y = m_sweep.localCenter.y;
}
示例3: getMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Get the mass data of the body. The rotational inertia is relative
* to the center of mass.
*
* @return a struct containing the mass, inertia and center of the body.
*/
public final void getMassData(MassData data) {
// data.mass = m_mass;
// data.I = m_I + m_mass * Vec2.dot(m_sweep.localCenter, m_sweep.localCenter);
// data.center.set(m_sweep.localCenter);
data.mass = m_mass;
data.I = m_I + m_mass
* (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y * m_sweep.localCenter.y);
data.center.x = m_sweep.localCenter.x;
data.center.y = m_sweep.localCenter.y;
}
示例4: getMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Get the mass data of the body. The rotational inertia is relative to the center of mass.
*
* @return a struct containing the mass, inertia and center of the body.
*/
public final void getMassData(MassData data) {
// data.mass = m_mass;
// data.I = m_I + m_mass * Vector2.dot(m_sweep.localCenter, m_sweep.localCenter);
// data.center.set(m_sweep.localCenter);
data.mass = m_mass;
data.I =
m_I
+ m_mass
* (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y
* m_sweep.localCenter.y);
data.center.x = m_sweep.localCenter.x;
data.center.y = m_sweep.localCenter.y;
}
示例5: getMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Get the mass data of the body. The rotational inertia is relative to the
* center of mass.
*
* @return a struct containing the mass, inertia and center of the body.
*/
public final void getMassData(MassData data) {
// data.mass = m_mass;
// data.I = m_I + m_mass * Vec2.dot(m_sweep.localCenter,
// m_sweep.localCenter);
// data.center.set(m_sweep.localCenter);
data.mass = m_mass;
data.I = m_I
+ m_mass
* (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y
* m_sweep.localCenter.y);
data.center.x = m_sweep.localCenter.x;
data.center.y = m_sweep.localCenter.y;
}
示例6: setMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Set the mass properties to override the mass properties of the fixtures. Note that this changes
* the center of mass position. Note that creating or destroying fixtures can also alter the mass.
* This function has no effect if the body isn't dynamic.
*
* @param massData the mass properties.
*/
public final void setMassData(MassData massData) {
// TODO_ERIN adjust linear velocity and torque to account for movement of center.
assert (m_world.isLocked() == false);
if (m_world.isLocked() == true) {
return;
}
if (m_type != BodyType.DYNAMIC) {
return;
}
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_mass = massData.mass;
if (m_mass <= 0.0f) {
m_mass = 1f;
}
m_invMass = 1.0f / m_mass;
if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
final Vec2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(massData.center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
final Vec2 temp = m_world.getPool().popVec2();
temp.set(m_sweep.c).subLocal(oldCenter);
Vec2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(2);
}
示例7: setMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Set the mass properties to override the mass properties of the fixtures.
* Note that this changes the center of mass position.
* Note that creating or destroying fixtures can also alter the mass.
* This function has no effect if the body isn't dynamic.
*
* @param massData
* the mass properties.
*/
public final void setMassData(MassData massData) {
// TODO_ERIN adjust linear velocity and torque to account for movement of center.
assert (m_world.isLocked() == false);
if (m_world.isLocked() == true) {
return;
}
if (m_type != BodyType.DYNAMIC) {
return;
}
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_mass = massData.mass;
if (m_mass <= 0.0f) {
m_mass = 1f;
}
m_invMass = 1.0f / m_mass;
if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
final Vec2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(massData.center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOut(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
final Vec2 temp = m_world.getPool().popVec2();
temp.set(m_sweep.c).subLocal(oldCenter);
Vec2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(2);
}
示例8: resetMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* This resets the mass properties to the sum of the mass properties of the fixtures.
* This normally does not need to be called unless you called setMassData to override
* the mass and you later want to reset the mass.
*/
public final void resetMassData() {
// Compute mass data from shapes. Each shape has its own density.
m_mass = 0.0f;
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_sweep.localCenter.setZero();
// Static and kinematic bodies have zero mass.
if (m_type == BodyType.STATIC || m_type == BodyType.KINEMATIC) {
// m_sweep.c0 = m_sweep.c = m_xf.position;
m_sweep.c.set(m_xf.position);
m_sweep.c0.set(m_xf.position);
return;
}
assert (m_type == BodyType.DYNAMIC);
// Accumulate mass over all fixtures.
final Vec2 center = m_world.getPool().popVec2();
center.setZero();
final Vec2 temp = m_world.getPool().popVec2();
final MassData massData = pmd;
for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
if (f.m_density == 0.0f) {
continue;
}
f.getMassData(massData);
m_mass += massData.mass;
// center += massData.mass * massData.center;
temp.set(massData.center).mulLocal(massData.mass);
center.addLocal(temp);
m_I += massData.I;
}
// Compute center of mass.
if (m_mass > 0.0f) {
m_invMass = 1.0f / m_mass;
center.mulLocal(m_invMass);
}
else {
// Force all dynamic bodies to have a positive mass.
m_mass = 1.0f;
m_invMass = 1.0f;
}
if (m_I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
// Center the inertia about the center of mass.
m_I -= m_mass * Vec2.dot(center, center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
else {
m_I = 0.0f;
m_invI = 0.0f;
}
Vec2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOut(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
temp.set(m_sweep.c).subLocal(oldCenter);
Vec2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(3);
}
示例9: checkBounds
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
private void checkBounds() {
for (int i=0; i<liquid.length; ++i) {
if (liquid[i].getWorldCenter().y < -10.0f) {
m_world.destroyBody(liquid[i]);
float massPerParticle = totalMass / nParticles;
CircleShape pd = new CircleShape();
FixtureDef fd = new FixtureDef();
fd.shape = pd;
fd.density = 1.0f;
fd.filter.groupIndex = -10;
pd.m_radius = .05f;
fd.restitution = 0.4f;
fd.friction = 0.0f;
float cx = 0.0f + MathUtils.randomFloat(-0.6f,0.6f);
float cy = 15.0f + MathUtils.randomFloat(-2.3f,2.0f);
BodyDef bd = new BodyDef();
bd.position = new Vec2( cx, cy );
bd.fixedRotation = true;
bd.type = BodyType.DYNAMIC;
Body b = m_world.createBody(bd);
b.createFixture(fd).setUserData(LIQUID_INT);
MassData md = new MassData();
md.mass = massPerParticle;
md.I = 1.0f;
b.setMassData(md);
b.setSleepingAllowed(false);
liquid[i] = b;
}
}
if (bod.getWorldCenter().y < -15.0f) {
m_world.destroyBody(bod);
PolygonShape polyDef = new PolygonShape();
polyDef.setAsBox(MathUtils.randomFloat(0.3f,0.7f), MathUtils.randomFloat(0.3f,0.7f));
BodyDef bodyDef = new BodyDef();
bodyDef.position = new Vec2(0.0f,25.0f);
bodyDef.type = BodyType.DYNAMIC;
bod = m_world.createBody(bodyDef);
bod.createFixture(polyDef, 1f);
}
}
示例10: setMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Set the mass properties to override the mass properties of the fixtures. Note that this changes
* the center of mass position. Note that creating or destroying fixtures can also alter the mass.
* This function has no effect if the body isn't dynamic.
*
* @param massData the mass properties.
*/
public final void setMassData(MassData massData) {
// TODO_ERIN adjust linear velocity and torque to account for movement of center.
assert (m_world.isLocked() == false);
if (m_world.isLocked() == true) {
return;
}
if (m_type != BodyType.DYNAMIC) {
return;
}
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_mass = massData.mass;
if (m_mass <= 0.0f) {
m_mass = 1f;
}
m_invMass = 1.0f / m_mass;
if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
m_I = massData.I - m_mass * Vector2.dot(massData.center, massData.center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
final Vector2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(massData.center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
final Vector2 temp = m_world.getPool().popVec2();
temp.set(m_sweep.c).subLocal(oldCenter);
Vector2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(2);
}
示例11: initialValue
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
protected MassData initialValue(){
return new MassData();
}
示例12: checkBounds
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
private void checkBounds() {
for (int i = 0; i < liquid.length; ++i) {
if (liquid[i].getWorldCenter().y < -10.0f) {
getWorld().destroyBody(liquid[i]);
float massPerParticle = totalMass / nParticles;
CircleShape pd = new CircleShape();
FixtureDef fd = new FixtureDef();
fd.shape = pd;
fd.density = 1.0f;
fd.filter.groupIndex = -10;
pd.m_radius = .05f;
fd.restitution = 0.4f;
fd.friction = 0.0f;
float cx = 0.0f + MathUtils.randomFloat(-0.6f, 0.6f);
float cy = 15.0f + MathUtils.randomFloat(-2.3f, 2.0f);
BodyDef bd = new BodyDef();
bd.position = new Vec2(cx, cy);
bd.fixedRotation = true;
bd.type = BodyType.DYNAMIC;
Body b = getWorld().createBody(bd);
b.createFixture(fd).setUserData(LIQUID_INT);
MassData md = new MassData();
md.mass = massPerParticle;
md.I = 1.0f;
b.setMassData(md);
b.setSleepingAllowed(false);
liquid[i] = b;
}
}
if (bod.getWorldCenter().y < -15.0f) {
getWorld().destroyBody(bod);
PolygonShape polyDef = new PolygonShape();
polyDef.setAsBox(MathUtils.randomFloat(0.3f, 0.7f), MathUtils.randomFloat(0.3f, 0.7f));
BodyDef bodyDef = new BodyDef();
bodyDef.position = new Vec2(0.0f, 25.0f);
bodyDef.type = BodyType.DYNAMIC;
bod = getWorld().createBody(bodyDef);
bod.createFixture(polyDef, 1f);
}
}
示例13: computeMass
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
@Override
public void computeMass(MassData massData, float density) {
massData.I = 0f;
massData.center.setZero();
massData.mass = (float) mass;
}
示例14: createBodyFixture
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
private void createBodyFixture(Node node, Body body) {
Shape s = NodeShapeBuilder.createShape(node);
MassData m = new MassData();
s.computeMass(m, 1);
body.createFixture(s, (float) layout.getMass(node) / m.mass);
}
示例15: setMassData
import org.jbox2d.collision.shapes.MassData; //导入依赖的package包/类
/**
* Set the mass properties to override the mass properties of the fixtures.
* Note that this changes the center of mass position. Note that creating or
* destroying fixtures can also alter the mass. This function has no effect
* if the body isn't dynamic.
*
* @param massData
* the mass properties.
*/
public final void setMassData(MassData massData) {
// TODO_ERIN adjust linear velocity and torque to account for movement
// of center.
assert (m_world.isLocked() == false);
if (m_world.isLocked() == true) {
return;
}
if (m_type != BodyType.DYNAMIC) {
return;
}
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_mass = massData.mass;
if (m_mass <= 0.0f) {
m_mass = 1f;
}
m_invMass = 1.0f / m_mass;
if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
m_I = massData.I - m_mass
* Vec2.dot(massData.center, massData.center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
final Vec2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(massData.center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOut(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
final Vec2 temp = m_world.getPool().popVec2();
temp.set(m_sweep.c).subLocal(oldCenter);
Vec2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(2);
}