Java源码示例:com.jme3.math.Vector3f

示例1
@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);

    capsule.write(getMass(), "mass", 1.0f);

    capsule.write(getGravity(), "gravity", Vector3f.ZERO);
    capsule.write(getFriction(), "friction", 0.5f);
    capsule.write(getRestitution(), "restitution", 0);
    capsule.write(getAngularFactor(), "angularFactor", 1);
    capsule.write(kinematic, "kinematic", false);

    capsule.write(getLinearDamping(), "linearDamping", 0);
    capsule.write(getAngularDamping(), "angularDamping", 0);
    capsule.write(getLinearSleepingThreshold(), "linearSleepingThreshold", 0.8f);
    capsule.write(getAngularSleepingThreshold(), "angularSleepingThreshold", 1.0f);

    capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0);
    capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0);

    capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f());
    capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f());

    capsule.writeSavableArrayList(joints, "joints", null);
}
 
示例2
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule capsule = im.getCapsule(this);
    wheelSpatial = (Spatial) capsule.readSavable("wheelSpatial", null);
    frontWheel = capsule.readBoolean("frontWheel", false);
    location = (Vector3f) capsule.readSavable("wheelLocation", new Vector3f());
    direction = (Vector3f) capsule.readSavable("wheelDirection", new Vector3f());
    axle = (Vector3f) capsule.readSavable("wheelAxle", new Vector3f());
    suspensionStiffness = capsule.readFloat("suspensionStiffness", 20.0f);
    wheelsDampingRelaxation = capsule.readFloat("wheelsDampingRelaxation", 2.3f);
    wheelsDampingCompression = capsule.readFloat("wheelsDampingCompression", 4.4f);
    frictionSlip = capsule.readFloat("frictionSlip", 10.5f);
    rollInfluence = capsule.readFloat("rollInfluence", 1.0f);
    maxSuspensionTravelCm = capsule.readFloat("maxSuspensionTravelCm", 500f);
    maxSuspensionForce = capsule.readFloat("maxSuspensionForce", 6000f);
    radius = capsule.readFloat("wheelRadius", 0.5f);
    restLength = capsule.readFloat("restLength", 1f);
}
 
示例3
private void createFlash(){
    flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
    flash.setSelectRandomImage(true);
    flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1f / COUNT_FACTOR_F)));
    flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    flash.setStartSize(.1f);
    flash.setEndSize(3.0f);
    flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
    flash.setParticlesPerSec(0);
    flash.setGravity(0, 0, 0);
    flash.setLowLife(.2f);
    flash.setHighLife(.2f);
    flash.setInitialVelocity(new Vector3f(0, 5f, 0));
    flash.setVelocityVariation(1);
    flash.setImagesX(2);
    flash.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flash.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flash.setMaterial(mat);
    explosionEffect.attachChild(flash);
}
 
示例4
protected void attachSelectionShape(Spatial spat) {
    if (selectionShape != null) {
        selectionShape.removeFromParent();
        selectionShape = null;
    }
    selctionShapeOffset.set(Vector3f.ZERO);
    if (spat instanceof ParticleEmitter) {
        attachBoxSelection(spat);

    } else if (spat instanceof Geometry) {
        attachGeometrySelection((Geometry) spat);
    } else if (spat.getControl(PhysicsControl.class) != null) {
        attachPhysicsSelection(spat);
    } else {
        attachBoxSelection(spat);
    }
}
 
示例5
@Override
public void simpleInitApp() {
  /** Set up Physics Game */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
  /** Configure cam to look at scene */
  cam.setLocation(new Vector3f(0, 4f, 6f));
  cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);
  /** Initialize the scene, materials, inputs, and physics space */
  initInputs();
  initMaterials();
  initWall();
  initFloor();
  initCrossHairs();
}
 
示例6
/**
 * De-serialize this character from the specified importer, for example when
 * loading from a J3O file.
 *
 * @param e importer (not null)
 * @throws IOException from importer
 */
@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule capsule = e.getCapsule(this);
    stepHeight = capsule.readFloat("stepHeight", 1.0f);
    buildObject();
    setGravity(capsule.readFloat("gravity", 9.8f * 3));
    setMaxSlope(capsule.readFloat("maxSlope", 1.0f));
    setFallSpeed(capsule.readFloat("fallSpeed", 55.0f));
    setJumpSpeed(capsule.readFloat("jumpSpeed", 10.0f));
    setUpAxis(capsule.readInt("upAxis", 1));
    setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
    setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0));
    setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f()));
}
 
