Adding static gravity object

Posts: 2
Joined: 2008.03
Post: #1
I would like to preface by saying that I know C++(a fair bit) and I am a complete n00b to objc and cocoa. I am trying to learn cocoa by doing a simple project using chipmunk(which I am also trying to figure out).

1. To make an object called pWorld that basically inits chipmunk, runs the chipmunk space and introduces bodies into its space.
2. To make an object called pWorldShape that can become either a simple circle, line, box, static circle, static line, static box.
3. To have pWoldShape object draw itself using opengl.
4. To create a program using NSOpenGLView with circles that can be manipulated using a mouse for initial force that can bounce off each other and the GLView walls.

I still have a ways to go and alot of reading to do but my question is:
Is there a simple way to create a function in chipmunk to allow for a static gravity object or force? I am imagining double clicking a circle and having it have an attractive force towards the other circle and then double clicking it again to create a repulsive force. Something like a magnet. Or it there a simple way to create this using the available functions?

I would like to eventually create an interactive lava-lamp style app where blobs combine and repel each other and the user can apply forces of attraction/repulsive to the blobs.

Sorry for the long ass post.
Quote this message in a reply
Posts: 254
Joined: 2005.10
Post: #2
As far as I can tell, there is no way to implement what you are describing in Chipmunk Physics. CP only supports a global gravity force and it exposes only collisions to the end user. That is not to say that it can't be done, but rather that you probably have to edit the source code for chipmunk physics directly to achieve the effect.
Quote this message in a reply
Posts: 452
Joined: 2008.04
Post: #3
CP does support a global gravity force in any one direction you want.

To do what you want, simply apply forces to the objects you want in the direction and magnitude that you desire. Update them every update loop of your program. It should be no problem.

However, chipmunk physics supports static geometry. Lava lamp blobs are very not static, so you might be looking for something else. I don't really see why creating a lavalamp-like simulator would benefit from using chipmunk physics.
Quote this message in a reply
Posts: 2
Joined: 2008.03
Post: #4
But it only supplies 1 force. Say I had 5 circles and I want to push one of those circles around. I would like to apply gravity to all 5 so that the closest circle to the moving circle would pull it, and as circles start to move the gravity from each of the circles would start to attract each other. Or maybe set gravity on all four corners of the screen and if a circle gets too close it will become trapped and get pulled towards a corner. You can also attempt the reverse. Once the circle touches a corner the gravity will then reverse and expel the circle.

With the lava-lamp there would be two fluctuating attractive gravity fields, one at the to and one at the bottom. Also the blobs would have smaller attractive gravity field. There could also be two repellant randomly floating gravity field to break blobs up. But the lava-lamp thing is just an example idea of sorts. I guess my original question is how to make multiple gravity points in CP and assign them to bodies so that those bodies attract each other according to proximity.

What would be a good solution then if not with CP?
Quote this message in a reply
Posts: 1,482
Joined: 2002.09
Post: #5
Add all of the forces together if you have more than one, that's how it works in the real world. (referred to as the net force)

To get the blob like lava lamp behavior, you want objects to attract each other when far away, but repel when they get too close. Then you would need some sort of fluctuating force field to put them in to move them around. With no forces or a static force, they would all clump together. Make the forces too crazy and they would never clump. Animated perlin noise would probably work well for this.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Adding lots of static shapes in Chipmunk - performance question TomorrowPlusX 3 7,194 Jul 11, 2011 01:39 PM
Last Post: Skorche
  giving gravity and weight to object 9livesoftware 2 2,986 Aug 23, 2009 01:46 AM
Last Post: mikey
  To STATIC or not to STATIC... Elphaba 10 3,989 Aug 6, 2009 09:17 AM
Last Post: Elphaba
  gravity control renman3000 4 3,065 Jun 9, 2009 09:41 PM
Last Post: renman3000
  Adding message handlers rove 3 4,030 Mar 13, 2005 08:53 AM
Last Post: sealfin