本文整理汇总了Java中org.jbox2d.common.MathUtils.distanceSquared方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.distanceSquared方法的具体用法?Java MathUtils.distanceSquared怎么用?Java MathUtils.distanceSquared使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.common.MathUtils
的用法示例。
在下文中一共展示了MathUtils.distanceSquared方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLoop
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Create a loop. This automatically adjusts connectivity.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
public void createLoop(final Vec2[] vertices, int count) {
assert (m_vertices == null && m_count == 0);
assert (count >= 3);
m_count = count + 1;
m_vertices = new Vec2[m_count];
for (int i = 1; i < count; i++) {
Vec2 v1 = vertices[i - 1];
Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
throw new RuntimeException("Vertices of chain shape are too close together");
}
}
for (int i = 0; i < count; i++) {
m_vertices[i] = new Vec2(vertices[i]);
}
m_vertices[count] = new Vec2(m_vertices[0]);
m_prevVertex.set(m_vertices[m_count - 2]);
m_nextVertex.set(m_vertices[1]);
m_hasPrevVertex = true;
m_hasNextVertex = true;
}
示例2: createChain
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Create a chain with isolated end vertices.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
public void createChain(final Vec2 vertices[], int count) {
assert (m_vertices == null && m_count == 0);
assert (count >= 2);
m_count = count;
m_vertices = new Vec2[m_count];
for (int i = 1; i < m_count; i++) {
Vec2 v1 = vertices[i - 1];
Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
throw new RuntimeException("Vertices of chain shape are too close together");
}
}
for (int i = 0; i < m_count; i++) {
m_vertices[i] = new Vec2(vertices[i]);
}
m_hasPrevVertex = false;
m_hasNextVertex = false;
m_prevVertex.setZero();
m_nextVertex.setZero();
}
示例3: createChain
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Create a chain with isolated end vertices.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
public void createChain(final Vec2 vertices[], int count) {
assert (m_vertices == null && m_count == 0);
assert (count >= 2);
m_count = count;
m_vertices = new Vec2[m_count];
for (int i = 1; i < m_count; i++) {
Vec2 v1 = vertices[i - 1];
Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
throw new RuntimeException("Vertices of chain shape are too close together");
}
}
for (int i = 0; i < m_count; i++) {
m_vertices[i] = new Vec2(vertices[i]);
}
m_hasPrevVertex = false;
m_hasNextVertex = false;
}
示例4: initialize
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void initialize(ContactConstraint cc, int index){
assert(cc.pointCount > 0);
switch (cc.type){
case CIRCLES:{
cc.bodyA.getWorldPointToOut(cc.localPoint, pointA);
cc.bodyB.getWorldPointToOut(cc.points[0].localPoint, pointB);
if (MathUtils.distanceSquared(pointA, pointB) > Settings.EPSILON * Settings.EPSILON){
normal.set(pointB).subLocal(pointA);
normal.normalize();
}
else{
normal.set(1.0f, 0.0f);
}
point.set(pointA).addLocal(pointB).mulLocal(.5f);
temp.set(pointB).subLocal(pointA);
separation = Vec2.dot(temp, normal) - cc.radius;
break;
}
case FACE_A:{
cc.bodyA.getWorldVectorToOut(cc.localNormal, normal);
cc.bodyA.getWorldPointToOut(cc.localPoint, planePoint);
cc.bodyB.getWorldPointToOut(cc.points[index].localPoint, clipPoint);
temp.set(clipPoint).subLocal(planePoint);
separation = Vec2.dot(temp, normal) - cc.radius;
point.set(clipPoint);
break;
}
case FACE_B:
{
cc.bodyB.getWorldVectorToOut(cc.localNormal, normal);
cc.bodyB.getWorldPointToOut(cc.localPoint, planePoint);
cc.bodyA.getWorldPointToOut(cc.points[index].localPoint, clipPoint);
temp.set(clipPoint).subLocal(planePoint);
separation = Vec2.dot(temp, normal) - cc.radius;
point.set(clipPoint);
// Ensure normal points from A to B
normal.negateLocal();
}
break;
}
}
示例5: initialize
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void initialize(TOIConstraint cc, int index){
assert(cc.pointCount > 0);
switch (cc.type){
case CIRCLES : {
cc.bodyA.getWorldPointToOut(cc.localPoint, pointA);
cc.bodyB.getWorldPointToOut(cc.localPoints[0], pointB);
if (MathUtils.distanceSquared(pointA, pointB) > Settings.EPSILON * Settings.EPSILON) {
normal.set(pointB).subLocal(pointA);
normal.normalize();
}
else {
normal.set(1.0f, 0.0f);
}
point.set(pointA).addLocal(pointB).mulLocal(.5f);
temp.set(pointB).subLocal(pointA);
separation = Vec2.dot(temp, normal) - cc.radius;
break;
}
case FACE_A : {
cc.bodyA.getWorldVectorToOut(cc.localNormal, normal);
cc.bodyA.getWorldPointToOut(cc.localPoint, planePoint);
cc.bodyB.getWorldPointToOut(cc.localPoints[index], clipPoint);
temp.set(clipPoint).subLocal(planePoint);
separation = Vec2.dot(temp, normal) - cc.radius;
point.set(clipPoint);
break;
}
case FACE_B : {
cc.bodyB.getWorldVectorToOut(cc.localNormal, normal);
cc.bodyB.getWorldPointToOut(cc.localPoint, planePoint);
cc.bodyA.getWorldPointToOut(cc.localPoints[index], clipPoint);
temp.set(clipPoint).subLocal(planePoint);
separation = Vec2.dot(temp, normal) - cc.radius;
point.set(clipPoint);
// Ensure normal points from A to B
normal.negateLocal();
}
break;
}
}