About java3d collision detection

I import a 3ds model.
I want to use keyboard to view the model by first person view.
How can I use the collision detectiont to prevent I go though the wall of model

You can (as you move) test distance between camera position and the centre of imaginary sphere around your object. Not the best solution for non - sphere - shaped objects, but as first implementation of collision will suffice…
EDIT: if your next move is about to shorten distance, don’t allow it! else - go …

But the model is a building,the cann’t regard as a imaginary sphere so…
By the way ,how can i get the camera position.

I’m not a Java3D expert, but I don’t think it has got that kind of collision detection and response buildt in. You might have to code it yourself.

I am a freshman in java3d,and i am not good at collision arithmetic such as bsp…So I want to know how can I complete the function by java3d build in class.

Oka, firs off, forget all about what Java3D calls “collision detection”. It doesnt do what you want to know when a collision occurs on the frame it occurs, or even ebfore so you can stop it. This is soemtimes called “collision avoidance.”

Its not simple, even to cheat. Its even harder to do right.

But the smplest cheat is this: When you get a command to move the character, you project a pick-ray from the character in the direction of m otion. You test it against the environment to find the first point of collision of that ray against the environment and use that to limit the motion.

Now you will have to add some “fudge” to the starting position of the ray, which we assume will be at model center, to get you to the outside edge of the model. Effectively what you are doing by subtracting this fudge is treating the character like a cylinder around the center point.

There are plenty of examples aroudn of pick-rays, so look in tyhe docs, the J3D exampels, and then doa google on "Java3D pick-ray " if you still can’t figure it out.

As I said, this is a cheat. It will work for simple situations but fail for many complex ones. The only complete solution is a real physics based solution with multiple bounding volumes and “push-back” from object inter-penetration but that frankly soudns way beyond what you want to get into.

I know the collision detection by picking,and i know the principle by the book “java3d programing”,i want to know i use keyboardbehavior to move my view,whether the principle is the same?

Sure. No difference. Even if you dont have an obejct rerpesenting your body the camera has a position in the world and there is a physical radius around that which I would assume you want to keep free so you dont run the camera right into the wall.

For smooth collision detection and response, you can implement that algorithm, it works very well:

http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.html

Bruno

Here is a good example of doing collision detection in j3d
http://java3d.j3d.org/tutorials/collision/index.html

Another approach, used by games such as NWN, is a walk-mesh. This is basically a free-form blockign map made up of triangles.

The down-side is you have to create that map as a seperate asset for all your 3D spatial geometry. It also only works for worlds where your feet are stuck to the ground.

The upside is it scales great as its a very very low cost way to do blocking.

Im just about done integrating NWN’s walkmeshes into JNWN. Theres an early versio nin the code-base now.