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


C++ PhysicalObject::getVelocity方法代码示例

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


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

示例1: collided

    const SUCCESS PhysicalObject::collided(PhysicalObject &object, const Radians angle)
    {
        Vector initVec(getVelocity()-object.getVelocity());
        Mag_t<double> initVel(initVec.mag());
        Radians initTheta(initVec.theta());
        
		if(fabs(getX(initVel, initTheta-angle)) < REST_THRESHOLD)
        {
			setVelocity(getVelocity()+initVec/2.0);
			object.setVelocity(object.getVelocity()-initVec/2.0);
            antigravitate(object);
            object.antigravitate(*this);
			return SUCCEEDED;
		}
		
        // Frame of reference with the object at rest with this approaching it with an angle of 0
        Point<double> p2(Vector(Mag_t<double>(2.0*getMass()*getX(initVel, initTheta-angle)/(getMass()+object.getMass())), initTheta-angle));  // Gets the velocity of 2 based on elastic collision equation
        Point<double> p1((initVel*getMass()-p2.x()*object.getMass())/getMass(), -p2.y()*object.getMass()/getMass());   // Gets the velocity of 1 based off of elastic collision rulez
        
        if(fabs(p1.x()) < REST_THRESHOLD && fabs(p2.x()) < REST_THRESHOLD)
        {
            p1.x(0.0);
            p2.x(0.0);
        }
        
        Vector v1(p1);
        Vector v2(p2);
        
        v1.theta(-v1.theta()+initTheta);
        v2.theta(angle);
        
        v1 += object.getVelocity();
        v2 += object.getVelocity();
        
        Point<double> dif(object.getPosition()-*position);
        while(getCollider()->collides(*object.getCollider()))
            acceleration.set(*position-dif/pythagoras<double>(dif));
        
        setVelocity(v1);
        object.setVelocity(v2);
        
        return SUCCEEDED;
    }
开发者ID:JERlabs,项目名称:JERonimo,代码行数:43,代码来源:PhysicalObject.cpp

示例2: collided

 const SUCCESS StaticObject::collided(PhysicalObject &object, const Radians angle)
 {
     Vector v(object.getVelocity());
     v.theta() -= angle;
     Point<double> appliedMomentum(v);
     if(fabs(appliedMomentum.x()) < REST_THRESHOLD)
     {
         appliedMomentum.x(0);
     }
     appliedMomentum.x() *= -1;
     v = appliedMomentum;
     v.theta() += angle;
     object.setVelocity(v);
     
     Point<double> dif(getPosition()-object.getPosition());
     while(getCollider()->collides(*object.getCollider()))
         object.setPosition(object.getPosition()-dif/pythagoras<double>(dif));
     
     return SUCCEEDED;
 }
开发者ID:JERlabs,项目名称:JERonimo,代码行数:20,代码来源:StaticObject.cpp


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