[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Rotate around a point with a spring

Rotate around a point with a spring

Official forum for the .

Rotate around a point with a spring

Postby the source » Mon Sep 13, 2010 6:27 am

Hi folks,

I am looking for a little advice on how to get an image to move with a spring action around a point (coords inside the sprite) to simulate a swinging effect and show movement with the accelerometer.

This code here doesn't do what I expect. Can someone enlighten me on what is wrong? What are good values for stiffness and spring constants?

TIA.

anObject = [CCSprite spriteWithFile:@"anObject.png"];
anObject = ccp(511 + 502/2, 8 + 414/2);
[self addChild:anObject z: 5 tag:5];

int numVerts = 4;
CGPoint objectVerts[] = {
cpv(50.0f, 50.0f),
cpv(-50.0f, 50.0f),
cpv(-50.0f, -50.0f),
cpv(50.0f, -50.0f)
};

objectBody = cpBodyNew(1.0f, cpMomentForPoly(1.0f, numVerts, objectVerts, CGPointZero));
objectBody->p = anObject.position;
objectBody->data = anObject;
cpSpaceAddBody(space, objectBody);

anObjectShape = cpCircleShapeNew(objectBody, 100.0, CGPointZero);
anObjectShape->data = anObject;
cpSpaceAddShape(space, anObjectShape);

// place pivot point at the center of anObject
pivotBody = cpBodyNew(INFINITY, INFINITY);
CGPoint aPoint = anObject.position;
pivotBody->p = ccp(aPoint.x, aPoint.y);

pivotShape = cpCircleShapeNew(pivotBody, 1.0f, cpvzero);
pivotShape->e = 0.9f; // dummy value
pivotShape->u = 0.9f; // dummy value
cpSpaceAddStaticShape(space, pivotShape);

// join both at their center points
joint = cpPivotJointNew(bearHeadBody, pivotBody, aPoint);

cpSpaceAddConstraint(space, joint);

// create another point that is the center of anObject + 10 for each of the axes
springPointBody = cpBodyNew(INFINITY, INFINITY);
springPointBody->p = ccp(aPoint.x + 10, aPoint.y);

springPointShape = cpCircleShapeNew(springPointBody, 1.0f, cpvzero);
springPointShape->e = 0.9f;
springPointShape->u = 0.9f;
cpSpaceAddStaticShape(space, springPointShape);

cpVect objectSpringAttachPoint = cpv(aPoint.x+10, aPoint.y+10);
cpFloat restLength = 10.0f;
cpFloat stiffness = 5.0f; // no idea what this should be
cpFloat damping = 0.999f;

spring = cpDampedSpringNew(springPointBody, objectBody, springPointBody->p, objectSpringAttachPoint, restLength, stiffness, damping );
cpSpaceAddConstraint(space, spring);
the source
 
Posts: 6
Joined: Sun Sep 12, 2010 3:49 pm

Re: Rotate around a point with a spring

Postby jason_rogers » Mon Sep 13, 2010 8:39 pm

Hi
not a big expert in chipmunk
however I don't really see anything fundamentally wrong in your code.
Can you be a bit more specific on the effect your looking to do and what is this not expected behavior your having
jason_rogers
 
Posts: 81
Joined: Fri Aug 27, 2010 1:00 am

Re: Rotate around a point with a spring

Postby the source » Thu Sep 23, 2010 10:53 am

Hi, I worked out - I was defining a shape for the pivot point. This is what was making it go crazy. Removing the shape and it worked fine.
the source
 
Posts: 6
Joined: Sun Sep 12, 2010 3:49 pm

Re: Rotate around a point with a spring

Postby the source » Thu Sep 23, 2010 10:54 am

and the shape for the spring ... not necessary.
the source
 
Posts: 6
Joined: Sun Sep 12, 2010 3:49 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests

cron