本文整理汇总了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;
}
}