diff options
| author | Daniel-Junior Dubé <[email protected]> | 2020-10-04 06:12:52 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-10-04 12:12:52 +0200 |
| commit | a8685ee4fd6eaba79fa53f4adf261d672947a000 (patch) | |
| tree | aea04cb686e18e926d54f7a98c32304f11d4cf6b /src | |
| parent | 7e62d973f95383a9e09a3520baad515e2e9b0705 (diff) | |
| download | raylib-a8685ee4fd6eaba79fa53f4adf261d672947a000.tar.gz raylib-a8685ee4fd6eaba79fa53f4adf261d672947a000.zip | |
Add Vector2Reflect to raymath.h (#1400)
Vector3Reflect exists but not Vector2Reflect. The code is pretty much the same.
I'm not sure what RMDEF does, but I added it to match other function definitions (haven't done much C programming, maybe I'm missing something). Can someone explain to me what it does?
Diffstat (limited to 'src')
| -rw-r--r-- | src/raymath.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/raymath.h b/src/raymath.h index 783c4449..06ab1320 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -297,6 +297,19 @@ RMDEF Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount) return result; } +// Calculate reflected vector to normal +RMDEF Vector2 Vector2Reflect(Vector2 v, Vector2 normal) +{ + Vector2 result = { 0 }; + + float dotProduct = Vector2DotProduct(v, normal); + + result.x = v.x - (2.0f*normal.x)*dotProduct; + result.y = v.y - (2.0f*normal.y)*dotProduct; + + return result; +} + // Rotate Vector by float in Degrees. RMDEF Vector2 Vector2Rotate(Vector2 v, float degs) { |
