mirror of
https://github.com/NoelFB/blah.git
synced 2025-06-29 19:25:26 +08:00
vec2 & rect code cleanup
This commit is contained in:
@ -45,6 +45,7 @@
|
||||
#include "blah/math/rectI.h"
|
||||
#include "blah/math/stopwatch.h"
|
||||
#include "blah/math/vec2.h"
|
||||
#include "blah/math/vec3.h"
|
||||
#include "blah/math/vec4.h"
|
||||
|
||||
#include "blah/streams/bufferstream.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// error / abort
|
||||
#ifdef DEBUG
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
|
||||
#include <stdlib.h>
|
||||
#define BLAH_ERROR(message) \
|
||||
|
@ -17,12 +17,12 @@ namespace Blah
|
||||
RectI(int rx, int ry, int rw, int rh);
|
||||
RectI(Point pos, Point size);
|
||||
|
||||
int left() const { return x; }
|
||||
int right() const { return x + w; }
|
||||
int top() const { return y; }
|
||||
int bottom() const { return y + h; }
|
||||
int centerX() const { return x + w / 2; }
|
||||
int centerY() const { return y + h / 2; }
|
||||
int left() const;
|
||||
int right() const;
|
||||
int top() const;
|
||||
int bottom() const;
|
||||
int center_x() const;
|
||||
int center_y() const;
|
||||
|
||||
Point center() const;
|
||||
Point top_left() const;
|
||||
@ -30,14 +30,7 @@ namespace Blah
|
||||
Point bottom_left() const;
|
||||
Point bottom_right() const;
|
||||
|
||||
bool overlaps(const RectI& other) const
|
||||
{
|
||||
return x < other.x + other.w
|
||||
&& other.x < x + w
|
||||
&& y < other.y + other.h
|
||||
&& other.y < y + h;
|
||||
}
|
||||
|
||||
bool overlaps(const RectI& other) const;
|
||||
bool contains(const Point& pt) const;
|
||||
bool contains(const Vec2& pt) const;
|
||||
|
||||
@ -51,14 +44,14 @@ namespace Blah
|
||||
char get_sector(const Point& pt) const;
|
||||
char get_sector(const Vec2& pt) const;
|
||||
|
||||
bool operator==(const RectI& rhs) const { return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h; }
|
||||
bool operator!=(const RectI& rhs) const { return !(*this == rhs); }
|
||||
bool operator==(const RectI& rhs) const;
|
||||
bool operator!=(const RectI& rhs) const;
|
||||
|
||||
RectI operator+(const Point& rhs) const;
|
||||
RectI operator-(const Point& rhs) const;
|
||||
RectI operator*(const int& rhs) const;
|
||||
RectI operator/(const int& rhs) const;
|
||||
RectI& operator+=(const Point& rhs);
|
||||
RectI& operator-=(const Point& rhs);
|
||||
|
||||
RectI operator*(const int& rhs) const { return RectI(x * rhs, y * rhs, w * rhs, h * rhs); }
|
||||
};
|
||||
}
|
@ -33,39 +33,108 @@ namespace Blah
|
||||
|
||||
bool operator ==(const Vec2& rhs) const;
|
||||
bool operator !=(const Vec2& rhs) const;
|
||||
|
||||
|
||||
// Returns the absolute value of the Vector
|
||||
Vec2 abs() const;
|
||||
|
||||
// Returns the Normalized Vector
|
||||
// If the length is 0, the resulting Vector is 0,0
|
||||
Vec2 normal() const;
|
||||
|
||||
// Rotates the Vector 90 degrees right (y, -x)
|
||||
Vec2 turn_right() const;
|
||||
|
||||
// Rotates the Vector 90 degrees left (-y, x)
|
||||
Vec2 turn_left() const;
|
||||
|
||||
// Returns the length of the Vector
|
||||
float length() const;
|
||||
|
||||
// Returns the squared length of the Vector
|
||||
float length_squared() const;
|
||||
|
||||
// Gets the perpendicular Vector (-y, x)
|
||||
Vec2 perpendicular() const;
|
||||
|
||||
// Gets the angle, in radians, of the Vector
|
||||
float angle() const;
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static float dot(Vec2 a, Vec2 b);
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static float dot(float x, float y, Vec2 b);
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static float dot(float x1, float y1, float x2, float y2);
|
||||
|
||||
// Transforms a Vector by the given Matrix
|
||||
static Vec2 transform(const Vec2& vec, const Mat3x2& matrix);
|
||||
|
||||
// Transforms a Vector by the given Matrix
|
||||
static Vec2 transform(float x, float y, const Mat3x2& matrix);
|
||||
static Vec2 from_angle(float radians, float length);
|
||||
static Vec2 from_angle(float radians);
|
||||
|
||||
// Transforms a Vector Normal by the given Matrix
|
||||
static Vec2 transform_normal(const Vec2& vec, const Mat3x2& matrix);
|
||||
|
||||
// Transforms a Vector Normal by the given Matrix
|
||||
static Vec2 transform_normal(float x, float y, const Mat3x2& matrix);
|
||||
|
||||
// Calculates a Vector value from the given radians
|
||||
static Vec2 from_angle(float radians, float length = 1.0f);
|
||||
|
||||
// Lerps between two Vectors
|
||||
static Vec2 lerp(Vec2 start, Vec2 end, float t);
|
||||
static Vec2 bezier_lerp(Vec2 start, Vec2 b, Vec2 end, float t);
|
||||
static Vec2 bezier_lerp(Vec2 start, Vec2 b, Vec2 c, Vec2 end, float t);
|
||||
|
||||
// Lerps between two Vectors along a Bezier curve
|
||||
static Vec2 lerp_bezier(Vec2 start, Vec2 b, Vec2 end, float t);
|
||||
|
||||
// Lerps between two Vectors along a Bezier curve
|
||||
static Vec2 lerp_bezier(Vec2 start, Vec2 b, Vec2 c, Vec2 end, float t);
|
||||
|
||||
// Reflects a vector along the given Normal
|
||||
static Vec2 reflect(const Vec2& vector, const Vec2& normal);
|
||||
|
||||
// Gets the minimum between two vectors
|
||||
static Vec2 min(const Vec2& a, const Vec2& b);
|
||||
|
||||
// Gets the maximum between two vectors
|
||||
static Vec2 max(const Vec2& a, const Vec2& b);
|
||||
|
||||
// (1, 0)
|
||||
static const Vec2 unit_x;
|
||||
|
||||
// (0, 1)
|
||||
static const Vec2 unit_y;
|
||||
|
||||
// (1, 0)
|
||||
static const Vec2 right;
|
||||
|
||||
// (0, -1)
|
||||
static const Vec2 up;
|
||||
|
||||
// (0, 1)
|
||||
static const Vec2 down;
|
||||
|
||||
// (-1, 0)
|
||||
static const Vec2 left;
|
||||
|
||||
// (0, 0)
|
||||
static const Vec2 zero;
|
||||
|
||||
// (1, 1)
|
||||
static const Vec2 one;
|
||||
|
||||
// (0.707, -0.707)
|
||||
static const Vec2 up_right;
|
||||
|
||||
// (-0.707, -0.707)
|
||||
static const Vec2 up_left;
|
||||
|
||||
// (0.707, 0.707)
|
||||
static const Vec2 down_right;
|
||||
|
||||
// (-0.707, 0.707)
|
||||
static const Vec2 down_left;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user