本文整理汇总了Java中org.jbox2d.collision.RayCastInput类的典型用法代码示例。如果您正苦于以下问题:Java RayCastInput类的具体用法?Java RayCastInput怎么用?Java RayCastInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RayCastInput类属于org.jbox2d.collision包,在下文中一共展示了RayCastInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
示例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;
}