当前位置: 首页>>代码示例>>Java>>正文


Java Mat22.invertToOut方法代码示例

本文整理汇总了Java中org.jbox2d.common.Mat22.invertToOut方法的典型用法代码示例。如果您正苦于以下问题:Java Mat22.invertToOut方法的具体用法?Java Mat22.invertToOut怎么用?Java Mat22.invertToOut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jbox2d.common.Mat22的用法示例。


在下文中一共展示了Mat22.invertToOut方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initVelocityConstraints

import org.jbox2d.common.Mat22; //导入方法依赖的package包/类
@Override
  public void initVelocityConstraints(final SolverData data) {
    m_indexB = m_bodyB.m_islandIndex;
    m_localCenterB.set(m_bodyB.m_sweep.localCenter);
    m_invMassB = m_bodyB.m_invMass;
    m_invIB = m_bodyB.m_invI;

    Vec2 cB = data.positions[m_indexB].c;
    float aB = data.positions[m_indexB].a;
    Vec2 vB = data.velocities[m_indexB].v;
    float wB = data.velocities[m_indexB].w;

    final Rot qB = pool.popRot();

    qB.set(aB);

    float mass = m_bodyB.getMass();

    // Frequency
    float omega = 2.0f * MathUtils.PI * m_frequencyHz;

    // Damping coefficient
    float d = 2.0f * mass * m_dampingRatio * omega;

    // Spring stiffness
    float k = mass * (omega * omega);

    // magic formulas
    // gamma has units of inverse mass.
    // beta has units of inverse time.
    float h = data.step.dt;
    assert (d + h * k > Settings.EPSILON);
    m_gamma = h * (d + h * k);
    if (m_gamma != 0.0f) {
      m_gamma = 1.0f / m_gamma;
    }
    m_beta = h * k * m_gamma;

    Vec2 temp = pool.popVec2();

    // Compute the effective mass matrix.
    Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB);

    // K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
    // = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
    // [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
    final Mat22 K = pool.popMat22();
    K.ex.x = m_invMassB + m_invIB * m_rB.y * m_rB.y + m_gamma;
    K.ex.y = -m_invIB * m_rB.x * m_rB.y;
    K.ey.x = K.ex.y;
    K.ey.y = m_invMassB + m_invIB * m_rB.x * m_rB.x + m_gamma;

    K.invertToOut(m_mass);

    m_C.set(cB).addLocal(m_rB).subLocal(m_targetA);
    m_C.mulLocal(m_beta);

    // Cheat with some damping
    wB *= 0.98f;

    if (data.step.warmStarting) {
      m_impulse.mulLocal(data.step.dtRatio);
      vB.x += m_invMassB * m_impulse.x;
      vB.y += m_invMassB * m_impulse.y;
      wB += m_invIB * Vec2.cross(m_rB, m_impulse);
    } else {
      m_impulse.setZero();
    }

//    data.velocities[m_indexB].v.set(vB);
    data.velocities[m_indexB].w = wB;

    pool.pushVec2(1);
    pool.pushMat22(1);
    pool.pushRot(1);
  }
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:77,代码来源:MouseJoint.java

示例2: initVelocityConstraints

