void Nbody_derivs1(double x, double y[], double dydx[]) //for use with standard integrators { //I want the input vector to look like //[N x1 x2 ... v1 v2 ... m1 m2 ...] static int first=1, N; int i,j,k; double a; if(first==1) N = (int)y[0]; //build mass vector static double m[3]; double d[N][N]; if(first==1) { Vcopy(N,&y[6*N+1],m); first=0; } //zero out output vector for(i=0;i<7*N+1;i++) dydx[i]=0; //for N-body, position derivatives are the velocities for(i=1;i<=3*N;i++) dydx[i] = y[i+3*N]; //build distance matrix for(i=0; i<N; i++) { for(j=0; j<i; j++) d[i][j] = sqrt( pow((y[3*i+1]-y[3*j+1]),2) + pow((y[3*i+2]-y[3*j+2]),2) + pow((y[3*i+3]-y[3*j+3]),2) ); } //for simple N-body, this will calculate pairwise forces for(i=0; i<N; i++) { for(j=0;j<i;j++) { for(k=0;k<3;k++) { a = -G*m[j]*(y[3*i+k+1] - y[3*j+k+1]) / pow(d[i][j],3); dydx[3*i+k+3*N+1] += a; dydx[3*j+k+3*N+1] -= m[i]/m[j]*a; } } } }
/* compute the normal and the point of * a bezier patch corner from the close-by control points */ void evalPN(vector v00, vector v01, vector v10, vector P, vector N) { vector hv1, hv2, Normal; int i; VVminus(v10 , v00, hv1); VVminus(v01 , v00, hv2); VVcross(hv1, hv2, Normal); Normalize(Normal); Vcopy(Normal, N); for(i=0;i<DIM;i++) // nomalize the rational point P[i] = v00[i]/v00[3]; // for(i=0;i<3;i++) // temp // N[i] = -N[i]; }
void Camera::Update(float deltaTime) { glm::mat4 V = glm::lookAt(eye, target, up); for(unsigned int i=0; i<shaders.size(); ++i) { // skybox shader if(shaders[i]->GetName().compare("Skybox") == 0) { glm::mat4 Vcopy(V); Vcopy[3] = shaders[i]->GetViewMatrix()[3]; shaders[i]->SetViewMatrix(Vcopy); } // model shaders else { shaders[i]->SetViewMatrix(V); shaders[i]->SetEyeVector(eye); } } }
void Nbody_derivs2(double x, double y[], double dydx[]) //for use with leap frog integration { //I want the input vector to look like //[N x1 x2 ... v1 v2 ... m1 m2 ...] static int first=1, N; int i,j,k,f_or_g = dydx[0]; if(first==1) N = (int)y[0]; //zero out output vector for(i=0;i<7*N+1;i++) dydx[i]=0; /* Calculate f(p) */ if(f_or_g==0) { //for N-body, this will just return velocities for(i=1;i<=3*N;i++) dydx[i] = y[i+3*N]; } /* Calculate g(y) */ else { //build mass vector static double m[3]; double d[N][N], a; if(first==1) { Vcopy(N,&y[6*N+1],m); first=0; } //build distance matrix for(i=0; i<N; i++) { for(j=0; j<i; j++) d[i][j] = sqrt( pow((y[3*i+1]-y[3*j+1]),2) + pow((y[3*i+2]-y[3*j+2]),2) + pow((y[3*i+3]-y[3*j+3]),2) ); } //for simple N-body, this will calculate pairwise forces for(i=0; i<N; i++) { for(j=0;j<i;j++) { for(k=0;k<3;k++) { if(i!=j) { a = -G*m[j]*(y[3*i+k+1] - y[3*j+k+1]) / pow(d[i][j],3); dydx[3*i+k+3*N+1] += a; dydx[3*j+k+3*N+1] -= m[i]/m[j]*a; } } } } } }
// ------------------------------------------------------------------- // main function: // Compute the surface envelope // void EncQuadBezier::compute_enclosure() { //int tr[4][4][2]; // translation from xy to ccw int need_subdiv; // allocate the memory storing the results o_enc = alloc_mem_db(d1*d1*DIM); i_enc = alloc_mem_db(d1*d1*DIM); cralong = (int *) allocate (sizeof (int) * segu*segv ); // compute the bilinear envelope make_env(); // determine the support points and normals make_sup(); // average normals along the boundary between two neighboring // patch. (there is no affect for C1 surfaces) // //average_nor_PN(fp, sup_nor[fc], tr); // temp hack!!: use PN average Norm // compute and store intersection lambdas in w's need_subdiv = make_lam(); #ifdef FIX_BY_SUBDIVIDE if(need_subdiv) { int sizeu = dg*2+1; // int sizev = dg*2+1; // REAL bb[sizeu*sizev][DIM]; // space for subdivision // subdivide the patch for(i=0;i<d1;i++) { for(j=0;j<d1;j++) { Vcopy( get_bb[i][j], bb[(i*2)*sizev+(j*2)]); } } RSubDiv(bb, 2, dg, dg, sizeu-1, sizev-1); /* for(i=0;i<sizeu;i++) for(j=0;j<sizev;j++) { printf("v: %f %f %f \n", bb[i*sizev+j][0], bb[i*sizev+j][1], bb[i*sizev+j][2]); } */ // si and sj are the starting (i,j) position for subpatches for(si = 0; si<=dg; si+=dg) for(sj = 0; sj<=dg; sj+=dg) { int sub_fc; // where to place this new subdivied patch // use the first subdivided patch to overwrite // the original patch if(si==0 && sj==0) sub_fc = fc; else { sub_fc = new_patch(FNum, Face, fc); FNum++; printf("Add a new face %d, now %d faces\n", sub_fc, FNum); } for(i=0;i<d1;i++) for(j=0;j<d1;j++) Vcopy(bb[(i+si)*sizev+(j+sj)], &(Face[sub_fc].buf[(i*d1+j)*DIM])); } // increase number of patches by 3 object[index].patch_num +=3; fc --; // move back one spot to recompute the subdivided one printf("fc = %d\n", fc); // add four patches into the array // disable the current patch (quick way to delete) } #endif // this should after global lambda fix make_tri(); enc_computed = true; }