use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class TestDepthStencil method simpleInitApp.
@Override
public void simpleInitApp() {
int w = settings.getWidth();
int h = settings.getHeight();
//setup framebuffer
fb = new FrameBuffer(w, h, 1);
Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
fb.setDepthBuffer(Format.Depth24Stencil8);
fb.setColorTexture(fbTex);
// setup framebuffer's scene
Sphere sphMesh = new Sphere(20, 20, 1);
Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
final Geometry sphere = new Geometry("sphere", sphMesh);
sphere.setMaterial(solidColor);
fbNode.attachChild(sphere);
sphere.addControl(new AbstractControl() {
@Override
protected void controlUpdate(float tpf) {
Material mat = sphere.getMaterial();
mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}
});
//setup main scene
Picture p = new Picture("Picture");
p.setPosition(0, 0);
p.setWidth(w);
p.setHeight(h);
p.setTexture(assetManager, fbTex, false);
rootNode.attachChild(p);
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
ActionListener acl = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("toggle") && keyPressed) {
if (enableStencil) {
enableStencil = false;
System.out.println("Stencil Enabled (model should be hidden)");
} else {
enableStencil = true;
System.out.println("Stencil Disabled (model should be visible)");
}
}
}
};
inputManager.addListener(acl, "toggle");
System.out.println("Press space to toggle stencil");
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class LightsDebugState method initialize.
@Override
protected void initialize(Application app) {
debugNode = new Node("Environment debug Node");
Sphere s = new Sphere(16, 16, 1);
debugGeom = new Geometry("debugEnvProbe", s);
debugMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/reflect.j3md");
debugGeom.setMaterial(debugMaterial);
debugBounds = BoundingSphereDebug.createDebugSphere(app.getAssetManager());
if (scene == null) {
scene = app.getViewPort().getScenes().get(0);
}
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class SpotLight method intersectsBox.
@Override
public boolean intersectsBox(BoundingBox box, TempVars vars) {
if (this.spotRange > 0f) {
// Sphere v. box collision
if (!Intersection.intersect(box, position, spotRange)) {
return false;
}
}
Vector3f otherCenter = box.getCenter();
Vector3f radVect = vars.vect4;
radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
float otherRadiusSquared = radVect.lengthSquared();
float otherRadius = FastMath.sqrt(otherRadiusSquared);
// Check if sphere is within spot angle.
// Cone v. sphere collision.
Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
Vector3f U = position.subtract(E, vars.vect2);
Vector3f D = otherCenter.subtract(U, vars.vect3);
float dsqr = D.dot(D);
float e = direction.dot(D);
if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
D = otherCenter.subtract(position, vars.vect3);
dsqr = D.dot(D);
e = -direction.dot(D);
if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
return dsqr <= otherRadiusSquared;
} else {
return true;
}
}
return false;
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class SpotLight method intersectsSphere.
@Override
public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) {
if (this.spotRange > 0f) {
// Sphere v. sphere collision
if (!Intersection.intersect(sphere, position, spotRange)) {
return false;
}
}
float otherRadiusSquared = FastMath.sqr(sphere.getRadius());
float otherRadius = sphere.getRadius();
// Check if sphere is within spot angle.
// Cone v. sphere collision.
Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
Vector3f U = position.subtract(E, vars.vect2);
Vector3f D = sphere.getCenter().subtract(U, vars.vect3);
float dsqr = D.dot(D);
float e = direction.dot(D);
if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
D = sphere.getCenter().subtract(position, vars.vect3);
dsqr = D.dot(D);
e = -direction.dot(D);
if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
return dsqr <= otherRadiusSquared;
} else {
return true;
}
}
return false;
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class BoundingSphereDebug method createDebugSphere.
/**
* Convenience factory method that creates a debuging bounding sphere geometry
* @param assetManager the assetManager
* @return the bounding sphere debug geometry.
*/
public static Geometry createDebugSphere(AssetManager assetManager) {
BoundingSphereDebug b = new BoundingSphereDebug();
Geometry geom = new Geometry("BoundingDebug", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setBoolean("VertexColor", true);
mat.getAdditionalRenderState().setWireframe(true);
geom.setMaterial(mat);
return geom;
}
Aggregations