|
@@ -21,17 +21,12 @@ bool BlocksLayer::init() {
|
|
|
|
|
|
this->setPosition(center);
|
|
|
|
|
|
- for (int i = 0; i >= 0; i--) {
|
|
|
- auto circle = createCircle(CORE_RADIUS, i, 10, 0.1);
|
|
|
+ for (int i = 5; i >= 0; i--) {
|
|
|
+ auto circle = createCircle(CORE_RADIUS*0.75, i, 10, 0.1);
|
|
|
this->addChild(circle, 9);
|
|
|
}
|
|
|
|
|
|
- auto material = PHYSICSBODY_MATERIAL_DEFAULT;
|
|
|
- material.density = 1.0f;
|
|
|
- material.restitution = 1.0f;
|
|
|
- material.friction = 0.0f;
|
|
|
-
|
|
|
- auto physicsBody = PhysicsBody::createCircle(CORE_RADIUS, material);
|
|
|
+ auto physicsBody = PhysicsBody::createCircle(CORE_RADIUS, PhysicsMaterial(0.1f, 1.0f, 0.0f));
|
|
|
physicsBody->setGravityEnable(false);
|
|
|
physicsBody->setVelocity(Vec2(0,0));
|
|
|
physicsBody->setLinearDamping(0);
|
|
@@ -42,20 +37,20 @@ bool BlocksLayer::init() {
|
|
|
|
|
|
core->drawDot(Vec2(), CORE_RADIUS, COLOR_red);
|
|
|
core->addComponent(physicsBody);
|
|
|
- this->addChild(core);
|
|
|
+ this->addChild(core, 40);
|
|
|
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-Node* BlocksLayer::createCircle (float size, int number, int number_of_segments, float p) {
|
|
|
+Node* BlocksLayer::createCircle (double size, int number, int number_of_segments, double p) {
|
|
|
auto node = Node::create();
|
|
|
- float interna = number * size + CORE_RADIUS;
|
|
|
- float externa = (1 + number) * size + CORE_RADIUS;
|
|
|
+ double interna = number * size + CORE_RADIUS;
|
|
|
+ double externa = (1 + number) * size + CORE_RADIUS;
|
|
|
+
|
|
|
+ double* points = new double[number_of_segments+2];
|
|
|
+
|
|
|
|
|
|
- float* points = new float[number_of_segments+2];
|
|
|
- bool* indestrictible = new bool[number_of_segments+1];
|
|
|
-
|
|
|
for (int i = 0; i < number_of_segments; i++) {
|
|
|
points[i] = 2.0*M_PI/number_of_segments * i;
|
|
|
points[i] += rand_minus1_1()*0.9*M_PI/number_of_segments;
|
|
@@ -64,44 +59,82 @@ Node* BlocksLayer::createCircle (float size, int number, int number_of_segments,
|
|
|
points[number_of_segments] = points[0] + 2*M_PI;
|
|
|
|
|
|
for (int i = 0; i < number_of_segments; i++) {
|
|
|
- CCLOG(">> %d (%f %f)", i, points[i], points[i+1]);
|
|
|
- auto seg = createSegment(interna+3, externa, points[i]+0.02, points[i+1]-0.015, 1, false);
|
|
|
+ auto seg = createSegment(interna, externa, points[i], points[i+1], false);
|
|
|
node->addChild(seg);
|
|
|
}
|
|
|
+ auto back = DrawNode::create();
|
|
|
+ back->drawDot(Vec2(), interna+2, Color4F(COLOR_back));
|
|
|
+ node->addChild(back, 1);
|
|
|
+
|
|
|
+ auto rotate = RotateBy::create(1, rand_minus1_1()*30.0);
|
|
|
+
|
|
|
+ node->runAction(RepeatForever::create(rotate));
|
|
|
|
|
|
delete [] points;
|
|
|
return node;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-Node* BlocksLayer::createSegment (float r_internal, float r_externa, float begin, float end, int resolution, bool especial) {
|
|
|
+Node* BlocksLayer::createSegment (double r_internal, double r_externa, double begin, double end, bool especial) {
|
|
|
int i;
|
|
|
+ double sinV, cosV, step;
|
|
|
auto draw = DrawNode::create();
|
|
|
- auto material = PHYSICSBODY_MATERIAL_DEFAULT;
|
|
|
- material.density = 1.0f;
|
|
|
- material.restitution = 1.0f;
|
|
|
- material.friction = 0.0f;
|
|
|
|
|
|
-
|
|
|
- int n_points = roundf((end-begin)*r_externa*resolution);
|
|
|
+
|
|
|
+ begin += 1/r_externa;
|
|
|
+ end -= 1/r_externa;
|
|
|
+
|
|
|
+ int ns_ex_draw;
|
|
|
+ int ns_in_phy;
|
|
|
+ int ns_ex_phy;
|
|
|
+
|
|
|
+ ns_ex_draw = (end - begin)*r_externa/10.0;
|
|
|
+ ns_ex_phy = (end - begin)*r_externa/50.0;
|
|
|
+ ns_in_phy = (end - begin)*r_internal/50.0;
|
|
|
+
|
|
|
+
|
|
|
+ if (ns_ex_draw < 2) ns_ex_draw = 2;
|
|
|
+ if (ns_ex_phy < 2) ns_ex_phy = 2;
|
|
|
+ if (ns_in_phy < 2) ns_in_phy = 2;
|
|
|
+
|
|
|
+ std::vector<Vec2> p_ex_draw(ns_ex_draw+2);
|
|
|
+ p_ex_draw[ns_ex_draw+1] = Vec2();
|
|
|
|
|
|
- std::vector<Vec2> points(2*n_points+2);
|
|
|
+ std::vector<Vec2> p_physics(ns_in_phy+ns_ex_phy+2);
|
|
|
|
|
|
- float step = (end-begin)/n_points;
|
|
|
|
|
|
- for (i = 0; i <= n_points; i++) {
|
|
|
- float sin = sinf(begin+step*i);
|
|
|
- float cos = cosf(begin+step*i);
|
|
|
-
|
|
|
- points[i] = Vec2 (sin * r_externa, cos * r_externa);
|
|
|
- points[2*n_points-i+1] = Vec2 (sin * r_internal, cos * r_internal);
|
|
|
+ step = (end - begin)/(double)ns_ex_draw;
|
|
|
+ for (i = 0; i <= ns_ex_draw; i++) {
|
|
|
+ sinV = sin(begin + step * (double) i) * r_externa;
|
|
|
+ cosV = cos(begin + step * (double) i) * r_externa;
|
|
|
+ p_ex_draw[i] = Vec2 (sinV, cosV);
|
|
|
+ }
|
|
|
+
|
|
|
+ step = (end - begin)/(double)ns_ex_phy;
|
|
|
+ for (i = 0; i <= ns_ex_phy; i++) {
|
|
|
+ sinV = sin(begin + step * (double) i) * r_externa;
|
|
|
+ cosV = cos(begin + step * (double) i) * r_externa;
|
|
|
+ p_physics[i] = Vec2 (sinV, cosV);
|
|
|
+ }
|
|
|
+
|
|
|
+ step = (end - begin)/(double)ns_in_phy;
|
|
|
+ for (i = 0; i <= ns_in_phy; i++) {
|
|
|
+ sinV = sin(begin + step * (double) i) * r_internal;
|
|
|
+ cosV = cos(begin + step * (double) i) * r_internal;
|
|
|
+ p_physics[ns_ex_phy - i + 1 + ns_in_phy] = Vec2 (sinV, cosV);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
Color4B color = Color4B(102*(rand_0_1()/5+0.5), 217*(rand_0_1()/5+0.5), 239*(rand_0_1()/5+0.5), 255);
|
|
|
- draw->drawSolidPoly(points.data(), 2*n_points+2, Color4F(color));
|
|
|
-
|
|
|
+ draw->drawSolidPoly(p_ex_draw.data(), ns_ex_draw + 2, Color4F(color));
|
|
|
+
|
|
|
+ auto physicsBody = PhysicsBody::createEdgePolygon(p_physics.data(), ns_in_phy+ns_ex_phy+2, PhysicsMaterial(0.1f, 1.0f, 0.0f));
|
|
|
+ physicsBody->setGravityEnable(false);
|
|
|
+ physicsBody->setDynamic(false);
|
|
|
+ physicsBody->setContactTestBitmask(0xFFFFFFFF);
|
|
|
+
|
|
|
+ draw->addComponent(physicsBody);
|
|
|
+ draw->setTag(BLOCK_TAG);
|
|
|
+
|
|
|
return draw;
|
|
|
}
|
|
|
|