import org.jbox2d.common.Mat22; //导入方法依赖的package包/类
@Override
public void initVelocityConstraints(TimeStep step) {
	Body b = m_bodyB;

	float mass = b.getMass();

	// Frequency
	float omega = 2.0f * MathUtils.PI * m_frequencyHz;

	// Damping coefficient
	float d = 2.0f * mass * m_dampingRatio * omega;

	// Spring stiffness
	float k = mass * (omega * omega);

	// magic formulas
	// gamma has units of inverse mass.
	// beta has units of inverse time.
	assert(d + step.dt * k > Settings.EPSILON);
	m_gamma = step.dt * (d + step.dt * k);
	if (m_gamma != 0.0f){
		m_gamma = 1.0f / m_gamma;
	}
	m_beta = step.dt * k * m_gamma;

	Vec2 r = pool.popVec2();
	
	// Compute the effective mass matrix.
	//Vec2 r = Mul(b.getTransform().R, m_localAnchor - b.getLocalCenter());
	r.set(m_localAnchor).subLocal(b.getLocalCenter());
	Mat22.mulToOut(b.getTransform().R, r, r);
	
	// K    = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
	//      = [1/m1+1/m2     0    ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
	//        [    0     1/m1+1/m2]           [-r1.x*r1.y r1.x*r1.x]           [-r1.x*r1.y r1.x*r1.x]
	float invMass = b.m_invMass;
	float invI = b.m_invI;

	Mat22 K1 = pool.popMat22();
	K1.col1.x = invMass;	K1.col2.x = 0.0f;
	K1.col1.y = 0.0f;		K1.col2.y = invMass;

	Mat22 K2 = pool.popMat22();
	K2.col1.x =  invI * r.y * r.y;	K2.col2.x = -invI * r.x * r.y;
	K2.col1.y = -invI * r.x * r.y;	K2.col2.y =  invI * r.x * r.x;

	Mat22 K = pool.popMat22();
	K.set(K1).addLocal(K2);
	K.col1.x += m_gamma;
	K.col2.y += m_gamma;

	K.invertToOut(m_mass);

	m_C.set(b.m_sweep.c).addLocal(r).subLocal(m_target);

	// Cheat with some damping
	b.m_angularVelocity *= 0.98f;

	// Warm starting.
	m_impulse.mulLocal(step.dtRatio);
	// pool
	Vec2 temp = pool.popVec2();
	temp.set(m_impulse).mulLocal(invMass);
	b.m_linearVelocity.addLocal(temp);
	b.m_angularVelocity += invI * Vec2.cross(r, m_impulse);
	
	pool.pushVec2(2);
	pool.pushMat22(3);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:70,代码来源:MouseJoint.java

示例3: initVelocityConstraints

import org.jbox2d.common.Mat22; //导入方法依赖的package包/类
@Override
public void initVelocityConstraints(TimeStep step) {
	Body b = m_bodyB;

	float mass = b.getMass();

	// Frequency
	float omega = 2.0f * MathUtils.PI * m_frequencyHz;

	// Damping coefficient
	float d = 2.0f * mass * m_dampingRatio * omega;

	// Spring stiffness
	float k = mass * (omega * omega);

	// magic formulas
	// gamma has units of inverse mass.
	// beta has units of inverse time.
	assert(d + step.dt * k > Settings.EPSILON);
	m_gamma = step.dt * (d + step.dt * k);
	if (m_gamma != 0.0f){
		m_gamma = 1.0f / m_gamma;
	}
	m_beta = step.dt * k * m_gamma;

	Vec2 r = pool.popVec2();
	
	// Compute the effective mass matrix.
	//Vec2 r = Mul(b.getTransform().R, m_localAnchor - b.getLocalCenter());
	r.set(m_localAnchor).subLocal(b.getLocalCenter());
	Mat22.mulToOut(b.getTransform().R, r, r);
	
	// K    = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
	//      = [1/m1+1/m2     0    ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
	//        [    0     1/m1+1/m2]           [-r1.x*r1.y r1.x*r1.x]           [-r1.x*r1.y r1.x*r1.x]
	float invMass = b.m_invMass;
	float invI = b.m_invI;

	Mat22 K1 = pool.popMat22();
   K1.m11 = invMass; K1.m21 = 0.0f;
   K1.m12 = 0.0f;    K1.m22 = invMass;

   Mat22 K2 = pool.popMat22();
   K2.m11 =  invI * r.y * r.y; K2.m21 = -invI * r.x * r.y;
   K2.m12 = -invI * r.x * r.y; K2.m22 =  invI * r.x * r.x;

   Mat22 K = pool.popMat22();
   K.set(K1).addLocal(K2);
   K.m11 += m_gamma;
   K.m22 += m_gamma;

	K.invertToOut(m_mass);

	m_C.set(b.m_sweep.c).addLocal(r).subLocal(m_target);

	// Cheat with some damping
	b.m_angularVelocity *= 0.98f;

	// Warm starting.
	m_impulse.mulLocal(step.dtRatio);
	// pool
	Vec2 temp = pool.popVec2();
	temp.set(m_impulse).mulLocal(invMass);
	b.m_linearVelocity.addLocal(temp);
	b.m_angularVelocity += invI * Vec2.cross(r, m_impulse);
	
	pool.pushVec2(2);
	pool.pushMat22(3);
}
 
开发者ID:fredsa,项目名称:forplay,代码行数:70,代码来源:MouseJoint.java


注:本文中的org.jbox2d.common.Mat22.invertToOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。