2012-10-21 45 views
7

मैं यह जानना चाहता हूं कि जब कोई (गेंद) किसी अन्य वस्तु को स्पर्श करता है (लक्ष्य) और मैं उस संपर्क के आवेग को जानना चाहता हूं।बुलेटफिसिक: संपर्क बल/आवेग

मैं संपर्कों

gContactAddedCallback 

या

int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds(); 
    for (int i=0;i<numManifolds;i++) 
    { 
     btRigidBody* obA = static_cast<btRigidBody*>(contactManifold->getBody0()); 
     btRigidBody* obB = static_cast<btRigidBody*>(contactManifold->getBody1()); 
     // May be there is contact obA and obB 

     btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i); 
     int numContacts = contactManifold->getNumContacts(); 
     for (int j=0;j<numContacts;j++) 
     { 
      btManifoldPoint& pt = contactManifold->getContactPoint(j); 
      if (pt.getDistance()<0.f) 
      { 
       // One contact point is inside of another object 
       // But some contacts are ignored 
      } 
     } 
    } 

या

रैखिक और कोणीय वेग परिवर्तन की जाँच करें पता लगाने के लिए तीन तरीके से जानते हैं। (यदि वहाँ संपर्क था नहीं स्पष्ट और क्या वस्तु की गति परिवर्तन किया है, यह आपत्ति थी या उदासीनता, गुरुत्वाकर्षण या कुछ बल क्षेत्र।


मैं संपर्क जानकारी है के लिए संपर्क आवेग शामिल करना चाहते हैं। मैं कुछ है कि देखा 1 फ्रेम सिमुलेशन में हल किए गए संपर्क में 2 फ्रेम लेते हैं और आवेग दो गुना कम होता है। (मुझे इसे डिबगिंग कोड मिला है।) मैं कुल आवेग के साथ 1 संपर्क अधिसूचना प्राप्त करने के लिए सही होगा।

मुझे सूचीबद्ध तरीकों में से कोई भी मुझे नहीं देता संपर्क के लिए पूरी जानकारी। जब गेंद लक्ष्य के पास उड़ती है और यहां तक ​​कि इसे छूती नहीं है तो कुछ बार यह आग लगती है।

ऐसा करने का अनुमानित तरीका क्या है?

ऐसी जानकारी प्रभाव ध्वनि चलाने या कुछ एनीमेशन शुरू करने के लिए उपयोग की जा सकती है यदि संपर्क ऊर्जा अधिक है।

+1

pt.getAppliedImpulse() – rraallvv

+0

pt.getAppliedImpulse() में posible दिशा पर आप में इंगित करना चाहिए - मैं इस एक याद किया! उत्तर जोड़ें और मैं इसे इस तरह चिह्नित करूंगा। धन्यवाद – Max

उत्तर

3

इस कोड

// some global constants needed 

enum collisiontypes { 
    NOTHING   = 0, // things that don't collide 
    BALL_BODY  = 1<<2, // is ball 
    TARGET_BODY  = 1<<3 // is target 
}; 

int ballBodyCollidesWith = TARGET_BODY | BALL_BODY; // balls collide with targets and other balls 
int targetBodyCollidesWith = BALL_BODY; // targets collide with balls 

// ... 
// bodies creation 

dynamicsWorld->addRigidBody(ballBody, BALL_BODY, ballBodyCollidesWith); 

dynamicsWorld->addRigidBody(targetBody, TARGET_BODY, targetBodyCollidesWith); 

//... 
// find out whether a ball collides with a target 

int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds(); 
for (int i=0;i<numManifolds;i++) 
{ 
    btRigidBody* obA = static_cast<btRigidBody*>(contactManifold->getBody0()); 
    btRigidBody* obB = static_cast<btRigidBody*>(contactManifold->getBody1()); 
    // May be there is contact obA and obB 

    // ignore bodies that are not balls or targets 
    if (
     (!(obA->getCollisionFlags() | BALL_TYPE) && !(obB->getCollisionFlags() | BALL_TYPE)) // there is no BALL_TYPE colliding 
     || 
     (!(obA->getCollisionFlags() | TARGET_TYPE) && !(obB->getCollisionFlags() | TARGET_TYPE)) // there is no TARGET_TYPE colliding 
     ) 
     continue; // no more searching needed 

    btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i); 
    int numContacts = contactManifold->getNumContacts(); 
    for (int j=0;j<numContacts;j++) 
    { 
     btManifoldPoint& pt = contactManifold->getContactPoint(j); 

     printf("%f\n", pt.getAppliedImpulse()); // log to see the variation range of getAppliedImpulse and to chose the appropriate impulseThreshold 
     if (pt.getAppliedImpulse() > impulseThreshold) 
     { 
       // increase score or something 
       break; // no more searching needed 
     } 
    } 
} 
+2

मुझे खेद है। मैं इसे जवाब नहीं दे सकता। मैं केवल +1 देता हूं। मैंने pt.getAppliedImpulse() का परीक्षण किया और यह काम नहीं करता है। जब मुझे लगता है कि यह सिमुलेशन में हुआ था और मेरी गति में काफी बदलाव आया है, तब भी इसमें अक्सर कुल आवेग होता है। या numContacts शून्य है। – Max

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^