Tutorials

Sections

j3d.org

Implementing Terrain Following and Collision Detection in Java 3D

By:Justin Couch

This tutorial is about how to implement terrain following and collision avoidance schemes in Java 3D. Although we are Java 3D specific here, the same basic principles can be implemented in any 3D graphics rendering system - just take the algorithms and recode to your API of choice.

In another article on this site, we discuss Java 3D's internal collision detection system. What this describes is how Java 3D uses behaviors to notify you of a collision that has already occurred. For many applications that is not sufficient. These apps need a collision avoidance system so that you can detect a collision before it is supposed to occur, not after it.

What we discuss here is a general purpose collision and terrain following solution that can be used in any application - just plug in the code and go. For a lot of single purpose apps, such as games, where you have a lot of control over the scenegraph structure, this may well be overkill, there are a lot of simplifications that you can do to the code, we'll highlight these as we go along.

If you want to be lazy and use some already built code, this describes the implementation of the navigation code in the j3d.org Code Repository. In particular, look at the classes org.j3d.geom.IntersectionUtils and org.j3d.ui.navigation.NavigationHandler.

 

Contents

The tutorial is broken into three parts - setting up the environment, implementing generalised collision avoidance and then terrain following. There is quite a lot to this, so hopefully you won't be too squeemish over a collection of vector math (although I do try to keep the explanations in plain english).
  1. Getting Ready
  2. Collision Detection
  3. Terrain Following