well i made a model in blender say a big model
new1.j3o
it took 4 hours i make it big in blender by scaling
i use jmonkey scenegraph and locate it everywhere on the terrain by using add to scene composer
then i use code for travelling here and there in the rooms ,walking stairs
when the capsule size is small the motion is smooth and fast u can say ok
but when the capsule size is large
the motion of the game is shivering,its not smooth
tell me if make
jvm 1024 memory
then my game motion will be smooth.
/*
- Copyright © 2009-2012 jMonkeyEngine
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
-
- Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-
- Neither the name of âjMonkeyEngineâ nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- âAS ISâ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package newpackage;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Sphere;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import java.util.ArrayList;
import java.util.List;
/**
- This demo shows a terrain with collision detection,
- that you can walk around in with a first-person perspective.
- This code combines HelloCollision and HelloTerrain.
*/
public class HelloTerrainCollision1 extends SimpleApplication
implements ActionListener {
private BulletAppState bulletAppState;
private RigidBodyControl landscape;
private CharacterControl player;
private Vector3f walkDirection = new Vector3f();
private boolean left = false, right = false, up = false, down = false;
private TerrainQuad terrain;
private Material mat_terrain;
float angle1;
float angle2;
PointLight pl;
PointLight p2;
Spatial lightMdl;
Spatial lightMd2;
//Temporary vectors used on each frame.
//They here to avoid instanciating new vectors on each frame
private Vector3f camDir = new Vector3f();
private Vector3f camLeft = new Vector3f();
public static void main(String[] args) {
HelloTerrainCollision1 app = new HelloTerrainCollision1();
app.start();
}
@Override
public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
flyCam.setMoveSpeed(50);
setUpKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
//rootNode.attachChild(lightMdl);
lightMd2 = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMd2.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
//rootNode.attachChild(lightMd2);
pl = new PointLight();
pl.setColor(new ColorRGBA(1, 0.9f, 0.9f, 0));
pl.setPosition(new Vector3f(0f, 0f, 4f));
//rootNode.addLight(pl);
p2 = new PointLight();
p2.setColor(new ColorRGBA(0.9f, 10, 0.9f, 0));
p2.setPosition(new Vector3f(10f, 60f, 3f));
//rootNode.addLight(p2);
Spatial elephant = (Spatial) assetManager.loadModel(âModels/Untitled2/new.j3oâ);
float scale = .3f;
elephant.scale(scale, scale, scale);
//rootNode.attachChild(elephant);
/** 4. We give the terrain its material, position & scale it, and attach it. */
//terrain.setMaterial(mat_terrain);
// terrain.setLocalTranslation(0, -100, 0);
//terrain.setLocalScale(2f, 1f, 2f);
rootNode.attachChild(elephant);
/** 5. The LOD (level of detail) depends on were the camera is: */
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(getCamera());
//TerrainLodControl control = new TerrainLodControl(terrain, cameras);
//terrain.addControl(control);
/** 6. Add physics: */
/* We set up collision detection for the scene by creating a static
* RigidBodyControl with mass zero.*/
elephant.addControl(new RigidBodyControl(0));
// We set up collision detection for the player by creating
// a capsule collision shape and a CharacterControl.
// The CharacterControl offers extra settings for
// size, stepheight, jumping, falling, and gravity.
// We also put the player in its starting position.
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(.3f, .3f, 1);
player = new CharacterControl(capsuleShape, .5f);
player.setJumpSpeed(60);
player.setFallSpeed(30);
player.setGravity(60);
player.setPhysicsLocation(new Vector3f(-10, 100, 100));
// We attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
bulletAppState.getPhysicsSpace().add(elephant);
bulletAppState.getPhysicsSpace().add(player);
}
/** We over-write some navigational key mappings here, so we can
- add physics-controlled walking and jumping: */
private void setUpKeys() {
inputManager.addMapping(âLeftâ, new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(âRightâ, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(âUpâ, new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping(âDownâ, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(âJumpâ, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, âLeftâ);
inputManager.addListener(this, âRightâ);
inputManager.addListener(this, âUpâ);
inputManager.addListener(this, âDownâ);
inputManager.addListener(this, âJumpâ);
}
/** These are our custom actions triggered by key presses.
- We do not walk yet, we just keep track of the direction the user pressed. */
public void onAction(String binding, boolean value, float tpf) {
if (binding.equals(âLeftâ)) {
if (value) { left = true; } else { left = false; }
} else if (binding.equals(âRightâ)) {
if (value) { right = true; } else { right = false; }
} else if (binding.equals(âUpâ)) {
if (value) { up = true; } else { up = false; }
} else if (binding.equals(âDownâ)) {
if (value) { down = true; } else { down = false; }
} else if (binding.equals(âJumpâ)) {
player.jump();
}
}
/**
- This is the main event loopâwalking happens here.
- We check in which direction the player is walking by interpreting
- the camera direction forward (camDir) and to the side (camLeft).
- The setWalkDirection() command is what lets a physics-controlled player walk.
- We also make sure here that the camera moves with player.
*/
@Override
public void simpleUpdate(float tpf) {
camDir.set(cam.getDirection()).multLocal(0.6f);
camLeft.set(cam.getLeft()).multLocal(0.4f);
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
player.setWalkDirection(walkDirection);
cam.setLocation(player.getPhysicsLocation());
}
}