Box2d selected Rigid Body in coco2d-x

Source: Internet
Author: User

The normal selection won't be mentioned here. As provided in box2d, a quick selection class with relatively high efficiency is b2QueryCallback.

#ifndef QueryCallback_H#define QueryCallback_H#include 
 
  class QueryCallback :public b2QueryCallback{public:QueryCallback(void);QueryCallback(const b2Vec2& point);~QueryCallback(void);bool ReportFixture(b2Fixture* fixture);b2Vec2 m_point;b2Fixture* m_fixture;std::vector
  
    m_vectFixture;};#endif
  
 

#include "QueryCallback.h"QueryCallback::QueryCallback(void){}QueryCallback::QueryCallback(const b2Vec2& point){m_point = point;m_fixture = NULL;}QueryCallback::~QueryCallback(void){}bool QueryCallback::ReportFixture(b2Fixture* fixture){b2Body* body = fixture->GetBody();if (body->GetType() == b2_dynamicBody){bool inside = fixture->TestPoint(m_point);if (inside){m_fixture = fixture;m_vectFixture.push_back(fixture);// We are done, terminate the query.return true;}}// Continue the query.return true;}

Using this class, you can quickly select a rigid body for callback, with high efficiency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.