types.cpp

changeset 162
b7d65e89861a
parent 161
c9fba92c4e35
child 163
46955613626d
equal deleted inserted replaced
161:c9fba92c4e35 162:b7d65e89861a
26 } 26 }
27 27
28 // ============================================================================= 28 // =============================================================================
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30 // ============================================================================= 30 // =============================================================================
31 void vertex::transform (matrix transmatrx, vertex pos) { 31 void vertex::transform (matrix<3> matr, vertex pos) {
32 double x2, y2, z2; 32 double x2, y2, z2;
33 x2 = (transmatrx[0] * coord (X)) + (transmatrx[1] * coord (Y)) + (transmatrx[2] * coord (Z)) + pos[X]; 33 x2 = (matr[0] * coord (X)) + (matr[1] * coord (Y)) + (matr[2] * coord (Z)) + pos[X];
34 y2 = (transmatrx[3] * coord (X)) + (transmatrx[4] * coord (Y)) + (transmatrx[5] * coord (Z)) + pos[Y]; 34 y2 = (matr[3] * coord (X)) + (matr[4] * coord (Y)) + (matr[5] * coord (Z)) + pos[Y];
35 z2 = (transmatrx[6] * coord (X)) + (transmatrx[7] * coord (Y)) + (transmatrx[8] * coord (Z)) + pos[Z]; 35 z2 = (matr[6] * coord (X)) + (matr[7] * coord (Y)) + (matr[8] * coord (Z)) + pos[Z];
36 36
37 coord (X) = x2; 37 coord (X) = x2;
38 coord (Y) = y2; 38 coord (Y) = y2;
39 coord (Z) = z2; 39 coord (Z) = z2;
40 } 40 }
41
42 // =============================================================================
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
44 // =============================================================================
45 matrix::matrix (vector<double> vals) {
46 assert (vals.size() == (sizeof m_vals / sizeof *m_vals));
47 memcpy (&m_vals[0], &(*vals.begin ()), sizeof m_vals);
48 }
49
50 // -----------------------------------------------------------------------------
51 matrix::matrix (double fillval) {
52 for (short i = 0; i < 9; ++i)
53 m_vals[i] = fillval;
54 }
55
56 // -----------------------------------------------------------------------------
57 matrix::matrix (double a, double b, double c, double d, double e, double f,
58 double g, double h, double i)
59 {
60 m_vals[0] = a; m_vals[1] = b; m_vals[2] = c;
61 m_vals[3] = d; m_vals[4] = e; m_vals[5] = f;
62 m_vals[6] = g; m_vals[7] = h; m_vals[8] = i;
63 }
64
65 // =============================================================================
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
67 // =============================================================================
68 void matrix::zero () {
69 memset (&m_vals[0], 0, sizeof m_vals);
70 }
71
72 // =============================================================================
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74 // =============================================================================
75 matrix matrix::mult (matrix other) {
76 matrix val;
77 val.zero ();
78
79 for (short i = 0; i < 3; ++i)
80 for (short j = 0; j < 3; ++j)
81 for (short k = 0; k < 3; ++k)
82 val[(i * 3) + j] += m_vals[(i * 3) + k] * other[(k * 3) + j];
83
84 return val;
85 }
86
87 // =============================================================================
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
89 // =============================================================================
90 void matrix::testOutput () {
91 for (short i = 0; i < 3; ++i) {
92 for (short j = 0; j < 3; ++j)
93 printf ("%*f\t", 10, m_vals[(i * 3) + j]);
94
95 printf ("\n");
96 }
97 }
98
99 // =============================================================================
100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
101 // =============================================================================
102 str matrix::stringRep () {
103 str val;
104 for (short i = 0; i < 9; ++i) {
105 if (i > 0)
106 val += ' ';
107
108 val.appendformat ("%s", ftoa (m_vals[i]).chars());
109 }
110
111 return val;
112 }

mercurial