/** * This method moves each child shape of a compound shape by the given vector * @param vector */ public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) { for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape child = childCollisionShape.shape; Vector3f location = childCollisionShape.location; Matrix3f rotation = childCollisionShape.rotation; compoundShape.removeChildShape(child); compoundShape.addChildShape(child, location.add(vector), rotation); } } }
private void scaleAsParent(float percent, Vector3f playerPos, Vector3f dist) { float scale = mapValue(percent, 1.0f, poiRadius); Vector3f distToHorizon = dist.subtract(dist.normalize()); Vector3f offLocation = playerPos.add(distToHorizon); Vector3f rootOff = offLocation.mult(scale).negate(); rootOff.addLocal(dist); debugTools.setGreenArrow(Vector3f.ZERO, offLocation); getRootNode().setLocalScale(scale); getRootNode().setLocalTranslation(rootOff); }
/** * This method moves each child shape of a compound shape by the given vector * @param vector */ public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) { for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); CollisionShape child = childCollisionShape.shape; Vector3f location = childCollisionShape.location; Matrix3f rotation = childCollisionShape.rotation; compoundShape.removeChildShape(child); compoundShape.addChildShape(child, location.add(vector), rotation); } } }
public Vector3f getPositiveEnd(Vector3f store) { if (store == null) { store = new Vector3f(); } return origin.add((direction.mult(extent, store)), store); }
/** * @return the centroid of the edge */ public Vector3f computeCentroid() { return this.getFirstVertex().add(this.getSecondVertex()).divideLocal(2); }
public void getAllTerrainPatchesWithTranslation(Map<TerrainPatch,Vector3f> holder, Vector3f translation) { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).getAllTerrainPatchesWithTranslation(holder, translation.clone().add(child.getLocalTranslation())); } else if (child instanceof TerrainPatch) { //if (holder.size() < 4) holder.put((TerrainPatch)child, translation.clone().add(child.getLocalTranslation())); } } } }
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("stop") && isPressed) { ikControl.setEnabled(!ikControl.isEnabled()); ikControl.setIKMode(); } if (name.equals("one") && isPressed) { //ragdoll.setKinematicMode(); targetPoint = model.getWorldTranslation().add(new Vector3f(0,2,4)); targetNode.setLocalTranslation(targetPoint); ikControl.setIKTarget(ikControl.getBone("Hand.L"), targetPoint, 2); ikControl.setIKMode(); } if (name.equals("two") && isPressed) { //ragdoll.setKinematicMode(); targetPoint = model.getWorldTranslation().add(new Vector3f(-3,3,0)); targetNode.setLocalTranslation(targetPoint); ikControl.setIKTarget(ikControl.getBone("Hand.R"), targetPoint, 3); ikControl.setIKMode(); } } }, "one", "two");
/** * The method updates the geometry according to the positions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); } }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f compVec1 = vars.vect1; point.subtract(origin, compVec1); float segmentParameter = direction.dot(compVec1); if (-extent < segmentParameter) { if (segmentParameter < extent) { origin.add(direction.mult(segmentParameter, compVec1), compVec1); } else { origin.add(direction.mult(extent, compVec1), compVec1); } } else { origin.subtract(direction.mult(extent, compVec1), compVec1); } compVec1.subtractLocal(point); float len = compVec1.lengthSquared(); vars.release(); return len; }
protected Vector3f getNormal(float x, float z, Vector2f xz) { x-=0.5f; z-=0.5f; float col = FastMath.floor(x); float row = FastMath.floor(z); boolean onX = false; if(1 - (x - col)-(z - row) < 0) // what triangle to interpolate on onX = true; // v1--v2 ^ // | / | | // | / | | // v3--v4 | Z // | // <-------Y // X Vector3f n1 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.ceil(z)); Vector3f n2 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.ceil(z)); Vector3f n3 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.floor(z)); Vector3f n4 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.floor(z)); return n1.add(n2).add(n3).add(n4).normalize(); }
public void simpleUpdate( float tpf ) { if( scroll.lengthSquared() != 0 ) { scrollRoot.move(scroll.mult(tpf)); } if( zoom.lengthSquared() != 0 ) { Vector3f current = testRoot.getLocalScale(); testRoot.setLocalScale(current.add(zoom.mult(tpf))); } }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f compVec1 = vars.vect1; Vector3f compVec2 = vars.vect2; point.subtract(origin, compVec1); float lineParameter = direction.dot(compVec1); origin.add(direction.mult(lineParameter, compVec2), compVec2); compVec2.subtract(point, compVec1); float len = compVec1.lengthSquared(); vars.release(); return len; }
/** * Stores the skinning transform in the specified Matrix4f. * The skinning transform applies the animation of the bone to a vertex. * * This assumes that the world transforms for the entire bone hierarchy * have already been computed, otherwise this method will return undefined * results. * * @param outTransform */ void getOffsetTransform(Matrix4f outTransform, Quaternion tmp1, Vector3f tmp2, Vector3f tmp3, Matrix3f tmp4) { // Computing scale Vector3f scale = modelScale.mult(modelBindInverseScale, tmp3); // Computing rotation Quaternion rotate = modelRot.mult(modelBindInverseRot, tmp1); // Computing translation // Translation depend on rotation and scale Vector3f translate = modelPos.add(rotate.mult(scale.mult(modelBindInversePos, tmp2), tmp2), tmp2); // Populating the matrix outTransform.setTransform(translate, scale, rotate.toRotationMatrix(tmp4)); }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f tempVa = vars.vect1, tempVb = vars.vect2; point.subtract(origin, tempVa); float rayParam = direction.dot(tempVa); if (rayParam > 0) { origin.add(direction.mult(rayParam, tempVb), tempVb); } else { tempVb.set(origin); rayParam = 0.0f; } tempVb.subtract(point, tempVa); float len = tempVa.lengthSquared(); vars.release(); return len; }
/** * Forcefully takes over Camera adding functionality and placing it behind the character * @param tpf Tickes Per Frame */ private void camTakeOver(float tpf) { cam.setLocation(player.getLocalTranslation().add(-8, 2, 0)); cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y); Quaternion rot = new Quaternion(); rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z); cam.setRotation(cam.getRotation().mult(rot)); camAngle *= FastMath.pow(.99f, fpsRate * tpf); }
@Override public void simpleUpdate(float tpf) { float move = tpf * 1; boolean colliding = false; List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0))); for (PhysicsSweepTestResult result : sweepTest) { if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) { PhysicsCollisionObject collisionObject = result.getCollisionObject(); fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString()); colliding = true; } } if (!colliding) { // if the sweep is clear then move the spatial capsule.move(move, 0, 0); } } }
private void scaleAsChild(float percent, Vector3f dist) { float childScale = mapValue(percent, 1.0f / poiRadius, 1); Vector3f distToHorizon = dist.normalize(); Vector3f scaledDistToHorizon = distToHorizon.mult(childScale * poiRadius); Vector3f rootOff = dist.add(scaledDistToHorizon); debugTools.setBlueArrow(Vector3f.ZERO, rootOff); getRootNode().setLocalScale(childScale); getRootNode().setLocalTranslation(rootOff); //prepare player position already Vector3f playerPosition = dist.normalize().mult(-poiRadius); setPlayerPosition(playerPosition); }
/** * Compute bounds from an array of points * * @param pts * @param transform * @return */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transform) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); Vector3f temp = new Vector3f(); for (int i = 0; i < pts.length; i++) { transform.transformVector(pts[i], temp); min.minLocal(temp); max.maxLocal(temp); } Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); return new BoundingBox(center, extent.x, extent.y, extent.z); }
private void bulletControl() { shootingChannel.setAnim("Dodge", 0.1f); shootingChannel.setLoopMode(LoopMode.DontLoop); Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(matBullet); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(character.getPhysicsLocation().add(cam.getDirection().mult(5))); RigidBodyControl bulletControl = new BombControl(bulletCollisionShape, 1); bulletControl.setCcdMotionThreshold(0.1f); bulletControl.setLinearVelocity(cam.getDirection().mult(80)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletControl); }