• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RayCastInput类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
  assert (childIndex < m_count);

  final EdgeShape edgeShape = pool0;

  int i1 = childIndex;
  int i2 = childIndex + 1;
  if (i2 == m_count) {
    i2 = 0;
  }
  Vec2 v = m_vertices[i1];
  edgeShape.m_vertex1.x = v.x;
  edgeShape.m_vertex1.y = v.y;
  Vec2 v1 = m_vertices[i2];
  edgeShape.m_vertex2.x = v1.x;
  edgeShape.m_vertex2.y = v1.y;

  return edgeShape.raycast(output, input, xf, 0);
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:21,代码来源:ChainShape.java


示例2: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(RayCastInput input, int nodeId) {
  Object userData = broadPhase.getUserData(nodeId);
  FixtureProxy proxy = (FixtureProxy) userData;
  Fixture fixture = proxy.fixture;
  int index = proxy.childIndex;
  boolean hit = fixture.raycast(output, input, index);

  if (hit) {
    float fraction = output.fraction;
    // Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
    temp.set(input.p2).mulLocal(fraction);
    point.set(input.p1).mulLocal(1 - fraction).addLocal(temp);
    return callback.reportFixture(fixture, point, output.normal, fraction);
  }

  return input.maxFraction;
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:18,代码来源:World.java


示例3: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(final RayCastInput input,
		DynamicTreeNode proxyId) {
	Actor actor = (Actor) proxyId.userData;

	RayCastOutput output = new RayCastOutput();
	boolean hit = actor.aabb.raycast(output, input, m_world.getPool());

	if (hit) {
		m_rayCastOutput = output;
		m_rayActor = actor;
		m_rayActor.fraction = output.fraction;
		return output.fraction;
	}

	return input.maxFraction;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:DynamicTreeTest.java


示例4: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
  assert (childIndex < m_count);

  final EdgeShape edgeShape = pool0;

  int i1 = childIndex;
  int i2 = childIndex + 1;
  if (i2 == m_count) {
    i2 = 0;
  }
  Vector2 v = m_vertices[i1];
  edgeShape.m_vertex1.x = v.x;
  edgeShape.m_vertex1.y = v.y;
  Vector2 v1 = m_vertices[i2];
  edgeShape.m_vertex2.x = v1.x;
  edgeShape.m_vertex2.y = v1.y;

  return edgeShape.raycast(output, input, xf, 0);
}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:21,代码来源:ChainShape.java


示例5: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(RayCastInput input, int nodeId) {
  Object userData = broadPhase.getUserData(nodeId);
  FixtureProxy proxy = (FixtureProxy) userData;
  Fixture fixture = proxy.fixture;
  int index = proxy.childIndex;
  boolean hit = fixture.raycast(output, input, index);

  if (hit) {
    float fraction = output.fraction;
    // Vector2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
    temp.set(input.p2).mulLocal(fraction);
    point.set(input.p1).mulLocal(1 - fraction).addLocal(temp);
    return callback.reportFixture(fixture, point, output.normal, fraction);
  }

  return input.maxFraction;
}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:18,代码来源:World.java


示例6: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(final RayCastInput input,
		int proxyId) {
	Actor actor = (Actor) m_tree.getUserData(proxyId);

	RayCastOutput output = new RayCastOutput();
	boolean hit = actor.aabb.raycast(output, input, getWorld().getPool());

	if (hit) {
		m_rayCastOutput = output;
		m_rayActor = actor;
		m_rayActor.fraction = output.fraction;
		return output.fraction;
	}

	return input.maxFraction;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:17,代码来源:DynamicTreeTest.java


示例7: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(final RayCastInput input,
		DynamicTreeNode proxyId) {
	Actor actor = (Actor) proxyId.userData;

	RayCastOutput output = new RayCastOutput();
	boolean hit = actor.aabb.raycast(output, input, getWorld().getPool());

	if (hit) {
		m_rayCastOutput = output;
		m_rayActor = actor;
		m_rayActor.fraction = output.fraction;
		return output.fraction;
	}

	return input.maxFraction;
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:17,代码来源:DynamicTreeTest.java


示例8: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
/**
 * @see Shape#raycast(org.jbox2d.collision.RayCastOutput,
 *      org.jbox2d.collision.RayCastInput, org.jbox2d.common.Transform, int)
 */
@Override
public final boolean raycast(RayCastOutput argOutput, RayCastInput argInput, Transform argTransform) {
	
	final Vec2 position = pool1;
	final Vec2 s = pool2;
	final Vec2 r = pool3;
	
	Mat22.mulToOut(argTransform.R, m_p, position);
	position.addLocal(argTransform.position);
	s.set(argInput.p1).subLocal(position);
	final float b = Vec2.dot(s, s) - m_radius * m_radius;
	
	// Solve quadratic equation.
	r.set(argInput.p2).subLocal(argInput.p1);
	final float c = Vec2.dot(s, r);
	final float rr = Vec2.dot(r, r);
	final float sigma = c * c - rr * b;
	
	// Check for negative discriminant and short segment.
	if (sigma < 0.0f || rr < Settings.EPSILON) {
		return false;
	}
	
	// Find the point of intersection of the line with the circle.
	float a = -(c + MathUtils.sqrt(sigma));
	
	// Is the intersection point on the segment?
	if (0.0f <= a && a <= argInput.maxFraction * rr) {
		a /= rr;
		argOutput.fraction = a;
		argOutput.normal.set(r).mulLocal(a);
		argOutput.normal.addLocal(s);
		argOutput.normal.normalize();
		return true;
	}
	
	return false;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:43,代码来源:CircleShape.java


示例9: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
/**
 * Ray-cast against the proxies in the tree. This relies on the callback
 * to perform a exact ray-cast in the case were the proxy contains a shape.
 * The callback also performs the any collision filtering. This has performance
 * roughly equal to k * log(n), where k is the number of collisions and n is the
 * number of proxies in the tree.
 * 
 * @param argInput
 *            the ray-cast input data. The ray extends from p1 to p1 + maxFraction *
 *            (p2 - p1).
 * @param argCallback
 *            a callback class that is called for each proxy that is hit by the ray.
 */
public void raycast(TreeRayCastCallback argCallback, RayCastInput argInput) {
	
	final Vec2 r = vec2s.pop();
	final Vec2 v = vec2s.pop();
	final Vec2 absV = vec2s.pop();
	
	Vec2 p1 = argInput.p1;
	Vec2 p2 = argInput.p2;
	r.set(p2).subLocal(p1);
	assert (r.lengthSquared() > 0f);
	r.normalize();
	
	// v is perpendicular to the segment.
	Vec2.crossToOut(1f, r, v);
	absV.set(v).absLocal();
	
	// Separating axis for segment (Gino, p80).
	// |dot(v, p1 - c)| > dot(|v|, h)
	
	float[] maxFraction = new float[1];
	maxFraction[0] = argInput.maxFraction;
	
	// Build a bounding box for the segment.
	final AABB segAABB = aabb;
	// b2Vec2 t = p1 + maxFraction * (p2 - p1);
	final Vec2 temp = vec2s.pop();
	temp.set(p2).subLocal(p1).mulLocal(maxFraction[0]).addLocal(p1);
	Vec2.minToOut(p1, temp, segAABB.lowerBound);
	Vec2.maxToOut(p1, temp, segAABB.upperBound);
	
	raycast(m_root, argInput, 0, segAABB, v, p1, p2, absV, maxFraction, argCallback);
	vec2s.push(4);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:47,代码来源:DynamicTree.java


示例10: raycastCallback

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public float raycastCallback(RayCastInput input, DynamicTreeNode node) {
	Object userData = node.userData;
	Fixture fixture = (Fixture) userData;
	boolean hit = fixture.raycast(output, input);
	
	if (hit) {
		float fraction = output.fraction;
		// Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
		temp.set(input.p2).mulLocal(fraction);
		point.set(input.p1).mulLocal(1 - fraction).addLocal(temp);
		return callback.reportFixture(fixture, point, output.normal, fraction);
	}
	
	return input.maxFraction;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:World.java


示例11: initTest

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
/**
 * @see org.jbox2d.testbed.framework.TestbedTest#initTest()
 */
@Override
public void initTest() {
	worldExtent = 15.0f;
	m_proxyExtent = 0.5f;

	m_tree = new DynamicTree();

	for (int i = 0; i < e_actorCount; ++i) {
		Actor actor = m_actors[i] = new Actor();
		GetRandomAABB(actor.aabb);
		actor.proxyId = m_tree.createProxy(actor.aabb, actor);
	}

	m_stepCount = 0;

	float h = worldExtent;
	m_queryAABB = new AABB();
	m_queryAABB.lowerBound.set(-3.0f, -4.0f + h);
	m_queryAABB.upperBound.set(5.0f, 6.0f + h);

	m_rayCastInput = new RayCastInput();
	m_rayCastInput.p1.set(-5.0f, 5.0f + h);
	m_rayCastInput.p2.set(7.0f, -4.0f + h);
	// m_rayCastInput.p1.set(0.0f, 2.0f + h);
	// m_rayCastInput.p2.set(0.0f, -2.0f + h);
	m_rayCastInput.maxFraction = 1.0f;

	m_rayCastOutput = new RayCastOutput();

	m_automated = false;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:35,代码来源:DynamicTreeTest.java


示例12: RayCast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public void RayCast() {
	m_rayActor = null;

	RayCastInput input = m_rayCastInput;

	// Ray cast against the dynamic tree.
	m_tree.raycast(this, input);

	// Brute force ray cast.
	Actor bruteActor = null;
	RayCastOutput bruteOutput = new RayCastOutput();
	for (int i = 0; i < e_actorCount; ++i) {
		if (m_actors[i].proxyId == null) {
			continue;
		}

		RayCastOutput output = new RayCastOutput();
		boolean hit = m_actors[i].aabb.raycast(output, input,
				m_world.getPool());
		if (hit) {
			bruteActor = m_actors[i];
			bruteOutput = output;
		    //input.set(m_rayCastInput);
		}
	}

	if (bruteActor != null) {
		assert (MathUtils.abs(bruteOutput.fraction
				- m_rayCastOutput.fraction) <= Settings.EPSILON);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:DynamicTreeTest.java


示例13: initTest

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public void initTest(boolean argDeserialized) {
	worldExtent = 15.0f;
	m_proxyExtent = 0.5f;

	m_tree = new DynamicTree();

	for (int i = 0; i < e_actorCount; ++i) {
		Actor actor = m_actors[i] = new Actor();
		GetRandomAABB(actor.aabb);
		actor.proxyId = m_tree.createProxy(actor.aabb, actor);
	}

	m_stepCount = 0;

	float h = worldExtent;
	m_queryAABB = new AABB();
	m_queryAABB.lowerBound.set(-3.0f, -4.0f + h);
	m_queryAABB.upperBound.set(5.0f, 6.0f + h);

	m_rayCastInput = new RayCastInput();
	m_rayCastInput.p1.set(-5.0f, 5.0f + h);
	m_rayCastInput.p2.set(7.0f, -4.0f + h);
	// m_rayCastInput.p1.set(0.0f, 2.0f + h);
	// m_rayCastInput.p2.set(0.0f, -2.0f + h);
	m_rayCastInput.maxFraction = 1.0f;

	m_rayCastOutput = new RayCastOutput();

	m_automated = false;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:32,代码来源:DynamicTreeTest.java


示例14: RayCast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public void RayCast() {
	m_rayActor = null;

	RayCastInput input = new RayCastInput();
	input.set(m_rayCastInput);

	// Ray cast against the dynamic tree.
	m_tree.raycast(this, input);

	// Brute force ray cast.
	Actor bruteActor = null;
	RayCastOutput bruteOutput = new RayCastOutput();
	for (int i = 0; i < e_actorCount; ++i) {
		if (m_actors[i].proxyId == -1) {
			continue;
		}

		RayCastOutput output = new RayCastOutput();
		boolean hit = m_actors[i].aabb.raycast(output, input,
				getWorld().getPool());
		if (hit) {
			bruteActor = m_actors[i];
			bruteOutput = output;
			input.maxFraction = output.fraction;
		}
	}

	if (bruteActor != null) {
	  if(MathUtils.abs(bruteOutput.fraction
                   - m_rayCastOutput.fraction) > Settings.EPSILON) {
	    System.out.println("wrong!");
	    assert (MathUtils.abs(bruteOutput.fraction
             - m_rayCastOutput.fraction) <= 20 * Settings.EPSILON);
	  }
		
	}
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:38,代码来源:DynamicTreeTest.java


示例15: initTest

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
/**
 * @see org.jbox2d.testbed.framework.TestbedTest#initTest(boolean)
 */
@Override
public void initTest(boolean argDeserialized) {
	worldExtent = 15.0f;
	m_proxyExtent = 0.5f;

	m_tree = new DynamicTree();

	for (int i = 0; i < e_actorCount; ++i) {
		Actor actor = m_actors[i] = new Actor();
		GetRandomAABB(actor.aabb);
		actor.proxyId = m_tree.createProxy(actor.aabb, actor);
	}

	m_stepCount = 0;

	float h = worldExtent;
	m_queryAABB = new AABB();
	m_queryAABB.lowerBound.set(-3.0f, -4.0f + h);
	m_queryAABB.upperBound.set(5.0f, 6.0f + h);

	m_rayCastInput = new RayCastInput();
	m_rayCastInput.p1.set(-5.0f, 5.0f + h);
	m_rayCastInput.p2.set(7.0f, -4.0f + h);
	// m_rayCastInput.p1.set(0.0f, 2.0f + h);
	// m_rayCastInput.p2.set(0.0f, -2.0f + h);
	m_rayCastInput.maxFraction = 1.0f;

	m_rayCastOutput = new RayCastOutput();

	m_automated = false;
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:35,代码来源:DynamicTreeTest.java


示例16: RayCast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
public void RayCast() {
	m_rayActor = null;

	RayCastInput input = new RayCastInput();
	input.set(m_rayCastInput);

	// Ray cast against the dynamic tree.
	m_tree.raycast(this, input);

	// Brute force ray cast.
	Actor bruteActor = null;
	RayCastOutput bruteOutput = new RayCastOutput();
	for (int i = 0; i < e_actorCount; ++i) {
		if (m_actors[i].proxyId == null) {
			continue;
		}

		RayCastOutput output = new RayCastOutput();
		boolean hit = m_actors[i].aabb.raycast(output, input,
				getWorld().getPool());
		if (hit) {
			bruteActor = m_actors[i];
			bruteOutput = output;
			input.maxFraction = output.fraction;
		    //input.set(m_rayCastInput);
		}
	}

	if (bruteActor != null) {
		assert (MathUtils.abs(bruteOutput.fraction
				- m_rayCastOutput.fraction) <= Settings.EPSILON);
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:34,代码来源:DynamicTreeTest.java


示例17: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public final void raycast(final TreeRayCastCallback callback, final RayCastInput input) {
  m_tree.raycast(callback, input);
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:5,代码来源:DefaultBroadPhaseBuffer.java


示例18: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public void raycast(TreeRayCastCallback callback, RayCastInput input) {
  wrapper.setCallback(callback);
  raycast(wrapper, input.p1.x, input.p1.y, input.p2.x, input.p2.y, input.maxFraction);
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:6,代码来源:BroadPhaseJNI.java


示例19: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
@Override
public boolean raycast(RayCastOutput output, RayCastInput input, Transform transform, int childIndex) {
    return false;
}
 
开发者ID:cburschka,项目名称:PhysLayout,代码行数:5,代码来源:ShapelessShape.java


示例20: raycast

import org.jbox2d.collision.RayCastInput; //导入依赖的package包/类
/**
 * Ray-cast against the proxies in the tree. This relies on the callback to perform a exact
 * ray-cast in the case were the proxy contains a shape. The callback also performs the any
 * collision filtering. This has performance roughly equal to k * log(n), where k is the number of
 * collisions and n is the number of proxies in the tree.
 * 
 * @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
 * @param callback a callback class that is called for each proxy that is hit by the ray.
 */
public void raycast(TreeRayCastCallback callback, RayCastInput input) {
  final Vec2 p1 = input.p1;
  final Vec2 p2 = input.p2;
  r.set(p2).subLocal(p1);
  assert (r.lengthSquared() > 0f);
  r.normalize();

  // v is perpendicular to the segment.
  Vec2.crossToOut(1f, r, v);
  absV.set(v).absLocal();

  // Separating axis for segment (Gino, p80).
  // |dot(v, p1 - c)| > dot(|v|, h)

  float maxFraction = input.maxFraction;

  // Build a bounding box for the segment.
  final AABB segAABB = aabb;
  // Vec2 t = p1 + maxFraction * (p2 - p1);
  temp.set(p2).subLocal(p1).mulLocal(maxFraction).addLocal(p1);
  Vec2.minToOut(p1, temp, segAABB.lowerBound);
  Vec2.maxToOut(p1, temp, segAABB.upperBound);

  intStack.push(m_root);
  while (intStack.getCount() > 0) {
    int nodeId = intStack.pop();
    if (nodeId == DynamicTreeNode.NULL_NODE) {
      continue;
    }

    final DynamicTreeNode node = m_nodes[nodeId];

    if (!AABB.testOverlap(node.aabb, segAABB)) {
      continue;
    }

    // Separating axis for segment (Gino, p80).
    // |dot(v, p1 - c)| > dot(|v|, h)
    node.aabb.getCenterToOut(c);
    node.aabb.getExtentsToOut(h);
    temp.set(p1).subLocal(c);
    float separation = MathUtils.abs(Vec2.dot(v, temp)) - Vec2.dot(absV, h);
    if (separation > 0.0f) {
      continue;
    }

    if (node.isLeaf()) {
      subInput.p1.set(input.p1);
      subInput.p2.set(input.p2);
      subInput.maxFraction = maxFraction;

      float value = callback.raycastCallback(subInput, node);

      if (value == 0.0f) {
        // The client has terminated the ray cast.
        return;
      }

      if (value > 0.0f) {
        // Update segment bounding box.
        maxFraction = value;
        t.set(p2).subLocal(p1).mulLocal(maxFraction).addLocal(p1);
        Vec2.minToOut(p1, t, segAABB.lowerBound);
        Vec2.maxToOut(p1, t, segAABB.upperBound);
      }
    } else {
      intStack.push(node.child1);
      intStack.push(node.child2);
    }
  }
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:81,代码来源:DynamicTree.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SpelExpression类代码示例发布时间:2022-05-22
下一篇:
Java UrlImageViewHelper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap