本文整理汇总了C++中Double::IsNotZero方法的典型用法代码示例。如果您正苦于以下问题:C++ Double::IsNotZero方法的具体用法?C++ Double::IsNotZero怎么用?C++ Double::IsNotZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Double
的用法示例。
在下文中一共展示了Double::IsNotZero方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FixParameters
void SpriteCache::FixParameters(const Double& rotation_rad,
const Double& scale_x, const Double& scale_y,
bool force_color_key)
{
bool rotozoom = rotation_rad.IsNotZero() || scale_x!=ONE || scale_y!=ONE;
for (uint i=0; i<size(); i++) {
SpriteFrameCache& frame = operator[](i);
if (rotozoom)
frame.normal.surface = frame.normal.surface.RotoZoom(rotation_rad, scale_x, scale_y);
if (force_color_key)
frame.normal.surface = frame.normal.surface.DisplayFormatColorKey(128, true);
}
}
示例2: NotifyMove
// Move to a point with collision test
collision_t PhysicalObj::NotifyMove(Point2d oldPos, Point2d newPos)
{
if (IsGhost())
return NO_COLLISION;
Point2d contactPos;
Double contactAngle;
Point2d pos, offset;
PhysicalObj* collided_obj = NULL;
collision_t collision = NO_COLLISION;
// Convert meters to pixels.
oldPos *= PIXEL_PER_METER;
newPos *= PIXEL_PER_METER;
// Compute distance between old and new position.
Double lg = oldPos.SquareDistance(newPos);
MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), square distance: %s",
GetName().c_str(),
Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
Double2str(lg).c_str());
if (!lg.IsNotZero())
return NO_COLLISION;
// Compute increments to move the object step by step from the old
// to the new position.
lg = sqrt(lg);
offset = (newPos - oldPos) / lg;
// First iteration position.
pos = oldPos + offset;
if (!m_collides_with_ground || IsInWater()) {
MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), collides ground:%d, water:%d",
GetName().c_str(),
Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
m_collides_with_ground, IsInWater());
SetXY(newPos);
return NO_COLLISION;
}
do {
Point2i tmpPos(uround(pos.x), uround(pos.y));
// Check if we exit the GetWorld(). If so, we stop moving and return.
if (IsOutsideWorldXY(tmpPos)) {
if (!GetWorld().IsOpen()) {
tmpPos.x = InRange_Long(tmpPos.x, 0, GetWorld().GetWidth() - GetWidth() - 1);
tmpPos.y = InRange_Long(tmpPos.y, 0, GetWorld().GetHeight() - GetHeight() - 1);
MSG_DEBUG("physic.state", "%s - DeplaceTestCollision touche un bord : %d, %d",
GetName().c_str(), tmpPos.x, tmpPos.y);
collision = COLLISION_ON_GROUND;
break;
}
SetXY(pos);
MSG_DEBUG("physic.move", "%s moves (%f, %f) -> (%f, %f) : OUTSIDE WORLD",
GetName().c_str(), oldPos.x.tofloat(), oldPos.y.tofloat(),
newPos.x.tofloat(), newPos.y.tofloat());
return NO_COLLISION;
}
// Test if we collide...
collided_obj = CollidedObjectXY(tmpPos);
if (collided_obj) {
if (!m_go_through_objects || m_last_collided_object != collided_obj) {
MSG_DEBUG("physic.state", "%s collide on %s", GetName().c_str(), collided_obj->GetName().c_str());
if (m_go_through_objects) {
SignalObjectCollision(GetSpeed(), collided_obj, collided_obj->GetSpeed());
collision = NO_COLLISION;
} else {
collision = COLLISION_ON_OBJECT;
}
m_last_collided_object = collided_obj;
} else {
collided_obj = NULL;
collision = NO_COLLISION;
}
} else if (!IsInVacuumXY(tmpPos, false)) {
collision = COLLISION_ON_GROUND;
m_last_collided_object = NULL;
}
if (collision != NO_COLLISION) {
// Nothing more to do!
MSG_DEBUG("physic.state", "%s - Collision at %d,%d : on %s",
GetName().c_str(), tmpPos.x, tmpPos.y,
collision == COLLISION_ON_GROUND ? "ground" : "an object");
// Set the object position to the current position.
//.........这里部分代码省略.........
示例3: Refresh
void Parachute::Refresh()
{
if (Game::GetInstance()->GetRemainingTime() <= 0)
return;
if (Game::GetInstance()->ReadState() != Game::PLAYING)
return;
Character& active = ActiveCharacter();
Double speed = active.GetSpeedXY().Norm();
if (active.FootsInVacuum() && speed.IsNotZero()) { // We are falling
if (!open && (speed > GameMode::GetInstance()->safe_fall)) { // with a sufficient speed
if (EnoughAmmo() && !m_used_this_turn) { // We have enough ammo => start opening the parachute
if (!m_used_this_turn) {
UseAmmo();
m_used_this_turn = true;
}
active.SetAirResistFactor(cfg().air_resist_factor);
active.SetWindFactor(cfg().wind_factor);
open = true;
img->animation.SetPlayBackward(false);
img->Start();
active.SetSpeedXY(Point2d(0,0));
active.SetMovement("parachute");
Camera::GetInstance()->FollowObject(&active);
}
}
} else { // We are on the ground
if (open) { // The parachute is opened
active.SetMovement("walk");
if (!closing) { // We have just hit the ground. Start closing animation
img->animation.SetPlayBackward(true);
img->animation.SetShowOnFinish(SpriteAnimation::show_blank);
img->Start();
closing = true;
return;
} else { // The parachute is closing
if (img->IsFinished()) {
// The animation is finished... We are done with the parachute
open = false;
closing = false;
UseAmmoUnit();
}
}
}
m_used_this_turn = false;
}
if (open) {
active.UpdateLastMovingTime();
// If parachute is open => character can move a little to the left or to the right
const LRMoveIntention * lr_move_intention = active.GetLastLRMoveIntention();
if (lr_move_intention) {
LRDirection direction = lr_move_intention->GetDirection();
active.SetDirection(direction);
if (direction == DIRECTION_LEFT)
active.SetExternForce(-cfg().force_side_displacement, 0.0);
else
active.SetExternForce(cfg().force_side_displacement, 0.0);
}
}
}
示例4: Draw
void Weapon::Draw(){
if (Game::GetInstance()->ReadState() != Game::PLAYING &&
m_last_fire_time + 100 < Time::GetInstance()->Read())
return;
#ifndef DEBUG_HOLE
if (m_last_fire_time + m_fire_remanence_time > Time::GetInstance()->Read())
#endif
DrawWeaponFire();
DrawAmmoUnits();
ASSERT(drawable || !ShouldBeDrawn());
if (!(drawable && ShouldBeDrawn()))
return;
if (ActiveCharacter().IsGhost()
|| ActiveCharacter().IsDrowned()
|| ActiveCharacter().IsDead())
return;
// rotate weapon if needed
if (!EqualsZero(min_angle - max_angle)) {
if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle());
else
m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle()-PI);
} else {
m_image->SetRotation_rad(ZERO);
}
// flip image if needed
if (use_flipping) {
m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
}
// Calculate position of the image
int x,y;
PosXY (x, y);
// Animate the display of the weapon:
if (m_time_anim_begin + ANIM_DISPLAY_TIME > Time::GetInstance()->Read()) {
if (!EqualsZero(min_angle - max_angle)) {
Double angle = m_image->GetRotation_rad();
angle += sin(HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
* TWO_PI;
m_image->SetRotation_rad(angle);
m_image->Scale(ONE, ONE);
}
else {
Double scale = sin((Double)1.5 * HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
/ sin((Double)1.5 * HALF_PI);
if (scale.IsNotZero()) {
m_image->Scale(scale, scale);
m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
}
// Recompute position to get the icon centered over the skin
if (origin == weapon_origin_OVER)
PosXY(x,y);
}
} else
m_image->Scale(ONE, ONE);
if (m_image)
m_image->Blit(GetMainWindow(), Point2i(x, y) - Camera::GetInstance()->GetPosition());
#ifdef DEBUG
if (IsLOGGING("weapon")) {
Point2i hand;
ActiveCharacter().GetHandPosition(hand);
Rectanglei rect(hand - 1 - Camera::GetInstance()->GetPosition(),
Point2i(3, 3));
GetWorld().ToRedrawOnMap(rect);
GetMainWindow().RectangleColor(rect, c_red);
MSG_DEBUG("weapon.handposition", "Position: %d, %d - hand: %d, %d",
ActiveCharacter().GetX(), ActiveCharacter().GetY(),
hand.GetX(), hand.GetY());
}
if (IsLOGGING("weapon.hole")) {
Rectanglei rect(GetGunHolePosition() - Camera::GetInstance()->GetPosition() - 1,
Point2i(3, 3));
GetWorld().ToRedrawOnMap(rect);
GetMainWindow().RectangleColor(rect, c_red);
}
#endif
}