Collision strange behaviour

Started by Gvrv89, October 03, 2011, 02:15:40 PM

Previous topic - Next topic

Gvrv89

Hi all !

It's been two days I try to make collisions works. Unsuccessfully...

I load a 3ds terrain and want to stick 3ds trees on it.

Here's the project (simplified) : https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B34S8VzVRdKMMGQxY2UwNDItNWM2OC00YzdkLTlmZmEtMjNjNDg3NmIwZWMz&hl=fr

The important code parts are :


ground = Loader.load3DS("res" + c + "ground.3ds", 70f)[0];
ground.rotateX((float) (-Math.PI / 2));
ground.translate(-100f, 10f, 2f);
ground.setSpecularLighting(true);
ground.setShadingMode(Object3D.SHADING_GOURAUD);
ground.setTexture("ground");
ground.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
ground.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
ground.build();
world.addObject(ground);


And :


public TreeEngine(World world, Object3D ground)
{
char c = File.separatorChar;

Object3D tree = Loader.load3DS("res" + c + "tree.3ds", 3f)[0];
tree.setSpecularLighting(true);
tree.setShadingMode(Object3D.SHADING_GOURAUD);

trees = new Vector<Object3D>();
for (int i = 0; i < 25; i++)
{
trees.add(tree.cloneObject());
trees.get(i).rotateX((float) (-Math.PI / 2));
trees.get(i).rotateY((float) (-Math.PI / Math.random() * 2));
//trees.get(i).scale((float) Math.random() * 2f);
trees.get(i).setCenter(ground.getTransformedCenter());
trees.get(i).translate(new SimpleVector(Math.random() * 800f - 400f, 0, Math.random() * 800f - 400f));
trees.get(i).setCollisionMode(Object3D.COLLISION_CHECK_SELF);
trees.get(i).setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
trees.get(i).build();
world.addObject(trees.get(i));

dir = trees.get(i).checkForCollisionEllipsoid(dir, new SimpleVector(1, 1, 1), 1);
//System.out.print(dir);
trees.get(i).translate(dir);
}
}


Did your expert eyes seen something wrong on this ? :)

Btw I set "Config.collideOffset = 40;".

Thanks in advance.

EgonOlsen

You haven't written what the actual problem is...???

However, what is "dir" in your code? I don't see a definition of it in your code and even it there were one, your loop would constantly modify it. Also make sure that a tree's center is actually above the ground when you start the detection or otherwise, it will never be detected.

Gvrv89

The problem is that the trees are floating above or under the terrain, depending the initialisation location.

dir is a SimpleVector(0, 1, 0).

I tried various values of this, nothing changes...

PS : Look at the zip attached to my previous post for more details.

Thanks.

EgonOlsen

Have you tried to use a higher value for dir? It's not a direction vector, it's the translation. Maybe 0,1,0 just causes no collision. In addition, your loop changes the value of dir once a collision happens. I can't see any part that resets it to it initial value. And if tree are below the ground, then their initial position can't work. As said, you have to start above the ground to make this work. You can't trigger a collision if the tree is alread located below it and moves even lower. I suggest to increase the Config.collideOffset to something like 1000 and move all the trees 300 units up as initial position. Then let dir be 0,600,0 or something and try again.

Gvrv89

#4
Ok, thanks, I'll try it now.

And, yes, I put my tree above the ground to make sure the collision is computed.

I'll tell you if it works.

Nope, stille the same result...

I give you the new code :

http://pastebin.com/96nxsZVZ [HelloWorldOGL.java]
http://pastebin.com/96nxsZVZ [TreeEngine.java]

I'm giving up, if I don't succed, I put the trees by hand. :)
Nah, I'll play with variable settings tomorrow.

EgonOlsen

Both links link to the same source code...

Gvrv89

#6
Sorry for my mistake :P

Here are the links :

http://pastebin.com/96nxsZVZ [HelloWorldOGL.java]
http://pastebin.com/KCxLLmdi [TreeEngine.java]

EDIT :

I am thinking of a thing : Can I simply get axises mesh's point, thus I can set the Object3D.SetCenter() stick the the mesh's point (sorry for bad english).

EgonOlsen

I see...the issue is most likely that you expected the collision setting of tree to be cloned. That's not the case. Try to add


trees.get(i).setCollisionMode(Object3D.COLLISION_CHECK_SELF);
trees.get(i).setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);


and see if that helps. I'll extend the docs to cover this.