1
This commit is contained in:
parent
a88bf63b7c
commit
62373e21b4
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -222,3 +222,8 @@ void Human::FindPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Human::GetRadius()
|
||||
{
|
||||
return meta->i->radius();
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ class Human : public Entity
|
||||
void RecalcSelfCollider();
|
||||
bool IsCollision();
|
||||
void FindPath();
|
||||
float GetRadius();
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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_) {
|
||||
|
@ -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 <Eigen/Dense>
|
||||
#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<Vector2D>& vertices)
|
||||
return shape;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -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();
|
||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
||||
Subproject commit e7ff93f844ce7b7356f6d743be27618d7539c885
|
||||
Subproject commit 923b076d57a0ee4bdf0e15624e7f4595c8b2fb42
|
Loading…
x
Reference in New Issue
Block a user