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


Java Contact类代码示例

本文整理汇总了Java中org.jbox2d.dynamics.contacts.Contact的典型用法代码示例。如果您正苦于以下问题:Java Contact类的具体用法?Java Contact怎么用?Java Contact使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: beginContact

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void beginContact(Contact contact) {
	Fixture a = contact.m_fixtureA;
	Fixture b = contact.m_fixtureB;
	
	Collider ca = null;
	Collider cb = null;
	
	for(Collider c : p.colliders){
		if(c.body == a.getBody())
			ca = c;
		if(c.body == b.getBody())
			cb = c;
	}
	
	if(ca != null)
		if(ca.getCallback() != null)
			ca.getCallback().onCollisionEnter(cb);
	
	if(cb != null)
		if(cb.getCallback() != null)
			cb.getCallback().onCollisionEnter(ca);
}
 
开发者ID:tek256,项目名称:LD38,代码行数:24,代码来源:Physics.java

示例2: endContact

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void endContact(Contact contact) {
	Fixture a = contact.m_fixtureA;
	Fixture b = contact.m_fixtureB;
	
	Collider ca = null;
	Collider cb = null;
	
	for(Collider c : p.colliders){
		if(c.body == a.getBody())
			ca = c;
		if(c.body == b.getBody())
			cb = c;
	}
	
	if(ca != null)
		if(ca.getCallback() != null)
			ca.getCallback().onCollisionExit(cb);
	
	if(cb != null)
		if(cb.getCallback() != null)
			cb.getCallback().onCollisionExit(ca);
}
 
开发者ID:tek256,项目名称:LD38,代码行数:24,代码来源:Physics.java

