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


C++ MovableObject::getPosition方法代码示例

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


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

示例1: affect

/**
 * Affects a movable object with a planet's gravity, in proportion to the object's
 * mass.
 */
void GravityStrategy::affect(MovableObject& mwo, const Planet& swo) {

	// Vector from planet to object.
	Vector2d mwo_to_swo = swo.getPosition() - mwo.getPosition();

	// Distance between centers of object and planet.
	float distance = mwo_to_swo.getLength();

	// Unit vector pointing at planet from MovableObject.
	Vector2d planet_to_obj = mwo_to_swo/distance;

	// Note to Jesper: Should it be this way?
	// The gravity strategy seems to mess up when mass is 0...
	if (mwo.getMass() == 0) {
		return;
	}

	if(distance < 15.0)
		return;

	// std::cout << "Planet to obj: " << planet_to_obj.getX() << " " << planet_to_obj.getY() << std::endl;

	float G = 10.0f;

	// Value of force.
	float force = (G * mwo.getMass() * swo.getMass()) / (distance*distance);

	// Complete force with direction.
	Vector2d forcedir = planet_to_obj * force;

	// Amount of acceleration.
	Vector2d acc = forcedir / mwo.getMass();

	// Accelerate movableobject.
	Vector2d mov(mwo.getMovement());
	mov = mov + acc;
	mwo.setMovement(mov);
}
开发者ID:LukasKalinski,项目名称:Gravity-Game,代码行数:42,代码来源:GravityStrategy.cpp


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