com.jme3.bullet.objects.VehicleWheel Java Examples

The following examples show how to use com.jme3.bullet.objects.VehicleWheel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoveVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        for (int i = 0, length = control.getNumWheels(); i < length; i++) {
            final VehicleWheel wheel = control.getWheel(i);
            if (wheel == createdWheel) {
                control.removeWheel(i);
                break;
            }
        }

        final VehicleWheel toRemove = notNull(createdWheel);

        this.createdWheel = null;

        EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxRemovedChild(control, toRemove));
    });
}
 
Example #2
Source File: AddVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        for (int i = 0, length = control.getNumWheels(); i < length; i++) {
            final VehicleWheel wheel = control.getWheel(i);
            if (wheel == createdWheel) {
                control.removeWheel(i);
                break;
            }
        }

        final VehicleWheel toRemove = notNull(createdWheel);

        this.createdWheel = null;

        EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxRemovedChild(control, toRemove));
    });
}
 
Example #3
Source File: PrimitiveTreeNodeFactory.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public <T, V extends TreeNode<T>> @Nullable V createFor(@Nullable final T element, final long objectId) {

    if (element instanceof Vector3f) {
        return unsafeCast(new PositionTreeNode((Vector3f) element, objectId));
    } else if (element instanceof VertexBuffer) {
        return unsafeCast(new VertexBufferTreeNode((VertexBuffer) element, objectId));
    } else if (element instanceof Buffer) {
        return unsafeCast(new BufferTreeNode((Buffer) element, objectId));
    } else if (element instanceof VehicleWheel) {
        return unsafeCast(new VehicleWheelTreeNode((VehicleWheel) element, objectId));
    } else if (element instanceof MotionPath) {
        return unsafeCast(new MotionPathTreeNode((MotionPath) element, objectId));
    }

    return null;
}
 
Example #4
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * When set to true, the physics coordinates will be applied to the local
 * translation of the Spatial
 * @param applyPhysicsLocal
 */
public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {
    motionState.setApplyPhysicsLocal(applyPhysicsLocal);
    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel vehicleWheel = it.next();
        vehicleWheel.setApplyLocal(applyPhysicsLocal);
    }
}
 
Example #5
Source File: JmeVehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = Sheet.createDefault();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("VehicleWheel");
    set.setName(Light.class.getName());
    VehicleWheel obj = wheel;
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getLocation", "Location"));
    set.put(makeProperty(obj, Vector3f.class, "getAxle", "Axis"));
    set.put(makeProperty(obj, Vector3f.class, "getDirection", "Direction"));
    set.put(makeProperty(obj, boolean.class, "isFrontWheel", "setFrontWheel", "Front Wheel"));
    set.put(makeProperty(obj, float.class, "getFrictionSlip", "setFrictionSlip", "Friction Slip"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionForce", "setMaxSuspensionForce", "Max Suspension Force"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionTravelCm", "setMaxSuspensionTravelCm", "Max Suspension Travel"));
    set.put(makeProperty(obj, float.class, "getRadius", "setRadius", "Radius"));
    set.put(makeProperty(obj, float.class, "getRestLength", "setRestLength", "Rest Length"));
    set.put(makeProperty(obj, float.class, "getRollInfluence", "setRollInfluence", "Roll Influence"));
    set.put(makeProperty(obj, float.class, "getSuspensionStiffness", "setSuspensionStiffness", "Suspension Stiffness"));
    set.put(makeProperty(obj, float.class, "getWheelsDampingCompression", "setWheelsDampingCompression", "Damping Compression"));
    set.put(makeProperty(obj, float.class, "getWheelsDampingRelaxation", "setWheelsDampingRelaxation", "Damping Relaxation"));

    sheet.put(set);
    return sheet;

}
 
Example #6
Source File: JmeVehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JmeVehicleWheel(VehicleControl vehicle, VehicleWheel wheel) {
    super(Children.LEAF);
    this.vehicle=vehicle;
    this.wheel = wheel;
    getLookupContents().add(wheel);
    getLookupContents().add(this);
    setName("Wheel");
}
 
Example #7
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Node[] createNodes(Object key) {
    if (key instanceof VehicleWheel) {
        VehicleWheel assetKey = (VehicleWheel) key;
        return new Node[]{new JmeVehicleWheel(control, assetKey)};
    }
    return null;
}
 
Example #8
Source File: SuspensionSettings.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void applyData(VehicleWheel wheel){
    wheel.setRadius(getRadius());
    wheel.setFrictionSlip(getFriction());
    wheel.setRollInfluence(getRollInfluence());
    wheel.setMaxSuspensionForce(getMaxForce());
    wheel.setSuspensionStiffness(getStiffness());
    wheel.setWheelsDampingCompression(getCompression());
    wheel.setWheelsDampingRelaxation(getRelease());
}
 
