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


C++ PhysicsObject::passedThrough方法代码示例

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


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

示例1: update

void PhysicsObject::update(vector<PhysicsObject*> & otherObjects, float dTime)
{    
    for (int i=0; i<otherObjects.size(); i++){
        
        PhysicsObject *otherObject = otherObjects[i];
        
        // handle collisions
        // A-posteriori collision detection
        if (intersecting(otherObject) || passedThrough(otherObject) || otherObject->passedThrough(this)){
            
            collide(otherObject, dTime);
            
            // if still intersecting, split the difference
            if (intersecting(otherObject))
            {
                ofVec2f difference = otherObject->position - position;
                if (difference.length() == 0) difference = ofVec2f(1,0);
                float overlap = (boundingRadius + otherObject->boundingRadius - position.distance(otherObject->position));
                                
                difference.normalize();
                
                if (isAnchored){
                    otherObject->position += overlap * difference;
                }
                else if (otherObject->isAnchored){
                    position -= overlap * difference;
                }
                else{
                    position -= overlap * (difference/2.0f);
                    otherObject->position += overlap * (difference/2.0f);
                }
            }
        }
            
        // Calculate and update forces
        ofVec2f forceToMe = otherObject->forceAppliedTo(this, dTime);
        ofVec2f forceToOther = forceAppliedTo(otherObject, dTime);
        
        force += forceToMe;
        otherObject->force += forceToOther;

    }
    
    // Collide against walls
    if (position.x - boundingRadius < 0){
        velocity.x *= -1;
        position.x = boundingRadius;
    }
    else if (position.x + boundingRadius > ofGetWidth())
    {
        velocity.x *= -1;
        position.x = ofGetWidth() - boundingRadius;
    }
    
    if (position.y - boundingRadius < 0){
        velocity.y *= -1;
        position.y = boundingRadius;
    }
    else if (position.y + boundingRadius > ofGetHeight()){
        velocity.y *= -1;
        position.y = ofGetHeight() - boundingRadius;
    }
}
开发者ID:dylanrjames,项目名称:RaizWall,代码行数:63,代码来源:PhysicsObject.cpp


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