accelerate collision detection in x3 times (feat. Neirokan)

master
Vectozavr 2021-11-03 20:21:39 +07:00
parent e10521c5e2
commit f1c91f539c
5 changed files with 11 additions and 7 deletions

View File

@ -21,7 +21,7 @@ namespace ShooterConsts {
const std::string ABILITY_OBJ = "obj/ability.obj";
const std::string HILL_OBJ = "obj/hill.obj";
const std::string GUN_OBJ = "obj/gun.obj";
const std::string GUN_OBJ = "obj/weapon.obj";
const std::string GUN_FIRE_SOUND = "sound/weapons/gun.ogg";
const std::string GUN_RELOAD_SOUND = "sound/weapons/reload_gun.ogg";
const std::string AK47_OBJ = "obj/ak47.obj";

View File

@ -105,6 +105,8 @@ public:
[[nodiscard]] Matrix4x4 model() const { return Matrix4x4::Translation(_position) * _transformMatrix; }
[[nodiscard]] Matrix4x4 view() const { return Matrix4x4::View(left(), up(), lookAt(), position()); }
// OpenGL function
[[nodiscard]] GLfloat *glModel() const;

View File

@ -66,7 +66,7 @@ double Vec2D::abs() const {
Vec2D Vec2D::normalized() const {
double vecAbs = abs();
if (vecAbs > Consts::EPS) {
return Vec2D(*this) / abs();
return Vec2D(*this) / vecAbs;
} else {
return Vec2D(0);
}

View File

@ -67,7 +67,7 @@ double Vec4D::abs() const {
Vec4D Vec4D::normalized() const {
double vecAbs = abs();
if (vecAbs > Consts::EPS) {
return Vec4D(*this) / abs();
return Vec4D(*this) / vecAbs;
} else {
return Vec4D(1);
}

View File

@ -16,14 +16,16 @@ RigidBody::RigidBody(ObjectNameTag nameTag, const std::string &filename, const V
Vec3D RigidBody::_findFurthestPoint(const Vec3D &direction) {
Vec3D maxPoint{0, 0, 0};
double maxDistance = -std::numeric_limits<double>::max();
Vec3D transformedDirection = (view() * direction).normalized();
for (auto &tri : triangles()) {
for (int i = 0; i < 3; i++) {
// TODO: multiplying model() * tri[i] costs too much time to compute
Vec3D point(model() * tri[i]);
Vec3D point = Vec3D(tri[i]);
double distance = point.dot(transformedDirection);
double distance = point.dot(direction.normalized());
if (distance > maxDistance) {
maxDistance = distance;
maxPoint = point;
@ -31,7 +33,7 @@ Vec3D RigidBody::_findFurthestPoint(const Vec3D &direction) {
}
}
return maxPoint;
return model()*maxPoint + position();
}
Vec3D RigidBody::_support(std::shared_ptr<RigidBody> obj, const Vec3D &direction) {