OpenSiv3D icon indicating copy to clipboard operation
OpenSiv3D copied to clipboard

ベクトルクラスに反射関数の実装

Open yunba28 opened this issue 2 years ago • 3 comments

追加する機能の内容 | Describe the solution you'd like 引数に与えられた法線ベクトルに対する反射ベクトルを取得する

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe. ブロック崩しのようなゲームのコードがさらに短縮できる

備考 | Additional context

struct Vector2D<>
{
    Vector2D& reflection(const Vector2D& _normal)
    {
        auto inverse = -normalized();
        auto dotx2 = inverse.dot(_normal) * 2;
        return (*this) = (dotx2 * _normal - inverse).normalize();
    }
};

上記の'auto dotx2'の*2を消すと法線に垂直なベクトル(壁に沿った)が得られます。

yunba28 avatar Jul 24 '22 05:07 yunba28