示例7
@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}
 
示例8
protected void attachBoxSelection(Spatial geom) {
    BoundingVolume bound = geom.getWorldBound();
    if (bound instanceof BoundingBox) {
        BoundingBox bbox = (BoundingBox) bound;
        Vector3f extent = new Vector3f();
        bbox.getExtent(extent);
        WireBox wireBox = new WireBox();
        wireBox.fromBoundingBox(bbox);
        selctionShapeOffset.set(bbox.getCenter()).subtractLocal(geom.getWorldTranslation());
        Geometry selectionGeometry = new Geometry("selection_geometry_sceneviewer", wireBox);
        selectionGeometry.setMaterial(blueMat);
        selectionGeometry.setLocalTransform(geom.getWorldTransform());
        selectionGeometry.setLocalTranslation(bbox.getCenter());
        toolsNode.attachChild(selectionGeometry);
        selectionShape = selectionGeometry;

    }
}
 
示例9
/**
 * This checks if the character can go from ducked to unducked state by
 * doing a ray test.
 */
protected boolean checkCanUnDuck() {
    TempVars vars = TempVars.get();
    Vector3f location = vars.vect1;
    Vector3f rayVector = vars.vect2;
    location.set(localUp).multLocal(FastMath.ZERO_TOLERANCE).addLocal(this.location);
    rayVector.set(localUp).multLocal(height + FastMath.ZERO_TOLERANCE).addLocal(location);
    List<PhysicsRayTestResult> results = space.rayTest(location, rayVector);
    vars.release();
    for (PhysicsRayTestResult physicsRayTestResult : results) {
        if (!physicsRayTestResult.getCollisionObject().equals(rigidBody)) {
            return false;
        }
    }
    return true;
}
 
示例10
private static void doTransformTangents(FloatBuffer inBuf, int offset, int components, FloatBuffer outBuf, Matrix4f transform) {
    Vector3f tan = new Vector3f();

    // offset is given in element units
    // convert to be in component units
    offset *= components;

    for (int i = 0; i < inBuf.limit() / components; i++) {
        tan.x = inBuf.get(i * components + 0);
        tan.y = inBuf.get(i * components + 1);
        tan.z = inBuf.get(i * components + 2);

        transform.multNormal(tan, tan);

        outBuf.put(offset + i * components + 0, tan.x);
        outBuf.put(offset + i * components + 1, tan.y);
        outBuf.put(offset + i * components + 2, tan.z);

        if (components == 4) {
            outBuf.put(offset + i * components + 3, inBuf.get(i * components + 3));
        }
    }
}
 
示例11
private void reset() {
    // Reset the pickups
    for(Spatial pickUp : pickUps.getChildren()) {
        GhostControl pickUpControl = pickUp.getControl(GhostControl.class);
        if(pickUpControl != null) {
            pickUpControl.setEnabled(true);
        }
        pickUp.setLocalScale(1.0f);
    }
    // Reset the player
    player.setPhysicsLocation(PLAYER_START.clone());
    player.setAngularVelocity(Vector3f.ZERO.clone());
    player.setLinearVelocity(Vector3f.ZERO.clone());
    // Reset the score
    score = 0;
    // Reset the message
    messageText.setLocalScale(0.0f);
}
 
示例12
public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Mesh teaMesh = teaGeom.getMesh();
    ModelConverter.generateStrips(teaMesh, true, false, 24, 0);

    // show normals as material
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

    for (int y = -10; y < 10; y++){
        for (int x = -10; x < 10; x++){
            Geometry teaClone = new Geometry("teapot", teaMesh);
            teaClone.setMaterial(mat);

            teaClone.setLocalTranslation(x * .5f, 0, y * .5f);
            teaClone.setLocalScale(.5f);

            rootNode.attachChild(teaClone);
        }
    }

    cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
 
示例13
private void moveUndo(final Spatial spatial, final Vector3f before, final Vector3f after, final AbstractSceneExplorerNode parentNode) {
    if (spatial != null && before != null) {
        Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() {
            
            @Override
            public void sceneUndo() throws CannotUndoException {
                //undo stuff here
                spatial.setLocalTranslation(before);
            }
            
            @Override
            public void sceneRedo() throws CannotRedoException {
                //redo stuff here
                spatial.setLocalTranslation(after);
            }
        });
    }
}
 
