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
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 |
#ifndef MATRIX_HPP #define MATRIX_HPP template<typename T> class Matrix4 { public: union { T a [16]; struct { T a11, a21, a31, a41, a12, a22, a32, a42, a13, a23, a33, a43, a14, a24, a34, a44; }; }; void reset (const T& f = 0) { for (unsigned int j = 0; j < 16; ++j) { a [j] = f; } } void identity () { reset (); a11 = 1; a22 = 1; a33 = 1; a44 = 1; } Matrix4 (const T& f = 0) { reset (f); } Matrix4 (const T& _a11, const T& _a21, const T& _a31, const T& _a41, const T& _a12, const T& _a22, const T& _a32, const T& _a42, const T& _a13, const T& _a23, const T& _a33, const T& _a43, const T& _a14, const T& _a24, const T& _a34, const T& _a44) : a11 (_a11), a21 (_a21), a31 (_a31), a41 (_a41), a12 (_a12), a22 (_a22), a32 (_a32), a42 (_a42), a13 (_a13), a23 (_a23), a33 (_a33), a43 (_a43), a14 (_a14), a24 (_a24), a34 (_a34), a44 (_a44) { } Matrix4 (const Matrix4<T>& m) { Matrix4 (m.a11, m.a21, m.a31, m.a41, m.a12, m.a22, m.a32, m.a42, m.a13, m.a23, m.a33, m.a43, m.a14, m.a24, m.a34, m.a44); } }; template<typename T> std::ostream& operator<< (std::ostream& s, const Matrix4<T> m) { s << "/ " << m.a11 << " | " << m.a12 << " | " << m.a13 << " | " << m.a14 << " \\\n"; s << "| " << m.a21 << " | " << m.a22 << " | " << m.a23 << " | " << m.a24 << " |\n"; s << "| " << m.a31 << " | " << m.a32 << " | " << m.a33 << " | " << m.a34 << " |\n"; s << "\\ " << m.a41 << " | " << m.a42 << " | " << m.a43 << " | " << m.a44 << " /\n"; return s; } typedef Matrix4<float> Matrix4f; #endif // MATRIX_HPP |
C-/C++-Quelltext |
|
1 2 3 4 |
Matrix4f m; m.identity(); m.a44 = 1; std::cout << m << std::endl; |
C-/C++-Quelltext |
|
1 |
Matrix4 (const T& f = 0) { reset (f); } |
C-/C++-Quelltext |
|
1 |
Matrix4 (const T& f = T () ) { reset (f); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
Matrix4 (const Matrix4<T>& m) { Matrix4 (m.a11, m.a21, m.a31, m.a41, m.a12, m.a22, m.a32, m.a42, m.a13, m.a23, m.a33, m.a43, m.a14, m.a24, m.a34, m.a44); } |
C-/C++-Quelltext |
|
1 |
std::ostream& operator<< (std::ostream& s, const Matrix4<T> m) |
Zitat von »"dot"«
Jop, und da fehlt wohl ein &
C-/C++-Quelltext
1 std::ostream& operator<< (std::ostream& s, const Matrix4<T> m)
Zitat von »"David_pb"«
Der Kopierkonstruktor ist vollkommener Stuss.
C-/C++-Quelltext
1 2 3 4 5 6 7 Matrix4 (const Matrix4<T>& m) { Matrix4 (m.a11, m.a21, m.a31, m.a41, m.a12, m.a22, m.a32, m.a42, m.a13, m.a23, m.a33, m.a43, m.a14, m.a24, m.a34, m.a44); }
Zitat von »"the[V«
oid"]Oh Gott, was hat mich denn da nur geritten O.o
Aber dann bitte auch in der Initialisierungsliste.Zitat von »"drakon"«
Obwohl. Von der Idee her, wäre es schön, wenn es gehen würde.
Zitat von »"the[V«
oid"]Oh Gott, was hat mich denn da nur geritten O.o
Werbeanzeige