![]() |
|
|
Resources Assignments
|
FPS370 - Changes from Alpha3 to Alpha4 The changes from a3 to a4 include collision detection with our map model. The concept of collision detection in Java3d is very easy. The implementation takes some effort, but once you have it, it should be straight forward. In order to do collision detection in 3D you need to have information on your world space. Like where are all the 'things' you could run into. The easiest place to find all this information is in the Scene Graph. Since it contains everything currently being displayed, it has everything we need. The next thing we need is a way of detecting when we intersect with something. In Java3D this is called Picking. You create a ray and ask Java3D if it intersects anything. A ray is just a location in world space and a directional vector. The detail returned can be simple to complex. You set flags to get the specific information you want. By default, objects in the scene graph are not pickable. You need to set that state. The easiest way to do this is with:
This is great if all the objects in your scene graph are simple Shape3D objects, but we created all of our world space from models loaded from external files. All we were given from that model after it was loaded was a BranchGroup. This is also fairly straight forward. We need to traverse the branch group and set each shape in the branch group individually.
This method gets all the children from the BranchGroup and sets the Shape3D children to pickable using the static method setCapabilities provided by PickTool. The next step is the check our intersection distance on each movement. In the simpliest case we just ignore the movement if we intersect. In a later exercise we'll have to move the fractional distance towards the object we hit. Or slide along the wall or object. Those exercise are just exercises in vector mathematics. Here is the method to check the move to see if it is valid. If it is not, the movement is set to 0.
On each movement, we pass the move distance to this adjustMoveDistance method and it returns the value unchanged, or it sets the value(s) to zero. This is the new forward movement.
Notice the call to adjustMoveDistance. We should probably set it up for the boolean return and only adjust the viewPos if the distance was not changed. For a later exercise. We also made one other change and that was a pick when the space bar is pressed. It does a pick with a PickCanvas and prints out the closest Shape3D that was picked. We'll use this later when firing bullets and probably. For now it just prints out. A pick canvas creates a Pick from the current viewport into the scene. It does all the leg work we did in adjustMoveDistance, it just uses the screen instead of the current location.
doFire is called when the space bar is pressed. else if (keycode == KeyEvent.VK_SPACE) doFire(); It should look very familiar to you as much of the code for distance checking is the same code that is in adjustMoveDistance. Next up. Maybe some target practice using that nice doFire method. We'll have to add some targets first. There is that crazy ball that you may have noticed? |
|
CPSC370 - Games Development Chapman University Instructor: W. Wood Harter (c) copyright 2006 - W. Wood Harter - All Rights Reserved Screen shots on banner (c) copyright their resprective owners |
|