List of usage examples for com.badlogic.gdx.math Vector3 scl
@Override
public Vector3 scl(final Vector3 other)
From source file:com.badlogic.gdx.ai.tests.steer.bullet.SteeringBulletEntity.java
License:Apache License
protected void applySteering(SteeringAcceleration<Vector3> steering, float deltaTime) { boolean anyAccelerations = false; // Update position and linear velocity if (!steeringOutput.linear.isZero()) { body.applyCentralForce(steeringOutput.linear.scl(deltaTime)); anyAccelerations = true;/* w ww . jav a 2s .co m*/ } // Update orientation and angular velocity if (isIndependentFacing()) { if (steeringOutput.angular != 0) { body.applyTorque(tmpVector3.set(0, steeringOutput.angular * deltaTime, 0)); anyAccelerations = true; } } else { // If we haven't got any velocity, then we can do nothing. Vector3 linVel = getLinearVelocity(); if (!linVel.isZero(MathUtils.FLOAT_ROUNDING_ERROR)) { // // TODO: Commented out!!! // Looks like the code below creates troubles in combination with the applyCentralForce above // Maybe we should be more consistent by only applying forces or setting velocities. // // float newOrientation = vectorToAngle(linVel); // Vector3 angVel = body.getAngularVelocity(); // angVel.y = (newOrientation - oldOrientation) % MathUtils.PI2; // if (angVel.y > MathUtils.PI) angVel.y -= MathUtils.PI2; // angVel.y /= deltaTime; // body.setAngularVelocity(angVel); // anyAccelerations = true; // oldOrientation = newOrientation; } } if (anyAccelerations) { body.activate(); // TODO: // Looks like truncating speeds here after applying forces doesn't work as expected. // We should likely cap speeds form inside an InternalTickCallback, see // http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Simulation_Tick_Callbacks // Cap the linear speed Vector3 velocity = body.getLinearVelocity(); float currentSpeedSquare = velocity.len2(); float maxLinearSpeed = getMaxLinearSpeed(); if (currentSpeedSquare > maxLinearSpeed * maxLinearSpeed) { body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float) Math.sqrt(currentSpeedSquare))); } // Cap the angular speed Vector3 angVelocity = body.getAngularVelocity(); if (angVelocity.y > getMaxAngularSpeed()) { angVelocity.y = getMaxAngularSpeed(); body.setAngularVelocity(angVelocity); } } }
From source file:com.badlogic.gdx.tests.g3d.HeightField.java
public Vector3 getWeightedNormalAt(Vector3 out, int x, int y) { // This commented code is based on http://www.flipcode.com/archives/Calculating_Vertex_Normals_for_Height_Maps.shtml // Note that this approach only works for a heightfield on the XZ plane with a magnitude on the y axis // float sx = data[(x < width - 1 ? x + 1 : x) + y * width] + data[(x > 0 ? x-1 : x) + y * width]; // if (x == 0 || x == (width - 1)) // sx *= 2f;/*from ww w. ja v a 2 s . c o m*/ // float sy = data[(y < height - 1 ? y + 1 : y) * width + x] + data[(y > 0 ? y-1 : y) * width + x]; // if (y == 0 || y == (height - 1)) // sy *= 2f; // float xScale = (corner11.x - corner00.x) / (width - 1f); // float zScale = (corner11.z - corner00.z) / (height - 1f); // float yScale = magnitude.len(); // out.set(-sx * yScale, 2f * xScale, sy*yScale*xScale / zScale).nor(); // return out; // The following approach weights the normal of the four triangles (half quad) surrounding the position. // A more accurate approach would be to weight the normal of the actual triangles. int faces = 0; out.set(0, 0, 0); Vector3 center = getPositionAt(tmpV2, x, y); Vector3 left = x > 0 ? getPositionAt(tmpV3, x - 1, y) : null; Vector3 right = x < (width - 1) ? getPositionAt(tmpV4, x + 1, y) : null; Vector3 bottom = y > 0 ? getPositionAt(tmpV5, x, y - 1) : null; Vector3 top = y < (height - 1) ? getPositionAt(tmpV6, x, y + 1) : null; if (top != null && left != null) { out.add(tmpV7.set(top).sub(center).nor().crs(tmpV8.set(center).sub(left).nor()).nor()); faces++; } if (left != null && bottom != null) { out.add(tmpV7.set(left).sub(center).nor().crs(tmpV8.set(center).sub(bottom).nor()).nor()); faces++; } if (bottom != null && right != null) { out.add(tmpV7.set(bottom).sub(center).nor().crs(tmpV8.set(center).sub(right).nor()).nor()); faces++; } if (right != null && top != null) { out.add(tmpV7.set(right).sub(center).nor().crs(tmpV8.set(center).sub(top).nor()).nor()); faces++; } if (faces != 0) out.scl(1f / (float) faces); else out.set(magnitude).nor(); return out; }
From source file:com.mygdx.game.objects.HumanCharacter.java
License:Apache License
public void throwStick() { GameScreen.screen.engine.addEntity(stick); stick.body.setLinearVelocity(Vector3.Zero); stick.body.setAngularVelocity(Vector3.Zero); Vector3 rightHandPos = getBoneMidpointWorldPosition(HumanArmature.RIGHT_HAND.id, TMP_V1); stick.modelTransform.setToRotation(Vector3.Z, 90); stick.modelTransform.rotate(Constants.V3_UP, getOrientation() * MathUtils.radiansToDegrees); stick.modelTransform.setTranslation(rightHandPos); stick.body.setWorldTransform(stick.modelTransform); Vector3 humanDirection = getDirection(TMP_V1); TMP_Q.setFromAxis(TMP_V2.set(humanDirection).crs(Constants.V3_UP), STICK_THROW_ANGLE); Vector3 impulse = TMP_Q.transform(humanDirection).nor(); impulse.scl(STICK_THROW_IMPULSE_SCL); stick.body.applyImpulse(impulse, TMP_V2.set(Constants.V3_UP).scl(0.005f)); stick.hasLanded = false;//from ww w . java2 s . c o m hasStick = false; }
From source file:gaia.cu9.ari.gaiaorbit.util.g3d.MeshBuilder2.java
License:Apache License
@Override public void box(Vector3 corner000, Vector3 corner010, Vector3 corner100, Vector3 corner110, Vector3 corner001, Vector3 corner011, Vector3 corner101, Vector3 corner111) { if (norOffset < 0 && uvOffset < 0) { box(vertTmp1.set(corner000, null, null, null), vertTmp2.set(corner010, null, null, null), vertTmp3.set(corner100, null, null, null), vertTmp4.set(corner110, null, null, null), vertTmp5.set(corner001, null, null, null), vertTmp6.set(corner011, null, null, null), vertTmp7.set(corner101, null, null, null), vertTmp8.set(corner111, null, null, null)); } else {// ww w . j av a 2 s .c o m ensureRectangles(6); Vector3 nor = tempV1.set(corner000).lerp(corner110, 0.5f) .sub(tempV2.set(corner001).lerp(corner111, 0.5f)).nor(); rect(corner000, corner010, corner110, corner100, nor); rect(corner011, corner001, corner101, corner111, nor.scl(-1)); nor = tempV1.set(corner000).lerp(corner101, 0.5f).sub(tempV2.set(corner010).lerp(corner111, 0.5f)) .nor(); rect(corner001, corner000, corner100, corner101, nor); rect(corner010, corner011, corner111, corner110, nor.scl(-1)); nor = tempV1.set(corner000).lerp(corner011, 0.5f).sub(tempV2.set(corner100).lerp(corner111, 0.5f)) .nor(); rect(corner001, corner011, corner010, corner000, nor); rect(corner100, corner110, corner111, corner101, nor.scl(-1)); } }
From source file:MeshBoneUtil.dualQuat.java
License:Open Source License
public Vector3 transform(Vector3 p) { v0.x = real.x;//from w w w. j a v a 2 s . com v0.y = real.y; v0.z = real.z; ve.x = imaginary.x; ve.y = imaginary.y; ve.z = imaginary.z; Vector3 trans; //trans = (ve*real.w - v0*imaginary.w + Vector3.Cross(v0, ve)) * 2.0f; tmpVec1.set(v0); //Vector3 tmpVec1 = v0.cpy().scl((float)imaginary.w); tmpVec1 = tmpVec1.scl((float) imaginary.w); tmpVec2.set(v0); //Vector3 tmpVec2 = v0.cpy().crs(ve); tmpVec2 = tmpVec2.crs(ve); tmpVec0.set(ve); //Vector3 tmpVec0 = ve.cpy().scl(real.w); tmpVec0 = tmpVec0.scl(real.w); trans = tmpVec0.sub(tmpVec1).add(tmpVec2); trans.scl(2.0f); //Vector3 rot = real.transform(p.cpy()); tmpVec.set(p); Vector3 rot = real.transform(tmpVec); //return (XnaGeometry.Vector3.Transform(p, real)) + trans; return rot.add(trans); }