i just started to learn bullet physics So i Saw some tutorials as well as read wiki but i now am stuck at something now well lets say i have sphere and a box i want the box to turn red when sphere hits it how can i do it ?
gcontactadded doesnt work for me (i already have the box and the Sphere both are rigidbody and are running properly) there are some wiki which i cannot understand and do can someone please Show me a simple code example or something ?
Thank you i will appreciate it!
Simple callback question
-
- Posts: 4
- Joined: Sun Jan 20, 2013 8:17 am
Re: Simple callback question
Bump Please Help Anyone
-
- Posts: 66
- Joined: Tue Mar 02, 2010 6:13 am
Re: Simple callback question
Why isn't gContactAdded not working for you ?
It's called when a new contact is added to the world,
check that either of the rbd pointer is your sphere,
and that should be it ?
It's called when a new contact is added to the world,
check that either of the rbd pointer is your sphere,
and that should be it ?
-
- Posts: 4
- Joined: Sun Jan 20, 2013 8:17 am
Re: Simple callback question
i followed this guy's tutorialand pretty much everything else is the same hers the Code
Well here's the main/relevant code
this is the error i get
on this line
gContactAddedCallback=callbackFunc;
error C2440: '=' : cannot convert from 'bool (__cdecl *)(btManifoldPoint &,const btCollisionObject *,int,int,const btCollisionObject *,int,int)' to 'ContactAddedCallback'
1> This conversion requires a reinterpret_cast, a C-style cast or function-style cast
i wondered that gContactAddedCallback doesn't work in new i tried some casting i am not that good into that So Any help will be appreciated
Well here's the main/relevant code
Code: Select all
bool callbackFunc(btManifoldPoint& cp,const btCollisionObject* obj1,int id1,int index1,const btCollisionObject* obj2,int id2,int index2)
{
((bulletObject*)obj1->getUserPointer())->hit=true;
((bulletObject*)obj2->getUserPointer())->hit=true;
return false;
}
int main()
{
//main stuff
gContactAddedCallback=callbackFunc;
//continue main stuff
on this line
gContactAddedCallback=callbackFunc;
error C2440: '=' : cannot convert from 'bool (__cdecl *)(btManifoldPoint &,const btCollisionObject *,int,int,const btCollisionObject *,int,int)' to 'ContactAddedCallback'
1> This conversion requires a reinterpret_cast, a C-style cast or function-style cast
i wondered that gContactAddedCallback doesn't work in new i tried some casting i am not that good into that So Any help will be appreciated
-
- Posts: 1
- Joined: Tue Jan 22, 2013 8:29 pm
Re: Simple callback question
There's a better way to do what I think you're trying to do. Note: This is a little off-topic, I admit, but it's related to the OP's original question so I thought I would share. It's a simple way to receive callbacks (or notifications) when two objects have:
a) just collided
b) are currently in contact with one another
c) have just separated
I believe that's essentially what most people are looking for anyway, because I've come across a lot of threads about the same issue. I'm posting a solution here that's easy to implement and doesn't require any modification to the bullet source code. Instead of using the pre-existing bullet callbacks, I iterate over all the contact manifolds and keep track of the collision state that way. The only requirement is to have each instance of your game object / bullet object (or whatever your user pointer is set to) to have a unique ID associated with it. I wouldn't be posting this unless I felt that this would be useful for a lot of people, not just the OP.
The code is pretty self-explanatory. Just call checkCollisions() each frame, and replace the existing callback/event mechanism in that function with your own implementation. Then make sure you have a getUniqueID() function, or something similar, in your base object class.
a) just collided
b) are currently in contact with one another
c) have just separated
I believe that's essentially what most people are looking for anyway, because I've come across a lot of threads about the same issue. I'm posting a solution here that's easy to implement and doesn't require any modification to the bullet source code. Instead of using the pre-existing bullet callbacks, I iterate over all the contact manifolds and keep track of the collision state that way. The only requirement is to have each instance of your game object / bullet object (or whatever your user pointer is set to) to have a unique ID associated with it. I wouldn't be posting this unless I felt that this would be useful for a lot of people, not just the OP.
The code is pretty self-explanatory. Just call checkCollisions() each frame, and replace the existing callback/event mechanism in that function with your own implementation. Then make sure you have a getUniqueID() function, or something similar, in your base object class.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 66
- Joined: Tue Mar 02, 2010 6:13 am
Re: Simple callback question
for the casting issue, bullet has recently switched from btCollisionObject to btCollisionObjectWrapper,
casting you current function will likely crash when accessing the collision object
if you use a recent cut then your callback function should be of this prototype :
bool contactAddedCallbackBullet(
btManifoldPoint& cp,
const btCollisionObjectWrapper * colObj0,
int partId0,
int index0,
const btCollisionObjectWrapper * colObj1,
int partId1,
int index1)
casting you current function will likely crash when accessing the collision object
if you use a recent cut then your callback function should be of this prototype :
bool contactAddedCallbackBullet(
btManifoldPoint& cp,
const btCollisionObjectWrapper * colObj0,
int partId0,
int index0,
const btCollisionObjectWrapper * colObj1,
int partId1,
int index1)
-
- Posts: 4
- Joined: Sun Jan 20, 2013 8:17 am
Re: Simple callback question
Thanks guys (Both of you)that did it xD