示例14
/**
 * @see AbstractSteeringBehavior#calculateSteering()
 */
@Override
protected Vector3f calculateRawSteering() {
    // steering accumulator and count of neighbors, both initially zero
    Vector3f steering = new Vector3f();
    int realNeighbors = 0;

    // for each of the other vehicles...
    for (GameEntity neighbour : this.neighbours) {
        if (this.agent.inBoidNeighborhood(neighbour, this.agent.getRadius() * 3, this.maxDistance, this.maxAngle)) {
            // accumulate sum of neighbor's positions
            steering = steering.add(neighbour.getLocalTranslation());
            realNeighbors++;
        }
    }

    // divide by neighbors, subtract off current position to get error-correcting direction
    if (realNeighbors > 0) {
        steering = steering.divide(realNeighbors);
        steering = this.agent.offset(steering);
    }
    return steering;
}
 
示例15
@Override
public void simpleUpdate(float tpf) {
  time += tpf;

  if (time > nextTime) {
    Vector3f v = new Vector3f();
    v.setX(FastMath.nextRandomFloat());
    v.setY(FastMath.nextRandomFloat());
    v.setZ(FastMath.nextRandomFloat());
    v.multLocal(40, 2, 40);
    v.subtractLocal(20, 1, 20);

    audioSource.setLocalTranslation(v);
    audioSource.playInstance();
    time = 0;
    nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
  }
}
 
示例16
/**
 * Gets the array or vectors representing the 8 vertices of the box.
 *
 * @return a newly created array of vertex vectors.
 */
protected final Vector3f[] computeVertices() {
    Vector3f[] axes = {
            Vector3f.UNIT_X.mult(xExtent),
            Vector3f.UNIT_Y.mult(yExtent),
            Vector3f.UNIT_Z.mult(zExtent)
    };
    return new Vector3f[] {
            center.subtract(axes[0]).subtractLocal(axes[1]).subtractLocal(axes[2]),
            center.add(axes[0]).subtractLocal(axes[1]).subtractLocal(axes[2]),
            center.add(axes[0]).addLocal(axes[1]).subtractLocal(axes[2]),
            center.subtract(axes[0]).addLocal(axes[1]).subtractLocal(axes[2]),
            center.add(axes[0]).subtractLocal(axes[1]).addLocal(axes[2]),
            center.subtract(axes[0]).subtractLocal(axes[1]).addLocal(axes[2]),
            center.add(axes[0]).addLocal(axes[1]).addLocal(axes[2]),
            center.subtract(axes[0]).addLocal(axes[1]).addLocal(axes[2])
    };
}
 
示例17
@Override
public Vector3f getPosition() {
    // the hmdPose comes in rotated funny, fix that here
    hmdPose.toTranslationVector(posStore);
    posStore.x = -posStore.x;
    posStore.z = -posStore.z;
    return posStore;
}
 
示例18
@Override
@JmeThread
protected @NotNull Vector3f getScaleAxis(@NotNull final Transform transform,
                                         @NotNull final PickedAxis pickedAxis,
                                         @NotNull final Camera camera) {

    final LocalObjects local = LocalObjects.get();

    if (pickedAxis == PickedAxis.Y) {
        return getUp(camera.getRotation(), local.nextVector());
    } else if (pickedAxis == PickedAxis.Z) {
        return getDirection(camera.getRotation(), local.nextVector());
    } else return getLeft(camera.getRotation(), local.nextVector());
}
 