Example #9
Source File: SuspensionSettings.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SuspensionSettings(VehicleWheel wheel) {
    this.direction.set(wheel.getDirection());
    this.axle.set(wheel.getAxle());
    this.frontWheel = wheel.isFrontWheel();
    this.radius = wheel.getRadius();
    this.restLength = wheel.getRestLength();
    this.maxForce = wheel.getMaxSuspensionForce();
    this.stiffness = wheel.getSuspensionStiffness();
    this.rollInfluence = wheel.getRollInfluence();
    this.compression = wheel.getWheelsDampingCompression();
    this.release = wheel.getWheelsDampingRelaxation();
    this.friction = wheel.getFrictionSlip();
}
 
Example #10
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void doApplyWheelData(VehicleControl control, int wheels, SuspensionSettings settings) {
        for (int i = 0; i < control.getNumWheels(); i++) {
            VehicleWheel wheel = control.getWheel(i);
            switch (wheels) {
                case 0:
                    break;
                case 1:
                    if (!wheel.isFrontWheel()) {
                        continue;
                    }
                    break;
                case 2:
                    if (wheel.isFrontWheel()) {
                        continue;
                    }
                    break;
            }
            wheel.setRestLength(settings.getRestLength());
            wheel.setMaxSuspensionForce(settings.getMaxForce());
            wheel.setSuspensionStiffness(settings.getStiffness());
            wheel.setRollInfluence(settings.getRollInfluence());
            wheel.setWheelsDampingCompression(settings.getCompression());
            wheel.setWheelsDampingRelaxation(settings.getRelease());
//            wheel.setRadius(settings.getRadius());
            wheel.setFrictionSlip(settings.getFriction());
        }
    }
 
Example #11
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public VehicleEditorController(JmeSpatial jmeRootNode, BinaryModelDataObject currentFileObject) {
    this.jmeRootNode = jmeRootNode;
    this.currentFileObject = currentFileObject;
    rootNode = jmeRootNode.getLookup().lookup(Node.class);
    toolsNode = new Node("ToolsNode");
    toolController = new SceneToolController(toolsNode, currentFileObject.getLookup().lookup(ProjectAssetManager.class));
    toolController.setShowSelection(true);
    result = Utilities.actionsGlobalContext().lookupResult(JmeSpatial.class);
    result.addLookupListener(this);
    toolsNode.addLight(new DirectionalLight());
    Node track = (Node) new DesktopAssetManager(true).loadModel("Models/Racetrack/Raceway.j3o");
    track.getChild("Grass").getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(30, -1, 0));
    track.getChild("Grass").getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI * 0.68f, Vector3f.UNIT_Y).toRotationMatrix());
    track.getChild("Road").getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(30, 0, 0));
    track.getChild("Road").getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI * 0.68f, Vector3f.UNIT_Y).toRotationMatrix());
    toolsNode.attachChild(track);
    bulletState = new BulletAppState();

    result2 = Utilities.actionsGlobalContext().lookupResult(VehicleWheel.class);
    LookupListener listener = new LookupListener() {

        public void resultChanged(LookupEvent ev) {
            for (Iterator<? extends VehicleWheel> it = result2.allInstances().iterator(); it.hasNext();) {
                VehicleWheel wheel = it.next();
                toolController.updateSelection(wheel.getWheelSpatial());
            }
        }
    };
    result2.addLookupListener(listener);
}
 
Example #12
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * When set to true, the physics coordinates will be applied to the local
 * translation of the Spatial
 * @param applyPhysicsLocal
 */
public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {
    motionState.setApplyPhysicsLocal(applyPhysicsLocal);
    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel vehicleWheel = it.next();
        vehicleWheel.setApplyLocal(applyPhysicsLocal);
    }
}
 
Example #13
Source File: RemoveVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
public RemoveVehicleWheelOperation(@NotNull final VehicleControl control, @NotNull final VehicleWheel wheel) {
    this.control = control;
    this.connectionPoint = wheel.getLocation();
    this.direction = wheel.getDirection();
    this.axle = wheel.getAxle();
    this.restLength = wheel.getRestLength();
    this.wheelRadius = wheel.getRadius();
    this.isFrontWheel = wheel.isFrontWheel();
    this.createdWheel = wheel;
}
 
Example #14
Source File: VehicleControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Alter whether physics-space coordinates should match the spatial's local
 * coordinates.
 *
 * @param applyPhysicsLocal true&rarr;match local coordinates,
 * false&rarr;match world coordinates (default=false)
 */
