How to create shape like flipper in my pinball game

Hi,

I have to create body and shape like following image.

http://i785.photobucket.com/albums/yy13 ... r_left.png

So how can i create shape like this image.

If supposed i want to create polygon for this type of flipper then what vertex point should i give. I am =not getting vertex for my polygon.

Please advise me.

Thanks,
iPhone Dev.
Hi,

I am trying to create polygon for this flipper image like,

Code:
AtlasSprite* flipperSpt = [AtlasSprite spriteWithRect:CGRectMake(0,0,66,46) spriteManager:altSptMgr];
[flipperSpt setTransformAnchor: ccp([flipperSpt contentSize].width-12, [flipperSpt contentSize].height-14)];
flipperSpt.position = ccp(182, 260); //.Set(182/PTM_RATIO, 280/PTM_RATIO);
[altSptMgr addChild:flipperSpt z:0];
   
b2BodyDef bodyDef;
bodyDef.position.Set(182/PTM_RATIO, 260/PTM_RATIO);
BodyUserData* userData = [[BodyUserData alloc] initWithBodyType:kTagFlipperBodyType AtlasSprite:flipperSpt AtlasSpriteManager:altSptMgr];
bodyDef.userData = static_cast<void*>(userData);
body = mWorld->CreateBody(&bodyDef);
   
b2PolygonDef shapeDef;
shapeDef.friction = WALL_FRICTION;
shapeDef.vertexCount = 5;
shapeDef.density = 7.0f;
      
shapeDef.vertices[0].Set(-30.0f/PTM_RATIO, -2.0f);
shapeDef.vertices[1].Set(-33.0f/PTM_RATIO, 0);
shapeDef.vertices[2].Set(-30.0f/PTM_RATIO, -2.0f/PTM_RATIO);
shapeDef.vertices[3].Set(30.0f/PTM_RATIO, 5.0f/PTM_RATIO);
shapeDef.vertices[4].Set(30.0f/PTM_RATIO, -5.0f/PTM_RATIO);


This code is crashing apps and giving this error
Quote:
Assertion failed: (area > 1.19209290e-7F), function ComputeCentroid, file /Developer/Library/cocos2d-iphone-0.8/external/Box2d/Source/Collision/Shapes/b2PolygonShape.cpp, line 85.
. I don't know where i am going wrong.

Anybody can give some advise on vertex points.

Thanks.
What is the value of PTM_RATIO?

Try reversing the vertex order.
Hi,

Thanks for your reply,

PTM_RATIO is 50.

Thanks.
Hi,

I tried to reverse order of vertex but it didn't work. Please have a look on the following image, i need to have v0, v1, v2, v3, v4, v5. Now i am trying to give following points for polygon but it didn't work also.

Image

v0 = (25, 15),
v1 = (32, 5),
v2 = (32, -5),
v3 = (25, -15),
v4 = (32, 24),
v5 = (-32, -24),

Please give some advise that where i am wron this points.

Thanks a lot.
I just posted a video tutorial of how to create pinball flippers (rest of the tutorial is coming soon).

viewtopic.php?f=6&t=3552

It is a combination of two circles and a polygon forming a single body.

Fahri
Hi Friend,

Thanks for your reply and video tutorial.

Actually i am developing pinball game for iphone, so i have to do by coding.

Thanks.
If you type

>>> system.createBox2DCpp('c://your_directory//pinball.h')

at the interpreter, Mekanimo would create the equivalent C++ code for you.
your mesurements might be quite large, causing problems.

(in my experience with box2dFlash)
there are 30 pixels per meter (by default). so you may want to divide each of your measurements by 30 to bring things back down to scale.
iphonemobdev wrote:
shapeDef.vertices[0].Set(-30.0f/PTM_RATIO, -2.0f);
shapeDef.vertices[1].Set(-33.0f/PTM_RATIO, 0);
shapeDef.vertices[2].Set(-30.0f/PTM_RATIO, -2.0f/PTM_RATIO);
shapeDef.vertices[3].Set(30.0f/PTM_RATIO, 5.0f/PTM_RATIO);
shapeDef.vertices[4].Set(30.0f/PTM_RATIO, -5.0f/PTM_RATIO);


It looks like you have typos in your vertices and the order is wrong. Try this:
Code:
shapeDef.vertices[4].Set(-30.0f/PTM_RATIO, -2.0f/PTM_RATIO); // typo, forgot PTM_RATIO
shapeDef.vertices[3].Set(-33.0f/PTM_RATIO, 0);
shapeDef.vertices[2].Set(-30.0f/PTM_RATIO, 2.0f/PTM_RATIO); // typo, sign flipped
shapeDef.vertices[1].Set(30.0f/PTM_RATIO, 5.0f/PTM_RATIO);
shapeDef.vertices[0].Set(30.0f/PTM_RATIO, -5.0f/PTM_RATIO);

Original thread: https://box2d.org/forum/viewtopic.php?t=3555