Simple raycast tutorial

Starfox
Posts: 37
Joined: Wed Jul 27, 2011 12:01 am

Simple raycast tutorial

Post by Starfox »

Is there a basic ray cast tutorial around somewhere? I've been trying to go through the doxygen docs but it's merely a list of function / member (sometimes cryptic) names with no docs that I can find, unless I'm looking in the wrong place. I'm new to Bullet so if there's some documentation source elsewhere I'd appreciate it if you'd point me at it.
ouch67
Posts: 17
Joined: Tue Jul 26, 2011 9:24 pm

Re: Simple raycast tutorial

Post by ouch67 »

With bullet the demos are the best documentation there is unfortunately... But there is a raycast demo so I would take a look at that one.
Starfox
Posts: 37
Joined: Wed Jul 27, 2011 12:01 am

Re: Simple raycast tutorial

Post by Starfox »

Is there even a tutorial that covers ray casting? I can't seem to find one on the wiki ( http://bulletphysics.org/mediawiki-1.5. ... l_Articles ).
User avatar
Pyritie
Posts: 25
Joined: Thu Aug 11, 2011 6:42 pm

Re: Simple raycast tutorial

Post by Pyritie »

I'd like to know this too
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Simple raycast tutorial

Post by xexuxjy »

Maybe I've mis-understood but what sort of raycast were you looking to do? btCollisionWorld has a rayTest method and standard callbacks for closest point and all points .
Starfox
Posts: 37
Joined: Wed Jul 27, 2011 12:01 am

Re: Simple raycast tutorial

Post by Starfox »

What's the name of that closest point callback? And does anyone know the relevance of the btScalar returned by the callback method?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Simple raycast tutorial

Post by xexuxjy »

There are 2 standard callbacks defined in btCollisionWorld :
btCollisionWorld::ClosestRayResultCallback
btCollisionWorld::AllHitsRayResultCallback

I'm not sure which callback method you're referring to with the btScalar return as the standard ray test has a void return type. You can check the callback you provided to see if the ray test was succesful (hasHit) and then get the hit point and the hit normal.

The raytest demo (Demos/Raytracer )should give you a good example.
jazztickets
Posts: 21
Joined: Tue Dec 29, 2009 12:48 am

Re: Simple raycast tutorial

Post by jazztickets »

My raycast function:

Code: Select all

// Performs raycasting on the world and returns the point of collision
bool PhysicsClass::RaycastWorld(const btVector3 &Start, btVector3 &End, btVector3 &Normal) {

        if(Enabled) {
                btCollisionWorld::ClosestRayResultCallback RayCallback(Start, End);
                RayCallback.m_collisionFilterMask = FILTER_CAMERA;

                // Perform raycast
                World->rayTest(Start, End, RayCallback);
                if(RayCallback.hasHit()) {

                        End = RayCallback.m_hitPointWorld;
                        Normal = RayCallback.m_hitNormalWorld;
                        return true;
                }
        }

        return false;
}
gogiii
Posts: 8
Joined: Sat Oct 08, 2011 1:00 pm

Re: Simple raycast tutorial

Post by gogiii »

Can anybody explain what is the right way to do raycasting?
I mean:

Code: Select all

btCollisionWorld::ClosestRayResultCallback RayCallback(Start, End);
...
World->rayTest(Start, End, RayCallback);
...
Seriously why should I specify start and end twice? Doesn't the rayTest has its' own start/end?
This disallow me using something simple like:

Code: Select all

btCollisionWorld::ClosestRayResultCallback RayCallback;  // error, no such constructor and it wont work if you use something like (zeroVector, zeroVector) doesn't work.
World->rayTest(origin, origin + forward*100, RayCallback);
jazztickets
Posts: 21
Joined: Tue Dec 29, 2009 12:48 am

Re: Simple raycast tutorial

Post by jazztickets »

I asked the same question 3 years ago. Here is Erwin's response:

http://bulletphysics.org/Bullet/phpBB3/ ... 124#p11124
gogiii
Posts: 8
Joined: Sat Oct 08, 2011 1:00 pm

Re: Simple raycast tutorial

Post by gogiii »

oh thanks, I've tried to search but didn't noticed that topic.
Anyway that still doesn't make it clear for me.
As end-user I can't see how to inherit something from RayResultCallback to make it easy.
Maybe I'm a bit dumb but I just don't see the celar way of how can I remove those variables from ClosestRayResultCallback constructor,
because they are used in ClosestRayResultCallback::addSingleResult at the line where it computes intersection point.
So while looking at headers I don't see how I supposed to get\pass input from btCollisionWorld::raytest(...) variables (from/to) into RayResultCallback.
Can you give me an example?
I'm filling a bit sick digging into sources of bullet you know...
jazztickets
Posts: 21
Joined: Tue Dec 29, 2009 12:48 am

Re: Simple raycast tutorial

Post by jazztickets »

I posted an example two responses up.
gogiii
Posts: 8
Joined: Sat Oct 08, 2011 1:00 pm

Re: Simple raycast tutorial

Post by gogiii »

well that's the way I am doing raycasting now, but it doesn't define custom callback structure which doesn't take start/end as input.
nah nevermind I'll just wrap it into custom function call as you did..