use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class TestSceneWater method simpleInitApp.
public void simpleInitApp() {
this.flyCam.setMoveSpeed(10);
Node mainScene = new Node();
cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
// load sky
mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
File file = new File("wildhouse.zip");
if (file.exists()) {
useHttp = false;
}
// load the level from zip or http zip
if (useHttp) {
assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
}
Spatial scene = assetManager.loadModel("main.scene");
DirectionalLight sun = new DirectionalLight();
Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(2));
scene.addLight(sun);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//add lightPos Geometry
Sphere lite = new Sphere(8, 8, 3.0f);
Geometry lightSphere = new Geometry("lightsphere", lite);
lightSphere.setMaterial(mat);
Vector3f lightPos = lightDir.multLocal(-400);
lightSphere.setLocalTranslation(lightPos);
rootNode.attachChild(lightSphere);
SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
waterProcessor.setReflectionScene(mainScene);
waterProcessor.setDebug(false);
waterProcessor.setLightPosition(lightPos);
waterProcessor.setRefractionClippingOffset(1.0f);
//setting the water plane
Vector3f waterLocation = new Vector3f(0, -20, 0);
waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
WaterUI waterUi = new WaterUI(inputManager, waterProcessor);
waterProcessor.setWaterColor(ColorRGBA.Brown);
waterProcessor.setDebug(true);
//lower render size for higher performance
// waterProcessor.setRenderSize(128,128);
//raise depth to see through water
// waterProcessor.setWaterDepth(20);
//lower the distortion scale if the waves appear too strong
// waterProcessor.setDistortionScale(0.1f);
//lower the speed of the waves if they are too fast
// waterProcessor.setWaveSpeed(0.01f);
Quad quad = new Quad(400, 400);
//the texture coordinates define the general size of the waves
quad.scaleTextureCoordinates(new Vector2f(6f, 6f));
Geometry water = new Geometry("water", quad);
water.setShadowMode(ShadowMode.Receive);
water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
water.setMaterial(waterProcessor.getMaterial());
water.setLocalTranslation(-200, -20, 250);
rootNode.attachChild(water);
viewPort.addProcessor(waterProcessor);
mainScene.attachChild(scene);
rootNode.attachChild(mainScene);
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class TestSimpleWater method initScene.
private void initScene() {
//init cam location
cam.setLocation(new Vector3f(0, 10, 10));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
//init scene
sceneNode = new Node("Scene");
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
geom.setMaterial(mat);
sceneNode.attachChild(geom);
// load sky
sceneNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
rootNode.attachChild(sceneNode);
//add lightPos Geometry
Sphere lite = new Sphere(8, 8, 3.0f);
lightSphere = new Geometry("lightsphere", lite);
lightSphere.setMaterial(mat);
lightSphere.setLocalTranslation(lightPos);
rootNode.attachChild(lightSphere);
}
use of com.jme3.scene.shape.Sphere in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestCollision method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
setupKeys();
matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex1", grass);
matRock.setFloat("Tex1Scale", 64f);
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex2", dirt);
matRock.setFloat("Tex2Scale", 32f);
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex3", rock);
matRock.setFloat("Tex3Scale", 128f);
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
heightmap.load();
} catch (Exception e) {
}
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalScale(new Vector3f(2, 2, 2));
// unlock it so we can edit the height
terrain.setLocked(false);
rootNode.attachChild(terrain);
/**
* Create PhysicsRigidBodyControl for collision
*/
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
// let them drop from the sky
for (int i = 0; i < 5; i++) {
float r = (float) (8 * Math.random());
Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
sphere.setMaterial(matWire);
// random position
float x = (float) (20 * Math.random()) - 40;
// random position
float y = (float) (20 * Math.random()) - 40;
// random position
float z = (float) (20 * Math.random()) - 40;
sphere.setLocalTranslation(new Vector3f(x, 100 + y, z));
sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
rootNode.attachChild(sphere);
bulletAppState.getPhysicsSpace().add(sphere);
}
collisionBox = new Geometry("collisionBox", new Box(2, 2, 2));
collisionBox.setModelBound(new BoundingBox());
collisionBox.setLocalTranslation(new Vector3f(20, 95, 30));
collisionBox.setMaterial(matWire);
rootNode.attachChild(collisionBox);
selectedCollisionObject = collisionBox;
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
rootNode.addLight(dl);
cam.setLocation(new Vector3f(0, 25, -10));
cam.lookAtDirection(new Vector3f(0, -1, 0).normalizeLocal(), Vector3f.UNIT_Y);
}
use of com.jme3.scene.shape.Sphere in project Lina by MisterCavespider.
the class Test method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(45f);
stateManager.attach(new ScreenshotAppState("image/"));
//
// arr = new LineArray(8);
// Geometry geom = new Geometry("LineArray", arr);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTransparent(true);
mat.setBoolean("VertexColor", true);
// geom.setMaterial(mat);
// rootNode.attachChild(geom);
//
// arr.setVertex(0, new Vector3f(0, 0, 0));
// arr.setVertex(1, new Vector3f(1, 1, 1));
// arr.setVertex(2, new Vector3f(2, 6, 4));
// arr.setVertex(3, new Vector3f(3, 12, 9));
//
// arr.setVertex(4, new Vector3f(4, 20, 16));
// arr.setVertex(5, new Vector3f(5, 30, 25));
// arr.setVertex(6, new Vector3f(6, 42, 36));
// arr.setVertex(7, new Vector3f(7, 56, 49));
//
// System.out.println();
//
// str = new LineString(64);
// lineString = new Geometry("LineString", str);
// lineString.setMaterial(mat.clone());
// rootNode.attachChild(lineString);
//
// str.addPoint(Vector3f.ZERO, ColorRGBA.Red);
// str.addPoint(Vector3f.UNIT_X, ColorRGBA.Red);
// str.addPoint(Vector3f.UNIT_XYZ, ColorRGBA.Red);
g = new Geometry("g", new Sphere(8, 8, .5f));
g.setMaterial(mat.clone());
rootNode.attachChild(g);
g.addControl(new TimeTracer(mat.clone(), 64, 64));
}
Aggregations