Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#pragma once #include <ostream> #include "Vector2.hpp" class Matrix2 { public: Matrix2(); Matrix2( float m11, float m12, float m21, float m22); static const Matrix2 identity; bool isAlmostEqual(const Matrix2& mat) const; private: static const std::size_t ENTRIES = 4; float _matrix[ENTRIES]; // Befriend ALL the operators! friend std::ostream& operator << (std::ostream& out, const Matrix2& mat); friend bool operator == (const Matrix2& lhs, const Matrix2& rhs); friend bool operator != (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2& operator += (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2 operator + (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2& operator -= (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2 operator - (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2 operator - (const Matrix2& lhs); friend Matrix2& operator *= (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2 operator * (const Matrix2& lhs, const Matrix2& rhs); friend Matrix2& operator *= (const Matrix2& lhs, float rhs); friend Matrix2 operator * (const Matrix2& lhs, float rhs); friend Matrix2 operator * (float lhs, const Matrix2& rhs); template <typename T> friend Vector2<T>& operator *= (const Vector2<T>& lhs, const Matrix2& rhs); template <typename T> friend Vector2<T>& operator *= (const Matrix2& lhs, const Vector2<T>& rhs); template <typename T> friend Vector2<T> operator * (const Vector2<T>& lhs, const Matrix2& rhs); template <typename T> friend Vector2<T> operator * (const Matrix2& lhs, const Vector2<T>& rhs); }; /////////////// // Operators // /////////////// // Streams std::ostream& operator<<(std::ostream& out, const Matrix2& mat); // Comparison operators bool operator == (const Matrix2& lhs, const Matrix2& rhs); bool operator != (const Matrix2& lhs, const Matrix2& rhs); // Arithmetics // Addition with other matrix, assigning result to matrix Matrix2& operator += (const Matrix2& lhs, const Matrix2& rhs); // Addition with other matrix Matrix2 operator + (const Matrix2& lhs, const Matrix2& rhs); // Subtraction with other matrix, assigning result to matrix Matrix2& operator -= (const Matrix2& lhs, const Matrix2& rhs); // Subtraction with other matrix Matrix2 operator - (const Matrix2& lhs, const Matrix2& rhs); // Unary (Matrix2 a = -b) Matrix2 operator - (const Matrix2& lhs); // Multiplication and division // Multiplication with other matrix, assigning result to matrix Matrix2& operator *= (const Matrix2& lhs, const Matrix2& rhs); // Multiplication with other matrix Matrix2 operator * (const Matrix2& lhs, const Matrix2& rhs); // Multiplication with scalar, assigning result to matrix Matrix2& operator *= (const Matrix2& lhs, float rhs); // Multiplication with scalar, matrix on left side Matrix2 operator * (const Matrix2& lhs, float rhs); // Multiplication with scalar, matrix on right side Matrix2 operator * (float lhs, const Matrix2& rhs); // Multiplication with vector, matrix right, assigning result to vector template <typename T> Vector2<T>& operator *= (const Vector2<T>& lhs, const Matrix2& rhs); // Multiplication with vector, matrix left, assigning result to vector template <typename T> Vector2<T>& operator *= (const Matrix2& lhs, const Vector2<T>& rhs); // Multiplication with vector, matrix right template <typename T> Vector2<T> operator * (const Vector2<T>& lhs, const Matrix2& rhs); // Multiplication with vector, matrix right template <typename T> Vector2<T> operator * (const Matrix2& lhs, const Vector2<T>& rhs); |
Administrator
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
Egtl. versuche ich immer die Dinge private zu halten, soweit es geht, aber hier sind's ja wirklich nur reine Daten.
Administrator
Du hast halt beispielsweise noch die Größe als Wert in jedem Objekt gespeichert.
Werbeanzeige