159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * To change this template, choose Tools | Templates 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * and open the template in the editor. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.batching; 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved. 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met: 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer. 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer in the 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * documentation and/or other materials provided with the distribution. 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * may be used to endorse or promote products derived from this software 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * without specific prior written permission. 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.app.SimpleApplication; 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.TextureKey; 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.BulletAppState; 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.PhysicsSpace; 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.SphereCollisionShape; 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.control.RigidBodyControl; 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.font.BitmapText; 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.MouseInput; 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.ActionListener; 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.MouseButtonTrigger; 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.material.Material; 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector2f; 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f; 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.renderer.queue.RenderQueue.ShadowMode; 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.BatchNode; 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Geometry; 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.shape.Box; 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.shape.Sphere; 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.shape.Sphere.TextureMode; 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.shadow.PssmShadowRenderer; 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.shadow.PssmShadowRenderer.CompareMode; 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.shadow.PssmShadowRenderer.FilterMode; 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.system.AppSettings; 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.system.NanoTimer; 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture; 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture.WrapMode; 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport jme3test.bullet.BombControl; 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author double1984 (tower mod by atom) 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class TestBatchNodeTower extends SimpleApplication { 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta int bricksPerLayer = 8; 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta int brickLayers = 30; 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta static float brickWidth = .75f, brickHeight = .25f, brickDepth = .25f; 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta float radius = 3f; 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta float angle = 0; 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Material mat; 8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Material mat2; 8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Material mat3; 8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta PssmShadowRenderer bsr; 8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private Sphere bullet; 8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private Box brick; 8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private SphereCollisionShape bulletCollisionShape; 8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private BulletAppState bulletAppState; 9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta BatchNode batchNode = new BatchNode("batch Node"); 9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public static void main(String args[]) { 9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TestBatchNodeTower f = new TestBatchNodeTower(); 9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta AppSettings s = new AppSettings(true); 9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta f.setSettings(s); 9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta f.start(); 9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void simpleInitApp() { 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta timer = new NanoTimer(); 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletAppState = new BulletAppState(); 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL); 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // bulletAppState.setEnabled(false); 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta stateManager.attach(bulletAppState); 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bullet = new Sphere(32, 32, 0.4f, true, false); 10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bullet.setTextureMode(TextureMode.Projected); 10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletCollisionShape = new SphereCollisionShape(0.4f); 11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta brick = new Box(Vector3f.ZERO, brickWidth, brickHeight, brickDepth); 11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta brick.scaleTextureCoordinates(new Vector2f(1f, .5f)); 11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta //bulletAppState.getPhysicsSpace().enableDebug(assetManager); 11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta initMaterial(); 11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta initTower(); 11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta initFloor(); 11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta initCrossHairs(); 11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.cam.setLocation(new Vector3f(0, 25f, 8f)); 11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0)); 12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta cam.setFrustumFar(80); 12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); 12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addListener(actionListener, "shoot"); 12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rootNode.setShadowMode(ShadowMode.Off); 12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta batchNode.batch(); 12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta batchNode.setShadowMode(ShadowMode.CastAndReceive); 12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rootNode.attachChild(batchNode); 12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr = new PssmShadowRenderer(assetManager, 1024, 2); 13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); 13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr.setLambda(0.55f); 13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr.setShadowIntensity(0.6f); 13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr.setCompareMode(CompareMode.Hardware); 13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bsr.setFilterMode(FilterMode.PCF4); 13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta viewPort.addProcessor(bsr); 13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private PhysicsSpace getPhysicsSpace() { 14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return bulletAppState.getPhysicsSpace(); 14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private ActionListener actionListener = new ActionListener() { 14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void onAction(String name, boolean keyPressed, float tpf) { 14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (name.equals("shoot") && !keyPressed) { 14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Geometry bulletg = new Geometry("bullet", bullet); 14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletg.setMaterial(mat2); 14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletg.setShadowMode(ShadowMode.CastAndReceive); 14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletg.setLocalTranslation(cam.getLocation()); 15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); 15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); 15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletNode.setLinearVelocity(cam.getDirection().mult(25)); 15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta bulletg.addControl(bulletNode); 15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rootNode.attachChild(bulletg); 15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getPhysicsSpace().add(bulletNode); 15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta }; 15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void initTower() { 16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta double tempX = 0; 16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta double tempY = 0; 16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta double tempZ = 0; 16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta angle = 0f; 16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (int i = 0; i < brickLayers; i++){ 16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Increment rows 16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if(i!=0) 16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tempY+=brickHeight*2; 16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta else 17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tempY=brickHeight; 17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Alternate brick seams 17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta angle = 360.0f / bricksPerLayer * i/2f; 17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (int j = 0; j < bricksPerLayer; j++){ 17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tempZ = Math.cos(Math.toRadians(angle))*radius; 17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tempX = Math.sin(Math.toRadians(angle))*radius; 17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta System.out.println("x="+((float)(tempX))+" y="+((float)(tempY))+" z="+(float)(tempZ)); 17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Vector3f vt = new Vector3f((float)(tempX), (float)(tempY), (float)(tempZ)); 17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Add crenelation 17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (i==brickLayers-1){ 18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (j%2 == 0){ 18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta addBrick(vt); 18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Create main tower 18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta else { 18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta addBrick(vt); 18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta angle += 360.0/bricksPerLayer; 18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void initFloor() { 19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Box floorBox = new Box(Vector3f.ZERO, 10f, 0.1f, 5f); 19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); 19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Geometry floor = new Geometry("floor", floorBox); 19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta floor.setMaterial(mat3); 20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta floor.setShadowMode(ShadowMode.Receive); 20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta floor.setLocalTranslation(0, 0, 0); 20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta floor.addControl(new RigidBodyControl(0)); 20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.rootNode.attachChild(floor); 20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.getPhysicsSpace().add(floor); 20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void initMaterial() { 20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg"); 21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta key.setGenerateMips(true); 21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Texture tex = assetManager.loadTexture(key); 21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat.setTexture("ColorMap", tex); 21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); 21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta key2.setGenerateMips(true); 21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Texture tex2 = assetManager.loadTexture(key2); 21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat2.setTexture("ColorMap", tex2); 21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg"); 22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta key3.setGenerateMips(true); 22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Texture tex3 = assetManager.loadTexture(key3); 22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tex3.setWrap(WrapMode.Repeat); 22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta mat3.setTexture("ColorMap", tex3); 22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaint nbBrick =0; 22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void addBrick(Vector3f ori) { 22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Geometry reBoxg = new Geometry("brick", brick); 23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.setMaterial(mat); 23159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.setLocalTranslation(ori); 23259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); 23359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.addControl(new RigidBodyControl(1.5f)); 23459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.setShadowMode(ShadowMode.CastAndReceive); 23559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); 23659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.batchNode.attachChild(reBoxg); 23759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.getPhysicsSpace().add(reBoxg); 23859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta nbBrick++; 23959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 24059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 24159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected void initCrossHairs() { 24259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); 24359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta BitmapText ch = new BitmapText(guiFont, false); 24459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta ch.setSize(guiFont.getCharSet().getRenderedSize() * 2); 24559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta ch.setText("+"); // crosshairs 24659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta ch.setLocalTranslation( // center 24759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2, 24859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta settings.getHeight() / 2 + ch.getLineHeight() / 2, 0); 24959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta guiNode.attachChild(ch); 25059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 25159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}