public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {
    motionState.setApplyPhysicsLocal(applyPhysicsLocal);
    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel vehicleWheel = it.next();
        vehicleWheel.setApplyLocal(applyPhysicsLocal);
    }
}
 
Example #15
Source File: BulletVehicleDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, &ge;0)
 */
@Override
protected void controlUpdate(float tpf) {
    for (int i = 0; i < body.getNumWheels(); i++) {
        VehicleWheel physicsVehicleWheel = body.getWheel(i);
        Vector3f location = physicsVehicleWheel.getLocation().clone();
        Vector3f direction = physicsVehicleWheel.getDirection().clone();
        Vector3f axle = physicsVehicleWheel.getAxle().clone();
        float restLength = physicsVehicleWheel.getRestLength();
        float radius = physicsVehicleWheel.getRadius();

        Geometry locGeom = (Geometry) suspensionNode.getChild("WheelLocationDebugShape" + i);
        Geometry dirGeom = (Geometry) suspensionNode.getChild("WheelDirectionDebugShape" + i);
        Geometry axleGeom = (Geometry) suspensionNode.getChild("WheelAxleDebugShape" + i);
        Geometry wheelGeom = (Geometry) suspensionNode.getChild("WheelRadiusDebugShape" + i);

        Arrow locArrow = (Arrow) locGeom.getMesh();
        locArrow.setArrowExtent(location);
        Arrow axleArrow = (Arrow) axleGeom.getMesh();
        axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
        wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = (Arrow) dirGeom.getMesh();
        dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));

        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.addLocal(direction));
        wheelGeom.setLocalTranslation(location);
        i++;
    }
    applyPhysicsTransform(body.getPhysicsLocation(location), body.getPhysicsRotation(rotation));
}
 
Example #16
Source File: BulletVehicleDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createVehicle() {
    suspensionNode.detachAllChildren();
    for (int i = 0; i < body.getNumWheels(); i++) {
        VehicleWheel physicsVehicleWheel = body.getWheel(i);
        Vector3f location = physicsVehicleWheel.getLocation().clone();
        Vector3f direction = physicsVehicleWheel.getDirection().clone();
        Vector3f axle = physicsVehicleWheel.getAxle().clone();
        float restLength = physicsVehicleWheel.getRestLength();
        float radius = physicsVehicleWheel.getRadius();

        Arrow locArrow = new Arrow(location);
        Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
        Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
        Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
        Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
        Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.add(direction));
        wheelGeom.setLocalTranslation(location.add(direction));
        locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        suspensionNode.attachChild(locGeom);
        suspensionNode.attachChild(dirGeom);
        suspensionNode.attachChild(axleGeom);
        suspensionNode.attachChild(wheelGeom);
    }
}
 
Example #17
Source File: RemoveVehicleWheelAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void process() {

    final TreeNode<?> node = getNode();
    final Object element = node.getElement();
    final TreeNode<?> nodeParent = notNull(node.getParent());
    final VehicleControl vehicleControl = (VehicleControl) nodeParent.getElement();
    final VehicleWheel vehicleWheel = (VehicleWheel) element;

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new RemoveVehicleWheelOperation(vehicleControl, vehicleWheel));
}
 
Example #18
Source File: VehicleWheelTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FromAnyThread
public @NotNull String getName() {
    final VehicleWheel element = getElement();
    final Spatial wheelSpatial = element.getWheelSpatial();
    return wheelSpatial != null ? Messages.MODEL_FILE_EDITOR_NODE_WHEEL + " [" + wheelSpatial.getName() + "]" :
            Messages.MODEL_FILE_EDITOR_NODE_WHEEL;
}
 
Example #19
Source File: AddVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        final VehicleWheel vehicleWheel = control.addWheel(connectionPoint, direction, axle, restLength,
                wheelRadius, isFrontWheel);

        this.createdWheel = vehicleWheel;

        EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxAddedChild(control, vehicleWheel, -1, true));
    });
}
 
Example #20
Source File: RemoveVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
    EXECUTOR_MANAGER.addJmeTask(() -> {

        final VehicleWheel vehicleWheel = control.addWheel(connectionPoint, direction, axle, restLength,
                wheelRadius, isFrontWheel);

        this.createdWheel = vehicleWheel;

        EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxAddedChild(control, vehicleWheel, -1, false));
    });
}
 
Example #21
Source File: VehicleControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a shallow clone for the JME cloner.
 *
 * @return a new control (not null)
 */
@Override
public Object jmeClone() {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setContactResponse(isContactResponse());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());

    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());

    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());

        // Copy the wheel spatial reference directly for now.  They'll
        // get fixed up in the cloneFields() method
        newWheel.setWheelSpatial(wheel.getWheelSpatial());
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());
    control.setEnabled(isEnabled());
    
    control.spatial = spatial;
    return control;
}
 
