Hello people,
I'v been searching and trying all day to find some help on the forums. but i have had no luck.
I have seen that there are loads of question on this subject.
So it would be a good idea to create an tutorial on the specifc subject and put it on the wiki.
The situation i have is as follows.
I create my models in 3dsmax and export them as obj.
In jme i loads there models. add some light, etc
Now i want a camera in this scene that does noting else that the normal cam but has collission/physics. thus stay on the ground and does not go into objects.
first off the code that i have now:
public class HelloWorld extends SimplePhysicsGame{
private DynamicPhysicsNode player_node;
private ChaseCamera chaser;
private Node lnode = new Node("lightNode");
public static void main(String[] args) {
HelloWorld app = new HelloWorld(); // Create Object
// Signal to show properties dialog
app.setConfigShowMode(ConfigShowMode.ShowIfNoConfig);
app.start(); // Start the program
}
protected void simpleUpdate() {
KeyBindingManager manager = KeyBindingManager.getKeyBindingManager();
chaser.update(tpf);
if (manager.isValidCommand("i")) {
lnode.getLocalTranslation().y += 0.2;
rootNode.updateRenderState();
}
if (manager.isValidCommand("k")) {
lnode.getLocalTranslation().y += -0.2;
rootNode.updateRenderState();
}
}
protected void simpleInitGame() {
ObjToJme converter = new ObjToJme();
try {
URL objFile = TestObjJmeWrite.class.getClassLoader().getResource(
"models/test01.obj");
converter.setProperty("mtllib", objFile);
converter.setProperty("texdir",objFile);
ByteArrayOutputStream BO = new ByteArrayOutputStream();
System.out.println("Starting to convert .obj to .jme");
converter.convert(objFile.openStream(), BO);
Node model=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
model.setModelBound(new BoundingBox());
model.updateModelBound();
StaticPhysicsNode modelContainer = getPhysicsSpace().createStaticNode();
modelContainer.attachChild(model);
modelContainer.generatePhysicsGeometry();
rootNode.attachChild(modelContainer);
} catch (IOException e) {
System.out.println("error loading model");
e.printStackTrace();
}
setupCharacter();
setupLights();
rootNode.attachChild(lnode);
KeyBindingManager manager = KeyBindingManager.getKeyBindingManager();
manager.set("i", KeyInput.KEY_I);
manager.set("k", KeyInput.KEY_K);
rootNode.updateGeometricState(0.0f, true);
rootNode.updateRenderState();
}
public void setupCharacter() {
Box b = new Box("box", new Vector3f(), 2,2,2);
b.setModelBound(new BoundingBox());
b.updateModelBound();
player_node = getPhysicsSpace().createDynamicNode();
player_node.attachChild(b);
player_node.generatePhysicsGeometry();
rootNode.attachChild(player_node);
player_node.updateWorldBound();
}
private void setupLights() {
display.getRenderer().setBackgroundColor(ColorRGBA.lightGray);
lightState.setSeparateSpecular(true);
Sphere LightSphere = new Sphere("lp1", 10, 50, 0.2f);
LightSphere.setModelBound(new BoundingSphere());
LightSphere.updateModelBound();
LightSphere.setLightCombineMode(Spatial.LightCombineMode.Off);
LightSphere.setDefaultColor(new ColorRGBA(0.0f, 1.0f, 0.0f, 1.0f));
SpotLight sp1 = new SpotLight();
sp1.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
sp1.setAmbient(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
sp1.setDirection(new Vector3f(0, -1, 0));
sp1.setLocation(new Vector3f(0, 10, 0));
sp1.setAngle(180);
sp1.setEnabled(true);
SimpleLightNode ln = new SimpleLightNode("spNode", sp1);
lightState.detachAll();
lightState.attach(sp1);
lnode.attachChild(ln);
lnode.attachChild(LightSphere);
}
}
as you can see i have create a player object. and first i would like to have a chase cam... ??? but have not found a sollution for this.
Second and more important to me is not having a playerobject but only a camera. i'm guessing some sort of invisible object that has collision.. ?? but also i have not a clue how to build this.
i hope some1 is willing to help me out, cause this question is asked allot... :)
when i got it al worked out i shall create a tutorial for this and submit to the wiki's...
Many thanks in advance!
Cheers
Martijn