本文整理汇总了C++中fixed类的典型用法代码示例。如果您正苦于以下问题:C++ fixed类的具体用法?C++ fixed怎么用?C++ fixed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fixed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clamp
fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed z) const
{
// Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1)
const ssize_t xi = clamp((ssize_t)(x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2);
const ssize_t zi = clamp((ssize_t)(z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2);
const fixed one = fixed::FromInt(1);
const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), fixed::Zero(), one);
const fixed zf = clamp((z / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(zi), fixed::Zero(), one);
u16 h00 = m_Heightmap[zi*m_MapSize + xi];
u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi];
u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)];
u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)];
// Intermediate scaling of xf, so we don't overflow in the multiplications below
// (h00 <= 65535, xf <= 1, max fixed is < 32768; divide by 2 here so xf1*h00 <= 32767.5)
const fixed xf0 = xf / 2;
const fixed xf1 = (one - xf) / 2;
// Linearly interpolate
return ((one - zf).Multiply(xf1 * h00 + xf0 * h10)
+ zf.Multiply(xf1 * h01 + xf0 * h11)) / (int)(HEIGHT_UNITS_PER_METRE / 2);
// TODO: This should probably be more like GetExactGroundLevel()
// in handling triangulation properly
}
示例2: Rotate
void Rotate(const Angle alpha) {
const auto sc = alpha.SinCos();
const fixed sin = sc.first, cos = sc.second;
#ifdef FIXED_MATH
long s = sin.as_glfixed();
long c = cos.as_glfixed();
#else
long s = sin * (1<<16);
long c = cos * (1<<16);
#endif
Rotatex(s, c);
}
示例3: Scale
void Scale(const fixed &factor) {
#ifdef FIXED_MATH
Scalex(factor.as_glfixed_scale());
#else
Scalex(factor * (1LL<<32));
#endif
}
示例4: Deserialize
virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
{
Init(paramNode);
u32 oldSeed = GetActorSeed();
SerializeCommon(deserialize);
// If we serialized a different seed, reload actor
if (oldSeed != GetActorSeed())
ReloadActor();
fixed repeattime = m_AnimSyncRepeatTime; // save because SelectAnimation overwrites it
if (m_AnimRunThreshold.IsZero())
SelectAnimation(m_AnimName, m_AnimOnce, m_AnimSpeed, m_SoundGroup);
else
SelectMovementAnimation(m_AnimRunThreshold);
SetAnimationSyncRepeat(repeattime);
if (m_Unit)
{
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
if (cmpOwnership)
m_Unit->GetModel().SetPlayerID(cmpOwnership->GetOwner());
}
}
示例5: AdjustedColour
const Color Faction::AdjustedColour(fixed population, bool inRange)
{
Color result;
result = population == 0 ? BAD_FACTION_COLOUR : colour;
result.a = population > 0 ? FACTION_BASE_ALPHA + (M_E + (logf(population.ToFloat() / 1.25))) / ((2 * M_E) + FACTION_BASE_ALPHA) : FACTION_BASE_ALPHA;
result.a = inRange ? 1.f : result.a;
return result;
}
示例6: SetAnimationSyncOffset
virtual void SetAnimationSyncOffset(fixed actiontime)
{
if (m_Unit)
{
if (m_Unit->GetAnimation())
m_Unit->GetAnimation()->SetAnimationSyncOffset(actiontime.ToFloat());
}
}
示例7: SetAnimationSyncRepeat
virtual void SetAnimationSyncRepeat(fixed repeattime)
{
m_AnimSyncRepeatTime = repeattime;
if (m_Unit)
{
if (m_Unit->GetAnimation())
m_Unit->GetAnimation()->SetAnimationSyncRepeat(m_AnimSyncRepeatTime.ToFloat());
}
}
示例8: SelectAnimation
virtual void SelectAnimation(std::string name, bool once, fixed speed, std::wstring soundgroup)
{
m_AnimRunThreshold = fixed::Zero();
m_AnimName = name;
m_AnimOnce = once;
m_AnimSpeed = speed;
m_SoundGroup = soundgroup;
m_AnimDesync = fixed::FromInt(1)/20; // TODO: make this an argument
m_AnimSyncRepeatTime = fixed::Zero();
if (m_Unit)
{
m_Unit->SetEntitySelection(m_AnimName);
if (m_Unit->GetAnimation())
m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str());
}
}
示例12: ceilx
fixed ceilx(fixed fixedVal)
{
return fixedVal.ceil();
}
示例13: floorx
fixed floorx(fixed fixedVal)
{
return fixedVal.floor();
}
示例14: logx
fixed logx(fixed fixedVal)
{
return fixedVal.log();
}
示例15: expx
fixed expx(fixed fixedVal)
{
return fixedVal.exp();
}