Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 20 | pmbaty | 1 | #include "matrix23.h" |
| 2 | #include "harness/trace.h" |
||
| 3 | |||
| 4 | #include <math.h> |
||
| 5 | |||
| 6 | #define A(x, y) A->m[x][y] |
||
| 7 | #define B(x, y) B->m[x][y] |
||
| 8 | #define C(x, y) C->m[x][y] |
||
| 9 | #define M(x, y) mat->m[x][y] |
||
| 10 | |||
| 11 | #define BR_MAC2(a, b, c, d) ((a) * (b) + (c) * (d)) |
||
| 12 | |||
| 13 | br_matrix23 mattmp1_23; |
||
| 14 | br_matrix23 mattmp2_23; |
||
| 15 | |||
| 16 | // IDA: void __cdecl BrMatrix23Copy(br_matrix23 *A, br_matrix23 *B) |
||
| 17 | void BrMatrix23Copy(br_matrix23* A, br_matrix23* B) { |
||
| 18 | LOG_TRACE("(%p, %p)", A, B); |
||
| 19 | |||
| 20 | A(0, 0) = B(0, 0); |
||
| 21 | A(0, 1) = B(0, 1); |
||
| 22 | A(1, 0) = B(1, 0); |
||
| 23 | A(1, 1) = B(1, 1); |
||
| 24 | A(2, 0) = B(2, 0); |
||
| 25 | A(2, 1) = B(2, 1); |
||
| 26 | } |
||
| 27 | |||
| 28 | // IDA: void __cdecl BrMatrix23Mul(br_matrix23 *A, br_matrix23 *B, br_matrix23 *C) |
||
| 29 | void BrMatrix23Mul(br_matrix23* A, br_matrix23* B, br_matrix23* C) { |
||
| 30 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 31 | |||
| 32 | A(0, 0) = BR_MAC2(B(0, 0), C(0, 0), B(0, 1), C(1, 0)); |
||
| 33 | A(0, 1) = BR_MAC2(B(0, 0), C(0, 1), B(0, 1), C(1, 1)); |
||
| 34 | A(1, 0) = BR_MAC2(B(1, 0), C(0, 0), B(1, 1), C(1, 0)); |
||
| 35 | A(1, 1) = BR_MAC2(B(1, 0), C(0, 1), B(1, 1), C(1, 1)); |
||
| 36 | A(2, 0) = BR_MAC2(B(2, 0), C(0, 0), B(2, 1), C(1, 0)) + C(2, 0); |
||
| 37 | A(2, 1) = BR_MAC2(B(2, 0), C(0, 1), B(2, 1), C(1, 1)) + C(2, 1); |
||
| 38 | } |
||
| 39 | |||
| 40 | // IDA: void __cdecl BrMatrix23Identity(br_matrix23 *mat) |
||
| 41 | void BrMatrix23Identity(br_matrix23* mat) { |
||
| 42 | LOG_TRACE("(%p)", mat); |
||
| 43 | |||
| 44 | M(0, 0) = 1.f; |
||
| 45 | M(0, 1) = 0.f; |
||
| 46 | M(1, 0) = 0.f; |
||
| 47 | M(1, 1) = 1.f; |
||
| 48 | M(2, 0) = 0.f; |
||
| 49 | M(2, 1) = 0.f; |
||
| 50 | } |
||
| 51 | |||
| 52 | // IDA: void __cdecl BrMatrix23Rotate(br_matrix23 *mat, br_angle rz) |
||
| 53 | void BrMatrix23Rotate(br_matrix23* mat, br_angle rz) { |
||
| 54 | br_scalar s; |
||
| 55 | br_scalar c; |
||
| 56 | LOG_TRACE("(%p, %d)", mat, rz); |
||
| 57 | |||
| 58 | c = BR_COS(rz); |
||
| 59 | s = BR_SIN(rz); |
||
| 60 | |||
| 61 | M(0, 0) = c; |
||
| 62 | M(0, 1) = s; |
||
| 63 | M(1, 0) = -s; |
||
| 64 | M(1, 1) = c; |
||
| 65 | M(2, 0) = BR_SCALAR(0.f); |
||
| 66 | M(2, 1) = BR_SCALAR(0.f); |
||
| 67 | } |
||
| 68 | |||
| 69 | // IDA: void __cdecl BrMatrix23Translate(br_matrix23 *mat, br_scalar dx, br_scalar dy) |
||
| 70 | void BrMatrix23Translate(br_matrix23* mat, br_scalar dx, br_scalar dy) { |
||
| 71 | LOG_TRACE("(%p, %f, %f)", mat, dx, dy); |
||
| 72 | |||
| 73 | M(0, 0) = BR_SCALAR(1.f); |
||
| 74 | M(0, 1) = BR_SCALAR(0.f); |
||
| 75 | M(1, 0) = BR_SCALAR(0.f); |
||
| 76 | M(1, 1) = BR_SCALAR(1.f); |
||
| 77 | M(2, 0) = dx; |
||
| 78 | M(2, 1) = dy; |
||
| 79 | } |
||
| 80 | |||
| 81 | // IDA: void __cdecl BrMatrix23Scale(br_matrix23 *mat, br_scalar sx, br_scalar sy) |
||
| 82 | void BrMatrix23Scale(br_matrix23* mat, br_scalar sx, br_scalar sy) { |
||
| 83 | LOG_TRACE("(%p, %f, %f)", mat, sx, sy); |
||
| 84 | |||
| 85 | M(0, 0) = sx; |
||
| 86 | M(0, 1) = BR_SCALAR(0.f); |
||
| 87 | M(1, 0) = BR_SCALAR(0.f); |
||
| 88 | M(1, 1) = sy; |
||
| 89 | M(2, 0) = BR_SCALAR(0.f); |
||
| 90 | M(2, 1) = BR_SCALAR(0.f); |
||
| 91 | } |
||
| 92 | |||
| 93 | // IDA: void __cdecl BrMatrix23ShearX(br_matrix23 *mat, br_scalar sy) |
||
| 94 | void BrMatrix23ShearX(br_matrix23* mat, br_scalar sy) { |
||
| 95 | LOG_TRACE("(%p, %f)", mat, sy); |
||
| 96 | |||
| 97 | M(0, 0) = BR_SCALAR(1.f); |
||
| 98 | M(0, 1) = sy; |
||
| 99 | M(1, 0) = BR_SCALAR(0.f); |
||
| 100 | M(1, 1) = BR_SCALAR(1.f); |
||
| 101 | M(2, 0) = BR_SCALAR(0.f); |
||
| 102 | M(2, 1) = BR_SCALAR(0.f); |
||
| 103 | } |
||
| 104 | |||
| 105 | // IDA: void __cdecl BrMatrix23ShearY(br_matrix23 *mat, br_scalar sx) |
||
| 106 | void BrMatrix23ShearY(br_matrix23* mat, br_scalar sx) { |
||
| 107 | LOG_TRACE("(%p, %f)", mat, sx); |
||
| 108 | |||
| 109 | M(0, 0) = BR_SCALAR(1.f); |
||
| 110 | M(0, 1) = BR_SCALAR(0.f); |
||
| 111 | M(1, 0) = sx; |
||
| 112 | M(1, 1) = BR_SCALAR(1.f); |
||
| 113 | M(2, 0) = BR_SCALAR(0.f); |
||
| 114 | M(2, 1) = BR_SCALAR(0.f); |
||
| 115 | } |
||
| 116 | |||
| 117 | // IDA: br_scalar __cdecl BrMatrix23Inverse(br_matrix23 *B, br_matrix23 *A) |
||
| 118 | br_scalar BrMatrix23Inverse(br_matrix23* B, br_matrix23* A) { |
||
| 119 | br_scalar det; |
||
| 120 | br_scalar idet; |
||
| 121 | br_scalar pos; |
||
| 122 | br_scalar neg; |
||
| 123 | LOG_TRACE("(%p, %p)", B, A); |
||
| 124 | |||
| 125 | idet = A(0, 0) * A(1, 1); |
||
| 126 | if (idet < BR_SCALAR(0.f)) { |
||
| 127 | pos = BR_SCALAR(0.f); |
||
| 128 | neg = idet; |
||
| 129 | } else { |
||
| 130 | pos = idet; |
||
| 131 | neg = BR_SCALAR(0.f); |
||
| 132 | } |
||
| 133 | idet = -A(0, 1) * A(1, 0); |
||
| 134 | if (idet < BR_SCALAR(0.f)) { |
||
| 135 | neg = neg + idet; |
||
| 136 | } else { |
||
| 137 | pos = pos + idet; |
||
| 138 | } |
||
| 139 | det = pos + neg; |
||
| 140 | |||
| 141 | if (fabs(det) < 2.384186e-07f) { |
||
| 142 | return BR_SCALAR(0.f); |
||
| 143 | } |
||
| 144 | idet = 1 / det; |
||
| 145 | B(0, 0) = A(1, 1) * idet; |
||
| 146 | B(0, 1) = -A(0, 1) * idet; |
||
| 147 | B(1, 0) = -A(1, 0) * idet; |
||
| 148 | B(1, 1) = A(0, 0) * idet; |
||
| 149 | B(2, 0) = BR_MAC2(A(1, 0), A(2, 1), -A(2, 0), A(1, 1)) * idet; |
||
| 150 | B(2, 1) = BR_MAC2(-A(2, 1), A(0, 0), A(0, 1), A(2, 0)) * idet; |
||
| 151 | return det; |
||
| 152 | } |
||
| 153 | |||
| 154 | // IDA: void __cdecl BrMatrix23LPInverse(br_matrix23 *B, br_matrix23 *A) |
||
| 155 | void BrMatrix23LPInverse(br_matrix23* B, br_matrix23* A) { |
||
| 156 | LOG_TRACE("(%p, %p)", B, A); |
||
| 157 | |||
| 158 | B(0, 0) = A(1, 1); |
||
| 159 | B(0, 1) = -A(0, 1); |
||
| 160 | B(1, 0) = -A(1, 0); |
||
| 161 | B(1, 1) = A(0, 0); |
||
| 162 | B(2, 0) = BR_MAC2(A(1, 0), A(2, 1), -A(2, 0), A(1, 1)); |
||
| 163 | B(2, 1) = BR_MAC2(-A(2, 1), A(0, 0), A(0, 1), A(2, 0)); |
||
| 164 | } |
||
| 165 | |||
| 166 | // IDA: void __cdecl BrMatrix23LPNormalise(br_matrix23 *A, br_matrix23 *B) |
||
| 167 | void BrMatrix23LPNormalise(br_matrix23* A, br_matrix23* B) { |
||
| 168 | LOG_TRACE("(%p, %p)", A, B); |
||
| 169 | |||
| 170 | br_scalar norm = sqrtf(BR_MAC2(B(1, 0), B(1, 0), B(1, 1), B(1,1))); |
||
| 171 | if (norm < 2.384186e-07f) { |
||
| 172 | A(1, 0) = BR_SCALAR(1.f); |
||
| 173 | A(1, 1) = BR_SCALAR(0.f); |
||
| 174 | } else { |
||
| 175 | A(1, 0) = B(1, 0) / norm; |
||
| 176 | A(1, 1) = B(1, 1) / norm; |
||
| 177 | } |
||
| 178 | A(0, 0) = A(1, 1); |
||
| 179 | A(0, 1) = -A(1, 0); |
||
| 180 | A(2, 0) = B(2, 0); |
||
| 181 | A(2, 1) = B(2, 1); |
||
| 182 | } |
||
| 183 | |||
| 184 | // IDA: void __cdecl BrMatrix23ApplyP(br_vector2 *A, br_vector2 *B, br_matrix23 *C) |
||
| 185 | void BrMatrix23ApplyP(br_vector2* A, br_vector2* B, br_matrix23* C) { |
||
| 186 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 187 | |||
| 188 | A->v[0] = BR_MAC2(B->v[0], C(0, 0), B->v[1], C(1, 0)) + C(2, 0); |
||
| 189 | A->v[1] = BR_MAC2(B->v[0], C(0, 1), B->v[1], C(1, 1)) + C(2, 1); |
||
| 190 | } |
||
| 191 | |||
| 192 | // IDA: void __cdecl BrMatrix23ApplyV(br_vector2 *A, br_vector2 *B, br_matrix23 *C) |
||
| 193 | void BrMatrix23ApplyV(br_vector2* A, br_vector2* B, br_matrix23* C) { |
||
| 194 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 195 | |||
| 196 | A->v[0] = BR_MAC2(B->v[0], C(0, 0), B->v[1], C(1, 0)); |
||
| 197 | A->v[1] = BR_MAC2(B->v[0], C(0, 1), B->v[1], C(1, 1)); |
||
| 198 | } |
||
| 199 | |||
| 200 | // IDA: void __cdecl BrMatrix23TApplyP(br_vector2 *A, br_vector2 *B, br_matrix23 *C) |
||
| 201 | void BrMatrix23TApplyP(br_vector2* A, br_vector2* B, br_matrix23* C) { |
||
| 202 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 203 | |||
| 204 | A->v[0] = BR_MAC2(B->v[0], C(0, 0), B->v[1], C(0, 1)); |
||
| 205 | A->v[1] = BR_MAC2(B->v[0], C(1, 0), B->v[1], C(1, 1)); |
||
| 206 | } |
||
| 207 | |||
| 208 | // IDA: void __cdecl BrMatrix23TApplyV(br_vector2 *A, br_vector2 *B, br_matrix23 *C) |
||
| 209 | void BrMatrix23TApplyV(br_vector2* A, br_vector2* B, br_matrix23* C) { |
||
| 210 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 211 | |||
| 212 | A->v[0] = BR_MAC2(B->v[0], C(0, 0), B->v[1], C(0, 1)); |
||
| 213 | A->v[1] = BR_MAC2(B->v[0], C(1, 0), B->v[1], C(1, 1)); |
||
| 214 | } |
||
| 215 | |||
| 216 | // IDA: void __cdecl BrMatrix23Pre(br_matrix23 *mat, br_matrix23 *A) |
||
| 217 | void BrMatrix23Pre(br_matrix23* mat, br_matrix23* A) { |
||
| 218 | LOG_TRACE("(%p, %p)", mat, A); |
||
| 219 | |||
| 220 | BrMatrix23Mul(&mattmp1_23, A, mat); |
||
| 221 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 222 | } |
||
| 223 | |||
| 224 | // IDA: void __cdecl BrMatrix23Post(br_matrix23 *mat, br_matrix23 *A) |
||
| 225 | void BrMatrix23Post(br_matrix23* mat, br_matrix23* A) { |
||
| 226 | LOG_TRACE("(%p, %p)", mat, A); |
||
| 227 | |||
| 228 | BrMatrix23Mul(&mattmp1_23, mat, A); |
||
| 229 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 230 | } |
||
| 231 | |||
| 232 | // IDA: void __cdecl BrMatrix23PreRotate(br_matrix23 *mat, br_angle rz) |
||
| 233 | void BrMatrix23PreRotate(br_matrix23* mat, br_angle rz) { |
||
| 234 | LOG_TRACE("(%p, %d)", mat, rz); |
||
| 235 | |||
| 236 | BrMatrix23Rotate(&mattmp2_23, rz); |
||
| 237 | BrMatrix23Mul(&mattmp1_23, &mattmp2_23, mat); |
||
| 238 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 239 | } |
||
| 240 | |||
| 241 | // IDA: void __cdecl BrMatrix23PostRotate(br_matrix23 *mat, br_angle rz) |
||
| 242 | void BrMatrix23PostRotate(br_matrix23* mat, br_angle rz) { |
||
| 243 | LOG_TRACE("(%p, %d)", mat, rz); |
||
| 244 | |||
| 245 | BrMatrix23Rotate(&mattmp2_23, rz); |
||
| 246 | BrMatrix23Mul(&mattmp1_23, mat, &mattmp2_23); |
||
| 247 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 248 | } |
||
| 249 | |||
| 250 | // IDA: void __cdecl BrMatrix23PreTranslate(br_matrix23 *mat, br_scalar x, br_scalar y) |
||
| 251 | void BrMatrix23PreTranslate(br_matrix23* mat, br_scalar x, br_scalar y) { |
||
| 252 | LOG_TRACE("(%p, %f, %f)", mat, x, y); |
||
| 253 | |||
| 254 | BrMatrix23Translate(&mattmp2_23, x, y); |
||
| 255 | BrMatrix23Mul(&mattmp1_23, &mattmp2_23, mat); |
||
| 256 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 257 | } |
||
| 258 | |||
| 259 | // IDA: void __cdecl BrMatrix23PostTranslate(br_matrix23 *A, br_scalar x, br_scalar y) |
||
| 260 | void BrMatrix23PostTranslate(br_matrix23* A, br_scalar x, br_scalar y) { |
||
| 261 | LOG_TRACE("(%p, %f, %f)", A, x, y); |
||
| 262 | |||
| 263 | A(2, 0) += x; |
||
| 264 | A(2, 1) += y; |
||
| 265 | } |
||
| 266 | |||
| 267 | // IDA: void __cdecl BrMatrix23PreScale(br_matrix23 *mat, br_scalar sx, br_scalar sy) |
||
| 268 | void BrMatrix23PreScale(br_matrix23* mat, br_scalar sx, br_scalar sy) { |
||
| 269 | LOG_TRACE("(%p, %f, %f)", mat, sx, sy); |
||
| 270 | |||
| 271 | BrMatrix23Scale(&mattmp2_23, sx, sy); |
||
| 272 | BrMatrix23Mul(&mattmp1_23, &mattmp2_23, mat); |
||
| 273 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 274 | } |
||
| 275 | |||
| 276 | // IDA: void __cdecl BrMatrix23PostScale(br_matrix23 *mat, br_scalar sx, br_scalar sy) |
||
| 277 | void BrMatrix23PostScale(br_matrix23* mat, br_scalar sx, br_scalar sy) { |
||
| 278 | LOG_TRACE("(%p, %f, %f)", mat, sx, sy); |
||
| 279 | |||
| 280 | BrMatrix23Scale(&mattmp2_23, sx, sy); |
||
| 281 | BrMatrix23Mul(&mattmp1_23, mat, &mattmp2_23); |
||
| 282 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 283 | } |
||
| 284 | |||
| 285 | // IDA: void __cdecl BrMatrix23PreShearX(br_matrix23 *mat, br_scalar sy) |
||
| 286 | void BrMatrix23PreShearX(br_matrix23* mat, br_scalar sy) { |
||
| 287 | LOG_TRACE("(%p, %f)", mat, sy); |
||
| 288 | |||
| 289 | BrMatrix23ShearX(&mattmp2_23, sy); |
||
| 290 | BrMatrix23Mul(&mattmp1_23, &mattmp2_23, mat); |
||
| 291 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 292 | } |
||
| 293 | |||
| 294 | // IDA: void __cdecl BrMatrix23PostShearX(br_matrix23 *mat, br_scalar sy) |
||
| 295 | void BrMatrix23PostShearX(br_matrix23* mat, br_scalar sy) { |
||
| 296 | LOG_TRACE("(%p, %f)", mat, sy); |
||
| 297 | |||
| 298 | BrMatrix23ShearX(&mattmp2_23, sy); |
||
| 299 | BrMatrix23Mul(&mattmp1_23, mat, &mattmp2_23); |
||
| 300 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 301 | } |
||
| 302 | |||
| 303 | // IDA: void __cdecl BrMatrix23PreShearY(br_matrix23 *mat, br_scalar sx) |
||
| 304 | void BrMatrix23PreShearY(br_matrix23* mat, br_scalar sx) { |
||
| 305 | LOG_TRACE("(%p, %f)", mat, sx); |
||
| 306 | |||
| 307 | BrMatrix23ShearY(&mattmp2_23, sx); |
||
| 308 | BrMatrix23Mul(&mattmp1_23, &mattmp2_23, mat); |
||
| 309 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 310 | } |
||
| 311 | |||
| 312 | // IDA: void __cdecl BrMatrix23PostShearY(br_matrix23 *mat, br_scalar sx) |
||
| 313 | void BrMatrix23PostShearY(br_matrix23* mat, br_scalar sx) { |
||
| 314 | LOG_TRACE("(%p, %f)", mat, sx); |
||
| 315 | |||
| 316 | BrMatrix23ShearY(&mattmp2_23, sx); |
||
| 317 | BrMatrix23Mul(&mattmp1_23, mat, &mattmp2_23); |
||
| 318 | BrMatrix23Copy(mat, &mattmp1_23); |
||
| 319 | } |