Calculation verts for cpShape of polygons


#1

Hi! I’ve recently started working on my firs game for mobile devices using this awesome engine and I’ve encounered some difficulties with creating a physical objects in my game. The thing is that when I use the following code I use cpVert array of 4 points and then the cpShape would be a rectangle.
So as it’s just a rectangle it behaves as a rectangle but the image in the space is a cloud. Basically this cloud has a non-rectangle shape and I’d like it to behave as ab object of an irregular shape. Is there any methods to calculate cpVect verts[] = array from textures or what else can I do for my purpose?

Thanks in advance!
I’d really appreciate your help!

@ CPhiysicsSprite* Sprite = new CPhiysicsSprite;

CCSize size = pNode~~>getTexture~~>getContentSize;
Sprite~~>initWithTexture);
Sprite~~>autorelease();
Sprite~~>setScale;
pNode~~>addChild(Sprite);

Sprite~~>setPosition;
int num = 4;
cpVect verts[] = {
cpv,
cpv,
cpv,
cpv,
};
float mass = 3.0f;
cpBody *body = cpBodyNew);
body~~>p = cpv(pos.x, pos.y);
cpSpaceAddBody(m_pSpace, body);

cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);

shape~~>e = 0.5f; shape~~>u = 0.5f;
cpSpaceAddShape(m_pSpace, shape);
Sprite->setPhysicsBody(body);

cpBodyApplyForce(body,cpv(0,1000),cpvzero);@


#2

Cocos2d and box2d don’t have auto create physic shape with the texture.
You can create this polygons shape with many little shapes, or used physics editor cocos2d and that create many shape without you.
I use http://www.codeandweb.com/physicseditor


#3

Misha Philypchuk,

I guess this physics editor generates some plist file? I would really like to see some example of using this file. I’ve seen using this file for animation but their solution is not applicable for us. Could you please show how to use this editor in code or point me on a right link with example? Thanks!


#4

Not sure if this thread still alive but if it is can anyone clear this field out please? I apreciate in advance!


#5

The basics is to understand what do I make cpVect verts[] = for shape of?


#6

GB2ShapeCache class for loading physics .plist in cocos2d-x/box2d
You can see how then create physics shape.
Look this:
http://www.cocos2d-iphone.org/forum/topic/13456


#7

Thanks alot Misha,

It seems like they’re using box2d. How about chipmunk? do you have any examples for that in C++ ?


#8

Sorry but I have not worked with chipmunk.
But I think that working with GB2ShapeCache possible.


#9

Yeah but not in C++ unfortunately…


#10

Misha Philypchuk,

Do you know anybody who’s been working with Chipmunk? :slight_smile:

I’m just trying to find a solution….


#11

No, I do not know anyone who works with chipmunk.
You can translate with Objective-C to c++, is not difficult


#12

okay, thanks. I think we’re gonna have to write up some image self tracer on Qt that would just generate the cpVect [] array to copy-and-paste… So manually hit the edjes of a picture and save their position.


#13

Well, making an editor didn’t resolve the problem. Still thinking of how to make polygons to behave as an adequatic physics body…