示例19
@FxThread
private void build(@NotNull final CylinderCollisionShape shape, @NotNull final VBox container,
                   @NotNull final ModelChangeConsumer changeConsumer) {

    final Vector3f halfExtents = shape.getHalfExtents();
    final float margin = shape.getMargin();
    final int axis = shape.getAxis();

    final DefaultSinglePropertyControl<ModelChangeConsumer, CylinderCollisionShape, Vector3f> halfExtentsControl =
            new DefaultSinglePropertyControl<>(halfExtents, Messages.MODEL_PROPERTY_HALF_EXTENTS, changeConsumer);

    halfExtentsControl.setSyncHandler(CylinderCollisionShape::getHalfExtents);
    halfExtentsControl.setToStringFunction(Vector3f::toString);
    halfExtentsControl.setEditObject(shape);

    final DefaultSinglePropertyControl<ModelChangeConsumer, CylinderCollisionShape, Float> marginControl =
            new DefaultSinglePropertyControl<>(margin, Messages.MODEL_PROPERTY_MARGIN, changeConsumer);

    marginControl.setSyncHandler(CylinderCollisionShape::getMargin);
    marginControl.setToStringFunction(value -> Float.toString(value));
    marginControl.setEditObject(shape);

    final DefaultSinglePropertyControl<ModelChangeConsumer, CylinderCollisionShape, Integer> axisControl =
            new DefaultSinglePropertyControl<>(axis, Messages.MODEL_PROPERTY_AXIS, changeConsumer);

    axisControl.setSyncHandler(CylinderCollisionShape::getAxis);
    axisControl.setToStringFunction(value -> Integer.toString(value));
    axisControl.setEditObject(shape);

    FXUtils.addToPane(halfExtentsControl, container);
    FXUtils.addToPane(marginControl, container);
    FXUtils.addToPane(axisControl, container);
}
 
示例20
@Override
@FxThread
protected @NotNull EmitterShape createEmitterShape(@NotNull final VarTable vars) {
    final Vector3f center = vars.get(PROPERTY_CENTER);
    final float radius = vars.getFloat(PROPERTY_RADIUS);
    return new EmitterSphereShape(center, radius);
}
 
示例21
@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(angularUpperLimit, "angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY));
    capsule.write(angularLowerLimit, "angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY));
    capsule.write(linearUpperLimit, "linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY));
    capsule.write(linearLowerLimit, "linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY));
    int i = 0;
    for (Iterator<RotationalLimitMotor> it = rotationalMotors.iterator(); it.hasNext();) {
        RotationalLimitMotor rotationalLimitMotor = it.next();
        capsule.write(rotationalLimitMotor.getBounce(), "rotMotor" + i + "_Bounce", 0.0f);
        capsule.write(rotationalLimitMotor.getDamping(), "rotMotor" + i + "_Damping", 1.0f);
        capsule.write(rotationalLimitMotor.getERP(), "rotMotor" + i + "_ERP", 0.5f);
        capsule.write(rotationalLimitMotor.getHiLimit(), "rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY);
        capsule.write(rotationalLimitMotor.getLimitSoftness(), "rotMotor" + i + "_LimitSoftness", 0.5f);
        capsule.write(rotationalLimitMotor.getLoLimit(), "rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY);
        capsule.write(rotationalLimitMotor.getMaxLimitForce(), "rotMotor" + i + "_MaxLimitForce", 300.0f);
        capsule.write(rotationalLimitMotor.getMaxMotorForce(), "rotMotor" + i + "_MaxMotorForce", 0.1f);
        capsule.write(rotationalLimitMotor.getTargetVelocity(), "rotMotor" + i + "_TargetVelocity", 0);
        capsule.write(rotationalLimitMotor.isEnableMotor(), "rotMotor" + i + "_EnableMotor", false);
        i++;
    }
    capsule.write(getTranslationalLimitMotor().getAccumulatedImpulse(), "transMotor_AccumulatedImpulse", Vector3f.ZERO);
    capsule.write(getTranslationalLimitMotor().getDamping(), "transMotor_Damping", 1.0f);
    capsule.write(getTranslationalLimitMotor().getLimitSoftness(), "transMotor_LimitSoftness", 0.7f);
    capsule.write(getTranslationalLimitMotor().getLowerLimit(), "transMotor_LowerLimit", Vector3f.ZERO);
    capsule.write(getTranslationalLimitMotor().getRestitution(), "transMotor_Restitution", 0.5f);
    capsule.write(getTranslationalLimitMotor().getUpperLimit(), "transMotor_UpperLimit", Vector3f.ZERO);
}
 
示例22
/**
 * Set the models padding.
 *
 * @param padding the models padding.
 */
@FxThread
public void setPadding(@NotNull Vector3f padding) {
    final boolean changed = !padding.equals(getPadding());
    this.padding = padding;
    if (changed) notifyChange();
}
 
示例23
@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(direction, "direction", new Vector3f());
    oc.write(position, "position", new Vector3f());
    oc.write(spotInnerAngle, "spotInnerAngle", FastMath.QUARTER_PI / 8);
    oc.write(spotOuterAngle, "spotOuterAngle", FastMath.QUARTER_PI / 6);
    oc.write(spotRange, "spotRange", 100);
}
 
示例24
public Texture setupOffscreenView(){
    Camera offCamera = new Camera(512, 512);

    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);

    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);

    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    //setup framebuffer's texture
    Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);

    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setColorTexture(offTex);
    
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);

    // setup framebuffer's scene
    Box boxMesh = new Box(1, 1, 1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);

    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
    
    return offTex;
}
 
