Search…

Chipmunk - Phần 4: Constraints (Tiếp Theo)

30/09/20201 min read
Giới thiệu về constraints và các loại constraints còn lại có sẵn trong thư viện Chipmunk.

Rotary spring joints

Giống như Spring Joints, nhưng làm việc với các trục quay. 

m_world->addJoint(PhysicsJointPin::construct(paddleBody1, boundBody, Vec2(300, 300)));
m_world->addJoint(PhysicsJointPin::construct(paddleBody2, boundBody, Vec2(600, 300)));

PhysicsJointRotarySpring* jointRotarySpring = PhysicsJointRotarySpring::construct(paddleBody1, 
                                                              paddleBody2, stiffness, damping);

m_world->addJoint(jointRotarySpring);

Với boundBody là Physics Body của cái khung bao quanh màn hình.

ss_1

Rotary limit joints

Giống như Limit Joint, nhưng làm việc với các trục quay.

m_world->addJoint(PhysicsJointPin::construct(paddleBody1, boundBody, Vec2(300, 300)));
m_world->addJoint(PhysicsJointPin::construct(paddleBody2, boundBody, Vec2(600, 300)));

PhysicsJointRotaryLimit* jointRotaryLimit = PhysicsJointRotarySpring::construct(paddleBody1,
                                                                       paddleBody2, min, max);

m_world->addJoint(jointRotarySpring);

Ratchet joints

Làm việc như một ổ khóa, nếu xoay một trong các bodies, body còn lại sẽ quay cùng chiều với body ban đầu. Khi quay càng nhanh thì body còn lại sẽ quay theo càng nhanh. Nhưng nếu quay ngược lại thì body còn lại vẫn quay theo chiều ban đầu. 

m_world->addJoint(PhysicsJointPin::construct(paddleBody1, boundBody, Vec2(300, 300)));
m_world->addJoint(PhysicsJointPin::construct(paddleBody2, boundBody, Vec2(600, 300)));

PhysicsJointRatchet* jointRotarySpring = PhysicsJointRachet::construct(paddleBody1, 
                                                           paddleBody2, phase, ratchet);

m_world->addJoint(jointRotarySpring);

Gear joints

Giữ tỷ lệ vận tốc góc của cặp bodies tham gia vào joint liên tục. Tỷ lệ luôn luôn được đo trong điều kiện tuyệt đối. 

m_world->addJoint(PhysicsJointPin::construct(paddleBody1, boundBody, Vec2(300, 300)));
m_world->addJoint(PhysicsJointPin::construct(paddleBody2, boundBody, Vec2(600, 300)));

PhysicsJointGear* jointRotarySpring = PhysicsJointGear::construct(paddleBody1, paddleBody2,
                                                                             phase, ratio);

m_world->addJoint(jointRotarySpring);

Motor joints

Giữ vận tốc góc tương đối của hai đối tượng tham gia vào joint liên tục.

m_world->addJoint(PhysicsJointPin::construct(paddleBody1, boundBody, Vec2(300, 300)));
m_world->addJoint(PhysicsJointPin::construct(paddleBody2, boundBody, Vec2(600, 300)));

PhysicsJointMotor* jointRotarySpring = PhysicsJointRotarySpring::construct(paddleBody1, 
                                                                     paddleBody2,rate);

m_world->addJoint(jointRotarySpring);
IO Stream

IO Stream Co., Ltd

30 Trinh Dinh Thao, Hoa Thanh ward, Tan Phu district, Ho Chi Minh city, Vietnam
+84 28 22 00 11 12
developer@iostream.co

383/1 Quang Trung, ward 10, Go Vap district, Ho Chi Minh city
Business license number: 0311563559 issued by the Department of Planning and Investment of Ho Chi Minh City on February 23, 2012

©IO Stream, 2013 - 2024