int graph3d_rotate(float a, float x, float y, float z) { Matrix rotation_matrix; float cosa = cos(a); float sina = sin(a); float norm = sqrt(x*x + y*y + z*z); float xp = x / norm; float yp = y / norm; float zp = z / norm; rotation_matrix[0] = xp*xp + cosa*(1.0-xp*xp) + sina*0; rotation_matrix[1] = xp*yp + cosa*(-xp*yp) + sina*zp; rotation_matrix[2] = xp*zp + cosa*(-xp*zp) + sina*-yp; rotation_matrix[3] = 0; rotation_matrix[4] = xp*yp + cosa*(-xp*yp) + sina*-zp; rotation_matrix[5] = yp*yp + cosa*(1.0-yp*yp) + sina*0; rotation_matrix[6] = yp*zp + cosa*(-yp*zp) + sina*xp; rotation_matrix[7] = 0; rotation_matrix[8] = xp*zp + cosa*(-xp*zp) + sina*yp; rotation_matrix[9] = yp*zp + cosa*(-yp*zp) + sina*-xp; rotation_matrix[10] = zp*zp + cosa*(1.0-zp*zp) + sina*0; rotation_matrix[11] = 0; rotation_matrix[12] = 0; rotation_matrix[13] = 0; rotation_matrix[14] = 0; rotation_matrix[15] = 1; mm_mul(modelview, rotation_matrix); return GRAPH3D_OK; }
static void cal_x(double **x, double **xx, double *bx, const int i) { int j; double t[4], s[4]; for (j = 1; j < i; j++) { crstrns(t, xx[i - j]); mm_mul(s, t, bx); x[j][0] -= s[0]; x[j][1] -= s[1]; x[j][2] -= s[2]; x[j][3] -= s[3]; } for (j = 1; j < i; j++) { xx[j][0] = x[j][0]; xx[j][1] = x[j][1]; xx[j][2] = x[j][2]; xx[j][3] = x[j][3]; } x[i][0] = xx[i][0] = -bx[0]; x[i][1] = xx[i][1] = -bx[1]; x[i][2] = xx[i][2] = -bx[2]; x[i][3] = xx[i][3] = -bx[3]; return; }
int main(int argc, char *argv[]) { int n = 300; double **a, **b, **m; n = (n/2) * 2; a = mm_gen(n); b = mm_gen(n); m = mm_mul(n, a, b); //fprintf(stderr, "%lf\n", m[n/2][n/2]); mm_destroy(n, a); mm_destroy(n, b); mm_destroy(n, m); return 0; }
static int cal_bx(double *bx, double *vx, double *ex, const double eps) { double t[4], s[4]; crstrns(t, vx); if (inverse(s, t, eps) == -1) return (-1); mm_mul(bx, s, ex); return (0); }
static void cal_vx(double *vx, double *ex, double *bx) { double t[4], s[4]; crstrns(t, ex); mm_mul(s, t, bx); vx[0] -= s[0]; vx[1] -= s[1]; vx[2] -= s[2]; vx[3] -= s[3]; return; }
static void cal_ex(double *ex, double **r, double **x, const int i) { int j; double t[4], s[4]; s[0] = s[1] = s[2] = s[3] = 0.; for (j = 0; j < i; j++) { mm_mul(t, r[i - j], x[j]); s[0] += t[0]; s[1] += t[1]; s[2] += t[2]; s[3] += t[3]; } ex[0] = s[0]; ex[1] = s[1]; ex[2] = s[2]; ex[3] = s[3]; return; }