raytest with obb in bullet physics

Post Reply
Nogiax
Posts: 1
Joined: Thu Jun 21, 2012 4:30 am

raytest with obb in bullet physics

Post by Nogiax » Thu Jun 21, 2012 4:33 am

i have a quick question about bullets raytest and i hope some experienced user can help me. I'm using BulletSharp ( with OpenTK ), the C# wrapper of bullet. I set up a very basic collision system to raytrace the scene for collisions. So i added a box to my scene and created a rigidBody with it and added it to the scene. When i now raytest the scene a collision is only detected for the aabb of the box ( world transformation is set to rotation in motion state). Is there a simple option i'm missing to let bullet use obb for raytesting? Maybe i need to use a different shape? If you need any code snippets just let me know.

Edit:

CollisionSystem.cs

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BulletSharp;
using Naps.Game.Math;
using OpenTK;
namespace Naps.Game.Systems
{
    public class CollisionSystem
    {
        DbvtBroadphase broadphase;
        DefaultCollisionConfiguration configuration;
        CollisionDispatcher dispatcher;
        SequentialImpulseConstraintSolver solver;
        public DiscreteDynamicsWorld world;

        public void Initialize()
        {
            broadphase = new DbvtBroadphase();    
            configuration = new DefaultCollisionConfiguration(); 
            dispatcher = new CollisionDispatcher(configuration);
            solver = new SequentialImpulseConstraintSolver();
            world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, configuration);
            world.Gravity = new OpenTK.Vector3(0, -9.81f, 0);
        }

        public BulletSharp.CollisionWorld.RayResultCallback Raycast(Ray ray)
        {
            Vector3 start = new Vector3(ray.position);
            Vector3 end = new Vector3(start + ray.direction * ray.length);
            BulletSharp.CollisionWorld.ClosestRayResultCallback callback = new CollisionWorld.ClosestRayResultCallback(start,end);
            world.RayTest(start, end, callback);
            return callback;
        }

        public void Update()
        {
        }

        public void Dispose()
        {
            broadphase.Dispose();
            configuration.Dispose();
            dispatcher.Dispose();
            solver.Dispose();
            world.Dispose();
        }
    }
}
Another snippet where the box is created

Code: Select all

CollisionShape box = new BoxShape(0.5f);
            Matrix4 mat = model.bone.CalculateTransformation();
            DefaultMotionState state = new DefaultMotionState(mat);
            RigidBodyConstructionInfo ci = new RigidBodyConstructionInfo(0, state, box);
            body = new RigidBody(ci);

Post Reply