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


Java ContactListener类代码示例

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


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

示例1: init

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void init(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener){
	m_bodyCapacity = bodyCapacity;
	m_contactCapacity = contactCapacity;
	m_jointCapacity = jointCapacity;
	m_bodyCount = 0;
	m_contactCount = 0;
	m_jointCount = 0;
	
	m_listener = listener;
	
	if(m_bodies == null || m_bodyCapacity > m_bodies.length){
		m_bodies = new Body[m_bodyCapacity];
	}
	if(m_joints == null || m_jointCapacity > m_joints.length){
		m_joints = new Joint[m_jointCapacity];			
	}
	if(m_contacts == null || m_contactCapacity > m_contacts.length){
		m_contacts = new Contact[m_contactCapacity];
	}
	
	// could do some copy stuff, but just a full creation for now
	// TODO djm do a copy
	if(m_velocities == null || m_bodyCapacity > m_velocities.length){
		m_velocities = new Velocity[m_bodyCapacity];
		for(int i=0; i<m_velocities.length; i++){
			m_velocities[i] = new Velocity();
		}
	}
	
	// could do some copy stuff, but just a full creation for now
	// TODO djm do a copy
	if(m_positions == null || m_bodyCapacity > m_positions.length){
		m_positions = new Position[m_bodyCapacity];
		for(int i=0; i<m_positions.length; i++){
			m_positions[i] = new Position();
		}
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:39,代码来源:Island.java

示例2: init

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void init(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener){
	m_bodyCapacity = bodyCapacity;
	m_contactCapacity = contactCapacity;
	m_jointCapacity = jointCapacity;
	m_bodyCount = 0;
	m_contactCount = 0;
	m_jointCount = 0;
	
	m_listener = listener;
	
	if(m_bodies == null || m_bodyCapacity >= m_bodies.length){
		m_bodies = new Body[m_bodyCapacity];
	}
	if(m_joints == null || m_jointCapacity > m_joints.length){
		m_joints = new Joint[m_jointCapacity];			
	}
	if(m_contacts == null || m_contactCapacity > m_contacts.length){
		m_contacts = new Contact[m_contactCapacity];
	}
	
	// could do some copy stuff, but just a full creation for now
	// TODO djm do a copy
	if(m_velocities == null || m_bodyCapacity > m_velocities.length){
		m_velocities = new Velocity[m_bodyCapacity];
		for(int i=0; i<m_velocities.length; i++){
			m_velocities[i] = new Velocity();
		}
	}
	
	// could do some copy stuff, but just a full creation for now
	// TODO djm do a copy
	if(m_positions == null || m_bodyCapacity > m_positions.length){
		m_positions = new Position[m_bodyCapacity];
		for(int i=0; i<m_positions.length; i++){
			m_positions[i] = new Position();
		}
	}
}
 
开发者ID:fredsa,项目名称:forplay,代码行数:39,代码来源:Island.java

示例3: setTracker

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void setTracker(ContactListener listener){
	world.setContactListener(listener);
}
 
开发者ID:tek256,项目名称:LD38,代码行数:4,代码来源:Physics.java

示例4: update

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void update(ContactListener listener) {

    oldManifold.set(m_manifold);

    // Re-enable this contact.
    m_flags |= ENABLED_FLAG;

    boolean touching = false;
    boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

    boolean sensorA = m_fixtureA.isSensor();
    boolean sensorB = m_fixtureB.isSensor();
    boolean sensor = sensorA || sensorB;

    Body bodyA = m_fixtureA.getBody();
    Body bodyB = m_fixtureB.getBody();
    Transform xfA = bodyA.getTransform();
    Transform xfB = bodyB.getTransform();
    // log.debug("TransformA: "+xfA);
    // log.debug("TransformB: "+xfB);

    if (sensor) {
      Shape shapeA = m_fixtureA.getShape();
      Shape shapeB = m_fixtureB.getShape();
      touching = pool.getCollision().testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);

      // Sensors don't generate manifolds.
      m_manifold.pointCount = 0;
    } else {
      evaluate(m_manifold, xfA, xfB);
      touching = m_manifold.pointCount > 0;

      // Match old contact ids to new contact ids and copy the
      // stored impulses to warm start the solver.
      for (int i = 0; i < m_manifold.pointCount; ++i) {
        ManifoldPoint mp2 = m_manifold.points[i];
        mp2.normalImpulse = 0.0f;
        mp2.tangentImpulse = 0.0f;
        ContactID id2 = mp2.id;

        for (int j = 0; j < oldManifold.pointCount; ++j) {
          ManifoldPoint mp1 = oldManifold.points[j];

          if (mp1.id.isEqual(id2)) {
            mp2.normalImpulse = mp1.normalImpulse;
            mp2.tangentImpulse = mp1.tangentImpulse;
            break;
          }
        }
      }

      if (touching != wasTouching) {
        bodyA.setAwake(true);
        bodyB.setAwake(true);
      }
    }

    if (touching) {
      m_flags |= TOUCHING_FLAG;
    } else {
      m_flags &= ~TOUCHING_FLAG;
    }

    if (listener == null) {
      return;
    }

    if (wasTouching == false && touching == true) {
      listener.beginContact(this);
    }

    if (wasTouching == true && touching == false) {
      listener.endContact(this);
    }

    if (sensor == false && touching) {
      listener.preSolve(this, oldManifold);
    }
  }
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:80,代码来源:Contact.java

示例5: update

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void update(ContactListener listener) {

		Manifold oldManifold = tloldManifold.get();
		oldManifold.set(m_manifold);

		// Re-enable this contact.
		m_flags |= ENABLED_FLAG;

		boolean touching = false;
		boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

		boolean sensorA = m_fixtureA.isSensor();
		boolean sensorB = m_fixtureB.isSensor();
		boolean sensor = sensorA || sensorB;

		Body bodyA = m_fixtureA.getBody();
		Body bodyB = m_fixtureB.getBody();
		Transform xfA = bodyA.getTransform();
		Transform xfB = bodyB.getTransform();
		//log.debug("TransformA: "+xfA);
		//log.debug("TransformB: "+xfB);
		
		if (sensor) {
			Shape shapeA = m_fixtureA.getShape();
			Shape shapeB = m_fixtureB.getShape();
			touching = pool.getCollision().testOverlap(shapeA, shapeB,
					xfA, xfB);

			// Sensors don't generate manifolds.
			m_manifold.pointCount = 0;
		} else {
			evaluate(m_manifold, xfA, xfB);
			touching = m_manifold.pointCount > 0;

			// Match old contact ids to new contact ids and copy the
			// stored impulses to warm start the solver.
			for (int i = 0; i < m_manifold.pointCount; ++i) {
				ManifoldPoint mp2 = m_manifold.points[i];
				mp2.normalImpulse = 0.0f;
				mp2.tangentImpulse = 0.0f;
				ContactID id2 = mp2.id;

				for (int j = 0; j < oldManifold.pointCount; ++j) {
					ManifoldPoint mp1 = oldManifold.points[j];

					if (mp1.id.isEqual(id2)) {
						mp2.normalImpulse = mp1.normalImpulse;
						mp2.tangentImpulse = mp1.tangentImpulse;
						break;
					}
				}
			}

			if (touching != wasTouching) {
				bodyA.setAwake(true);
				bodyB.setAwake(true);
			}
		}

		if (touching) {
			m_flags |= TOUCHING_FLAG;
		} else {
			m_flags &= ~TOUCHING_FLAG;
		}

		if (listener == null) {
			return;
		}

		if (wasTouching == false && touching == true) {
			listener.beginContact(this);
		}

		if (wasTouching == true && touching == false) {
			listener.endContact(this);
		}

		if (sensor == false && touching) {
			listener.preSolve(this, oldManifold);
		}
	}
 
开发者ID:mleoking,项目名称:PhET,代码行数:82,代码来源:Contact.java

示例6: update

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
public void update(ContactListener listener) {
	
	oldManifold.set(m_manifold);

	// Re-enable this contact.
	m_flags |= ENABLED_FLAG;

	boolean touching = false;
	boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

	boolean sensorA = m_fixtureA.isSensor();
	boolean sensorB = m_fixtureB.isSensor();
	boolean sensor = sensorA || sensorB;

	Body bodyA = m_fixtureA.getBody();
	Body bodyB = m_fixtureB.getBody();
	Transform xfA = bodyA.getTransform();
	Transform xfB = bodyB.getTransform();
	//log.debug("TransformA: "+xfA);
	//log.debug("TransformB: "+xfB);
	
	if (sensor) {
		Shape shapeA = m_fixtureA.getShape();
		Shape shapeB = m_fixtureB.getShape();
		touching = pool.getCollision().testOverlap(shapeA, shapeB,
				xfA, xfB);

		// Sensors don't generate manifolds.
		m_manifold.pointCount = 0;
	} else {
		evaluate(m_manifold, xfA, xfB);
		touching = m_manifold.pointCount > 0;

		// Match old contact ids to new contact ids and copy the
		// stored impulses to warm start the solver.
		for (int i = 0; i < m_manifold.pointCount; ++i) {
			ManifoldPoint mp2 = m_manifold.points[i];
			mp2.normalImpulse = 0.0f;
			mp2.tangentImpulse = 0.0f;
			ContactID id2 = mp2.id;

			for (int j = 0; j < oldManifold.pointCount; ++j) {
				ManifoldPoint mp1 = oldManifold.points[j];

				if (mp1.id.isEqual(id2)) {
					mp2.normalImpulse = mp1.normalImpulse;
					mp2.tangentImpulse = mp1.tangentImpulse;
					break;
				}
			}
		}

		if (touching != wasTouching) {
			bodyA.setAwake(true);
			bodyB.setAwake(true);
		}
	}

	if (touching) {
		m_flags |= TOUCHING_FLAG;
	} else {
		m_flags &= ~TOUCHING_FLAG;
	}

	if (listener == null) {
		return;
	}

	if (wasTouching == false && touching == true) {
		listener.beginContact(this);
	}

	if (wasTouching == true && touching == false) {
		listener.endContact(this);
	}

	if (sensor == false && touching) {
		listener.preSolve(this, oldManifold);
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:81,代码来源:Contact.java

示例7: setContactListener

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
/**
 * Register a contact event listener. The listener is owned by you and must remain in scope.
 * 
 * @param listener
 */
public void setContactListener(ContactListener listener) {
  m_contactManager.m_contactListener = listener;
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:9,代码来源:World.java

示例8: setContactListener

import org.jbox2d.callbacks.ContactListener; //导入依赖的package包/类
/**
 * Register a contact event listener. The listener is owned by you and must
 * remain in scope.
 * 
 * @param listener
 */
public void setContactListener(ContactListener listener) {
	m_contactManager.m_contactListener = listener;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:10,代码来源:World.java


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