当前位置: 首页>>代码示例>>C++>>正文


C++ ColliderBody类代码示例

本文整理汇总了C++中ColliderBody的典型用法代码示例。如果您正苦于以下问题:C++ ColliderBody类的具体用法?C++ ColliderBody怎么用?C++ ColliderBody使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ColliderBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    for(auto& element : armature2->getBoneDic())
    {
        Bone *bone = element.second;
        ColliderDetector *detector = bone->getColliderDetector();
        
        if (!detector)
            continue;
        
        const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
        
        for (auto& object : bodyList)
        {
            ColliderBody *body = static_cast<ColliderBody*>(object);
            const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();
            
            unsigned long length = vertexList.size();
            Vec2 *points = new Vec2[length];
            for (unsigned long i = 0; i<length; i++)
            {
                Vec2 p = vertexList.at(i);
                points[i].x = p.x;
                points[i].y = p.y;
            }
            drawNode->clear();
            drawNode->drawPoly(points, (unsigned int)length, true, Color4F(1.0, 1.0, 1.0, 1.0));
            
            delete []points;
        }
    }
}
开发者ID:songmiao,项目名称:WagonWar,代码行数:32,代码来源:ArmatureScene.cpp

示例2: setCPBody

KDvoid ColliderDetector::setCPBody ( cpBody* pBody )
{
    m_pCPBody = pBody;

    for(auto object : *m_pColliderBodyList)
    {
        ColliderBody *colliderBody = (ColliderBody *)object;

        ContourData *contourData = colliderBody->getContourData();

        int num = contourData->m_tVertexList.count();
        ContourVertex2 **vs = (ContourVertex2 **)contourData->m_tVertexList.data->arr;
        cpVect *verts = new cpVect[num];
        for (int i = 0; i < num; i++)
        {
            verts[num - 1 - i].x = vs[i]->x;
            verts[num - 1 - i].y = vs[i]->y;
        }

        cpShape *shape = cpPolyShapeNew(m_pCPBody, num, verts, cpvzero);

        shape->sensor = true;
        shape->data = m_pBone;

        if ( m_bActive )
        {
            cpSpaceAddShape(m_pCPBody->space, shape);
        }

        colliderBody->setShape(shape);
        colliderBody->getColliderFilter()->updateCPShape(shape);

        delete [] verts;
    }
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:35,代码来源:CCColliderDetector.cpp

示例3: drawContour

void CCArmature::drawContour()
{
    for(auto& element : _boneDic)
    {
        Bone *bone = element.second;
        ColliderDetector *detector = bone->getColliderDetector();

        if (!detector)
            continue;

        const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();

        for (auto& object : bodyList)
        {
            ColliderBody *body = static_cast<ColliderBody*>(object);
            const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();

            unsigned long length = vertexList.size();
            Vec2 *points = new Vec2[length];
            for (unsigned long i = 0; i<length; i++)
            {
                Vec2 p = vertexList.at(i);
                points[i].x = p.x;
                points[i].y = p.y;
            }
            DrawPrimitives::drawPoly( points, (unsigned int)length, true );

            delete []points;
        }
    }
}
开发者ID:2276225819,项目名称:Game,代码行数:31,代码来源:CCArmature.cpp

示例4: setBody

void ColliderDetector::setBody(cpBody *pBody)
{
    _body = pBody;

    for(auto& object : _colliderBodyList)
    {
        ColliderBody *colliderBody = (ColliderBody *)object;

        ContourData *contourData = colliderBody->getContourData();

        ssize_t num = contourData->vertexList.size();
        auto vs = contourData->vertexList;
        cpVect *verts = new cpVect[num];
        for (int i = 0; i < num; i++)
        {
            verts[num - 1 - i].x = vs.at(i).x;
            verts[num - 1 - i].y = vs.at(i).y;
        }

        cpShape *shape = cpPolyShapeNew(_body, (int)num, verts, cpvzero);

        shape->sensor = true;
        shape->data = _bone;

        if (_active)
        {
            cpSpaceAddShape(_body->space_private, shape);
        }

        colliderBody->setShape(shape);
        colliderBody->getColliderFilter()->updateShape(shape);

        delete []verts;
    }
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:35,代码来源:CCColliderDetector.cpp

示例5: removeContourData

void ColliderDetector::removeContourData(ContourData *contourData)
{
	for(auto object : *m_pColliderBodyList)
	{
		ColliderBody *body = (ColliderBody*)object;
		if (body && body->getContourData() == contourData)
		{
			m_pColliderBodyList->removeObject(body);
		}
	}
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:11,代码来源:CCColliderDetector.cpp

示例6: CCARRAY_FOREACH

ColliderDetector::~ColliderDetector()
{
	CCObject *object = NULL;
	CCARRAY_FOREACH(m_pColliderBodyList, object)
	{
		ColliderBody *colliderBody = (ColliderBody*)object;

		ContourData *contourData = colliderBody->getContourData();
		b2Body *body = colliderBody->getB2Body();
		PhysicsWorld::sharedPhysicsWorld()->getNoGravityWorld()->DestroyBody(body);
	}
开发者ID:bo-jwolf,项目名称:Graduation,代码行数:11,代码来源:CSColliderDetector.cpp

示例7: update

void TestColliderDetector::update(float delta)
{
    armature2->setVisible(true);

    Rect rect = bullet->getBoundingBox();

    // This code is just telling how to get the vertex.
    // For a more accurate collider detection, you need to implemente yourself.
    const Map<std::string, cocostudio::Bone*>& map = armature2->getBoneDic();
    for(const auto& element : map)
    {
        cocostudio::Bone *bone = element.second;
        ColliderDetector *detector = bone->getColliderDetector();

        if (!detector)
            continue;

        const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();

        for (const auto& object : bodyList)
        {
            ColliderBody *body = static_cast<ColliderBody*>(object);
            const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();

            float minx = 0, miny = 0, maxx = 0, maxy = 0;
            size_t length = vertexList.size();
            for (size_t i = 0; i<length; i++)
            {
                Vec2 vertex = vertexList.at(i);
                if (i == 0)
                {
                    minx = maxx = vertex.x;
                    miny = maxy = vertex.y;
                }
                else
                {
                    minx = vertex.x < minx ? vertex.x : minx;
                    miny = vertex.y < miny ? vertex.y : miny;
                    maxx = vertex.x > maxx ? vertex.x : maxx;
                    maxy = vertex.y > maxy ? vertex.y : maxy;
                }
            }
            Rect temp = Rect(minx, miny, maxx - minx, maxy - miny);

            if (temp.intersectsRect(rect))
            {
                armature2->setVisible(false);
            }
        }
    }
}
开发者ID:songmiao,项目名称:WagonWar,代码行数:51,代码来源:ArmatureScene.cpp

示例8: new

void ColliderDetector::addContourData(ContourData *contourData)
{
    ColliderBody *colliderBody = new (std::nothrow) ColliderBody(contourData);
    _colliderBodyList.pushBack(colliderBody);
    colliderBody->release();


#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
    std::vector<Vec2> &calculatedVertexList = colliderBody->_calculatedVertexList;
    
    unsigned long num = contourData->vertexList.size();
    for (unsigned long i = 0; i < num; i++)
    {
        calculatedVertexList.push_back(Vec2());
    }
#endif
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:17,代码来源:CCColliderDetector.cpp

示例9: CCDICT_FOREACH

void TestColliderDetector::update(float delta)
{
    armature2->setVisible(true);

    CCRect rect = bullet->boundingBox();

    // This code is just telling how to get the vertex.
    // For a more accurate collider detection, you need to implemente yourself.
    CCDictElement *element = NULL;
    CCDictionary *dict = armature2->getBoneDic();
    CCDICT_FOREACH(dict, element)
    {
        CCBone *bone = static_cast<CCBone*>(element->getObject());
        CCArray *bodyList = bone->getColliderBodyList();

        CCObject *object = NULL;
        CCARRAY_FOREACH(bodyList, object)
        {
            ColliderBody *body = static_cast<ColliderBody*>(object);
            CCArray *vertexList = body->getCalculatedVertexList();

            float minx, miny, maxx, maxy = 0;
            int length = vertexList->count();
            for (int i = 0; i<length; i++)
            {
                CCContourVertex2 *vertex = static_cast<CCContourVertex2*>(vertexList->objectAtIndex(i));
                if (i == 0)
                {
                  minx = maxx = vertex->x;
                  miny = maxy = vertex->y;
                }
                else
                {
                    minx = vertex->x < minx ? vertex->x : minx;
                    miny = vertex->y < miny ? vertex->y : miny;
                    maxx = vertex->x > maxx ? vertex->x : maxx;
                    maxy = vertex->y > maxy ? vertex->y : maxy;
                }
            }
            CCRect temp = CCRectMake(minx, miny, maxx - minx, maxy - miny);

            if (temp.intersectsRect(rect))
            {
                armature2->setVisible(false);
            }
        }
开发者ID:76299500,项目名称:cocos2d-x,代码行数:46,代码来源:ArmatureScene.cpp

示例10: drawContour

void Armature::drawContour()
{
    for(auto& element : _boneDic)
    {
        Bone *bone = element.second;
        ColliderDetector *detector = bone->getColliderDetector();

        if (!detector)
            continue;

        const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();

        for (auto& object : bodyList)
        {
            ColliderBody *body = static_cast<ColliderBody*>(object);
            const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();

            unsigned long length = vertexList.size();
            Vec2 *points = new (std::nothrow) Vec2[length];
            for (unsigned long i = 0; i<length; i++)
            {
                Vec2 p = vertexList.at(i);
                points[i].x = p.x;
                points[i].y = p.y;
            }
            
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
            
            DrawPrimitives::drawPoly( points, (unsigned int)length, true );

#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif
            
            delete []points;
        }
    }
}
开发者ID:funseek,项目名称:TransitionExample,代码行数:45,代码来源:CCArmature.cpp

示例11: ColliderBody

void ColliderDetector::addContourData(ContourData *contourData)
{
    ColliderBody *colliderBody = new ColliderBody(contourData);
    m_pColliderBodyList->addObject(colliderBody);
    colliderBody->release();


#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
    CCArray *calculatedVertexList = colliderBody->getCalculatedVertexList();
    
    int num = contourData->m_tVertexList.count();
    for (int i = 0; i < num; i++)
    {
        ContourVertex2 *newVertex = new ContourVertex2(0, 0);
        calculatedVertexList->addObject(newVertex);
        newVertex->release();
    }
#endif
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:19,代码来源:CCColliderDetector.cpp

示例12: setBody

void ColliderDetector::setActive(bool active)
{
    if (_active == active)
    {
        return;
    }

    _active = active;

#if ENABLE_PHYSICS_BOX2D_DETECT
    if (_body)
    {
        if (active)
        {
            setBody(_body);
        }
        else
        {
            for(auto object : *_colliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                b2Fixture *fixture = colliderBody->getB2Fixture();

                _body->DestroyFixture(fixture);
                colliderBody->setB2Fixture(nullptr);
            }
        }
    }
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
    if (_body)
    {
        if (_active)
        {
            for(auto object : *_colliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                cpShape *shape = colliderBody->getShape();
                if(shape->space_private == nullptr)
                {
                    cpSpaceAddShape(_body->space_private, shape);
                }
            }
        }
        else
        {
            for(auto object : *_colliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                cpShape *shape = colliderBody->getShape();
                if (shape->space_private != nullptr)
                {
                    cpSpaceRemoveShape(_body->space_private, shape);
                }
            }
        }
    }
#endif
}
开发者ID:CryQ,项目名称:coclua,代码行数:58,代码来源:CCColliderDetector.cpp

示例13: setB2Body

void ColliderDetector::setActive(bool active)
{
    if (m_bActive == active)
    {
        return;
    }

    m_bActive = active;

    if (m_pB2Body)
    {
        if (active)
        {
            setB2Body(m_pB2Body);
        }
        else
        {
            for(auto object : *m_pColliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                b2Fixture *fixture = colliderBody->getB2Fixture();

                m_pB2Body->DestroyFixture(fixture);
                colliderBody->setB2Fixture(nullptr);
            }
        }
    }
    else if (m_pCPBody)
    {
        if (m_bActive)
        {
            for(auto object : *m_pColliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                cpShape *shape = colliderBody->getShape();
                if(shape->space == nullptr)
                {
                    cpSpaceAddShape(m_pCPBody->space, shape);
                }
            }
        }
        else
        {
            for(auto object : *m_pColliderBodyList)
            {
                ColliderBody *colliderBody = (ColliderBody *)object;
                cpShape *shape = colliderBody->getShape();
                if (shape->space != nullptr)
                {
                    cpSpaceRemoveShape(m_pCPBody->space, shape);
                }
            }
        }
    }
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:55,代码来源:CCColliderDetector.cpp

示例14: setColliderFilter

void ColliderDetector::setColliderFilter(ColliderFilter *filter)
{
    *m_pFilter = *filter;
    
    for(auto object : *m_pColliderBodyList)
    {
        ColliderBody *colliderBody = (ColliderBody *)object;
        colliderBody->setColliderFilter(filter);


        if (colliderBody->getB2Fixture())
        {
            colliderBody->getColliderFilter()->updateB2Shape(colliderBody->getB2Fixture());
        }

        if (colliderBody->getShape())
        {
            colliderBody->getColliderFilter()->updateCPShape(colliderBody->getShape());
        }
    }
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:21,代码来源:CCColliderDetector.cpp

示例15: setColliderFilter

void ColliderDetector::setColliderFilter(ColliderFilter *filter)
{
    *_filter = *filter;
    
    for(auto object : *_colliderBodyList)
    {
        ColliderBody *colliderBody = (ColliderBody *)object;
        colliderBody->setColliderFilter(filter);

#if ENABLE_PHYSICS_BOX2D_DETECT
        if (colliderBody->getB2Fixture())
        {
            colliderBody->getColliderFilter()->updateShape(colliderBody->getB2Fixture());
        }
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
        if (colliderBody->getShape())
        {
            colliderBody->getColliderFilter()->updateShape(colliderBody->getShape());
        }
#endif
    }
}
开发者ID:CryQ,项目名称:coclua,代码行数:22,代码来源:CCColliderDetector.cpp


注:本文中的ColliderBody类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。