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