示例3: report

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void report(ContactVelocityConstraint[] constraints) {
  if (m_listener == null) {
    return;
  }

  for (int i = 0; i < m_contactCount; ++i) {
    Contact c = m_contacts[i];

    ContactVelocityConstraint vc = constraints[i];
    impulse.count = vc.pointCount;
    for (int j = 0; j < vc.pointCount; ++j) {
      impulse.normalImpulses[j] = vc.points[j].normalImpulse;
      impulse.tangentImpulses[j] = vc.points[j].tangentImpulse;
    }

    m_listener.postSolve(c, impulse);
  }
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:19,代码来源:Island.java

示例4: updateSensor

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void updateSensor(){
  
  Body bsensor = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 sensor_pos = bsensor.getWorldPoint(circle.m_p);

  // iterate through all contacts and apply a force on shapes that overlap the sensor.
  for(Contact contact = world.getContactList(); contact != null; contact = contact.m_next){

    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    
    Body body = null;
         if(fixtureA == m_sensor) body = fixtureB.getBody();
    else if(fixtureB == m_sensor) body = fixtureA.getBody();
    else continue;

    Vec2 body_pos = body.getPosition();
    Vec2 dist = sensor_pos.sub(body_pos);
    if (dist.lengthSquared() > Settings.EPSILON * Settings.EPSILON) {
      dist.normalize();
      Vec2 force = dist.mulLocal(200f);
      body.applyForce(force, body_pos);
    }
  }
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:27,代码来源:box2d_Collisions_SensorTest.java

示例5: postSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
  if (m_broke) {
    // The body already broke.
    return;
  }

  // Should the body break?
  int count = contact.getManifold().pointCount;

  float maxImpulse = 0.0f;
  for (int i = 0; i < count; ++i) {
    maxImpulse = MathUtils.max(maxImpulse, impulse.normalImpulses[i]);
  }
  
  if (maxImpulse > 30.0f) {
    // Flag the body for breaking.
    m_break = true;
  }
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:21,代码来源:box2d_Breakable.java

示例6: report

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void report(ContactConstraint[] constraints){
	if (m_listener == null){
		return;
	}

	for (int i = 0; i < m_contactCount; ++i){
		Contact c = m_contacts[i];

		ContactConstraint cc = constraints[i];
		
		for (int j = 0; j < cc.pointCount; ++j){
			impulse.normalImpulses[j] = cc.points[j].normalImpulse;
			impulse.tangentImpulses[j] = cc.points[j].tangentImpulse;
		}

		m_listener.postSolve(c, impulse);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:Island.java

示例7: setFilterData

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
/**
 * Set the contact filtering data. This is an expensive operation and should
 * not be called frequently. This will not update contacts until the next time
 * step when either parent body is awake.
 * @param filter
 */
public void setFilterData(final Filter filter){
	m_filter.set(filter);
	
	if(m_body == null){
		return;
	}
	
	// Flag associated contacts for filtering.
	ContactEdge edge = m_body.getContactList();
	while (edge != null){
		Contact contact = edge.contact;
		Fixture fixtureA = contact.getFixtureA();
		Fixture fixtureB = contact.getFixtureB();
		if (fixtureA == this || fixtureB == this){
			contact.flagForFiltering();
		}
		edge = edge.next;
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:Fixture.java

示例8: postSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
/**
 * @see org.jbox2d.testbed.framework.TestbedTest#postSolve(org.jbox2d.dynamics.contacts.Contact,
 *      org.jbox2d.callbacks.ContactImpulse)
 */
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	if (m_broke) {
		// The body already broke.
		return;
	}
	
	// Should the body break?
	int count = contact.getManifold().pointCount;
	
	float maxImpulse = 0.0f;
	for (int i = 0; i < count; ++i) {
		maxImpulse = MathUtils.max(maxImpulse, impulse.normalImpulses[i]);
	}
	
	if (maxImpulse > 40.0f) {
		// Flag the body for breaking.
		m_break = true;
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:Breakable.java

示例9: preSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
	super.preSolve(contact, oldManifold);
	
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();

	if (fixtureA != m_platform && fixtureA != m_character){
		return;
	}

	if (fixtureB != m_character && fixtureB != m_character){
		return;
	}

	Vec2 position = m_character.getBody().getPosition();

	if (position.y < m_top + m_radius - 3.0f * Settings.linearSlop){
		contact.setEnabled(false);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:OneSidedTest.java

示例10: preSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
/**
 * @see org.jbox2d.callbacks.ContactListener#preSolve(org.jbox2d.dynamics.contacts.Contact, org.jbox2d.collision.Manifold)
 */
public void preSolve(Contact contact, Manifold oldManifold) {
	Manifold manifold = contact.getManifold();
	
	if(manifold.pointCount == 0){
		return;
	}
	
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();
	
	Collision.getPointStates(state1, state2, oldManifold, manifold);
	
	contact.getWorldManifold(worldManifold);
	
	for(int i=0; i<manifold.pointCount && m_pointCount < MAX_CONTACT_POINTS; i++){
		ContactPoint cp = points[m_pointCount];
		cp.fixtureA = fixtureA;
		cp.fixtureB = fixtureB;
		cp.position.set(worldManifold.points[i]);
		cp.normal.set(worldManifold.normal);
		cp.state = state2[i];
		++m_pointCount;
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:28,代码来源:TestbedTest.java

示例11: processContacts

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void processContacts () {
  while (!contacts.isEmpty()) {
    Contact contact = contacts.pop();

    // handle collision
    PhysicsEntity entityA = bodyEntityLUT.get(contact.m_fixtureA.m_body);
    PhysicsEntity entityB = bodyEntityLUT.get(contact.m_fixtureB.m_body);

    if (entityA != null && entityB != null) {
      if (entityA instanceof PhysicsEntity.HasContactListener) {
        ((PhysicsEntity.HasContactListener) entityA).contact(entityB);
      }
      if (entityB instanceof PhysicsEntity.HasContactListener) {
        ((PhysicsEntity.HasContactListener) entityB).contact(entityA);
      }
    }
  }
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:19,代码来源:PeaWorld.java

示例12: preSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void preSolve(Contact contact, Manifold oldManifold) {
  Manifold manifold = contact.getManifold();

  if (manifold.pointCount == 0) {
    return;
  }

  Fixture fixtureA = contact.getFixtureA();
  Fixture fixtureB = contact.getFixtureB();

  Collision.getPointStates(state1, state2, oldManifold, manifold);

  contact.getWorldManifold(worldManifold);

  for (int i = 0; i < manifold.pointCount && pointCount < MAX_CONTACT_POINTS; i++) {
    ContactPoint cp = points[pointCount];
    cp.fixtureA = fixtureA;
    cp.fixtureB = fixtureB;
    cp.position.set(worldManifold.points[i]);
    cp.normal.set(worldManifold.normal);
    cp.state = state2[i];
    cp.normalImpulse = manifold.points[i].normalImpulse;
    cp.tangentImpulse = manifold.points[i].tangentImpulse;
    ++pointCount;
  }
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:27,代码来源:TestbedTest.java

示例13: processContacts

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
public void processContacts() {
  while (!contacts.isEmpty()) {
    Contact contact = contacts.pop();
    
    // handle collision
    PhysicsEntity entityA = bodyEntityLUT.get(contact.m_fixtureA.m_body);
    PhysicsEntity entityB = bodyEntityLUT.get(contact.m_fixtureB.m_body);
    
    if (entityA != null && entityB != null) {
      if (entityA instanceof PhysicsEntity.HasContactListener) {
        ((PhysicsEntity.HasContactListener) entityA).contact(entityB);
      }
      if (entityB instanceof PhysicsEntity.HasContactListener) {
        ((PhysicsEntity.HasContactListener) entityB).contact(entityA);
      }
    }
  }
}
 
开发者ID:fredsa,项目名称:forplay,代码行数:19,代码来源:PeaWorld.java

示例14: postSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
  if (m_broke) {
    // The body already broke.
    return;
  }

  // Should the body break?
  int count = contact.getManifold().pointCount;

  float maxImpulse = 0.0f;
  for (int i = 0; i < count; ++i) {
    maxImpulse = MathUtils.max(maxImpulse, impulse.normalImpulses[i]);
  }

  if (maxImpulse > 40.0f) {
    // Flag the body for breaking.
    m_break = true;
  }
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:21,代码来源:Breakable.java

示例15: preSolve

import org.jbox2d.dynamics.contacts.Contact; //导入依赖的package包/类
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
  super.preSolve(contact, oldManifold);

  Fixture fixtureA = contact.getFixtureA();
  Fixture fixtureB = contact.getFixtureB();

  if (fixtureA != m_platform && fixtureA != m_character) {
    return;
  }

  if (fixtureB != m_character && fixtureB != m_character) {
    return;
  }

  Vec2 position = m_character.getBody().getPosition();

  if (position.y < m_top + m_radius - 3.0f * Settings.linearSlop) {
    contact.setEnabled(false);
  }
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:22,代码来源:OneSidedTest.java


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