Direct Control?

Official forum for the Chipmunk2D Physics Library.
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Direct Control?

Post by chipmunkuser »

So what is the correct way to actually control an object with the mouse? Trying to get 1:1 correspondence.

The documents say to not use positions. Velocities aren't really recommended. Force is recommended but there doesn't seem to be a direct relationship of force vs position. (i.e. how much force to move the object 20 pixels?) Even velocities don't seem to be matching what woul be expected with positions. (i.e. a velocity of 10 doesn't seem to move the object relative in the time frame provided)

The posted mouse code was helpful but that involves make a direct link with a joint and moving the object around.
Is there a simpler, cleaner way to do this for something such as moving an object left and right in sync with the mouse?
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Direct Control?

Post by maximile »

From what I've seen, supertommy's mouse interaction code will give you the best results. There are almost certainly ways of making the object follow the mouse more closely, but anything colliding with it will be likely to mess up. I should think that joints are made to get it right as quickly as possible, which makes them a good choice in this case.

You can, as usual, greatly improve the accuracy by having more iterations, shorter steps, and a constant timestep.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Direct Control?

Post by supertommy »

The mouse code does actually have a body which represents the mouse. If you look at cpMouseMove, you'll see that I'm just setting the position of that body. I'm not using any forces or anything. The reason this works is the code in mouseUpdateVelocity which will update the velocity of the body according to how much it has been moved during the past few updates. If the approach with a joint is not exact enough for you, you could try to mimic the code that deals with mouse->body in cpMouse.c.
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Direct Control?

Post by chipmunkuser »

Thanks, I've been looking at that. It seems either you've modified a number of things in Chipmunk or have a different version than I do.
If I'm reading the code right you're accessing a data parameter in cpBody and have klass's and other items (velocity functions). Have you added all these to your base chipmunk code?

If I have only one body I wish to move then it sounds like I could set it's position as long as I update it's velocity information correctly. Would that be a safe assumption?
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Direct Control?

Post by supertommy »

chipmunkuser wrote:Thanks, I've been looking at that. It seems either you've modified a number of things in Chipmunk or have a different version than I do.
If I'm reading the code right you're accessing a data parameter in cpBody and have klass's and other items (velocity functions). Have you added all these to your base chipmunk code?
Again, this is the chipmunk checked out from the googlecode subversion repository with:

Code: Select all

svn checkout http://chipmunk-physics.googlecode.com/svn/trunk/ chipmunk-physics-read-only
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Direct Control?

Post by chipmunkuser »

Odd, I downloaded the code here directly a couple of months ago(?)
http://wiki.slembcke.net/main/published/Chipmunk

I'll have to see what the differences are.

Is there a real need for another body or should I be able to set an object to a given position as longs as I set the velocity accordingly and run it through the calculation pipeline update/
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Direct Control?

Post 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.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Direct Control?

Post by supertommy »

Nope. There's no initialization needed beyond calling cpMouseNew. How exactly are you moving the mouse object? cpMouseMove?
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Direct Control?

Post by chipmunkuser »

I've create a static version of the cpMouse . masterMouse = cpMouseNew( space);
I get coordinates and calculate world coordinates and pass that into cpMouseMove(masterMouse, position); as position vector.
I deal with a 300 x 400 or so size area so I scaled the mouse shape up to 30 to be able to see it.
In the MouseOver routine I placed some print statements and I check in the debugger there since it doesn't seem to grab the other objects.
It doesn't seem to be going through all the moving objects. I have a dozen or so but it only seems to provide 1 of the main objects besides the mouse.
These other objects are moving correctly as objects within Chipmunk.
The bb never seems to change for the mouse object so not sure how it will intersect other objects.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Direct Control?

Post by supertommy »

In that case, I have no idea what's wrong. I can certainly not guarantee that the cpMouse code does not have some crazy bug in it. After all, I haven't tested it all that much.
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests