本文整理汇总了Java中org.jbox2d.common.MathUtils.PI属性的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.PI属性的具体用法?Java MathUtils.PI怎么用?Java MathUtils.PI使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jbox2d.common.MathUtils
的用法示例。
在下文中一共展示了MathUtils.PI属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCircle
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
System.err.println("drawCircle: "+center +", "+radius+", "+color);
GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glColor4f(color.x, color.y, color.z, 1);
for (int i = 0; i < NUM_CIRCLE_POINTS; i++) {
gl.glVertex3f(x + cx, y + cy, 0);
// apply the rotation matrix
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
gl.glPopMatrix();
}
示例2: drawCircle
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
//GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glColor4f(color.x, color.y, color.z, 1);
for (int i = 0; i < NUM_CIRCLE_POINTS; i++) {
gl.glVertex3f(x + cx, y + cy, 0);
// apply the rotation matrix
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
gl.glPopMatrix();
}
示例3: step
/**
* @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.Testbe.settings)
*/
@Override
public void step(TestbedSettings settings) {
boolean advanceRay = settings.pause == false || settings.singleStep;
super.step(settings);
addTextLine("Press 1-5 to drop stuff");
float L = 25.0f;
Vec2 point1 = new Vec2(0.0f, 10.0f);
Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle)));
Vec2 point2 = point1.add(d);
callback.m_fixture = null;
m_world.raycast(callback, point1, point2);
if (callback.m_fixture != null)
{
m_debugDraw.drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
m_debugDraw.drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point);
m_debugDraw.drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f));
}
else
{
m_debugDraw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
if (advanceRay)
{
m_angle += 0.25f * MathUtils.PI / 180.0f;
}
}
示例4: keyPressed
@Override
public void keyPressed(char argKeyChar, int argKeyCode) {
switch (argKeyChar) {
case 'a' :
m_positionB.x -= 0.1f;
break;
case 'd' :
m_positionB.x += 0.1f;
break;
case 's' :
m_positionB.y -= 0.1f;
break;
case 'w' :
m_positionB.y += 0.1f;
break;
case 'q' :
m_angleB += 0.1f * MathUtils.PI;
break;
case 'e' :
m_angleB -= 0.1f * MathUtils.PI;
break;
}
m_transformB.set(m_positionB, m_angleB);
}
示例5: drawParticles
@Override
public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
for (int i = 0; i < count; i++) {
Vec2 center = centers[i];
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_TRIANGLE_FAN);
if (colors == null) {
gl.glColor4f(1, 1, 1, .4f);
} else {
ParticleColor color = colors[i];
gl.glColor4b(color.r, color.g, color.b, color.a);
}
for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
gl.glVertex3f(x + cx, y + cy, 0);
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
}
gl.glPopMatrix();
}
示例6: drawParticlesWireframe
@Override
public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
for (int i = 0; i < count; i++) {
Vec2 center = centers[i];
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_LINE_LOOP);
if (colors == null) {
gl.glColor4f(1, 1, 1, 1);
} else {
ParticleColor color = colors[i];
gl.glColor4b(color.r, color.g, color.b, (byte) 127);
}
for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
gl.glVertex3f(x + cx, y + cy, 0);
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
}
gl.glPopMatrix();
}
示例7: step
@Override
public void step(TestbedSettings settings) {
boolean advanceRay = settings.pause == false || settings.singleStep;
super.step(settings);
addTextLine("Press 1-5 to drop stuff");
float L = 25.0f;
Vec2 point1 = new Vec2(0.0f, 10.0f);
Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle)));
Vec2 point2 = point1.add(d);
callback.m_fixture = null;
getWorld().raycast(callback, point1, point2);
if (callback.m_fixture != null) {
getDebugDraw().drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
getDebugDraw().drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point);
getDebugDraw().drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f));
} else {
getDebugDraw().drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
if (advanceRay) {
m_angle += 0.25f * MathUtils.PI / 180.0f;
}
}
示例8: initTest
@Override
public void initTest(boolean deserialized) {
{
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.allowSleep = false;
bd.position.set(0.0f, 10.0f);
Body body = m_world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(0.5f, 10.0f, new Vec2(-10.0f, 0.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
body.createFixture(shape, 5.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.bodyA = getGroundBody();
jd.bodyB = body;
jd.localAnchorA.set(0.0f, 10.0f);
jd.localAnchorB.set(0.0f, 0.0f);
jd.referenceAngle = 0.0f;
jd.motorSpeed = 0.05f * MathUtils.PI;
jd.maxMotorTorque = 1e8f;
jd.enableMotor = true;
m_joint = (RevoluteJoint) m_world.createJoint(jd);
}
m_count = 0;
}
示例9: drawParticles
@Override
public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
// GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
for (int i = 0; i < count; i++) {
Vec2 center = centers[i];
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_TRIANGLE_FAN);
if (colors == null) {
gl.glColor4f(1, 1, 1, .4f);
} else {
ParticleColor color = colors[i];
gl.glColor4b(color.r, color.g, color.b, color.a);
}
for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
gl.glVertex3f(x + cx, y + cy, 0);
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
}
gl.glPopMatrix();
}
示例10: drawParticlesWireframe
@Override
public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
// GL2 gl = panel.getGL().getGL2();
gl.glPushMatrix();
transformViewport(gl, zero);
float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
float c = MathUtils.cos(theta);
float s = MathUtils.sin(theta);
float x = radius;
float y = 0;
for (int i = 0; i < count; i++) {
Vec2 center = centers[i];
float cx = center.x;
float cy = center.y;
gl.glBegin(GL2.GL_LINE_LOOP);
if (colors == null) {
gl.glColor4f(1, 1, 1, 1);
} else {
ParticleColor color = colors[i];
gl.glColor4b(color.r, color.g, color.b, (byte) 127);
}
for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
gl.glVertex3f(x + cx, y + cy, 0);
float temp = x;
x = c * x - s * y;
y = s * temp + c * y;
}
gl.glEnd();
}
gl.glPopMatrix();
}
示例11: initVelocityConstraints
@Override
public void initVelocityConstraints(final SolverData data) {
m_indexB = m_bodyB.m_islandIndex;
m_localCenterB.set(m_bodyB.m_sweep.localCenter);
m_invMassB = m_bodyB.m_invMass;
m_invIB = m_bodyB.m_invI;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
final Rot qB = pool.popRot();
qB.set(aB);
float mass = m_bodyB.getMass();
// Frequency
float omega = 2.0f * MathUtils.PI * m_frequencyHz;
// Damping coefficient
float d = 2.0f * mass * m_dampingRatio * omega;
// Spring stiffness
float k = mass * (omega * omega);
// magic formulas
// gamma has units of inverse mass.
// beta has units of inverse time.
float h = data.step.dt;
assert (d + h * k > Settings.EPSILON);
m_gamma = h * (d + h * k);
if (m_gamma != 0.0f) {
m_gamma = 1.0f / m_gamma;
}
m_beta = h * k * m_gamma;
Vec2 temp = pool.popVec2();
// Compute the effective mass matrix.
Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB);
// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
// = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
// [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
final Mat22 K = pool.popMat22();
K.ex.x = m_invMassB + m_invIB * m_rB.y * m_rB.y + m_gamma;
K.ex.y = -m_invIB * m_rB.x * m_rB.y;
K.ey.x = K.ex.y;
K.ey.y = m_invMassB + m_invIB * m_rB.x * m_rB.x + m_gamma;
K.invertToOut(m_mass);
m_C.set(cB).addLocal(m_rB).subLocal(m_targetA);
m_C.mulLocal(m_beta);
// Cheat with some damping
wB *= 0.98f;
if (data.step.warmStarting) {
m_impulse.mulLocal(data.step.dtRatio);
vB.x += m_invMassB * m_impulse.x;
vB.y += m_invMassB * m_impulse.y;
wB += m_invIB * Vec2.cross(m_rB, m_impulse);
} else {
m_impulse.setZero();
}
// data.velocities[m_indexB].v.set(vB);
data.velocities[m_indexB].w = wB;
pool.pushVec2(1);
pool.pushMat22(1);
pool.pushRot(1);
}
示例12: initScene
public void initScene() {
{
BodyDef bd = new BodyDef();
Body groundbody = world.createBody(bd);
bd.type = BodyType.DYNAMIC;
bd.allowSleep = false;
bd.position.set(0.0f, 0.0f);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(1, 11.0f, new Vec2(10.0f, 0.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(1, 11.0f, new Vec2(-10.0f, 0.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(11.0f, 1, new Vec2(0.0f, 10.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(11.0f, 1, new Vec2(0.0f, -10.0f), 0.0f);
body.createFixture(shape, 15.0f);
CircleShape obstacle = new CircleShape();
obstacle.m_radius = 1;
obstacle.m_p.set(-2, -6.5f);
body.createFixture(obstacle, 115.0f);
obstacle.m_p.set(2, +6.5f);
body.createFixture(obstacle, 115.0f);
// obstacle.m_p.set(-7.5f, 0);
// body.createFixture(obstacle, 15.0f);
// obstacle.m_p.set(+7.5f, 0);
// body.createFixture(obstacle, 15.0f);
world.bodies.add(body, true, color(224), true, color(0), 1f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.bodyA = groundbody;
jd.bodyB = body;
jd.localAnchorA.set(0.0f, 0.0f);
jd.localAnchorB.set(0.0f, 0.0f);
jd.referenceAngle = 0.0f;
jd.motorSpeed = 0.1f * MathUtils.PI;
jd.maxMotorTorque = 1e7f;
jd.enableMotor = true;
m_joint = (RevoluteJoint) world.createJoint(jd);
}
m_count = 0;
// creates shapes for all rigid bodies in the world.
world.bodies.addAll();
}
示例13: initVelocityConstraints
@Override
public void initVelocityConstraints(final TimeStep step) {
// TODO: fully inline temp Vec2 ops
final Body b1 = m_bodyA;
final Body b2 = m_bodyB;
Vec2 r1 = pool.popVec2();
Vec2 r2 = pool.popVec2();
// Compute the effective mass matrix.
r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
Mat22.mulToOut(b1.getTransform().R, r1, r1);
Mat22.mulToOut(b2.getTransform().R, r2, r2);
m_u.x = b2.m_sweep.c.x + r2.x - b1.m_sweep.c.x - r1.x;
m_u.y = b2.m_sweep.c.y + r2.y - b1.m_sweep.c.y - r1.y;
// Handle singularity.
float length = m_u.length();
if (length > Settings.linearSlop) {
m_u.x *= 1.0f / length;
m_u.y *= 1.0f / length;
}
else {
m_u.set(0.0f, 0.0f);
}
float cr1u = Vec2.cross(r1, m_u);
float cr2u = Vec2.cross(r2, m_u);
float invMass = b1.m_invMass + b1.m_invI * cr1u * cr1u + b2.m_invMass + b2.m_invI * cr2u * cr2u;
assert (invMass > Settings.EPSILON);
m_mass = 1.0f / invMass;
if (m_frequencyHz > 0.0f) {
float C = length - m_length;
// Frequency
float omega = 2.0f * MathUtils.PI * m_frequencyHz;
// Damping coefficient
float d = 2.0f * m_mass * m_dampingRatio * omega;
// Spring stiffness
float k = m_mass * omega * omega;
// magic formulas
m_gamma = step.dt * (d + step.dt * k);
m_gamma = m_gamma != 0.0f ? 1.0f / m_gamma : 0.0f;
m_bias = C * step.dt * k * m_gamma;
m_mass = invMass + m_gamma;
m_mass = m_mass != 0.0f ? 1.0f / m_mass : 0.0f;
}
if (step.warmStarting) {
// Scale the impulse to support a variable time step.
m_impulse *= step.dtRatio;
Vec2 P = pool.popVec2();
P.set(m_u).mulLocal(m_impulse);
b1.m_linearVelocity.x -= b1.m_invMass * P.x;
b1.m_linearVelocity.y -= b1.m_invMass * P.y;
b1.m_angularVelocity -= b1.m_invI * Vec2.cross(r1, P);
b2.m_linearVelocity.x += b2.m_invMass * P.x;
b2.m_linearVelocity.y += b2.m_invMass * P.y;
b2.m_angularVelocity += b2.m_invI * Vec2.cross(r2, P);
pool.pushVec2(1);
}
else {
m_impulse = 0.0f;
}
pool.pushVec2(2);
}
示例14: initVelocityConstraints
@Override
public void initVelocityConstraints(TimeStep step) {
Body b = m_bodyB;
float mass = b.getMass();
// Frequency
float omega = 2.0f * MathUtils.PI * m_frequencyHz;
// Damping coefficient
float d = 2.0f * mass * m_dampingRatio * omega;
// Spring stiffness
float k = mass * (omega * omega);
// magic formulas
// gamma has units of inverse mass.
// beta has units of inverse time.
assert(d + step.dt * k > Settings.EPSILON);
m_gamma = step.dt * (d + step.dt * k);
if (m_gamma != 0.0f){
m_gamma = 1.0f / m_gamma;
}
m_beta = step.dt * k * m_gamma;
Vec2 r = pool.popVec2();
// Compute the effective mass matrix.
//Vec2 r = Mul(b.getTransform().R, m_localAnchor - b.getLocalCenter());
r.set(m_localAnchor).subLocal(b.getLocalCenter());
Mat22.mulToOut(b.getTransform().R, r, r);
// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
// = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
// [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
float invMass = b.m_invMass;
float invI = b.m_invI;
Mat22 K1 = pool.popMat22();
K1.col1.x = invMass; K1.col2.x = 0.0f;
K1.col1.y = 0.0f; K1.col2.y = invMass;
Mat22 K2 = pool.popMat22();
K2.col1.x = invI * r.y * r.y; K2.col2.x = -invI * r.x * r.y;
K2.col1.y = -invI * r.x * r.y; K2.col2.y = invI * r.x * r.x;
Mat22 K = pool.popMat22();
K.set(K1).addLocal(K2);
K.col1.x += m_gamma;
K.col2.y += m_gamma;
K.invertToOut(m_mass);
m_C.set(b.m_sweep.c).addLocal(r).subLocal(m_target);
// Cheat with some damping
b.m_angularVelocity *= 0.98f;
// Warm starting.
m_impulse.mulLocal(step.dtRatio);
// pool
Vec2 temp = pool.popVec2();
temp.set(m_impulse).mulLocal(invMass);
b.m_linearVelocity.addLocal(temp);
b.m_angularVelocity += invI * Vec2.cross(r, m_impulse);
pool.pushVec2(2);
pool.pushMat22(3);
}
示例15: step
@Override
public void step(TestbedSettings settings) {
boolean advanceRay = settings.pause == false || settings.singleStep;
super.step(settings);
addTextLine("Press 1-5 to drop stuff, m to change the mode");
addTextLine("Polygon 1 is filtered");
addTextLine("Mode = " + m_mode);
float L = 11.0f;
point1.set(0.0f, 10.0f);
d.set(L * MathUtils.cos(m_angle), L * MathUtils.sin(m_angle));
point2.set(point1);
point2.addLocal(d);
if (m_mode == Mode.e_closest) {
ccallback.init();
m_world.raycast(ccallback, point1, point2);
if (ccallback.m_hit) {
m_debugDraw.drawPoint(ccallback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
m_debugDraw.drawSegment(point1, ccallback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
pooledHead.set(ccallback.m_normal);
pooledHead.mulLocal(.5f).addLocal(ccallback.m_point);
m_debugDraw.drawSegment(ccallback.m_point, pooledHead, new Color3f(0.9f, 0.9f, 0.4f));
}
else {
m_debugDraw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
}
else if (m_mode == Mode.e_any) {
acallback.init();
m_world.raycast(acallback, point1, point2);
if (acallback.m_hit) {
m_debugDraw.drawPoint(acallback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
m_debugDraw.drawSegment(point1, acallback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
pooledHead.set(acallback.m_normal);
pooledHead.mulLocal(.5f).addLocal(acallback.m_point);
m_debugDraw.drawSegment(acallback.m_point, pooledHead, new Color3f(0.9f, 0.9f, 0.4f));
}
else {
m_debugDraw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
}
else if (m_mode == Mode.e_multiple) {
mcallback.init();
m_world.raycast(mcallback, point1, point2);
m_debugDraw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
for (int i = 0; i < mcallback.m_count; ++i) {
Vec2 p = mcallback.m_points[i];
Vec2 n = mcallback.m_normals[i];
m_debugDraw.drawPoint(p, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
m_debugDraw.drawSegment(point1, p, new Color3f(0.8f, 0.8f, 0.8f));
pooledHead.set(n);
pooledHead.mulLocal(.5f).addLocal(p);
m_debugDraw.drawSegment(p, pooledHead, new Color3f(0.9f, 0.9f, 0.4f));
}
}
if (advanceRay) {
m_angle += 0.25f * MathUtils.PI / 180.0f;
}
}