示例25
public void updateGeometry(){
    VertexBuffer vb = getBuffer(Type.Position);
    FloatBuffer posBuf = getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); i++){
        Bone bone = skeleton.getBone(i);
        Vector3f bonePos = bone.getModelSpacePosition();

        posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ());
    }
    posBuf.flip();
    vb.updateData(posBuf);

    updateBound();
}
 
示例26
@Override
public void simpleUpdate(float tpf) {
    if (timeToNextPrint > 0f) {
        timeToNextPrint -= tpf;
        return;
    }

    if (numFalling > 0) {
        Vector3f fallingLocation = falling[0].getWorldTranslation();
        System.out.printf("  falling[0] location(x=%f, z=%f)",
                fallingLocation.x, fallingLocation.z);
        /*
         * If an object is falling vertically, its X- and Z-coordinates 
         * should not change.
         */
    }
    if (numPendulums > 0) {
        Vector3f bobLocation = bobs[0].getWorldTranslation();
        Vector3f pivotLocation = pivots[0].getWorldTranslation();
        float distance = bobLocation.distance(pivotLocation);
        System.out.printf("  bob[0] distance=%f", distance);
        /*
         * If the hinge is working properly, the distance from the
         * pivot to the bob should remain roughly constant.
         */
    }
    System.out.println();
    timeToNextPrint = 1f;
}
 
示例27
private void init(int nbSplits, int shadowMapSize) {
    nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1);
    if (nbShadowMaps != nbSplits) {
        throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits);
    }
    splits = new ColorRGBA();
    splitsArray = new float[nbSplits + 1];
    shadowCam = new Camera(shadowMapSize, shadowMapSize);
    shadowCam.setParallelProjection(true);
    for (int i = 0; i < points.length; i++) {
        points[i] = new Vector3f();
    }
}
 
示例28
/**
 *  Returns the slider range value for the specified location
 *  in the slider's local coordinate system.  (For example,
 *  for world space location use slider.worldToLocal() first.)
 */
public double getValueForLocation( Vector3f loc ) {

    Vector3f relative = loc.subtract(range.getLocalTranslation());

    // Components always grow down from their location
    // so we'll invert y
    relative.y *= -1;
            
    Vector3f axisDir = axis.getDirection();
    double projection = relative.dot(axisDir);
    if( projection < 0 ) {
        if( axis == Axis.Y ) {
            return model.getMaximum();
        } else {
            return model.getMinimum();
        }
    }
    
    Vector3f rangeSize = range.getSize().clone();
     
    double rangeLength = rangeSize.dot(axisDir);
    projection = Math.min(projection, rangeLength);
    double part = projection / rangeLength;       
    double rangeDelta = model.getMaximum() - model.getMinimum();
    
    // For the y-axis, the slider is inverted from the direction
    // that the component's grow... so our part is backwards
    if( axis == Axis.Y ) {
        part = 1 - part;
    }
 
    return model.getMinimum() + rangeDelta * part;        
}
 
示例29
private void createCollisionMesh(Mesh mesh, Vector3f worldScale) {
    this.worldScale = worldScale;
    bulletMesh = Converter.convert(mesh);
    this.numVertices = bulletMesh.numVertices;
    this.numTriangles = bulletMesh.numTriangles;
    this.vertexStride = bulletMesh.vertexStride;
    this.triangleIndexStride = bulletMesh.triangleIndexStride;
    this.triangleIndexBase = bulletMesh.triangleIndexBase;
    this.vertexBase = bulletMesh.vertexBase;
    createShape();
}
 
示例30
public VehicleWheel(Vector3f location, Vector3f direction, Vector3f axle,
        float restLength, float radius, boolean frontWheel) {
    this.location.set(location);
    this.direction.set(direction);
    this.axle.set(axle);
    this.frontWheel = frontWheel;
    this.restLength = restLength;
    this.radius = radius;
}