diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index c17bfe9..d69db25 100755 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -60,11 +60,10 @@ static void SavePerfLog() void App::Init(int argc, char* argv[]) { - #if 0 + #if 1 { - Vector2D v1(1, 1); - v1.Rotate(-0.25); - TestGlm(); + Vector2D v1(0.0f, 12.0f); + v1.Rotate2(-45 / 360.f); int i = 0; } #endif diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index fd32109..b374478 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -269,6 +269,15 @@ void Player::Shot() return; } + Vector2D bullet_born_offset = Vector2D(0, 12.0f); + #if 0 + Vector2D bullet_born_dir = Vector2D(0, 12.0f); + bullet_born_dir.Normalize(); + bullet_born_offset = bullet_born_dir * bullet_born_offset.Norm(); + #else + bullet_born_offset.Rotate2(attack_dir.Angle(Vector2D::UP)); + #endif + Vector2D bullet_born_pos = pos + bullet_born_offset; { cs::MFShot* shot = room->frame_data.shots.Add(); shot->set_player_id(entity_uniid); @@ -280,7 +289,7 @@ void Player::Shot() cs::MFBullet* bullet = room->frame_data.bullets.Add(); bullet->set_player_id(entity_uniid); bullet->set_bullet_id(curr_weapon->meta->i->use_bullet()); - pos.ToPB(bullet->mutable_pos()); + bullet_born_pos.ToPB(bullet->mutable_pos()); attack_dir.ToPB(bullet->mutable_dir()); bullet->set_bulletskin(10001); bullet->set_gun_id(curr_weapon->meta->i->id()); @@ -292,9 +301,9 @@ void Player::Shot() bullet->room = room; bullet->gun_meta = curr_weapon->meta; bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet()); - bullet->pos = pos; + bullet->pos = bullet_born_pos; bullet->dir = attack_dir; - bullet->born_pos = pos; + bullet->born_pos = bullet_born_pos; bullet->born_dir = attack_dir; bullet->fly_distance = fly_distance; bullet->entity_uniid = bullet->room->AllocUniid(); diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index 763b26c..5d6f74c 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -104,6 +104,39 @@ void Vector2D::Rotate(float angle) y = v[1]; } +void Vector2D::Rotate2(float angle) +{ + #if 1 + Eigen::Vector3f v(x, y, 0); + v = Eigen::AngleAxisf(angle * 3.1415926f, Eigen::Vector3f::UnitZ()) * v; + x = v[0]; + y = v[1]; + #else + float newx = x * cos(angle) - y * sin(angle); + float newy = x * sin(angle) + y * cos(angle); + x = newx; + y = newy; + int i = 0; + #endif +} + +float Vector2D::Angle(const Vector2D& b) +{ + float a1 = acos(Dot(b) / Norm() / b.Norm()); + float a2 = atan2(y, x); + float a3 = atan2(y, x) / 0.017 - 90.0f; + #if 0 + return a2; + #else + bool at_right_side = Vector2D::RIGHT.Dot(*this) > 0.0001f; + if (at_right_side) { + a1 = -a1; + } + return a1 / 3.14; + // return a3 / 360.0f; + #endif +} + Vector2D Vector2D::Perp() { return Vector2D(y, -x); @@ -114,7 +147,7 @@ float Vector2D::Dot(const Vector2D& v) const return x*v.x + y*v.y; } -float Vector2D::Norm() +float Vector2D::Norm() const { return fabs(sqrt(x*x + y*y)); } diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 375592f..3b14cff 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -26,6 +26,8 @@ struct Vector2D void FromPB(const cs::MFVector2D* pb_obj); void Normalize(); void Rotate(float angle); + void Rotate2(float angle); + float Angle(const Vector2D& b); bool operator == (const Vector2D& b) const; Vector2D operator + (const Vector2D& b) const; @@ -34,7 +36,7 @@ struct Vector2D Vector2D operator / (float scale) const; Vector2D Perp(); float Dot(const Vector2D& v) const; - float Norm(); + float Norm() const; static const Vector2D UP; static const Vector2D DOWN;