Search in sources :

Example 1 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class BoundingSphere method collideWith.

public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof Ray) {
        Ray ray = (Ray) other;
        return collideWithRay(ray, results);
    } else if (other instanceof Triangle) {
        Triangle t = (Triangle) other;
        return collideWithTri(t, results);
    } else if (other instanceof BoundingVolume) {
        if (intersects((BoundingVolume) other)) {
            CollisionResult result = new CollisionResult();
            results.addCollision(result);
            return 1;
        }
        return 0;
    } else if (other instanceof Spatial) {
        return ((Spatial) other).collideWith(this, results);
    } else {
        throw new UnsupportedCollisionException();
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Spatial(com.jme3.scene.Spatial) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Example 2 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class AnimationEvent method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    if (im.getFormatVersion() == 0) {
        modelName = ic.readString("modelName", "");
    }
    //FIXME always the same issue, because of the clonning of assets, this won't work
    //we have to somehow store userdata in the spatial and then recurse the 
    //scene sub scenegraph to find the correct instance of the model
    //This brings a reflaxion about the cinematic being an appstate, 
    //shouldn't it be a control over the scene
    // this would allow to use the cloneForSpatial method and automatically 
    //rebind cloned references of original objects.
    //for now as nobody probably ever saved a cinematic, this is not a critical issue
    model = (Spatial) ic.readSavable("model", null);
    animationName = ic.readString("animationName", "");
    blendTime = ic.readFloat("blendTime", 0f);
    channelIndex = ic.readInt("channelIndex", 0);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 3 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class MotionPath method interpolatePath.

/**
     * interpolate the path giving the time since the beginning and the motionControl     
     * this methods sets the new localTranslation to the spatial of the MotionEvent control.
     * @param time the time since the animation started
     * @param control the control over the moving spatial
     */
public float interpolatePath(float time, MotionEvent control, float tpf) {
    float traveledDistance = 0;
    TempVars vars = TempVars.get();
    Vector3f temp = vars.vect1;
    Vector3f tmpVector = vars.vect2;
    Vector2f v = vars.vect2d;
    //computing traveled distance according to new time
    traveledDistance = time * (getLength() / control.getInitialDuration());
    //getting waypoint index and current value from new traveled distance
    v = getWayPointIndexForDistance(traveledDistance, v);
    //setting values
    control.setCurrentWayPoint((int) v.x);
    control.setCurrentValue(v.y);
    //interpolating new position
    getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
    if (control.needsDirection()) {
        tmpVector.set(temp);
        control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
    }
    checkWayPoint(control, tpf);
    control.getSpatial().setLocalTranslation(temp);
    vars.release();
    return traveledDistance;
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 4 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class AudioTrack method findAudio.

/**    
     * recursive function responsible for finding the newly cloned AudioNode
     *
     * @param spat
     * @return
     */
private AudioNode findAudio(Spatial spat) {
    if (spat instanceof AudioNode) {
        //spat is an AudioNode
        AudioNode em = (AudioNode) spat;
        //getting the UserData TrackInfo so check if it should be attached to this Track
        TrackInfo t = (TrackInfo) em.getUserData("TrackInfo");
        if (t != null && t.getTracks().contains(this)) {
            return em;
        }
        return null;
    } else if (spat instanceof Node) {
        for (Spatial child : ((Node) spat).getChildren()) {
            AudioNode em = findAudio(child);
            if (em != null) {
                return em;
            }
        }
    }
    return null;
}
Also used : Spatial(com.jme3.scene.Spatial) AudioNode(com.jme3.audio.AudioNode) Node(com.jme3.scene.Node) AudioNode(com.jme3.audio.AudioNode)

Example 5 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method collideWith.

@Override
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof Ray) {
        Ray ray = (Ray) other;
        return collideWithRay(ray, results);
    } else if (other instanceof Triangle) {
        Triangle t = (Triangle) other;
        if (intersects(t.get1(), t.get2(), t.get3())) {
            CollisionResult r = new CollisionResult();
            results.addCollision(r);
            return 1;
        }
        return 0;
    } else if (other instanceof BoundingVolume) {
        if (intersects((BoundingVolume) other)) {
            CollisionResult r = new CollisionResult();
            results.addCollision(r);
            return 1;
        }
        return 0;
    } else if (other instanceof Spatial) {
        return ((Spatial) other).collideWith(this, results);
    } else {
        throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Spatial(com.jme3.scene.Spatial) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Aggregations

Spatial (com.jme3.scene.Spatial)123 Vector3f (com.jme3.math.Vector3f)74 Node (com.jme3.scene.Node)56 Geometry (com.jme3.scene.Geometry)50 DirectionalLight (com.jme3.light.DirectionalLight)46 Material (com.jme3.material.Material)39 Quaternion (com.jme3.math.Quaternion)34 FilterPostProcessor (com.jme3.post.FilterPostProcessor)17 Box (com.jme3.scene.shape.Box)17 KeyTrigger (com.jme3.input.controls.KeyTrigger)15 AmbientLight (com.jme3.light.AmbientLight)14 ColorRGBA (com.jme3.math.ColorRGBA)14 Camera (com.jme3.renderer.Camera)13 Sphere (com.jme3.scene.shape.Sphere)13 Texture (com.jme3.texture.Texture)12 TempVars (com.jme3.util.TempVars)12 InputCapsule (com.jme3.export.InputCapsule)11 ActionListener (com.jme3.input.controls.ActionListener)11 AnimControl (com.jme3.animation.AnimControl)10 OutputCapsule (com.jme3.export.OutputCapsule)9