Example #22
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Control cloneForSpatial(Spatial spatial) {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());

    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());

    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());

        //TODO: bad way finding children!
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
            if (wheelSpat != null) {
                newWheel.setWheelSpatial(wheelSpat);
            }
        }
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());

    control.setSpatial(spatial);
    return control;
}
 
Example #23
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void render(RenderManager rm, ViewPort vp) {
    if (enabled && space != null && space.getDebugManager() != null) {
        if (debugShape == null) {
            attachDebugShape(space.getDebugManager());
        }
        Node debugNode = (Node) debugShape;
        debugShape.setLocalTranslation(spatial.getWorldTranslation());
        debugShape.setLocalRotation(spatial.getWorldRotation());
        int i = 0;
        for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
            VehicleWheel physicsVehicleWheel = it.next();
            Vector3f location = physicsVehicleWheel.getLocation().clone();
            Vector3f direction = physicsVehicleWheel.getDirection().clone();
            Vector3f axle = physicsVehicleWheel.getAxle().clone();
            float restLength = physicsVehicleWheel.getRestLength();
            float radius = physicsVehicleWheel.getRadius();

            Geometry locGeom = (Geometry) debugNode.getChild("WheelLocationDebugShape" + i);
            Geometry dirGeom = (Geometry) debugNode.getChild("WheelDirectionDebugShape" + i);
            Geometry axleGeom = (Geometry) debugNode.getChild("WheelAxleDebugShape" + i);
            Geometry wheelGeom = (Geometry) debugNode.getChild("WheelRadiusDebugShape" + i);

            Arrow locArrow = (Arrow) locGeom.getMesh();
            locArrow.setArrowExtent(location);
            Arrow axleArrow = (Arrow) axleGeom.getMesh();
            axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
            Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
            wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
            Arrow dirArrow = (Arrow) dirGeom.getMesh();
            dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));

            dirGeom.setLocalTranslation(location);
            axleGeom.setLocalTranslation(location.addLocal(direction));
            wheelGeom.setLocalTranslation(location);
            i++;
        }
        debugShape.updateLogicalState(0);
        debugShape.updateGeometricState();
        rm.renderScene(debugShape, vp);
    }
}
 
Example #24
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Control cloneForSpatial(Spatial spatial) {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());

    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());

    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());

        //TODO: bad way finding children!
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
            if (wheelSpat != null) {
                newWheel.setWheelSpatial(wheelSpat);
            }
        }
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());

    control.setSpatial(spatial);
    return control;
}
 
Example #25
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void render(RenderManager rm, ViewPort vp) {
    if (enabled && space != null && space.getDebugManager() != null) {
        if (debugShape == null) {
            attachDebugShape(space.getDebugManager());
        }
        Node debugNode = (Node) debugShape;
        debugShape.setLocalTranslation(spatial.getWorldTranslation());
        debugShape.setLocalRotation(spatial.getWorldRotation());
        int i = 0;
        for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
            VehicleWheel physicsVehicleWheel = it.next();
            Vector3f location = physicsVehicleWheel.getLocation().clone();
            Vector3f direction = physicsVehicleWheel.getDirection().clone();
            Vector3f axle = physicsVehicleWheel.getAxle().clone();
            float restLength = physicsVehicleWheel.getRestLength();
            float radius = physicsVehicleWheel.getRadius();

            Geometry locGeom = (Geometry) debugNode.getChild("WheelLocationDebugShape" + i);
            Geometry dirGeom = (Geometry) debugNode.getChild("WheelDirectionDebugShape" + i);
            Geometry axleGeom = (Geometry) debugNode.getChild("WheelAxleDebugShape" + i);
            Geometry wheelGeom = (Geometry) debugNode.getChild("WheelRadiusDebugShape" + i);

            Arrow locArrow = (Arrow) locGeom.getMesh();
            locArrow.setArrowExtent(location);
            Arrow axleArrow = (Arrow) axleGeom.getMesh();
            axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
            Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
            wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
            Arrow dirArrow = (Arrow) dirGeom.getMesh();
            dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));

            dirGeom.setLocalTranslation(location);
            axleGeom.setLocalTranslation(location.addLocal(direction));
            wheelGeom.setLocalTranslation(location);
            i++;
        }
        debugShape.updateLogicalState(0);
        debugShape.updateGeometricState();
        rm.renderScene(debugShape, vp);
    }
}
 
Example #26
Source File: VehicleWheelTreeNode.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public VehicleWheelTreeNode(@NotNull final VehicleWheel element, final long objectId) {
    super(element, objectId);
}
 
Example #27
Source File: JmeVehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class getExplorerObjectClass() {
    return VehicleWheel.class;
}