Page 1 of 2

Mouse interaction

Posted: Sat Jun 14, 2008 8:55 am
by supertommy
I wrote a piece of code the other day, which may turn out to be useful to some of you. I basically wanted the objects in my world to be more interactive. So that I could move stuff around and impart velocity and spin on them by dragging and releasing the mouse. Previously I had been limited to initialising my world in code, and then running it to see the physics, but that got old real quick if I was experimenting with something.

The result looks like this: http://www.youtube.com/watch?v=nBwK3pY25Mo

Turns out it's quite fun to play around with those objects - especially after I added the basketball hoop. It's almost like a little game already.

The attached code is written in the same style as chipmunk and I've put the same license on it. It'll only work with the svn version of chipmunk, though.

Re: Mouse interaction

Posted: Sun Jun 15, 2008 5:26 am
by maximile
Looks excellent. Really nicely written too.

Re: Mouse interaction

Posted: Mon Jul 14, 2008 12:30 am
by chipmunkuser
There's a body->data access. I know there's a shape->data access but there's no data member in the body in my version of Chipmunk.
Guess I'll have to see if there's been an update.

Re: Mouse interaction

Posted: Mon Jul 14, 2008 1:53 am
by supertommy
You're going to have to use the latest version in svn for this.

Re: Mouse interaction

Posted: Sat Jul 19, 2008 4:07 pm
by chipmunkuser
So I updated to the latest version and folded in your source files.

Created the mouse object and moved it to new positions as that changes. It displays fine
but it never grabs anything.

If I review the mouseOver function one item is always an object I have jointed to the static space.
The other is always the mouse. No other objects seem to be checked for mouse over. The BoundingRects also don't relate to the moving
object. They always read the same center position even though they're moving. (i.e. the mouse is always the size I set it)
Am I missing an additional init or setup?

Thanks.

Re: Mouse interaction

Posted: Fri Dec 12, 2008 7:04 am
by shafijami
Hi Supertommy

I'm new to IPhone and Chipmunk. I want to do in my current game project almost same thing (with only difference i.e. after touching any side ball will bounce only once like using striker in Carom board game. So could you please help me for a small project (Xcode version) as I'm facing this hindrance in my project? I'll very thankful to you. Its critical. I'm avidly waiting of your reply. Please...

Shafi

Re: Mouse interaction

Posted: Fri Dec 18, 2009 4:34 pm
by JonKean
cpMouse is broken with the latest 5.0 Chipmunk release, and I've fixed it up to work again.
Note that shapes must have their layer set to GRABABLE_MASK_BIT for cpMouse to grab them.

Re: Mouse interaction

Posted: Fri Feb 05, 2010 1:06 pm
by maz
If anyone is using cpMouse, make sure that you have [window setMultipleTouchEnabled:NO];

Having it set to YES will cause errors and crashes. I found this out the hard way.

Re: Mouse interaction

Posted: Sat Feb 06, 2010 4:50 am
by Tam Toucan
I don't code on the iPhone, but what you're saying isn't strictly true....cpMouse is pure C code using chipmunk. It knows nothing about multiple touches or the iPhone. Therefore the problem is how to use cpMouse with mutiple touch enabled, i.e. cpMouse can be used with multiple touch, you just have to use it correctly.

Just guessing, since I know nothing about what multi-touch does, but if you only created one mouse object (cpMouseAlloc), but allowed multiple grabs then you would likely get crashes. i.e. if multi-touch lets you have "two mouse pointers" then your would need two cpMouse objects or would need to have extra code to handle it etc.

Re: Mouse interaction

Posted: Sat Feb 06, 2010 11:48 am
by slembcke
Well, it's basically as if you got two mousedown events in a row, then two mouseup events in a row. So my guess is what's happening is that it's creating the joint, adding it to the space, overwritting that joint, adding the new one to the space, then attempting to remove and free the second one twice. Bam.