void mrotate( mat* ma, const triple* v, f32 a ){ f32 c = vcos( a ); f32 s = vsin( a ); f32 t = 1 - c; static mat m; m.m[ 0 ][ 0 ] = t * v->x * v->x + c; m.m[ 0 ][ 1 ] = t * v->x * v->y + s * v->z; m.m[ 0 ][ 2 ] = t * v->x * v->z - s * v->y; m.m[ 0 ][ 3 ] = 0; m.m[ 1 ][ 0 ] = t * v->x * v->y - s * v->z; m.m[ 1 ][ 1 ] = t * v->y * v->y + c; m.m[ 1 ][ 2 ] = t * v->y * v->z + s * v->x; m.m[ 1 ][ 3 ] = 0; m.m[ 2 ][ 0 ] = t * v->x * v->z + s * v->y; m.m[ 2 ][ 1 ] = t * v->y * v->z - s * v->x; m.m[ 2 ][ 2 ] = t * v->z * v->z + c; m.m[ 2 ][ 3 ] = 0; m.m[ 3 ][ 0 ] = 0; m.m[ 3 ][ 1 ] = 0; m.m[ 3 ][ 2 ] = 0; m.m[ 3 ][ 3 ] = 1; mmult( ma, &m ); }
int main(int argc, char * argv[]) { float *host_A, *host_B, *host_C; float *dev_A, *dev_B, *dev_C; int n, i; if (argc == 1) n = 1024; else n = atoi(argv[1]); host_A = (float*)malloc( n*sizeof(float) ); host_B = (float*)malloc( n*sizeof(float) ); host_C = (float*)malloc( n*sizeof(float) ); for(i = 0; i < n; ++i ) { host_A[i] = (float) i; host_B[i] = (float) i; } for (i=0; i< n; i++) vcos(i, host_A, host_B, host_C); // print the result for (int i = 0; i<10; i++){ printf("%f ",host_C[i]); } free(host_A); free(host_B); free(host_C); return( 0 ); }
void shr_vmath_fwrap_vcos_(double *X, double *Y, int *n) { vcos(X, Y, *n, 1, 1); }