Hello guys, it's me, again.
I have some questions about, Orbit camera and PhysicsCharacterNode. I already have my orbir camera, which works preatty well.
package jme.game;
import java.util.concurrent.Callable;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.image.Texture.WrapMode;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.MouseInputListener;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.game.state.BasicGameState;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.shapes.CollisionShape;
import com.jmex.jbullet.nodes.PhysicsNode;
public class SimpleGameState extends BasicGameState {
protected Camera cam;
float camX = 0;
float camY = 0;
protected float tpf;
protected Timer timer;
private Node pivotNode;
final PhysicsSpace pSpace = PhysicsSpace.getPhysicsSpace(PhysicsSpace.BroadphaseTypes.AXIS_SWEEP_3);
protected LightState lightState;
public SimpleGameState(Camera camera) {
super("Test");
this.cam = camera;
init();
}
public void init() {
PointLight light = new PointLight();
light.setDiffuse(new ColorRGBA(0.75f, 0.75f, 0.75f, 0.75f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setLocation(new Vector3f(100, 100, 100));
light.setEnabled(true);
lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
rootNode.setRenderState(lightState);
timer = Timer.getTimer();
GameTaskQueueManager.getManager().update(new Callable<Object>() {
public Object call() throws Exception {
setupScene();
rootNode.updateRenderState();
return null;
}});
rootNode.updateRenderState();
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
}
@Override
public void update(float tpf) {
super.update(tpf);
pSpace.update(tpf);
timer.update();
tpf = timer.getTimePerFrame();
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)) {
Main.getGame().finish();
}
}
public void setupScene() {
Box floorNode = new Box("Floor", Vector3f.ZERO, new Vector3f(20, .2f, 40));
Texture text = TextureManager.loadTexture(Main.class.getClassLoader()
.getResource("jme/data/textures/floor.png"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
text.setScale(new Vector3f(9, 5, 5));
text.setWrap(WrapMode.Repeat);
PhysicsNode floor = new PhysicsNode(floorNode, CollisionShape.ShapeTypes.MESH, 0);
floor.setLocalTranslation(Vector3f.ZERO);
floor.setModelBound(new BoundingBox());
floor.updateModelBound();
TextureState tsCarpett = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
tsCarpett.setTexture(text);
floorNode.setRenderState(tsCarpett);
rootNode.attachChild(floor);
floor.updateRenderState();
pSpace.add(floor);
Box roomNode = new Box("Room Wall's and Roof", Vector3f.ZERO, new Vector3f(20, 30, 40));
Texture tex = TextureManager.loadTexture(Main.class.getClassLoader()
.getResource("jme/data/textures/wall.png"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
tex.setScale(new Vector3f(9, 9, 9));
tex.setWrap(WrapMode.Repeat);
PhysicsNode room = new PhysicsNode(roomNode, CollisionShape.ShapeTypes.MESH, 0);
room.setLocalTranslation(Vector3f.ZERO);
room.setModelBound(new BoundingBox());
room.updateModelBound();
TextureState tsCarpet = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
tsCarpet.setTexture(tex);
roomNode.setRenderState(tsCarpet);
rootNode.attachChild(roomNode);
floor.updateRenderState();
pSpace.add(floor);
MouseInput.get().addListener(new MouseInputListener() {
@Override
public void onWheel(int wheelDelta, int x, int y) {
}
@Override
public void onMove(int xDelta, int yDelta, int newX, int newY) {
float speed = 35f;
camX -= xDelta * timer.getTimePerFrame() * speed;
camY -= yDelta * timer.getTimePerFrame() * speed;
pivotNode.getLocalRotation().fromAngles(camY*FastMath.DEG_TO_RAD, camX*FastMath.DEG_TO_RAD, 0);
}
public void onButton(int arg0, boolean arg1, int arg2, int arg3) {
}
});
pivotNode = new Node("pivot");
pivotNode.setLocalTranslation(10, 1.8f, 20);
rootNode.attachChild(pivotNode);
CameraNode camNode = new CameraNode("camNode", cam);
camNode.setLocalTranslation(0, 0, 0);
pivotNode.attachChild(camNode);
}
}
But, I don't know how implement PhysicsCharacterNode on that Node. I already looked into TestPhysicsCharacterNode, but I'm like, kicking the air, cause I really don't know how. Can someone show me, using my code or something better? I would really appreciate it.
Regards, Gustavo Borba.
*Hope I don't need to bump this topic (:*