Chipmunk questions

Sage
Posts: 1,482
Joined: 2002.09
Post: #31
I think you are a little confused. Chipmunk spaces are pretty much infinite. They fill up everything.

"What are the window's center's coordinates in the space's coordinates?" Assuming that you draw the objects in the space in the window's coordinates, then the two coordinate systems are the same and the windows center is it's own coordinates.

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
Member
Posts: 131
Joined: 2010.08
Post: #32
Where is the space's origin? I could not find any method to change the origin.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #33
It's absolute coordinates, the origin is always at (0,0). If you need to draw the origin somewhere else you need to set up your drawing transforms or offsets to do so.

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
Member
Posts: 131
Joined: 2010.08
Post: #34
When a body is moving, I have tried pressing the key that causes acceleration in the other direction. When its velocity is 0 and I unpress the key, the body's velocity returns to the direction that it was moving in, although the speed is lower. I have to do this at least two times to get the velocity to truly 0. How to correct this problem?
Code:
When the right arrow key is pressed:
force.x = FORCE;

In the update method:
cpBodySetForce(body, force);
cpBodyUpdateVelocity(body, cpvzero, 1, deltaTime);
cpBodyUpdatePosition(body, deltaTime);
cpSpaceStep(space, deltaTime);
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #35
Chipmunk calls cpBodyUpdateVelocity() and cpBodyUpdatePosition() for you. You don't need to call them yourself.

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
Member
Posts: 131
Joined: 2010.08
Post: #36
I removed them but still got the behavior. I also noticed that the body starts moving in the same direction even if I accelerate beyond 0 velocity in the opposite direction, although only for a small opposite velocity.
Side question: if it calls them automatically, how does it know deltaTime?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #37
Because you pass the delta time to cpSpaceStep() and it forwards it on.

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
Member
Posts: 131
Joined: 2010.08
Post: #38
I added cpBodyResetForces(body) before cpBodySetForce(body, force), but the problem persisted. Then I tried changing cpBodySetForce(body, force) to cpBodyApplyForce(body, force, cpvzero) but the behavior still persisted. Could you tell what is wrong with using
Code:
[circle moveBody];
cpBodyResetForces(body);
cpBodyApplyForce(body, force, cpvzero);
cpSpaceStep(space, deltaTime);
to do a simple rigid body simulation.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #39
Chipmunk only changes the velocity of things if you have gravity set or are applying forces or impulses to the body. I'm not quite sure what you are describing either. Can you make a video of it maybe?

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
Member
Posts: 131
Joined: 2010.08
Post: #40
I solved the problem. It was not with Chipmunk, but in the glTranslate method.
Next question: In my application, two circle bodies do not collide when they touch. What is the problem?
Code:
In initialization:
    cpInitChipmunk();
    space = cpSpaceNew();
    cpSpaceAddBody(space, circle1.body);
    cpShape *shape = cpSpaceAddShape(space, cpCircleShapeNew(circle1.body, RADIUS*size.height, cpvzero));
    cpSpaceAddBody(space, circle2.body);
    cpShape *shape2 = cpSpaceAddShape(space, cpCircleShapeNew(circle2.body, RADIUS*size.height, cpvzero));

In update:
    [circle1 moveCircle];
    [circle2 moveCircle];
    cpBodyResetForces(circle1.body);
    cpBodyResetForces(circle2.body);
    cpBodyApplyForce(circle1.body, circle.force, cpvzero);
    cpBodyApplyForce(circle2.body, circle2.force, cpvzero);
    cpSpaceStep(space, deltaTime);
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #41
Is it bad that I ask so many questions in these forums?
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #42
Nope. That's what the forums are for!

Folks around here don't like to do the leg-work for other people though, so as long as it's obvious you're making an effort to solve your problems on your own first, feel free to ask as many questions as you wish. Smile
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #43
I think that by including relevant code, people understand that I have made an effort to try to solve the problem. It is much better than including no code or including the entire project. Could you answer the question that I asked before the last post
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #44
I don't see anything wrong with the code that you posted. How are you initializing the bodies?

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
Member
Posts: 131
Joined: 2010.08
Post: #45
circle1.body = cpBodyNew(1, 0);
Quote this message in a reply
Post Reply