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


C++ Body::GetMass方法代码示例

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


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

示例1: GetGravityAtPos

// returns acceleration due to gravity at that point
static double GetGravityAtPos(Frame *targframe, const vector3d &posoff)
{
	Body *body = targframe->GetBodyFor();
	if (!body || body->IsType(Object::SPACESTATION)) return 0;
	double rsqr = posoff.LengthSqr();
	return G * body->GetMass() / rsqr;
	// inverse is: sqrt(G * m1m2 / thrust)
}
开发者ID:gamebytes,项目名称:pioneer,代码行数:9,代码来源:ShipAICmd.cpp

示例2: GetGravityAtPos

/// Calculates acceleration due to gravity at given position
static double GetGravityAtPos(Frame *target_frame, const vector3d &position)
{
	Body *body = target_frame->GetBody();
	if (!body || body->IsType(Object::SPACESTATION)) {
		return 0.0;
	}
	return G * body->GetMass() / position.LengthSqr(); // inverse is: sqrt(G * m1m2 / thrust)	
}
开发者ID:MeteoricGames,项目名称:pioneer,代码行数:9,代码来源:ShipAICmdParagon.cpp

示例3: CalcExternalForce

void DynamicBody::CalcExternalForce()
{
	// gravity
	if (!GetFrame()) return;			// no external force if not in a frame
	Body *body = GetFrame()->GetBody();
	if (body && !body->IsType(Object::SPACESTATION)) {	// they ought to have mass though...
		vector3d b1b2 = GetPosition();
		double m1m2 = GetMass() * body->GetMass();
		double invrsqr = 1.0 / b1b2.LengthSqr();
		double force = G*m1m2 * invrsqr;
		m_externalForce = -b1b2 * sqrt(invrsqr) * force;
	}
	else m_externalForce = vector3d(0.0);
	m_gravityForce = m_externalForce;

	// atmospheric drag
	if (body && GetFrame()->IsRotFrame() && body->IsType(Object::PLANET))
	{
		Planet *planet = static_cast<Planet*>(body);
		double dist = GetPosition().Length();
		double speed = m_vel.Length();
		double pressure, density;
		planet->GetAtmosphericState(dist, &pressure, &density);
		const double radius = GetClipRadius();		// bogus, preserving behaviour
		const double AREA = radius;
		// ^^^ yes that is as stupid as it looks
		const double DRAG_COEFF = 0.1; // 'smooth sphere'
		vector3d dragDir = -m_vel.NormalizedSafe();
		vector3d fDrag = 0.5*density*speed*speed*AREA*DRAG_COEFF*dragDir;

		// make this a bit less daft at high time accel
		// only allow atmosForce to increase by .1g per frame
		vector3d f1g = m_atmosForce + dragDir * GetMass();
		if (fDrag.LengthSqr() > f1g.LengthSqr()) m_atmosForce = f1g;
		else m_atmosForce = fDrag;

		m_externalForce += m_atmosForce;
	}
	else m_atmosForce = vector3d(0.0);

	// centrifugal and coriolis forces for rotating frames
	if (GetFrame()->IsRotFrame()) {
		vector3d angRot(0, GetFrame()->GetAngSpeed(), 0);
		m_externalForce -= m_mass * angRot.Cross(angRot.Cross(GetPosition()));	// centrifugal
		m_externalForce -= 2 * m_mass * angRot.Cross(GetVelocity());			// coriolis
	}
}
开发者ID:giriko,项目名称:pioneer,代码行数:47,代码来源:DynamicBody.cpp

示例4: CalcExternalForce

void DynamicBody::CalcExternalForce()
{
    // gravity
    if (!GetFrame()) return;			// no external force if not in a frame
    Body *body = GetFrame()->GetBody();
    if (body && !body->IsType(Object::SPACESTATION)) {	// they ought to have mass though...
        vector3d b1b2 = GetPosition();
        double m1m2 = GetMass() * body->GetMass();
        double invrsqr = 1.0 / b1b2.LengthSqr();
        double force = G*m1m2 * invrsqr;
        m_externalForce = -b1b2 * sqrt(invrsqr) * force;
    }
    else m_externalForce = vector3d(0.0);
    m_gravityForce = m_externalForce;

    // atmospheric drag
    if (body && GetFrame()->IsRotFrame() && body->IsType(Object::PLANET))
    {
        vector3d dragDir = -m_vel.NormalizedSafe();
        vector3d fDrag = CalcAtmosphericForce(m_dragCoeff)*dragDir;

        // make this a bit less daft at high time accel
        // only allow atmosForce to increase by .1g per frame
        vector3d f1g = m_atmosForce + dragDir * GetMass();
        if (fDrag.LengthSqr() > f1g.LengthSqr()) m_atmosForce = f1g;
        else m_atmosForce = fDrag;

        m_externalForce += m_atmosForce;
    }
    else m_atmosForce = vector3d(0.0);

    // centrifugal and coriolis forces for rotating frames
    if (GetFrame()->IsRotFrame()) {
        vector3d angRot(0, GetFrame()->GetAngSpeed(), 0);
        m_externalForce -= m_mass * angRot.Cross(angRot.Cross(GetPosition()));	// centrifugal
        m_externalForce -= 2 * m_mass * angRot.Cross(GetVelocity());			// coriolis
    }
}
开发者ID:dreadk2002,项目名称:pioneer,代码行数:38,代码来源:DynamicBody.cpp


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