Content-Length: 266578 | pFad | http://github.com/Rajawali/Rajawali/wiki/v0.9-Tutorial-16-Collision-Detection

22 v0.9 Tutorial 16 Collision Detection · Rajawali/Rajawali Wiki · GitHub
Skip to content

v0.9 Tutorial 16 Collision Detection

contriteobserver edited this page Jul 16, 2017 · 1 revision

Rajawali supports simple collision detection using bounding boxes and bounding spheres. The Geometry3D class contains two methods that can be used to retrieve the bounding volumes:

// -- myObject is of type BaseObject3D
// -- get the bounding box

IBoundingVolume boundingBox = myObject.getGeometry().getBoundingBox();

// -- or get the bounding sphere

IBoundingVolume boundingSphere = myObject.getGeometry().getBoundingSphere();

Both the BoundingBox and BoundingSphere classes have a transform() method that takes the current model’s model matrix as the only parameter. This is needed to translate, rotate and scale the bounding volume.

boundingBox.transform(myObject.getModelMatrix());

Once the bounding volume has been transformed we can check if it intersects with another bounding volume (of the same kind):

boolean intersects = boundingBox.intersectsWith(otherBoundingBox);
if(intersects)
     // -- collision!
else
    // -- no collision 

The source code can be found here:

RajawaliCollisionDetectionActivity.java

RajawaliCollisionDetectionRenderer.java

Clone this wiki locally








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Rajawali/Rajawali/wiki/v0.9-Tutorial-16-Collision-Detection

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy