1
This commit is contained in:
parent
10e9252fba
commit
2414f407a0
@ -60,11 +60,10 @@ static void SavePerfLog()
|
|||||||
|
|
||||||
void App::Init(int argc, char* argv[])
|
void App::Init(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
#if 0
|
#if 1
|
||||||
{
|
{
|
||||||
Vector2D v1(1, 1);
|
Vector2D v1(0.0f, 12.0f);
|
||||||
v1.Rotate(-0.25);
|
v1.Rotate2(-45 / 360.f);
|
||||||
TestGlm();
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -269,6 +269,15 @@ void Player::Shot()
|
|||||||
return;
|
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();
|
cs::MFShot* shot = room->frame_data.shots.Add();
|
||||||
shot->set_player_id(entity_uniid);
|
shot->set_player_id(entity_uniid);
|
||||||
@ -280,7 +289,7 @@ void Player::Shot()
|
|||||||
cs::MFBullet* bullet = room->frame_data.bullets.Add();
|
cs::MFBullet* bullet = room->frame_data.bullets.Add();
|
||||||
bullet->set_player_id(entity_uniid);
|
bullet->set_player_id(entity_uniid);
|
||||||
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
|
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());
|
attack_dir.ToPB(bullet->mutable_dir());
|
||||||
bullet->set_bulletskin(10001);
|
bullet->set_bulletskin(10001);
|
||||||
bullet->set_gun_id(curr_weapon->meta->i->id());
|
bullet->set_gun_id(curr_weapon->meta->i->id());
|
||||||
@ -292,9 +301,9 @@ void Player::Shot()
|
|||||||
bullet->room = room;
|
bullet->room = room;
|
||||||
bullet->gun_meta = curr_weapon->meta;
|
bullet->gun_meta = curr_weapon->meta;
|
||||||
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
|
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
|
||||||
bullet->pos = pos;
|
bullet->pos = bullet_born_pos;
|
||||||
bullet->dir = attack_dir;
|
bullet->dir = attack_dir;
|
||||||
bullet->born_pos = pos;
|
bullet->born_pos = bullet_born_pos;
|
||||||
bullet->born_dir = attack_dir;
|
bullet->born_dir = attack_dir;
|
||||||
bullet->fly_distance = fly_distance;
|
bullet->fly_distance = fly_distance;
|
||||||
bullet->entity_uniid = bullet->room->AllocUniid();
|
bullet->entity_uniid = bullet->room->AllocUniid();
|
||||||
|
@ -104,6 +104,39 @@ void Vector2D::Rotate(float angle)
|
|||||||
y = v[1];
|
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()
|
Vector2D Vector2D::Perp()
|
||||||
{
|
{
|
||||||
return Vector2D(y, -x);
|
return Vector2D(y, -x);
|
||||||
@ -114,7 +147,7 @@ float Vector2D::Dot(const Vector2D& v) const
|
|||||||
return x*v.x + y*v.y;
|
return x*v.x + y*v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2D::Norm()
|
float Vector2D::Norm() const
|
||||||
{
|
{
|
||||||
return fabs(sqrt(x*x + y*y));
|
return fabs(sqrt(x*x + y*y));
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ struct Vector2D
|
|||||||
void FromPB(const cs::MFVector2D* pb_obj);
|
void FromPB(const cs::MFVector2D* pb_obj);
|
||||||
void Normalize();
|
void Normalize();
|
||||||
void Rotate(float angle);
|
void Rotate(float angle);
|
||||||
|
void Rotate2(float angle);
|
||||||
|
float Angle(const Vector2D& b);
|
||||||
|
|
||||||
bool operator == (const Vector2D& b) const;
|
bool operator == (const Vector2D& b) const;
|
||||||
Vector2D operator + (const Vector2D& b) const;
|
Vector2D operator + (const Vector2D& b) const;
|
||||||
@ -34,7 +36,7 @@ struct Vector2D
|
|||||||
Vector2D operator / (float scale) const;
|
Vector2D operator / (float scale) const;
|
||||||
Vector2D Perp();
|
Vector2D Perp();
|
||||||
float Dot(const Vector2D& v) const;
|
float Dot(const Vector2D& v) const;
|
||||||
float Norm();
|
float Norm() const;
|
||||||
|
|
||||||
static const Vector2D UP;
|
static const Vector2D UP;
|
||||||
static const Vector2D DOWN;
|
static const Vector2D DOWN;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user