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();
}
}
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);
}
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;
}
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;
}
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());
}
}
Aggregations