diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index 95157ea..0d3b38c 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -61,9 +61,8 @@ void AndroidAI::ChangeToState(AndroidState_e to_state) case AS_moving: { Human* hum = (Human*)owner; - float angle = ((float)rand() / RAND_MAX) * 2.0f; hum->move_dir = Vector2D(1.0f, 0); - hum->move_dir = hum->move_dir.Rotate(angle); + hum->move_dir.Rotate(a8::RandAngle()); hum->move_dir.Normalize(); hum->attack_dir = hum->move_dir; } diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index 7371fc3..c17bfe9 100755 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -63,7 +63,7 @@ void App::Init(int argc, char* argv[]) #if 0 { Vector2D v1(1, 1); - Vector2D v2 = v1.Rotate(-0.25); + v1.Rotate(-0.25); TestGlm(); int i = 0; } diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 975cc74..9dd933a 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -222,3 +222,8 @@ void Human::FindPath() } } } + +float Human::GetRadius() +{ + return meta->i->radius(); +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 22232d5..e59ce68 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -60,6 +60,7 @@ class Human : public Entity void RecalcSelfCollider(); bool IsCollision(); void FindPath(); + float GetRadius(); private: CircleCollider* self_collider_ = nullptr; diff --git a/server/gameserver/movement.cc b/server/gameserver/movement.cc index 6fd47c2..f9797ce 100644 --- a/server/gameserver/movement.cc +++ b/server/gameserver/movement.cc @@ -11,12 +11,17 @@ void MovementComponent::Update(int delta_time) ++path_index_; return; } - Vector2D path = target_point.pos - owner->pos; + #if 1 + assert(false); + #else + Vector2D dir = target_point.pos - owner->pos; + dir.Normalize(); float distance = path.Norm(); - owner->pos = owner->pos + path.Normalize() * std::min(move_speed_, distance); + owner->pos = owner->pos + dir * std::min(move_speed_, distance); if (owner->pos == target_point.pos) { ++path_index_; } + #endif } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 67c4037..5168952 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -72,8 +72,7 @@ void Room::AddPlayer(Player* hum) hum->pos.y = 2000 + rand() % 200; hum->attack_dir = hum->pos; hum->attack_dir.Normalize(); - float angle = ((float)rand() / RAND_MAX) * 2.0f; - hum->attack_dir.Rotate(angle); + hum->attack_dir.Rotate(a8::RandAngle()); } hum->room = this; uniid_hash_[hum->entity_uniid] = hum; @@ -118,8 +117,7 @@ void Room::ShuaAndroid() hum->pos.y = 200 + rand() % 500; hum->attack_dir = hum->pos; hum->attack_dir.Normalize(); - float angle = ((float)rand() / RAND_MAX) * 2.0f; - hum->attack_dir.Rotate(angle); + hum->attack_dir.Rotate(a8::RandAngle()); } hum->room = this; hum->Initialize(); @@ -147,6 +145,12 @@ void Room::ShuaObstacle(Human* hum) entity->room = this; entity->meta = thing; entity->entity_uniid = AllocUniid(); + #if 1 + { + Vector2D dir = hum->pos; + dir.Normalize(); + } + #endif entity->Initialize(); uniid_hash_[entity->entity_uniid] = entity; for (auto& pair : human_hash_) { @@ -158,10 +162,12 @@ void Room::ShuaObstacle(Human* hum) bool Room::RandomPos(Human* hum, float distance, Vector2D& out_pos) { - float angle = ((float)rand() / RAND_MAX) * 2.0f; + Vector2D dir = hum->pos; + dir.Rotate(a8::RandAngle()); + dir.Normalize(); CircleCollider collider; collider.owner = hum; - collider.pos = hum->pos.Rotate(angle).Normalize() * distance; + collider.pos = dir * distance; collider.rad = hum->meta->i->radius(); for (auto& pair : uniid_hash_) { diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index 4447003..f51b1cf 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -28,7 +28,7 @@ void Vector2D::FromPB(const cs::MFVector2D* pb_obj) y = pb_obj->y(); } -Vector2D& Vector2D::Normalize() +void Vector2D::Normalize() { #if 1 glm::vec2 v = glm::normalize(glm::vec2(x, y)); @@ -40,7 +40,6 @@ Vector2D& Vector2D::Normalize() x = v[0]; y = v[1]; #endif - return *this; } bool Vector2D::operator == (const Vector2D& b) const @@ -97,11 +96,12 @@ Vector2D Vector2D::operator / (float scale) const #include #endif -Vector2D Vector2D::Rotate(float angle) +void Vector2D::Rotate(float angle) { Eigen::Vector3f v(x, y, 0); v = Eigen::AngleAxisf(angle * 3.1415926f, Eigen::Vector3f::UnitZ()) * v; - return Vector2D(v[0], v[1]); + x = v[0]; + y = v[1]; } Vector2D Vector2D::Perp() @@ -213,4 +213,3 @@ static Polygon newPolygon(std::vector& vertices) return shape; } #endif - diff --git a/server/gameserver/types.h b/server/gameserver/types.h index aa115d9..9c7367c 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -23,14 +23,14 @@ struct Vector2D void ToPB(cs::MFVector2D* pb_obj); void FromPB(const cs::MFVector2D* pb_obj); - Vector2D& Normalize(); + void Normalize(); + void Rotate(float angle); bool operator == (const Vector2D& b) const; Vector2D operator + (const Vector2D& b) const; Vector2D operator - (const Vector2D& b) const; Vector2D operator * (float scale) const; Vector2D operator / (float scale) const; - Vector2D Rotate(float angle); Vector2D Perp(); float Dot(const Vector2D& v) const; float Norm(); diff --git a/third_party/a8engine b/third_party/a8engine index e7ff93f..923b076 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit e7ff93f844ce7b7356f6d743be27618d7539c885 +Subproject commit 923b076d57a0ee4bdf0e15624e7f4595c8b2fb42