Added editorconfig file for VS C++ code style formatting.
Applied C++ auto formatting.
This commit is contained in:
136
.editorconfig
Normal file
136
.editorconfig
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Visual Studio generated .editorconfig file with C++ settings.
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
|
||||||
|
|
||||||
|
# Visual C++ Code Style settings
|
||||||
|
|
||||||
|
cpp_generate_documentation_comments = xml
|
||||||
|
|
||||||
|
# Visual C++ Formatting settings
|
||||||
|
|
||||||
|
cpp_indent_braces = false
|
||||||
|
cpp_indent_multi_line_relative_to = innermost_parenthesis
|
||||||
|
cpp_indent_within_parentheses = indent
|
||||||
|
cpp_indent_preserve_within_parentheses = true
|
||||||
|
cpp_indent_case_contents = true
|
||||||
|
cpp_indent_case_labels = false
|
||||||
|
cpp_indent_case_contents_when_block = false
|
||||||
|
cpp_indent_lambda_braces_when_parameter = true
|
||||||
|
cpp_indent_goto_labels = one_left
|
||||||
|
cpp_indent_preprocessor = leftmost_column
|
||||||
|
cpp_indent_access_specifiers = false
|
||||||
|
cpp_indent_namespace_contents = false
|
||||||
|
cpp_indent_preserve_comments = false
|
||||||
|
cpp_new_line_before_open_brace_namespace = ignore
|
||||||
|
cpp_new_line_before_open_brace_type = ignore
|
||||||
|
cpp_new_line_before_open_brace_function = ignore
|
||||||
|
cpp_new_line_before_open_brace_block = false
|
||||||
|
cpp_new_line_before_open_brace_lambda = ignore
|
||||||
|
cpp_new_line_scope_braces_on_separate_lines = false
|
||||||
|
cpp_new_line_close_brace_same_line_empty_type = false
|
||||||
|
cpp_new_line_close_brace_same_line_empty_function = false
|
||||||
|
cpp_new_line_before_catch = true
|
||||||
|
cpp_new_line_before_else = true
|
||||||
|
cpp_new_line_before_while_in_do_while = false
|
||||||
|
cpp_space_before_function_open_parenthesis = remove
|
||||||
|
cpp_space_within_parameter_list_parentheses = false
|
||||||
|
cpp_space_between_empty_parameter_list_parentheses = false
|
||||||
|
cpp_space_after_keywords_in_control_flow_statements = true
|
||||||
|
cpp_space_within_control_flow_statement_parentheses = false
|
||||||
|
cpp_space_before_lambda_open_parenthesis = false
|
||||||
|
cpp_space_within_cast_parentheses = false
|
||||||
|
cpp_space_after_cast_close_parenthesis = false
|
||||||
|
cpp_space_within_expression_parentheses = false
|
||||||
|
cpp_space_before_block_open_brace = true
|
||||||
|
cpp_space_between_empty_braces = false
|
||||||
|
cpp_space_before_initializer_list_open_brace = false
|
||||||
|
cpp_space_within_initializer_list_braces = true
|
||||||
|
cpp_space_preserve_in_initializer_list = true
|
||||||
|
cpp_space_before_open_square_bracket = false
|
||||||
|
cpp_space_within_square_brackets = false
|
||||||
|
cpp_space_before_empty_square_brackets = false
|
||||||
|
cpp_space_between_empty_square_brackets = false
|
||||||
|
cpp_space_group_square_brackets = true
|
||||||
|
cpp_space_within_lambda_brackets = false
|
||||||
|
cpp_space_between_empty_lambda_brackets = false
|
||||||
|
cpp_space_before_comma = false
|
||||||
|
cpp_space_after_comma = true
|
||||||
|
cpp_space_remove_around_member_operators = true
|
||||||
|
cpp_space_before_inheritance_colon = true
|
||||||
|
cpp_space_before_constructor_colon = true
|
||||||
|
cpp_space_remove_before_semicolon = true
|
||||||
|
cpp_space_after_semicolon = true
|
||||||
|
cpp_space_remove_around_unary_operator = true
|
||||||
|
cpp_space_around_binary_operator = insert
|
||||||
|
cpp_space_around_assignment_operator = insert
|
||||||
|
cpp_space_pointer_reference_alignment = left
|
||||||
|
cpp_space_around_ternary_operator = insert
|
||||||
|
cpp_wrap_preserve_blocks = one_liners
|
||||||
|
|
||||||
|
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
|
||||||
|
|
||||||
|
# Visual C++ Code Style settings
|
||||||
|
|
||||||
|
cpp_generate_documentation_comments = xml
|
||||||
|
|
||||||
|
# Visual C++ Formatting settings
|
||||||
|
|
||||||
|
cpp_indent_braces = false
|
||||||
|
cpp_indent_multi_line_relative_to = outermost_parenthesis
|
||||||
|
cpp_indent_within_parentheses = indent
|
||||||
|
cpp_indent_preserve_within_parentheses = true
|
||||||
|
cpp_indent_case_contents = true
|
||||||
|
cpp_indent_case_labels = false
|
||||||
|
cpp_indent_case_contents_when_block = false
|
||||||
|
cpp_indent_lambda_braces_when_parameter = true
|
||||||
|
cpp_indent_goto_labels = one_left
|
||||||
|
cpp_indent_preprocessor = leftmost_column
|
||||||
|
cpp_indent_access_specifiers = false
|
||||||
|
cpp_indent_namespace_contents = false
|
||||||
|
cpp_indent_preserve_comments = false
|
||||||
|
cpp_new_line_before_open_brace_namespace = same_line
|
||||||
|
cpp_new_line_before_open_brace_type = new_line
|
||||||
|
cpp_new_line_before_open_brace_function = new_line
|
||||||
|
cpp_new_line_before_open_brace_block = same_line
|
||||||
|
cpp_new_line_before_open_brace_lambda = same_line
|
||||||
|
cpp_new_line_scope_braces_on_separate_lines = true
|
||||||
|
cpp_new_line_close_brace_same_line_empty_type = false
|
||||||
|
cpp_new_line_close_brace_same_line_empty_function = false
|
||||||
|
cpp_new_line_before_catch = false
|
||||||
|
cpp_new_line_before_else = false
|
||||||
|
cpp_new_line_before_while_in_do_while = false
|
||||||
|
cpp_space_before_function_open_parenthesis = remove
|
||||||
|
cpp_space_within_parameter_list_parentheses = false
|
||||||
|
cpp_space_between_empty_parameter_list_parentheses = false
|
||||||
|
cpp_space_after_keywords_in_control_flow_statements = true
|
||||||
|
cpp_space_within_control_flow_statement_parentheses = false
|
||||||
|
cpp_space_before_lambda_open_parenthesis = false
|
||||||
|
cpp_space_within_cast_parentheses = false
|
||||||
|
cpp_space_after_cast_close_parenthesis = false
|
||||||
|
cpp_space_within_expression_parentheses = false
|
||||||
|
cpp_space_before_block_open_brace = true
|
||||||
|
cpp_space_between_empty_braces = false
|
||||||
|
cpp_space_before_initializer_list_open_brace = false
|
||||||
|
cpp_space_within_initializer_list_braces = true
|
||||||
|
cpp_space_preserve_in_initializer_list = true
|
||||||
|
cpp_space_before_open_square_bracket = false
|
||||||
|
cpp_space_within_square_brackets = false
|
||||||
|
cpp_space_before_empty_square_brackets = false
|
||||||
|
cpp_space_between_empty_square_brackets = false
|
||||||
|
cpp_space_group_square_brackets = true
|
||||||
|
cpp_space_within_lambda_brackets = false
|
||||||
|
cpp_space_between_empty_lambda_brackets = false
|
||||||
|
cpp_space_before_comma = false
|
||||||
|
cpp_space_after_comma = true
|
||||||
|
cpp_space_remove_around_member_operators = true
|
||||||
|
cpp_space_before_inheritance_colon = true
|
||||||
|
cpp_space_before_constructor_colon = true
|
||||||
|
cpp_space_remove_before_semicolon = true
|
||||||
|
cpp_space_after_semicolon = true
|
||||||
|
cpp_space_remove_around_unary_operator = true
|
||||||
|
cpp_space_around_binary_operator = insert
|
||||||
|
cpp_space_around_assignment_operator = insert
|
||||||
|
cpp_space_pointer_reference_alignment = left
|
||||||
|
cpp_space_around_ternary_operator = insert
|
||||||
|
cpp_wrap_preserve_blocks = never
|
||||||
@@ -43,7 +43,8 @@ namespace kraken {
|
|||||||
|
|
||||||
class Matrix4;
|
class Matrix4;
|
||||||
|
|
||||||
class AABB {
|
class AABB
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Vector3 min;
|
Vector3 min;
|
||||||
Vector3 max;
|
Vector3 max;
|
||||||
@@ -89,7 +90,8 @@ static_assert(std::is_pod<AABB>::value, "kraken::AABB must be a POD type.");
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::AABB> {
|
struct hash<kraken::AABB>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::AABB& s) const
|
size_t operator()(const kraken::AABB& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ class KRNode;
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class HitInfo {
|
class HitInfo
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
HitInfo();
|
HitInfo();
|
||||||
HitInfo(const Vector3& position, const Vector3& normal, const float distance);
|
HitInfo(const Vector3& position, const Vector3& normal, const float distance);
|
||||||
|
|||||||
@@ -36,11 +36,14 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Matrix2 {
|
class Matrix2
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
Vector2 axis_x, axis_y;
|
Vector2 axis_x, axis_y;
|
||||||
};
|
};
|
||||||
// Matrix components, in column-major order
|
// Matrix components, in column-major order
|
||||||
@@ -92,7 +95,8 @@ static_assert(std::is_pod<Matrix2>::value, "kraken::Matrix2 must be a POD type."
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Matrix2> {
|
struct hash<kraken::Matrix2>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Matrix2& s) const
|
size_t operator()(const kraken::Matrix2& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,11 +37,14 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Matrix2x3 {
|
class Matrix2x3
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
Vector2 axis_x, axis_y, transform;
|
Vector2 axis_x, axis_y, transform;
|
||||||
};
|
};
|
||||||
// Matrix components, in column-major order
|
// Matrix components, in column-major order
|
||||||
@@ -94,7 +97,8 @@ static_assert(std::is_pod<Matrix2x3>::value, "kraken::Matrix2x3 must be a POD ty
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Matrix2x3> {
|
struct hash<kraken::Matrix2x3>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Matrix2x3& s) const
|
size_t operator()(const kraken::Matrix2x3& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
enum class AXIS {
|
enum class AXIS
|
||||||
|
{
|
||||||
X_AXIS,
|
X_AXIS,
|
||||||
Y_AXIS,
|
Y_AXIS,
|
||||||
Z_AXIS
|
Z_AXIS
|
||||||
@@ -46,11 +47,14 @@ enum class AXIS {
|
|||||||
|
|
||||||
class Quaternion;
|
class Quaternion;
|
||||||
|
|
||||||
class Matrix4 {
|
class Matrix4
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
Vector4 axis_x, axis_y, axis_z, transform;
|
Vector4 axis_x, axis_y, axis_z, transform;
|
||||||
};
|
};
|
||||||
// Matrix components, in column-major order
|
// Matrix components, in column-major order
|
||||||
@@ -116,7 +120,8 @@ static_assert(std::is_pod<Matrix4>::value, "kraken::Matrix4 must be a POD type."
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Matrix4> {
|
struct hash<kraken::Matrix4>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Matrix4& s) const
|
size_t operator()(const kraken::Matrix4& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,10 +36,13 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Quaternion {
|
class Quaternion
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
float w, x, y, z;
|
float w, x, y, z;
|
||||||
};
|
};
|
||||||
float c[4];
|
float c[4];
|
||||||
@@ -102,7 +105,8 @@ static_assert(std::is_pod<Quaternion>::value, "kraken::Quaternion must be a POD
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Quaternion> {
|
struct hash<kraken::Quaternion>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Quaternion& s) const
|
size_t operator()(const kraken::Quaternion& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ static_assert(std::is_pod<Triangle3>::value, "kraken::Triangle3 must be a POD ty
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Triangle3> {
|
struct hash<kraken::Triangle3>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Triangle3& s) const
|
size_t operator()(const kraken::Triangle3& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,11 +38,14 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Vector2 {
|
class Vector2
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
};
|
};
|
||||||
float c[2];
|
float c[2];
|
||||||
@@ -108,7 +111,8 @@ static_assert(std::is_pod<Vector2>::value, "kraken::Vector2 must be a POD type."
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Vector2> {
|
struct hash<kraken::Vector2>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Vector2& s) const
|
size_t operator()(const kraken::Vector2& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,11 +37,14 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Vector2i {
|
class Vector2i
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
};
|
};
|
||||||
int c[2];
|
int c[2];
|
||||||
@@ -108,7 +111,8 @@ static_assert(std::is_pod<Vector2i>::value, "kraken::Vector2i must be a POD type
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Vector2i> {
|
struct hash<kraken::Vector2i>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Vector2i& s) const
|
size_t operator()(const kraken::Vector2i& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,11 +38,14 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
class Vector3 {
|
class Vector3
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
float c[3];
|
float c[3];
|
||||||
@@ -139,7 +142,8 @@ static_assert(std::is_pod<Vector3>::value, "kraken::Vector3 must be a POD type."
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Vector3> {
|
struct hash<kraken::Vector3>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Vector3& s) const
|
size_t operator()(const kraken::Vector3& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,11 +37,14 @@ namespace kraken {
|
|||||||
|
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
|
||||||
class Vector4 {
|
class Vector4
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
union {
|
union
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
};
|
};
|
||||||
float c[4];
|
float c[4];
|
||||||
@@ -112,7 +115,8 @@ static_assert(std::is_pod<Vector4>::value, "kraken::Vector4 must be a POD type."
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<kraken::Vector4> {
|
struct hash<kraken::Vector4>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const kraken::Vector4& s) const
|
size_t operator()(const kraken::Vector4& s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -250,7 +250,8 @@ bool AABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
|
|||||||
|
|
||||||
// FINDME, TODO - Perhaps there is a more efficient algorithm, as we don't actually need the exact coordinate of the intersection
|
// FINDME, TODO - Perhaps there is a more efficient algorithm, as we don't actually need the exact coordinate of the intersection
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
RIGHT = 0,
|
RIGHT = 0,
|
||||||
LEFT = 1,
|
LEFT = 1,
|
||||||
MIDDLE = 2
|
MIDDLE = 2
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Matrix2::init() {
|
void Matrix2::init()
|
||||||
|
{
|
||||||
// Default constructor - Initialize with an identity matrix
|
// Default constructor - Initialize with an identity matrix
|
||||||
static const float IDENTITY_MATRIX[] = {
|
static const float IDENTITY_MATRIX[] = {
|
||||||
1.0, 0.0,
|
1.0, 0.0,
|
||||||
@@ -45,7 +46,8 @@ void Matrix2::init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2::init(float *pMat) {
|
void Matrix2::init(float* pMat)
|
||||||
|
{
|
||||||
memcpy(c, pMat, sizeof(float) * 4);
|
memcpy(c, pMat, sizeof(float) * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,37 +57,41 @@ void Matrix2::init(const Vector2 &new_axis_x, const Vector2 &new_axis_y)
|
|||||||
c[2] = new_axis_y.x; c[3] = new_axis_y.y;
|
c[2] = new_axis_y.x; c[3] = new_axis_y.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2::init(const Matrix2 &m) {
|
void Matrix2::init(const Matrix2& m)
|
||||||
|
{
|
||||||
memcpy(c, m.c, sizeof(float) * 4);
|
memcpy(c, m.c, sizeof(float) * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
float *Matrix2::getPointer() {
|
float* Matrix2::getPointer()
|
||||||
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Matrix2::operator[](unsigned i) {
|
float& Matrix2::operator[](unsigned i)
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Matrix2::operator[](unsigned i) const {
|
float Matrix2::operator[](unsigned i) const
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload comparison operator
|
// Overload comparison operator
|
||||||
bool Matrix2::operator==(const Matrix2 &m) const {
|
bool Matrix2::operator==(const Matrix2& m) const
|
||||||
|
{
|
||||||
return memcmp(c, m.c, sizeof(float) * 4) == 0;
|
return memcmp(c, m.c, sizeof(float) * 4) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload compound multiply operator
|
// Overload compound multiply operator
|
||||||
Matrix2& Matrix2::operator*=(const Matrix2 &m) {
|
Matrix2& Matrix2::operator*=(const Matrix2& m)
|
||||||
|
{
|
||||||
float temp[4];
|
float temp[4];
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (x=0; x < 2; x++)
|
for (x = 0; x < 2; x++) {
|
||||||
{
|
for (y = 0; y < 2; y++) {
|
||||||
for(y=0; y < 2; y++)
|
|
||||||
{
|
|
||||||
temp[y + (x * 2)] = (c[x * 2] * m.c[y]) +
|
temp[y + (x * 2)] = (c[x * 2] * m.c[y]) +
|
||||||
(c[x * 2 + 1] * m.c[y + 2]);
|
(c[x * 2 + 1] * m.c[y + 2]);
|
||||||
}
|
}
|
||||||
@@ -96,14 +102,16 @@ Matrix2& Matrix2::operator*=(const Matrix2 &m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Overload multiply operator
|
// Overload multiply operator
|
||||||
Matrix2 Matrix2::operator*(const Matrix2 &m) const {
|
Matrix2 Matrix2::operator*(const Matrix2& m) const
|
||||||
|
{
|
||||||
Matrix2 ret = *this;
|
Matrix2 ret = *this;
|
||||||
ret *= m;
|
ret *= m;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
||||||
void Matrix2::rotate(float angle) {
|
void Matrix2::rotate(float angle)
|
||||||
|
{
|
||||||
|
|
||||||
Matrix2 newMatrix; // Create new identity matrix
|
Matrix2 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
@@ -116,7 +124,8 @@ void Matrix2::rotate(float angle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Scale matrix by separate x, y, and z amounts */
|
/* Scale matrix by separate x, y, and z amounts */
|
||||||
void Matrix2::scale(float x, float y) {
|
void Matrix2::scale(float x, float y)
|
||||||
|
{
|
||||||
Matrix2 newMatrix; // Create new identity matrix
|
Matrix2 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
|
|
||||||
@@ -126,17 +135,20 @@ void Matrix2::scale(float x, float y) {
|
|||||||
*this *= newMatrix;
|
*this *= newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2::scale(const Vector2 &v) {
|
void Matrix2::scale(const Vector2& v)
|
||||||
|
{
|
||||||
scale(v.x, v.y);
|
scale(v.x, v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scale all dimensions equally */
|
/* Scale all dimensions equally */
|
||||||
void Matrix2::scale(float s) {
|
void Matrix2::scale(float s)
|
||||||
|
{
|
||||||
scale(s, s);
|
scale(s, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace matrix with its inverse */
|
/* Replace matrix with its inverse */
|
||||||
bool Matrix2::invert() {
|
bool Matrix2::invert()
|
||||||
|
{
|
||||||
float det = c[0] * c[3] - c[1] * c[2];
|
float det = c[0] * c[3] - c[1] * c[2];
|
||||||
if (det == 0) {
|
if (det == 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -151,14 +163,16 @@ bool Matrix2::invert() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2::transpose() {
|
void Matrix2::transpose()
|
||||||
|
{
|
||||||
float tmp = c[1];
|
float tmp = c[1];
|
||||||
c[1] = c[2];
|
c[1] = c[2];
|
||||||
c[2] = tmp;
|
c[2] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product, returning Vector2 */
|
/* Dot Product, returning Vector2 */
|
||||||
Vector2 Matrix2::Dot(const Matrix2 &m, const Vector2 &v) {
|
Vector2 Matrix2::Dot(const Matrix2& m, const Vector2& v)
|
||||||
|
{
|
||||||
return Vector2::Create(
|
return Vector2::Create(
|
||||||
v.c[0] * m.c[0] + v.c[1] * m.c[2],
|
v.c[0] * m.c[0] + v.c[1] * m.c[2],
|
||||||
v.c[0] * m.c[1] + v.c[1] * m.c[3]
|
v.c[0] * m.c[1] + v.c[1] * m.c[3]
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Matrix2x3::init() {
|
void Matrix2x3::init()
|
||||||
|
{
|
||||||
// Default constructor - Initialize with an identity matrix
|
// Default constructor - Initialize with an identity matrix
|
||||||
static const float IDENTITY_MATRIX[] = {
|
static const float IDENTITY_MATRIX[] = {
|
||||||
1.0, 0.0,
|
1.0, 0.0,
|
||||||
@@ -46,7 +47,8 @@ void Matrix2x3::init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2x3::init(float *pMat) {
|
void Matrix2x3::init(float* pMat)
|
||||||
|
{
|
||||||
memcpy(c, pMat, sizeof(float) * 6);
|
memcpy(c, pMat, sizeof(float) * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,29 +59,35 @@ void Matrix2x3::init(const Vector2 &new_axis_x, const Vector2 &new_axis_y, const
|
|||||||
c[4] = new_transform.x; c[5] = new_transform.y;
|
c[4] = new_transform.x; c[5] = new_transform.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2x3::init(const Matrix2x3 &m) {
|
void Matrix2x3::init(const Matrix2x3& m)
|
||||||
|
{
|
||||||
memcpy(c, m.c, sizeof(float) * 6);
|
memcpy(c, m.c, sizeof(float) * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
float *Matrix2x3::getPointer() {
|
float* Matrix2x3::getPointer()
|
||||||
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Matrix2x3::operator[](unsigned i) {
|
float& Matrix2x3::operator[](unsigned i)
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Matrix2x3::operator[](unsigned i) const {
|
float Matrix2x3::operator[](unsigned i) const
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload comparison operator
|
// Overload comparison operator
|
||||||
bool Matrix2x3::operator==(const Matrix2x3 &m) const {
|
bool Matrix2x3::operator==(const Matrix2x3& m) const
|
||||||
|
{
|
||||||
return memcmp(c, m.c, sizeof(float) * 6) == 0;
|
return memcmp(c, m.c, sizeof(float) * 6) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload compound multiply operator
|
// Overload compound multiply operator
|
||||||
Matrix2x3& Matrix2x3::operator*=(const Matrix2x3 &m) {
|
Matrix2x3& Matrix2x3::operator*=(const Matrix2x3& m)
|
||||||
|
{
|
||||||
float temp[6];
|
float temp[6];
|
||||||
/*
|
/*
|
||||||
temp[0] = c[0] * m[0] + c[2] * m[1];
|
temp[0] = c[0] * m[0] + c[2] * m[1];
|
||||||
@@ -101,14 +109,16 @@ Matrix2x3& Matrix2x3::operator*=(const Matrix2x3 &m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Overload multiply operator
|
// Overload multiply operator
|
||||||
Matrix2x3 Matrix2x3::operator*(const Matrix2x3 &m) const {
|
Matrix2x3 Matrix2x3::operator*(const Matrix2x3& m) const
|
||||||
|
{
|
||||||
Matrix2x3 ret = *this;
|
Matrix2x3 ret = *this;
|
||||||
ret *= m;
|
ret *= m;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform translation operations on a matrix */
|
/* Perform translation operations on a matrix */
|
||||||
void Matrix2x3::translate(float x, float y) {
|
void Matrix2x3::translate(float x, float y)
|
||||||
|
{
|
||||||
Matrix2x3 newMatrix; // Create new identity matrix
|
Matrix2x3 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
|
|
||||||
@@ -124,7 +134,8 @@ void Matrix2x3::translate(const Vector2 &v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
||||||
void Matrix2x3::rotate(float angle) {
|
void Matrix2x3::rotate(float angle)
|
||||||
|
{
|
||||||
Matrix2x3 newMatrix;
|
Matrix2x3 newMatrix;
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
newMatrix.c[0] = cosf(angle);
|
newMatrix.c[0] = cosf(angle);
|
||||||
@@ -136,7 +147,8 @@ void Matrix2x3::rotate(float angle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Scale matrix by separate x, y, and z amounts */
|
/* Scale matrix by separate x, y, and z amounts */
|
||||||
void Matrix2x3::scale(float x, float y) {
|
void Matrix2x3::scale(float x, float y)
|
||||||
|
{
|
||||||
Matrix2x3 newMatrix; // Create new identity matrix
|
Matrix2x3 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
|
|
||||||
@@ -146,16 +158,19 @@ void Matrix2x3::scale(float x, float y) {
|
|||||||
*this *= newMatrix;
|
*this *= newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix2x3::scale(const Vector2 &v) {
|
void Matrix2x3::scale(const Vector2& v)
|
||||||
|
{
|
||||||
scale(v.x, v.y);
|
scale(v.x, v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scale all dimensions equally */
|
/* Scale all dimensions equally */
|
||||||
void Matrix2x3::scale(float s) {
|
void Matrix2x3::scale(float s)
|
||||||
|
{
|
||||||
scale(s, s);
|
scale(s, s);
|
||||||
}
|
}
|
||||||
/* Replace matrix with its inverse */
|
/* Replace matrix with its inverse */
|
||||||
bool Matrix2x3::invert() {
|
bool Matrix2x3::invert()
|
||||||
|
{
|
||||||
float det = c[0] * c[3] - c[1] * c[2];
|
float det = c[0] * c[3] - c[1] * c[2];
|
||||||
if (det == 0) {
|
if (det == 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -174,7 +189,8 @@ bool Matrix2x3::invert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product, returning Vector2 */
|
/* Dot Product, returning Vector2 */
|
||||||
Vector2 Matrix2x3::Dot(const Matrix2x3 &m, const Vector2 &v) {
|
Vector2 Matrix2x3::Dot(const Matrix2x3& m, const Vector2& v)
|
||||||
|
{
|
||||||
return Vector2::Create(
|
return Vector2::Create(
|
||||||
v.c[0] * m.c[0] + v.c[1] * m.c[2] + m.c[4],
|
v.c[0] * m.c[0] + v.c[1] * m.c[2] + m.c[4],
|
||||||
v.c[0] * m.c[1] + v.c[1] * m.c[3] + m.c[5]
|
v.c[0] * m.c[1] + v.c[1] * m.c[3] + m.c[5]
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Matrix4::init() {
|
void Matrix4::init()
|
||||||
|
{
|
||||||
// Default constructor - Initialize with an identity matrix
|
// Default constructor - Initialize with an identity matrix
|
||||||
static const float IDENTITY_MATRIX[] = {
|
static const float IDENTITY_MATRIX[] = {
|
||||||
1.0, 0.0, 0.0, 0.0,
|
1.0, 0.0, 0.0, 0.0,
|
||||||
@@ -47,7 +48,8 @@ void Matrix4::init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4::init(float *pMat) {
|
void Matrix4::init(float* pMat)
|
||||||
|
{
|
||||||
memcpy(c, pMat, sizeof(float) * 16);
|
memcpy(c, pMat, sizeof(float) * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +61,8 @@ void Matrix4::init(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const V
|
|||||||
c[12] = new_transform.x; c[13] = new_transform.y; c[14] = new_transform.z; c[15] = 1.0f;
|
c[12] = new_transform.x; c[13] = new_transform.y; c[14] = new_transform.z; c[15] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4::init(const Matrix4 &m) {
|
void Matrix4::init(const Matrix4& m)
|
||||||
|
{
|
||||||
memcpy(c, m.c, sizeof(float) * 16);
|
memcpy(c, m.c, sizeof(float) * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,33 +80,36 @@ Matrix4 Matrix4::Create(const Vector3 &new_axis_x, const Vector3 &new_axis_y, co
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *Matrix4::getPointer() {
|
float* Matrix4::getPointer()
|
||||||
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Matrix4::operator[](unsigned i) {
|
float& Matrix4::operator[](unsigned i)
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Matrix4::operator[](unsigned i) const {
|
float Matrix4::operator[](unsigned i) const
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload comparison operator
|
// Overload comparison operator
|
||||||
bool Matrix4::operator==(const Matrix4 &m) const {
|
bool Matrix4::operator==(const Matrix4& m) const
|
||||||
|
{
|
||||||
return memcmp(c, m.c, sizeof(float) * 16) == 0;
|
return memcmp(c, m.c, sizeof(float) * 16) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload compound multiply operator
|
// Overload compound multiply operator
|
||||||
Matrix4& Matrix4::operator*=(const Matrix4 &m) {
|
Matrix4& Matrix4::operator*=(const Matrix4& m)
|
||||||
|
{
|
||||||
float temp[16];
|
float temp[16];
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (x=0; x < 4; x++)
|
for (x = 0; x < 4; x++) {
|
||||||
{
|
for (y = 0; y < 4; y++) {
|
||||||
for(y=0; y < 4; y++)
|
|
||||||
{
|
|
||||||
temp[y + (x * 4)] = (c[x * 4] * m.c[y]) +
|
temp[y + (x * 4)] = (c[x * 4] * m.c[y]) +
|
||||||
(c[(x * 4) + 1] * m.c[y + 4]) +
|
(c[(x * 4) + 1] * m.c[y + 4]) +
|
||||||
(c[(x * 4) + 2] * m.c[y + 8]) +
|
(c[(x * 4) + 2] * m.c[y + 8]) +
|
||||||
@@ -116,7 +122,8 @@ Matrix4& Matrix4::operator*=(const Matrix4 &m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Overload multiply operator
|
// Overload multiply operator
|
||||||
Matrix4 Matrix4::operator*(const Matrix4 &m) const {
|
Matrix4 Matrix4::operator*(const Matrix4& m) const
|
||||||
|
{
|
||||||
Matrix4 ret = *this;
|
Matrix4 ret = *this;
|
||||||
ret *= m;
|
ret *= m;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -125,7 +132,8 @@ Matrix4 Matrix4::operator*(const Matrix4 &m) const {
|
|||||||
|
|
||||||
/* Generate a perspective view matrix using a field of view angle fov,
|
/* Generate a perspective view matrix using a field of view angle fov,
|
||||||
* window aspect ratio, near and far clipping planes */
|
* window aspect ratio, near and far clipping planes */
|
||||||
void Matrix4::perspective(float fov, float aspect, float nearz, float farz) {
|
void Matrix4::perspective(float fov, float aspect, float nearz, float farz)
|
||||||
|
{
|
||||||
|
|
||||||
memset(c, 0, sizeof(float) * 16);
|
memset(c, 0, sizeof(float) * 16);
|
||||||
|
|
||||||
@@ -149,7 +157,8 @@ void Matrix4::perspective(float fov, float aspect, float nearz, float farz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform translation operations on a matrix */
|
/* Perform translation operations on a matrix */
|
||||||
void Matrix4::translate(float x, float y, float z) {
|
void Matrix4::translate(float x, float y, float z)
|
||||||
|
{
|
||||||
Matrix4 newMatrix; // Create new identity matrix
|
Matrix4 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
|
|
||||||
@@ -166,7 +175,8 @@ void Matrix4::translate(const Vector3 &v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
||||||
void Matrix4::rotate(float angle, AXIS axis) {
|
void Matrix4::rotate(float angle, AXIS axis)
|
||||||
|
{
|
||||||
const int cos1[3] = { 5, 0, 0 }; // cos(angle)
|
const int cos1[3] = { 5, 0, 0 }; // cos(angle)
|
||||||
const int cos2[3] = { 10, 10, 5 }; // cos(angle)
|
const int cos2[3] = { 10, 10, 5 }; // cos(angle)
|
||||||
const int sin1[3] = { 9, 2, 4 }; // -sin(angle)
|
const int sin1[3] = { 9, 2, 4 }; // -sin(angle)
|
||||||
@@ -214,7 +224,8 @@ void Matrix4::rotate(const Quaternion &q)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Scale matrix by separate x, y, and z amounts */
|
/* Scale matrix by separate x, y, and z amounts */
|
||||||
void Matrix4::scale(float x, float y, float z) {
|
void Matrix4::scale(float x, float y, float z)
|
||||||
|
{
|
||||||
Matrix4 newMatrix; // Create new identity matrix
|
Matrix4 newMatrix; // Create new identity matrix
|
||||||
newMatrix.init();
|
newMatrix.init();
|
||||||
|
|
||||||
@@ -225,17 +236,20 @@ void Matrix4::scale(float x, float y, float z) {
|
|||||||
*this *= newMatrix;
|
*this *= newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4::scale(const Vector3 &v) {
|
void Matrix4::scale(const Vector3& v)
|
||||||
|
{
|
||||||
scale(v.x, v.y, v.z);
|
scale(v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scale all dimensions equally */
|
/* Scale all dimensions equally */
|
||||||
void Matrix4::scale(float s) {
|
void Matrix4::scale(float s)
|
||||||
|
{
|
||||||
scale(s, s, s);
|
scale(s, s, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize with a bias matrix
|
// Initialize with a bias matrix
|
||||||
void Matrix4::bias() {
|
void Matrix4::bias()
|
||||||
|
{
|
||||||
static const float BIAS_MATRIX[] = {
|
static const float BIAS_MATRIX[] = {
|
||||||
0.5, 0.0, 0.0, 0.0,
|
0.5, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.5, 0.0, 0.0,
|
0.0, 0.5, 0.0, 0.0,
|
||||||
@@ -247,7 +261,8 @@ void Matrix4::bias() {
|
|||||||
|
|
||||||
|
|
||||||
/* Generate an orthographic view matrix */
|
/* Generate an orthographic view matrix */
|
||||||
void Matrix4::ortho(float left, float right, float top, float bottom, float nearz, float farz) {
|
void Matrix4::ortho(float left, float right, float top, float bottom, float nearz, float farz)
|
||||||
|
{
|
||||||
memset(c, 0, sizeof(float) * 16);
|
memset(c, 0, sizeof(float) * 16);
|
||||||
c[0] = 2.0f / (right - left);
|
c[0] = 2.0f / (right - left);
|
||||||
c[5] = 2.0f / (bottom - top);
|
c[5] = 2.0f / (bottom - top);
|
||||||
@@ -257,7 +272,8 @@ void Matrix4::ortho(float left, float right, float top, float bottom, float near
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Replace matrix with its inverse */
|
/* Replace matrix with its inverse */
|
||||||
bool Matrix4::invert() {
|
bool Matrix4::invert()
|
||||||
|
{
|
||||||
// Based on gluInvertMatrix implementation
|
// Based on gluInvertMatrix implementation
|
||||||
|
|
||||||
float inv[16], det;
|
float inv[16], det;
|
||||||
@@ -311,7 +327,8 @@ bool Matrix4::invert() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4::transpose() {
|
void Matrix4::transpose()
|
||||||
|
{
|
||||||
float trans[16];
|
float trans[16];
|
||||||
for (int x = 0; x < 4; x++) {
|
for (int x = 0; x < 4; x++) {
|
||||||
for (int y = 0; y < 4; y++) {
|
for (int y = 0; y < 4; y++) {
|
||||||
@@ -322,7 +339,8 @@ void Matrix4::transpose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product, returning Vector3 */
|
/* Dot Product, returning Vector3 */
|
||||||
Vector3 Matrix4::Dot(const Matrix4 &m, const Vector3 &v) {
|
Vector3 Matrix4::Dot(const Matrix4& m, const Vector3& v)
|
||||||
|
{
|
||||||
return Vector3::Create(
|
return Vector3::Create(
|
||||||
v.c[0] * m.c[0] + v.c[1] * m.c[4] + v.c[2] * m.c[8] + m.c[12],
|
v.c[0] * m.c[0] + v.c[1] * m.c[4] + v.c[2] * m.c[8] + m.c[12],
|
||||||
v.c[0] * m.c[1] + v.c[1] * m.c[5] + v.c[2] * m.c[9] + m.c[13],
|
v.c[0] * m.c[1] + v.c[1] * m.c[5] + v.c[2] * m.c[9] + m.c[13],
|
||||||
@@ -330,7 +348,8 @@ Vector3 Matrix4::Dot(const Matrix4 &m, const Vector3 &v) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Matrix4::Dot4(const Matrix4 &m, const Vector4 &v) {
|
Vector4 Matrix4::Dot4(const Matrix4& m, const Vector4& v)
|
||||||
|
{
|
||||||
#ifdef KRAKEN_USE_ARM_NEON
|
#ifdef KRAKEN_USE_ARM_NEON
|
||||||
|
|
||||||
Vector4 d;
|
Vector4 d;
|
||||||
@@ -374,12 +393,14 @@ Vector3 Matrix4::DotNoTranslate(const Matrix4 &m, const Vector3 &v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product, returning w component as if it were a Vector4 (This will be deprecated once Vector4 is implemented instead*/
|
/* Dot Product, returning w component as if it were a Vector4 (This will be deprecated once Vector4 is implemented instead*/
|
||||||
float Matrix4::DotW(const Matrix4 &m, const Vector3 &v) {
|
float Matrix4::DotW(const Matrix4& m, const Vector3& v)
|
||||||
|
{
|
||||||
return v.x * m.c[0 * 4 + 3] + v.y * m.c[1 * 4 + 3] + v.z * m.c[2 * 4 + 3] + m.c[3 * 4 + 3];
|
return v.x * m.c[0 * 4 + 3] + v.y * m.c[1 * 4 + 3] + v.z * m.c[2 * 4 + 3] + m.c[3 * 4 + 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product followed by W-divide */
|
/* Dot Product followed by W-divide */
|
||||||
Vector3 Matrix4::DotWDiv(const Matrix4 &m, const Vector3 &v) {
|
Vector3 Matrix4::DotWDiv(const Matrix4& m, const Vector3& v)
|
||||||
|
{
|
||||||
Vector4 r = Dot4(m, Vector4::Create(v, 1.0f));
|
Vector4 r = Dot4(m, Vector4::Create(v, 1.0f));
|
||||||
return Vector3::Create(r) / r.w;
|
return Vector3::Create(r) / r.w;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Quaternion::init() {
|
void Quaternion::init()
|
||||||
|
{
|
||||||
c[0] = 1.0;
|
c[0] = 1.0;
|
||||||
c[1] = 0.0;
|
c[1] = 0.0;
|
||||||
c[2] = 0.0;
|
c[2] = 0.0;
|
||||||
@@ -49,7 +50,8 @@ Quaternion Quaternion::Create()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::init(float w, float x, float y, float z) {
|
void Quaternion::init(float w, float x, float y, float z)
|
||||||
|
{
|
||||||
c[0] = w;
|
c[0] = w;
|
||||||
c[1] = x;
|
c[1] = x;
|
||||||
c[2] = y;
|
c[2] = y;
|
||||||
@@ -63,7 +65,8 @@ Quaternion Quaternion::Create(float w, float x, float y, float z)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::init(const Quaternion& p) {
|
void Quaternion::init(const Quaternion& p)
|
||||||
|
{
|
||||||
c[0] = p[0];
|
c[0] = p[0];
|
||||||
c[1] = p[1];
|
c[1] = p[1];
|
||||||
c[2] = p[2];
|
c[2] = p[2];
|
||||||
@@ -77,7 +80,8 @@ Quaternion Quaternion::Create(const Quaternion& p)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::init(const Vector3 &euler) {
|
void Quaternion::init(const Vector3& euler)
|
||||||
|
{
|
||||||
setEulerZYX(euler);
|
setEulerZYX(euler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +92,8 @@ Quaternion Quaternion::Create(const Vector3 &euler)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::init(const Vector3 &from_vector, const Vector3 &to_vector) {
|
void Quaternion::init(const Vector3& from_vector, const Vector3& to_vector)
|
||||||
|
{
|
||||||
|
|
||||||
Vector3 a = Vector3::Cross(from_vector, to_vector);
|
Vector3 a = Vector3::Cross(from_vector, to_vector);
|
||||||
c[0] = a[0];
|
c[0] = a[0];
|
||||||
@@ -112,7 +117,8 @@ void Quaternion::setEulerXYZ(const Vector3 &euler)
|
|||||||
* Quaternion::FromAngleAxis(Vector3::Create(0.0f, 0.0f, 1.0f), euler.z);
|
* Quaternion::FromAngleAxis(Vector3::Create(0.0f, 0.0f, 1.0f), euler.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::setEulerZYX(const Vector3 &euler) {
|
void Quaternion::setEulerZYX(const Vector3& euler)
|
||||||
|
{
|
||||||
// ZYX Order!
|
// ZYX Order!
|
||||||
float c1 = cosf(euler[0] * 0.5f);
|
float c1 = cosf(euler[0] * 0.5f);
|
||||||
float c2 = cosf(euler[1] * 0.5f);
|
float c2 = cosf(euler[1] * 0.5f);
|
||||||
@@ -127,15 +133,18 @@ void Quaternion::setEulerZYX(const Vector3 &euler) {
|
|||||||
c[3] = c1 * c2 * s3 - s1 * s2 * c3;
|
c[3] = c1 * c2 * s3 - s1 * s2 * c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Quaternion::operator [](unsigned i) const {
|
float Quaternion::operator [](unsigned i) const
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
float &Quaternion::operator [](unsigned i) {
|
float& Quaternion::operator [](unsigned i)
|
||||||
|
{
|
||||||
return c[i];
|
return c[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Quaternion::eulerXYZ() const {
|
Vector3 Quaternion::eulerXYZ() const
|
||||||
|
{
|
||||||
float a2 = 2 * (c[0] * c[2] - c[1] * c[3]);
|
float a2 = 2 * (c[0] * c[2] - c[1] * c[3]);
|
||||||
if (a2 <= -0.99999) {
|
if (a2 <= -0.99999) {
|
||||||
return Vector3::Create(
|
return Vector3::Create(
|
||||||
@@ -160,7 +169,8 @@ Vector3 Quaternion::eulerXYZ() const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(Quaternion &v1, Quaternion &v2) {
|
bool operator ==(Quaternion& v1, Quaternion& v2)
|
||||||
|
{
|
||||||
return
|
return
|
||||||
v1[0] == v2[0]
|
v1[0] == v2[0]
|
||||||
&& v1[1] == v2[1]
|
&& v1[1] == v2[1]
|
||||||
@@ -168,7 +178,8 @@ bool operator ==(Quaternion &v1, Quaternion &v2) {
|
|||||||
&& v1[3] == v2[3];
|
&& v1[3] == v2[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator !=(Quaternion &v1, Quaternion &v2) {
|
bool operator !=(Quaternion& v1, Quaternion& v2)
|
||||||
|
{
|
||||||
return
|
return
|
||||||
v1[0] != v2[0]
|
v1[0] != v2[0]
|
||||||
|| v1[1] != v2[1]
|
|| v1[1] != v2[1]
|
||||||
@@ -176,7 +187,8 @@ bool operator !=(Quaternion &v1, Quaternion &v2) {
|
|||||||
|| v1[3] != v2[3];
|
|| v1[3] != v2[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator *(const Quaternion &v) {
|
Quaternion Quaternion::operator *(const Quaternion& v)
|
||||||
|
{
|
||||||
float t0 = (c[3] - c[2]) * (v[2] - v[3]);
|
float t0 = (c[3] - c[2]) * (v[2] - v[3]);
|
||||||
float t1 = (c[0] + c[1]) * (v[0] + v[1]);
|
float t1 = (c[0] + c[1]) * (v[0] + v[1]);
|
||||||
float t2 = (c[0] - c[1]) * (v[2] + v[3]);
|
float t2 = (c[0] - c[1]) * (v[2] + v[3]);
|
||||||
@@ -196,24 +208,29 @@ Quaternion Quaternion::operator *(const Quaternion &v) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator *(float v) const {
|
Quaternion Quaternion::operator *(float v) const
|
||||||
|
{
|
||||||
return Quaternion::Create(c[0] * v, c[1] * v, c[2] * v, c[3] * v);
|
return Quaternion::Create(c[0] * v, c[1] * v, c[2] * v, c[3] * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator /(float num) const {
|
Quaternion Quaternion::operator /(float num) const
|
||||||
|
{
|
||||||
float inv_num = 1.0f / num;
|
float inv_num = 1.0f / num;
|
||||||
return Quaternion::Create(c[0] * inv_num, c[1] * inv_num, c[2] * inv_num, c[3] * inv_num);
|
return Quaternion::Create(c[0] * inv_num, c[1] * inv_num, c[2] * inv_num, c[3] * inv_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator +(const Quaternion &v) const {
|
Quaternion Quaternion::operator +(const Quaternion& v) const
|
||||||
|
{
|
||||||
return Quaternion::Create(c[0] + v[0], c[1] + v[1], c[2] + v[2], c[3] + v[3]);
|
return Quaternion::Create(c[0] + v[0], c[1] + v[1], c[2] + v[2], c[3] + v[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator -(const Quaternion &v) const {
|
Quaternion Quaternion::operator -(const Quaternion& v) const
|
||||||
|
{
|
||||||
return Quaternion::Create(c[0] - v[0], c[1] - v[1], c[2] - v[2], c[3] - v[3]);
|
return Quaternion::Create(c[0] - v[0], c[1] - v[1], c[2] - v[2], c[3] - v[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion& Quaternion::operator +=(const Quaternion& v) {
|
Quaternion& Quaternion::operator +=(const Quaternion& v)
|
||||||
|
{
|
||||||
c[0] += v[0];
|
c[0] += v[0];
|
||||||
c[1] += v[1];
|
c[1] += v[1];
|
||||||
c[2] += v[2];
|
c[2] += v[2];
|
||||||
@@ -221,7 +238,8 @@ Quaternion& Quaternion::operator +=(const Quaternion& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion& Quaternion::operator -=(const Quaternion& v) {
|
Quaternion& Quaternion::operator -=(const Quaternion& v)
|
||||||
|
{
|
||||||
c[0] -= v[0];
|
c[0] -= v[0];
|
||||||
c[1] -= v[1];
|
c[1] -= v[1];
|
||||||
c[2] -= v[2];
|
c[2] -= v[2];
|
||||||
@@ -229,7 +247,8 @@ Quaternion& Quaternion::operator -=(const Quaternion& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion& Quaternion::operator *=(const Quaternion& v) {
|
Quaternion& Quaternion::operator *=(const Quaternion& v)
|
||||||
|
{
|
||||||
float t0 = (c[3] - c[2]) * (v[2] - v[3]);
|
float t0 = (c[3] - c[2]) * (v[2] - v[3]);
|
||||||
float t1 = (c[0] + c[1]) * (v[0] + v[1]);
|
float t1 = (c[0] + c[1]) * (v[0] + v[1]);
|
||||||
float t2 = (c[0] - c[1]) * (v[2] + v[3]);
|
float t2 = (c[0] - c[1]) * (v[2] + v[3]);
|
||||||
@@ -249,7 +268,8 @@ Quaternion& Quaternion::operator *=(const Quaternion& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion& Quaternion::operator *=(const float& v) {
|
Quaternion& Quaternion::operator *=(const float& v)
|
||||||
|
{
|
||||||
c[0] *= v;
|
c[0] *= v;
|
||||||
c[1] *= v;
|
c[1] *= v;
|
||||||
c[2] *= v;
|
c[2] *= v;
|
||||||
@@ -257,7 +277,8 @@ Quaternion& Quaternion::operator *=(const float& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion& Quaternion::operator /=(const float& v) {
|
Quaternion& Quaternion::operator /=(const float& v)
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
c[0] *= inv_v;
|
c[0] *= inv_v;
|
||||||
c[1] *= inv_v;
|
c[1] *= inv_v;
|
||||||
@@ -266,15 +287,18 @@ Quaternion& Quaternion::operator /=(const float& v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator +() const {
|
Quaternion Quaternion::operator +() const
|
||||||
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::operator -() const {
|
Quaternion Quaternion::operator -() const
|
||||||
|
{
|
||||||
return Quaternion::Create(-c[0], -c[1], -c[2], -c[3]);
|
return Quaternion::Create(-c[0], -c[1], -c[2], -c[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::Normalize(const Quaternion &v1) {
|
Quaternion Quaternion::Normalize(const Quaternion& v1)
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
float inv_magnitude = 1.0f / sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||||
return Quaternion::Create(
|
return Quaternion::Create(
|
||||||
v1[0] * inv_magnitude,
|
v1[0] * inv_magnitude,
|
||||||
@@ -284,7 +308,8 @@ Quaternion Quaternion::Normalize(const Quaternion &v1) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::normalize() {
|
void Quaternion::normalize()
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(c[0] * c[0] + c[1] * c[1] + c[2] * c[2] + c[3] * c[3]);
|
float inv_magnitude = 1.0f / sqrtf(c[0] * c[0] + c[1] * c[1] + c[2] * c[2] + c[3] * c[3]);
|
||||||
c[0] *= inv_magnitude;
|
c[0] *= inv_magnitude;
|
||||||
c[1] *= inv_magnitude;
|
c[1] *= inv_magnitude;
|
||||||
@@ -292,26 +317,31 @@ void Quaternion::normalize() {
|
|||||||
c[3] *= inv_magnitude;
|
c[3] *= inv_magnitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::Conjugate(const Quaternion &v1) {
|
Quaternion Quaternion::Conjugate(const Quaternion& v1)
|
||||||
|
{
|
||||||
return Quaternion::Create(v1[0], -v1[1], -v1[2], -v1[3]);
|
return Quaternion::Create(v1[0], -v1[1], -v1[2], -v1[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::conjugate() {
|
void Quaternion::conjugate()
|
||||||
|
{
|
||||||
c[1] = -c[1];
|
c[1] = -c[1];
|
||||||
c[2] = -c[2];
|
c[2] = -c[2];
|
||||||
c[3] = -c[3];
|
c[3] = -c[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quaternion::invert() {
|
void Quaternion::invert()
|
||||||
|
{
|
||||||
conjugate();
|
conjugate();
|
||||||
normalize();
|
normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::Invert(const Quaternion &v1) {
|
Quaternion Quaternion::Invert(const Quaternion& v1)
|
||||||
|
{
|
||||||
return Normalize(Conjugate(v1));
|
return Normalize(Conjugate(v1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4 Quaternion::rotationMatrix() const {
|
Matrix4 Quaternion::rotationMatrix() const
|
||||||
|
{
|
||||||
Matrix4 matRotate;
|
Matrix4 matRotate;
|
||||||
matRotate.init();
|
matRotate.init();
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Vector2::init() {
|
void Vector2::init()
|
||||||
|
{
|
||||||
x = 0.0;
|
x = 0.0;
|
||||||
y = 0.0;
|
y = 0.0;
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,8 @@ Vector2 Vector2::Create()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::init(float X, float Y) {
|
void Vector2::init(float X, float Y)
|
||||||
|
{
|
||||||
x = X;
|
x = X;
|
||||||
y = Y;
|
y = Y;
|
||||||
}
|
}
|
||||||
@@ -58,7 +60,8 @@ Vector2 Vector2::Create(float X, float Y)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::init(float v) {
|
void Vector2::init(float v)
|
||||||
|
{
|
||||||
x = v;
|
x = v;
|
||||||
y = v;
|
y = v;
|
||||||
}
|
}
|
||||||
@@ -70,7 +73,8 @@ Vector2 Vector2::Create(float v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::init(float *v) {
|
void Vector2::init(float* v)
|
||||||
|
{
|
||||||
x = v[0];
|
x = v[0];
|
||||||
y = v[1];
|
y = v[1];
|
||||||
}
|
}
|
||||||
@@ -82,7 +86,8 @@ Vector2 Vector2::Create(float *v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::init(const Vector2 &v) {
|
void Vector2::init(const Vector2& v)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
}
|
}
|
||||||
@@ -107,54 +112,66 @@ void Vector2::yx(const Vector2 &v)
|
|||||||
x = v.y;
|
x = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::Min() {
|
Vector2 Vector2::Min()
|
||||||
|
{
|
||||||
return Vector2::Create(-std::numeric_limits<float>::max());
|
return Vector2::Create(-std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::Max() {
|
Vector2 Vector2::Max()
|
||||||
|
{
|
||||||
return Vector2::Create(std::numeric_limits<float>::max());
|
return Vector2::Create(std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::Zero() {
|
Vector2 Vector2::Zero()
|
||||||
|
{
|
||||||
return Vector2::Create(0.0f);
|
return Vector2::Create(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::One() {
|
Vector2 Vector2::One()
|
||||||
|
{
|
||||||
return Vector2::Create(1.0f);
|
return Vector2::Create(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator +(const Vector2& b) const {
|
Vector2 Vector2::operator +(const Vector2& b) const
|
||||||
|
{
|
||||||
return Vector2::Create(x + b.x, y + b.y);
|
return Vector2::Create(x + b.x, y + b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator -(const Vector2& b) const {
|
Vector2 Vector2::operator -(const Vector2& b) const
|
||||||
|
{
|
||||||
return Vector2::Create(x - b.x, y - b.y);
|
return Vector2::Create(x - b.x, y - b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator +() const {
|
Vector2 Vector2::operator +() const
|
||||||
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator -() const {
|
Vector2 Vector2::operator -() const
|
||||||
|
{
|
||||||
return Vector2::Create(-x, -y);
|
return Vector2::Create(-x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator *(const float v) const {
|
Vector2 Vector2::operator *(const float v) const
|
||||||
|
{
|
||||||
return Vector2::Create(x * v, y * v);
|
return Vector2::Create(x * v, y * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator /(const float v) const {
|
Vector2 Vector2::operator /(const float v) const
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
return Vector2::Create(x * inv_v, y * inv_v);
|
return Vector2::Create(x * inv_v, y * inv_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& Vector2::operator +=(const Vector2& b) {
|
Vector2& Vector2::operator +=(const Vector2& b)
|
||||||
|
{
|
||||||
x += b.x;
|
x += b.x;
|
||||||
y += b.y;
|
y += b.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& Vector2::operator -=(const Vector2& b) {
|
Vector2& Vector2::operator -=(const Vector2& b)
|
||||||
|
{
|
||||||
x -= b.x;
|
x -= b.x;
|
||||||
y -= b.y;
|
y -= b.y;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -162,13 +179,15 @@ Vector2& Vector2::operator -=(const Vector2& b) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vector2& Vector2::operator *=(const float v) {
|
Vector2& Vector2::operator *=(const float v)
|
||||||
|
{
|
||||||
x *= v;
|
x *= v;
|
||||||
y *= v;
|
y *= v;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& Vector2::operator /=(const float v) {
|
Vector2& Vector2::operator /=(const float v)
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
x *= inv_v;
|
x *= inv_v;
|
||||||
y *= inv_v;
|
y *= inv_v;
|
||||||
@@ -176,11 +195,13 @@ Vector2& Vector2::operator /=(const float v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Vector2::operator ==(const Vector2& b) const {
|
bool Vector2::operator ==(const Vector2& b) const
|
||||||
|
{
|
||||||
return x == b.x && y == b.y;
|
return x == b.x && y == b.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector2::operator !=(const Vector2& b) const {
|
bool Vector2::operator !=(const Vector2& b) const
|
||||||
|
{
|
||||||
return x != b.x || y != b.y;
|
return x != b.x || y != b.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +233,8 @@ bool Vector2::operator <(const Vector2& b) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Vector2::operator[] (unsigned i) {
|
float& Vector2::operator[] (unsigned i)
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -222,7 +244,8 @@ float& Vector2::operator[] (unsigned i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::operator[](unsigned i) const {
|
float Vector2::operator[](unsigned i) const
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -232,39 +255,47 @@ float Vector2::operator[](unsigned i) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::normalize() {
|
void Vector2::normalize()
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y);
|
float inv_magnitude = 1.0f / sqrtf(x * x + y * y);
|
||||||
x *= inv_magnitude;
|
x *= inv_magnitude;
|
||||||
y *= inv_magnitude;
|
y *= inv_magnitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::sqrMagnitude() const {
|
float Vector2::sqrMagnitude() const
|
||||||
|
{
|
||||||
return x * x + y * y;
|
return x * x + y * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::magnitude() const {
|
float Vector2::magnitude() const
|
||||||
|
{
|
||||||
return sqrtf(x * x + y * y);
|
return sqrtf(x * x + y * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2 Vector2::Normalize(const Vector2 &v) {
|
Vector2 Vector2::Normalize(const Vector2& v)
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y);
|
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y);
|
||||||
return Vector2::Create(v.x * inv_magnitude, v.y * inv_magnitude);
|
return Vector2::Create(v.x * inv_magnitude, v.y * inv_magnitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::Cross(const Vector2 &v1, const Vector2 &v2) {
|
float Vector2::Cross(const Vector2& v1, const Vector2& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.y - v1.y * v2.x;
|
return v1.x * v2.y - v1.y * v2.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::Dot(const Vector2 &v1, const Vector2 &v2) {
|
float Vector2::Dot(const Vector2& v1, const Vector2& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.x + v1.y * v2.y;
|
return v1.x * v2.x + v1.y * v2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::Min(const Vector2 &v1, const Vector2 &v2) {
|
Vector2 Vector2::Min(const Vector2& v1, const Vector2& v2)
|
||||||
|
{
|
||||||
return Vector2::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y));
|
return Vector2::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::Max(const Vector2 &v1, const Vector2 &v2) {
|
Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2)
|
||||||
|
{
|
||||||
return Vector2::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
|
return Vector2::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
|
|
||||||
void Vector2i::init() {
|
void Vector2i::init()
|
||||||
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,8 @@ Vector2i Vector2i::Create()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2i::init(int X, int Y) {
|
void Vector2i::init(int X, int Y)
|
||||||
|
{
|
||||||
x = X;
|
x = X;
|
||||||
y = Y;
|
y = Y;
|
||||||
}
|
}
|
||||||
@@ -58,7 +60,8 @@ Vector2i Vector2i::Create(int X, int Y)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2i::init(int v) {
|
void Vector2i::init(int v)
|
||||||
|
{
|
||||||
x = v;
|
x = v;
|
||||||
y = v;
|
y = v;
|
||||||
}
|
}
|
||||||
@@ -70,7 +73,8 @@ Vector2i Vector2i::Create(int v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2i::init(int *v) {
|
void Vector2i::init(int* v)
|
||||||
|
{
|
||||||
x = v[0];
|
x = v[0];
|
||||||
y = v[1];
|
y = v[1];
|
||||||
}
|
}
|
||||||
@@ -82,7 +86,8 @@ Vector2i Vector2i::Create(int *v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2i::init(const Vector2i &v) {
|
void Vector2i::init(const Vector2i& v)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
}
|
}
|
||||||
@@ -107,75 +112,91 @@ void Vector2i::yx(const Vector2i &v)
|
|||||||
x = v.y;
|
x = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Min() {
|
Vector2i Vector2i::Min()
|
||||||
|
{
|
||||||
return Vector2i::Create(-std::numeric_limits<int>::max());
|
return Vector2i::Create(-std::numeric_limits<int>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Max() {
|
Vector2i Vector2i::Max()
|
||||||
|
{
|
||||||
return Vector2i::Create(std::numeric_limits<int>::max());
|
return Vector2i::Create(std::numeric_limits<int>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Zero() {
|
Vector2i Vector2i::Zero()
|
||||||
|
{
|
||||||
return Vector2i::Create(0);
|
return Vector2i::Create(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::One() {
|
Vector2i Vector2i::One()
|
||||||
|
{
|
||||||
return Vector2i::Create(1);
|
return Vector2i::Create(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator +(const Vector2i& b) const {
|
Vector2i Vector2i::operator +(const Vector2i& b) const
|
||||||
|
{
|
||||||
return Vector2i::Create(x + b.x, y + b.y);
|
return Vector2i::Create(x + b.x, y + b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator -(const Vector2i& b) const {
|
Vector2i Vector2i::operator -(const Vector2i& b) const
|
||||||
|
{
|
||||||
return Vector2i::Create(x - b.x, y - b.y);
|
return Vector2i::Create(x - b.x, y - b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator +() const {
|
Vector2i Vector2i::operator +() const
|
||||||
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator -() const {
|
Vector2i Vector2i::operator -() const
|
||||||
|
{
|
||||||
return Vector2i::Create(-x, -y);
|
return Vector2i::Create(-x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator *(const int v) const {
|
Vector2i Vector2i::operator *(const int v) const
|
||||||
|
{
|
||||||
return Vector2i::Create(x * v, y * v);
|
return Vector2i::Create(x * v, y * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::operator /(const int v) const {
|
Vector2i Vector2i::operator /(const int v) const
|
||||||
|
{
|
||||||
return Vector2i::Create(x / v, y / v);
|
return Vector2i::Create(x / v, y / v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i& Vector2i::operator +=(const Vector2i& b) {
|
Vector2i& Vector2i::operator +=(const Vector2i& b)
|
||||||
|
{
|
||||||
x += b.x;
|
x += b.x;
|
||||||
y += b.y;
|
y += b.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i& Vector2i::operator -=(const Vector2i& b) {
|
Vector2i& Vector2i::operator -=(const Vector2i& b)
|
||||||
|
{
|
||||||
x -= b.x;
|
x -= b.x;
|
||||||
y -= b.y;
|
y -= b.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i& Vector2i::operator *=(const int v) {
|
Vector2i& Vector2i::operator *=(const int v)
|
||||||
|
{
|
||||||
x *= v;
|
x *= v;
|
||||||
y *= v;
|
y *= v;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i& Vector2i::operator /=(const int v) {
|
Vector2i& Vector2i::operator /=(const int v)
|
||||||
|
{
|
||||||
x /= v;
|
x /= v;
|
||||||
y /= v;
|
y /= v;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector2i::operator ==(const Vector2i& b) const {
|
bool Vector2i::operator ==(const Vector2i& b) const
|
||||||
|
{
|
||||||
return x == b.x && y == b.y;
|
return x == b.x && y == b.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector2i::operator !=(const Vector2i& b) const {
|
bool Vector2i::operator !=(const Vector2i& b) const
|
||||||
|
{
|
||||||
return x != b.x || y != b.y;
|
return x != b.x || y != b.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +228,8 @@ bool Vector2i::operator <(const Vector2i& b) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int& Vector2i::operator[] (unsigned i) {
|
int& Vector2i::operator[] (unsigned i)
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -217,7 +239,8 @@ int& Vector2i::operator[] (unsigned i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector2i::operator[](unsigned i) const {
|
int Vector2i::operator[](unsigned i) const
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -227,38 +250,46 @@ int Vector2i::operator[](unsigned i) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2i::normalize() {
|
void Vector2i::normalize()
|
||||||
|
{
|
||||||
int m = magnitude();
|
int m = magnitude();
|
||||||
x /= m;
|
x /= m;
|
||||||
y /= m;
|
y /= m;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector2i::sqrMagnitude() const {
|
int Vector2i::sqrMagnitude() const
|
||||||
|
{
|
||||||
return x * x + y * y;
|
return x * x + y * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector2i::magnitude() const {
|
int Vector2i::magnitude() const
|
||||||
|
{
|
||||||
return static_cast<int>(sqrtf((float)x * (float)x + (float)y * (float)y));
|
return static_cast<int>(sqrtf((float)x * (float)x + (float)y * (float)y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Normalize(const Vector2i &v) {
|
Vector2i Vector2i::Normalize(const Vector2i& v)
|
||||||
|
{
|
||||||
int m = v.magnitude();
|
int m = v.magnitude();
|
||||||
return Vector2i::Create(v.x / m, v.y / m);
|
return Vector2i::Create(v.x / m, v.y / m);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector2i::Cross(const Vector2i &v1, const Vector2i &v2) {
|
int Vector2i::Cross(const Vector2i& v1, const Vector2i& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.y - v1.y * v2.x;
|
return v1.x * v2.y - v1.y * v2.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector2i::Dot(const Vector2i &v1, const Vector2i &v2) {
|
int Vector2i::Dot(const Vector2i& v1, const Vector2i& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.x + v1.y * v2.y;
|
return v1.x * v2.x + v1.y * v2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Min(const Vector2i &v1, const Vector2i &v2) {
|
Vector2i Vector2i::Min(const Vector2i& v1, const Vector2i& v2)
|
||||||
|
{
|
||||||
return Vector2i::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y));
|
return Vector2i::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Vector2i::Max(const Vector2i &v1, const Vector2i &v2) {
|
Vector2i Vector2i::Max(const Vector2i& v1, const Vector2i& v2)
|
||||||
|
{
|
||||||
return Vector2i::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
|
return Vector2i::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
123
src/vector3.cpp
123
src/vector3.cpp
@@ -49,7 +49,8 @@ Vector3 Vector3::Create()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::init(const Vector3 &v) {
|
void Vector3::init(const Vector3& v)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
z = v.z;
|
z = v.z;
|
||||||
@@ -62,7 +63,8 @@ Vector3 Vector3::Create(const Vector3 &v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::init(const Vector4 &v) {
|
void Vector3::init(const Vector4& v)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
z = v.z;
|
z = v.z;
|
||||||
@@ -75,7 +77,8 @@ Vector3 Vector3::Create(const Vector4 &v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::init(float *v) {
|
void Vector3::init(float* v)
|
||||||
|
{
|
||||||
x = v[0];
|
x = v[0];
|
||||||
y = v[1];
|
y = v[1];
|
||||||
z = v[2];
|
z = v[2];
|
||||||
@@ -89,7 +92,8 @@ Vector3 Vector3::Create(float *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Vector3::init(double *v) {
|
void Vector3::init(double* v)
|
||||||
|
{
|
||||||
x = (float)v[0];
|
x = (float)v[0];
|
||||||
y = (float)v[1];
|
y = (float)v[1];
|
||||||
z = (float)v[2];
|
z = (float)v[2];
|
||||||
@@ -103,7 +107,8 @@ Vector3 Vector3::Create(double *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Vector3::init(float v) {
|
void Vector3::init(float v)
|
||||||
|
{
|
||||||
x = v;
|
x = v;
|
||||||
y = v;
|
y = v;
|
||||||
z = v;
|
z = v;
|
||||||
@@ -211,43 +216,53 @@ void Vector3::zy(const Vector2 &v)
|
|||||||
y = v.y;
|
y = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Min() {
|
Vector3 Vector3::Min()
|
||||||
|
{
|
||||||
return Vector3::Create(-std::numeric_limits<float>::max());
|
return Vector3::Create(-std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Max() {
|
Vector3 Vector3::Max()
|
||||||
|
{
|
||||||
return Vector3::Create(std::numeric_limits<float>::max());
|
return Vector3::Create(std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Zero() {
|
Vector3 Vector3::Zero()
|
||||||
|
{
|
||||||
return Vector3::Create();
|
return Vector3::Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::One() {
|
Vector3 Vector3::One()
|
||||||
|
{
|
||||||
return Vector3::Create(1.0f, 1.0f, 1.0f);
|
return Vector3::Create(1.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Forward() {
|
Vector3 Vector3::Forward()
|
||||||
|
{
|
||||||
return Vector3::Create(0.0f, 0.0f, 1.0f);
|
return Vector3::Create(0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Backward() {
|
Vector3 Vector3::Backward()
|
||||||
|
{
|
||||||
return Vector3::Create(0.0f, 0.0f, -1.0f);
|
return Vector3::Create(0.0f, 0.0f, -1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Up() {
|
Vector3 Vector3::Up()
|
||||||
|
{
|
||||||
return Vector3::Create(0.0f, 1.0f, 0.0f);
|
return Vector3::Create(0.0f, 1.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Down() {
|
Vector3 Vector3::Down()
|
||||||
|
{
|
||||||
return Vector3::Create(0.0f, -1.0f, 0.0f);
|
return Vector3::Create(0.0f, -1.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Left() {
|
Vector3 Vector3::Left()
|
||||||
|
{
|
||||||
return Vector3::Create(-1.0f, 0.0f, 0.0f);
|
return Vector3::Create(-1.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Right() {
|
Vector3 Vector3::Right()
|
||||||
|
{
|
||||||
return Vector3::Create(1.0f, 0.0f, 0.0f);
|
return Vector3::Create(1.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +279,13 @@ Vector3 Vector3::Scale(const Vector3 &v1, const Vector3 &v2)
|
|||||||
return Vector3::Create(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
return Vector3::Create(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Lerp(const Vector3 &v1, const Vector3 &v2, float d) {
|
Vector3 Vector3::Lerp(const Vector3& v1, const Vector3& v2, float d)
|
||||||
|
{
|
||||||
return v1 + (v2 - v1) * d;
|
return v1 + (v2 - v1) * d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Slerp(const Vector3 &v1, const Vector3 &v2, float d) {
|
Vector3 Vector3::Slerp(const Vector3& v1, const Vector3& v2, float d)
|
||||||
|
{
|
||||||
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||||
// Dot product - the cosine of the angle between 2 vectors.
|
// Dot product - the cosine of the angle between 2 vectors.
|
||||||
float dot = Vector3::Dot(v1, v2);
|
float dot = Vector3::Dot(v1, v2);
|
||||||
@@ -285,7 +302,8 @@ Vector3 Vector3::Slerp(const Vector3 &v1, const Vector3 &v2, float d) {
|
|||||||
return ((v1 * cosf(theta)) + (RelativeVec * sinf(theta)));
|
return ((v1 * cosf(theta)) + (RelativeVec * sinf(theta)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::OrthoNormalize(Vector3 &normal, Vector3 &tangent) {
|
void Vector3::OrthoNormalize(Vector3& normal, Vector3& tangent)
|
||||||
|
{
|
||||||
// Gram-Schmidt Orthonormalization
|
// Gram-Schmidt Orthonormalization
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
Vector3 proj = normal * Dot(tangent, normal);
|
Vector3 proj = normal * Dot(tangent, normal);
|
||||||
@@ -293,36 +311,44 @@ void Vector3::OrthoNormalize(Vector3 &normal, Vector3 &tangent) {
|
|||||||
tangent.normalize();
|
tangent.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator =(const Vector4 &b) {
|
Vector3& Vector3::operator =(const Vector4& b)
|
||||||
|
{
|
||||||
x = b.x;
|
x = b.x;
|
||||||
y = b.y;
|
y = b.y;
|
||||||
z = b.z;
|
z = b.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator +(const Vector3& b) const {
|
Vector3 Vector3::operator +(const Vector3& b) const
|
||||||
|
{
|
||||||
return Vector3::Create(x + b.x, y + b.y, z + b.z);
|
return Vector3::Create(x + b.x, y + b.y, z + b.z);
|
||||||
}
|
}
|
||||||
Vector3 Vector3::operator -(const Vector3& b) const {
|
Vector3 Vector3::operator -(const Vector3& b) const
|
||||||
|
{
|
||||||
return Vector3::Create(x - b.x, y - b.y, z - b.z);
|
return Vector3::Create(x - b.x, y - b.y, z - b.z);
|
||||||
}
|
}
|
||||||
Vector3 Vector3::operator +() const {
|
Vector3 Vector3::operator +() const
|
||||||
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Vector3 Vector3::operator -() const {
|
Vector3 Vector3::operator -() const
|
||||||
|
{
|
||||||
return Vector3::Create(-x, -y, -z);
|
return Vector3::Create(-x, -y, -z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator *(const float v) const {
|
Vector3 Vector3::operator *(const float v) const
|
||||||
|
{
|
||||||
return Vector3::Create(x * v, y * v, z * v);
|
return Vector3::Create(x * v, y * v, z * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator /(const float v) const {
|
Vector3 Vector3::operator /(const float v) const
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
return Vector3::Create(x * inv_v, y * inv_v, z * inv_v);
|
return Vector3::Create(x * inv_v, y * inv_v, z * inv_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator +=(const Vector3& b) {
|
Vector3& Vector3::operator +=(const Vector3& b)
|
||||||
|
{
|
||||||
x += b.x;
|
x += b.x;
|
||||||
y += b.y;
|
y += b.y;
|
||||||
z += b.z;
|
z += b.z;
|
||||||
@@ -330,7 +356,8 @@ Vector3& Vector3::operator +=(const Vector3& b) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator -=(const Vector3& b) {
|
Vector3& Vector3::operator -=(const Vector3& b)
|
||||||
|
{
|
||||||
x -= b.x;
|
x -= b.x;
|
||||||
y -= b.y;
|
y -= b.y;
|
||||||
z -= b.z;
|
z -= b.z;
|
||||||
@@ -338,7 +365,8 @@ Vector3& Vector3::operator -=(const Vector3& b) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator *=(const float v) {
|
Vector3& Vector3::operator *=(const float v)
|
||||||
|
{
|
||||||
x *= v;
|
x *= v;
|
||||||
y *= v;
|
y *= v;
|
||||||
z *= v;
|
z *= v;
|
||||||
@@ -346,7 +374,8 @@ Vector3& Vector3::operator *=(const float v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator /=(const float v) {
|
Vector3& Vector3::operator /=(const float v)
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
x *= inv_v;
|
x *= inv_v;
|
||||||
y *= inv_v;
|
y *= inv_v;
|
||||||
@@ -355,15 +384,18 @@ Vector3& Vector3::operator /=(const float v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::operator ==(const Vector3& b) const {
|
bool Vector3::operator ==(const Vector3& b) const
|
||||||
|
{
|
||||||
return x == b.x && y == b.y && z == b.z;
|
return x == b.x && y == b.y && z == b.z;
|
||||||
|
|
||||||
}
|
}
|
||||||
bool Vector3::operator !=(const Vector3& b) const {
|
bool Vector3::operator !=(const Vector3& b) const
|
||||||
|
{
|
||||||
return x != b.x || y != b.y || z != b.z;
|
return x != b.x || y != b.y || z != b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Vector3::operator[](unsigned i) {
|
float& Vector3::operator[](unsigned i)
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -375,7 +407,8 @@ float& Vector3::operator[](unsigned i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::operator[](unsigned i) const {
|
float Vector3::operator[](unsigned i) const
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -387,41 +420,49 @@ float Vector3::operator[](unsigned i) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::sqrMagnitude() const {
|
float Vector3::sqrMagnitude() const
|
||||||
|
{
|
||||||
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||||
return x * x + y * y + z * z;
|
return x * x + y * y + z * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::magnitude() const {
|
float Vector3::magnitude() const
|
||||||
|
{
|
||||||
return sqrtf(x * x + y * y + z * z);
|
return sqrtf(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::normalize() {
|
void Vector3::normalize()
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z);
|
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z);
|
||||||
x *= inv_magnitude;
|
x *= inv_magnitude;
|
||||||
y *= inv_magnitude;
|
y *= inv_magnitude;
|
||||||
z *= inv_magnitude;
|
z *= inv_magnitude;
|
||||||
}
|
}
|
||||||
Vector3 Vector3::Normalize(const Vector3 &v) {
|
Vector3 Vector3::Normalize(const Vector3& v)
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||||
return Vector3::Create(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude);
|
return Vector3::Create(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Cross(const Vector3 &v1, const Vector3 &v2) {
|
Vector3 Vector3::Cross(const Vector3& v1, const Vector3& v2)
|
||||||
|
{
|
||||||
return Vector3::Create(v1.y * v2.z - v1.z * v2.y,
|
return Vector3::Create(v1.y * v2.z - v1.z * v2.y,
|
||||||
v1.z * v2.x - v1.x * v2.z,
|
v1.z * v2.x - v1.x * v2.z,
|
||||||
v1.x * v2.y - v1.y * v2.x);
|
v1.x * v2.y - v1.y * v2.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::Dot(const Vector3 &v1, const Vector3 &v2) {
|
float Vector3::Dot(const Vector3& v1, const Vector3& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Min(const Vector3 &v1, const Vector3 &v2) {
|
Vector3 Vector3::Min(const Vector3& v1, const Vector3& v2)
|
||||||
|
{
|
||||||
return Vector3::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z));
|
return Vector3::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::Max(const Vector3 &v1, const Vector3 &v2) {
|
Vector3 Vector3::Max(const Vector3& v1, const Vector3& v2)
|
||||||
|
{
|
||||||
return Vector3::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z));
|
return Vector3::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
114
src/vector4.cpp
114
src/vector4.cpp
@@ -50,7 +50,8 @@ Vector4 Vector4::Create()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::init(const Vector4 &v) {
|
void Vector4::init(const Vector4& v)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
z = v.z;
|
z = v.z;
|
||||||
@@ -64,7 +65,8 @@ Vector4 Vector4::Create(const Vector4 &v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::init(const Vector3 &v, float W) {
|
void Vector4::init(const Vector3& v, float W)
|
||||||
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
z = v.z;
|
z = v.z;
|
||||||
@@ -78,7 +80,8 @@ Vector4 Vector4::Create(const Vector3 &v, float W)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::init(float *v) {
|
void Vector4::init(float* v)
|
||||||
|
{
|
||||||
x = v[0];
|
x = v[0];
|
||||||
y = v[1];
|
y = v[1];
|
||||||
z = v[2];
|
z = v[2];
|
||||||
@@ -92,7 +95,8 @@ Vector4 Vector4::Create(float *v)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::init(float v) {
|
void Vector4::init(float v)
|
||||||
|
{
|
||||||
x = v;
|
x = v;
|
||||||
y = v;
|
y = v;
|
||||||
z = v;
|
z = v;
|
||||||
@@ -121,51 +125,63 @@ Vector4 Vector4::Create(float X, float Y, float Z, float W)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Min() {
|
Vector4 Vector4::Min()
|
||||||
|
{
|
||||||
return Vector4::Create(-std::numeric_limits<float>::max());
|
return Vector4::Create(-std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Max() {
|
Vector4 Vector4::Max()
|
||||||
|
{
|
||||||
return Vector4::Create(std::numeric_limits<float>::max());
|
return Vector4::Create(std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Zero() {
|
Vector4 Vector4::Zero()
|
||||||
|
{
|
||||||
return Vector4::Create();
|
return Vector4::Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::One() {
|
Vector4 Vector4::One()
|
||||||
|
{
|
||||||
return Vector4::Create(1.0f, 1.0f, 1.0f, 1.0f);
|
return Vector4::Create(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Forward() {
|
Vector4 Vector4::Forward()
|
||||||
|
{
|
||||||
return Vector4::Create(0.0f, 0.0f, 1.0f, 1.0f);
|
return Vector4::Create(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Backward() {
|
Vector4 Vector4::Backward()
|
||||||
|
{
|
||||||
return Vector4::Create(0.0f, 0.0f, -1.0f, 1.0f);
|
return Vector4::Create(0.0f, 0.0f, -1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Up() {
|
Vector4 Vector4::Up()
|
||||||
|
{
|
||||||
return Vector4::Create(0.0f, 1.0f, 0.0f, 1.0f);
|
return Vector4::Create(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Down() {
|
Vector4 Vector4::Down()
|
||||||
|
{
|
||||||
return Vector4::Create(0.0f, -1.0f, 0.0f, 1.0f);
|
return Vector4::Create(0.0f, -1.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Left() {
|
Vector4 Vector4::Left()
|
||||||
|
{
|
||||||
return Vector4::Create(-1.0f, 0.0f, 0.0f, 1.0f);
|
return Vector4::Create(-1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Right() {
|
Vector4 Vector4::Right()
|
||||||
|
{
|
||||||
return Vector4::Create(1.0f, 0.0f, 0.0f, 1.0f);
|
return Vector4::Create(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Lerp(const Vector4 &v1, const Vector4 &v2, float d) {
|
Vector4 Vector4::Lerp(const Vector4& v1, const Vector4& v2, float d)
|
||||||
|
{
|
||||||
return v1 + (v2 - v1) * d;
|
return v1 + (v2 - v1) * d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Slerp(const Vector4 &v1, const Vector4 &v2, float d) {
|
Vector4 Vector4::Slerp(const Vector4& v1, const Vector4& v2, float d)
|
||||||
|
{
|
||||||
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||||
// Dot product - the cosine of the angle between 2 vectors.
|
// Dot product - the cosine of the angle between 2 vectors.
|
||||||
float dot = Vector4::Dot(v1, v2);
|
float dot = Vector4::Dot(v1, v2);
|
||||||
@@ -182,7 +198,8 @@ Vector4 Vector4::Slerp(const Vector4 &v1, const Vector4 &v2, float d) {
|
|||||||
return ((v1 * cosf(theta)) + (RelativeVec * sinf(theta)));
|
return ((v1 * cosf(theta)) + (RelativeVec * sinf(theta)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::OrthoNormalize(Vector4 &normal, Vector4 &tangent) {
|
void Vector4::OrthoNormalize(Vector4& normal, Vector4& tangent)
|
||||||
|
{
|
||||||
// Gram-Schmidt Orthonormalization
|
// Gram-Schmidt Orthonormalization
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
Vector4 proj = normal * Dot(tangent, normal);
|
Vector4 proj = normal * Dot(tangent, normal);
|
||||||
@@ -190,28 +207,35 @@ void Vector4::OrthoNormalize(Vector4 &normal, Vector4 &tangent) {
|
|||||||
tangent.normalize();
|
tangent.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::operator +(const Vector4& b) const {
|
Vector4 Vector4::operator +(const Vector4& b) const
|
||||||
|
{
|
||||||
return Vector4::Create(x + b.x, y + b.y, z + b.z, w + b.w);
|
return Vector4::Create(x + b.x, y + b.y, z + b.z, w + b.w);
|
||||||
}
|
}
|
||||||
Vector4 Vector4::operator -(const Vector4& b) const {
|
Vector4 Vector4::operator -(const Vector4& b) const
|
||||||
|
{
|
||||||
return Vector4::Create(x - b.x, y - b.y, z - b.z, w - b.w);
|
return Vector4::Create(x - b.x, y - b.y, z - b.z, w - b.w);
|
||||||
}
|
}
|
||||||
Vector4 Vector4::operator +() const {
|
Vector4 Vector4::operator +() const
|
||||||
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Vector4 Vector4::operator -() const {
|
Vector4 Vector4::operator -() const
|
||||||
|
{
|
||||||
return Vector4::Create(-x, -y, -z, -w);
|
return Vector4::Create(-x, -y, -z, -w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::operator *(const float v) const {
|
Vector4 Vector4::operator *(const float v) const
|
||||||
|
{
|
||||||
return Vector4::Create(x * v, y * v, z * v, w * v);
|
return Vector4::Create(x * v, y * v, z * v, w * v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::operator /(const float v) const {
|
Vector4 Vector4::operator /(const float v) const
|
||||||
|
{
|
||||||
return Vector4::Create(x / v, y / v, z / v, w / v);
|
return Vector4::Create(x / v, y / v, z / v, w / v);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4& Vector4::operator +=(const Vector4& b) {
|
Vector4& Vector4::operator +=(const Vector4& b)
|
||||||
|
{
|
||||||
x += b.x;
|
x += b.x;
|
||||||
y += b.y;
|
y += b.y;
|
||||||
z += b.z;
|
z += b.z;
|
||||||
@@ -220,7 +244,8 @@ Vector4& Vector4::operator +=(const Vector4& b) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4& Vector4::operator -=(const Vector4& b) {
|
Vector4& Vector4::operator -=(const Vector4& b)
|
||||||
|
{
|
||||||
x -= b.x;
|
x -= b.x;
|
||||||
y -= b.y;
|
y -= b.y;
|
||||||
z -= b.z;
|
z -= b.z;
|
||||||
@@ -229,7 +254,8 @@ Vector4& Vector4::operator -=(const Vector4& b) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4& Vector4::operator *=(const float v) {
|
Vector4& Vector4::operator *=(const float v)
|
||||||
|
{
|
||||||
x *= v;
|
x *= v;
|
||||||
y *= v;
|
y *= v;
|
||||||
z *= v;
|
z *= v;
|
||||||
@@ -238,7 +264,8 @@ Vector4& Vector4::operator *=(const float v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4& Vector4::operator /=(const float v) {
|
Vector4& Vector4::operator /=(const float v)
|
||||||
|
{
|
||||||
float inv_v = 1.0f / v;
|
float inv_v = 1.0f / v;
|
||||||
x *= inv_v;
|
x *= inv_v;
|
||||||
y *= inv_v;
|
y *= inv_v;
|
||||||
@@ -248,15 +275,18 @@ Vector4& Vector4::operator /=(const float v) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector4::operator ==(const Vector4& b) const {
|
bool Vector4::operator ==(const Vector4& b) const
|
||||||
|
{
|
||||||
return x == b.x && y == b.y && z == b.z && w == b.w;
|
return x == b.x && y == b.y && z == b.z && w == b.w;
|
||||||
|
|
||||||
}
|
}
|
||||||
bool Vector4::operator !=(const Vector4& b) const {
|
bool Vector4::operator !=(const Vector4& b) const
|
||||||
|
{
|
||||||
return x != b.x || y != b.y || z != b.z || w != b.w;
|
return x != b.x || y != b.y || z != b.z || w != b.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& Vector4::operator[](unsigned i) {
|
float& Vector4::operator[](unsigned i)
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -270,7 +300,8 @@ float& Vector4::operator[](unsigned i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector4::operator[](unsigned i) const {
|
float Vector4::operator[](unsigned i) const
|
||||||
|
{
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return x;
|
return x;
|
||||||
@@ -284,23 +315,27 @@ float Vector4::operator[](unsigned i) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector4::sqrMagnitude() const {
|
float Vector4::sqrMagnitude() const
|
||||||
|
{
|
||||||
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||||
return x * x + y * y + z * z + w * w;
|
return x * x + y * y + z * z + w * w;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector4::magnitude() const {
|
float Vector4::magnitude() const
|
||||||
|
{
|
||||||
return sqrtf(x * x + y * y + z * z + w * w);
|
return sqrtf(x * x + y * y + z * z + w * w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector4::normalize() {
|
void Vector4::normalize()
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z + w * w);
|
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z + w * w);
|
||||||
x *= inv_magnitude;
|
x *= inv_magnitude;
|
||||||
y *= inv_magnitude;
|
y *= inv_magnitude;
|
||||||
z *= inv_magnitude;
|
z *= inv_magnitude;
|
||||||
w *= inv_magnitude;
|
w *= inv_magnitude;
|
||||||
}
|
}
|
||||||
Vector4 Vector4::Normalize(const Vector4 &v) {
|
Vector4 Vector4::Normalize(const Vector4& v)
|
||||||
|
{
|
||||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
|
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
|
||||||
return Vector4::Create(v.x * inv_magnitude,
|
return Vector4::Create(v.x * inv_magnitude,
|
||||||
v.y * inv_magnitude,
|
v.y * inv_magnitude,
|
||||||
@@ -309,15 +344,18 @@ Vector4 Vector4::Normalize(const Vector4 &v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float Vector4::Dot(const Vector4 &v1, const Vector4 &v2) {
|
float Vector4::Dot(const Vector4& v1, const Vector4& v2)
|
||||||
|
{
|
||||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Min(const Vector4 &v1, const Vector4 &v2) {
|
Vector4 Vector4::Min(const Vector4& v1, const Vector4& v2)
|
||||||
|
{
|
||||||
return Vector4::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z), KRMIN(v1.w, v2.w));
|
return Vector4::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z), KRMIN(v1.w, v2.w));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector4 Vector4::Max(const Vector4 &v1, const Vector4 &v2) {
|
Vector4 Vector4::Max(const Vector4& v1, const Vector4& v2)
|
||||||
|
{
|
||||||
return Vector4::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z), KRMAX(v1.w, v2.w));
|
return Vector4::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z), KRMAX(v1.w, v2.w));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user