Hello everybody. I created a polygon, added a physicsbody to it, set rotation and position, how ever, the result is something strange.Sometimes it works and other times not working.Actually position of created node will be (0, 0).
Vector<PhysicsShape*> allShapes = node->getPhysicsBody()->getShapes();
std::vector<DrawNode*> allNodes;
DrawNode* drawNode;
PhysicsBody* physicsBody;
std::vector<Vec2> points;
PhysicsShapePolygon* shapePolygon;
shapePolygon = dynamic_cast<PhysicsShapePolygon*>(allShapes.at(0));
drawNode = DrawNode::create();
for(int i = 0; i < shapePolygon->getPointsCount(); i++)
{
points.push_back(shapePolygon->getPoint(i));
}
drawNode->drawPolygon(&points[0], points.size(), Color4F::WHITE, 2, Color4F::RED);
drawNode->setPosition(node->getPosition());
drawNode->setRotation(node->getRotation());
physicsBody = PhysicsBody::createPolygon(&points[0], points.size(),
PHYSICSBODY_MATERIAL_DEFAULT, Vec2::ZERO);
physicsBody->setGravityEnable(false);
physicsBody->setDynamic(true);
drawNode->addComponent(physicsBody);
allNodes.push_back(drawNode);
currentScene->addChild(drawNode);
points.clear();
Note that when there is no physicsbody, drawnode is positioned correctly but that physics body has problem.