glue_static Camera glueDefaultcamera(float dist) { Camera c; c.pos=new_v(0, 0, -dist); c.tgt=new_v(0, 0, 0); c.yvec=new_v(0, 1, 0); c.cen=new_v(0, 0, 0); c.znear=0.1; c.zfar=1000.0; c.per=90; c.tilt=0; return c; }
glue_static Camera glueDefaultcamera2(float t, float dist) { Camera c; c.pos=new_v(sin(t*pi)*dist, 0, cos(t*pi)*dist); c.tgt=new_v(0, 0, 0); c.yvec=new_v(0, 1, 0); c.cen=new_v(0, 0, 0); c.znear=0.1; c.zfar=1000.0; c.per=90; c.tilt=0; return c; }
inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl, int* element) { CvPoint new_v(ppNew[element[0]]->ptCenter.x - ppNew[element[1]]->ptCenter.x, ppNew[element[0]]->ptCenter.y - ppNew[element[1]]->ptCenter.y); CvPoint prev_v(pPrev[element[0]].ptCenter.x - pPrev[element[1]].ptCenter.x, pPrev[element[0]].ptCenter.y - pPrev[element[1]].ptCenter.y); double new_d = sqrt((double)new_v.x*new_v.x + new_v.y*new_v.y); double prev_d = sqrt((double)prev_v.x*prev_v.x + prev_v.y*prev_v.y); double dx = ptTempl[element[0]].x - ptTempl[element[1]].x; double dy = ptTempl[element[0]].y - ptTempl[element[1]].y; double templ_d = sqrt(dx*dx + dy*dy); double scale_templ = new_d / templ_d; double w0 = (double)ppNew[element[0]]->r.width * scale_templ; double h0 = (double)ppNew[element[0]]->r.height * scale_templ; double w1 = (double)ppNew[element[1]]->r.width * scale_templ; double h1 = (double)ppNew[element[1]]->r.height * scale_templ; int energy = ppNew[element[0]]->iEnergy + ppNew[element[1]]->iEnergy + - 2 * (ppNew[element[0]]->nRectsInThis - ppNew[element[1]]->nRectsInThis) + (int)pow(w0 - (double)rTempl[element[0]].width, 2) + (int)pow(h0 - (double)rTempl[element[0]].height, 2) + (int)pow(w1 - (double)rTempl[element[1]].width, 2) + (int)pow(h1 - (double)rTempl[element[1]].height, 2) + (int)pow(new_d - prev_d, 2) + 0; return energy; }
// Create new pool of threads pthread_t *pts_create(int tc, bstate_t *bs) { pthread_t *pts = malloc(sizeof(pthread_t) * tc); for (int i = 0; i < tc; i++) { pthread_create(&pts[i], NULL, vthread_init, (void *)new_v(i, bs, pts[i])); } return pts; }
static void transpose( std::vector<std::string> &v ) { if( v.empty() ) { return; } std::vector<std::string> new_v( v[0].size() ); for( size_t x = 0; x < v.size(); ++x ) { for( size_t y = 0; y < new_v.size(); ++y ) { new_v[y].push_back( v[x].at( y ) ); } } v = new_v; }
void CCurve::Reverse() { std::list<CVertex> new_vertices; CVertex* prev_v = NULL; for(std::list<CVertex>::reverse_iterator It = m_vertices.rbegin(); It != m_vertices.rend(); It++) { CVertex &v = *It; int type = 0; Point cp(0.0, 0.0); if(prev_v) { type = -prev_v->m_type; cp = prev_v->m_c; } CVertex new_v(type, v.m_p, cp); new_vertices.push_back(new_v); prev_v = &v; } m_vertices = new_vertices; }
void render_lodder_sphere(int group, Vertex spherepos, Vertex spherepos2, float diam, float powr, float push, float timex) { Vertex *loddata[MAX_LOD_REDUCTION+1]; Vertex *v, *n; int vc=loddermesh->groups[group]->vc; int fc=loddermesh->groups[group]->fc; int *i=loddermesh->groups[group]->indices; float *c; unsigned char *lodlevels; // assign lod buffers, 0=original loddata[0]=loddermesh->groups[group]->vertices; for (int i=0; i<MAX_LOD_REDUCTION; i++) loddata[i+1]=lodder_vertices[group][i]; v=tmpmalloc(sizeof(Vertex)*vc); n=tmpmalloc(sizeof(Vertex)*vc); c=tmpmalloc(sizeof(float)*vc*4); lodlevels=tmpmalloc(vc); // calc vertices for (int x=0; x<vc; x++) { Vertex l0pos=loddata[0][x]; float xx=(l0pos.x-spherepos.x); float yy=(l0pos.y-spherepos.y); float zz=(l0pos.z-spherepos.z); float xx2=(l0pos.x-spherepos2.x); float yy2=(l0pos.y-spherepos2.y); float zz2=(l0pos.z-spherepos2.z); float dist=sqrt(xx*xx+yy*yy+zz*zz); float dist2=sqrt(xx2*xx2+yy2*yy2+zz2*zz2); float powah=r0(diam-dist)/diam; // 0..1 sphere float powah2=r0(diam-dist2)/diam; float lod=clamp((powah+powah2)*powr); //lod=clamp(powr); float lodfract=lod*(float)MAX_LOD_REDUCTION; int bufnum=(int)floor(lodfract); lodfract=fmod(lodfract, 1.0); c[x*3+0]=c[x*3+1]=c[x*3+2]=clamp((lod-0.1)*4.0); // calc lodded pos if (lod==0.0) { v[x]=l0pos; lodlevels[x]=0; } else if (lod==1.0) { v[x]=loddata[MAX_LOD_REDUCTION][x]; lodlevels[x]=1; } else { Vertex l0=loddata[bufnum][x]; Vertex l1=loddata[bufnum+1][x]; v[x].x = l0.x*(1.0-lodfract)+l1.x*(lodfract); v[x].y = l0.y*(1.0-lodfract)+l1.y*(lodfract); v[x].z = l0.z*(1.0-lodfract)+l1.z*(lodfract); lodlevels[x]=1; } // push Vertex pd=new_v(v[x].x-spherepos.x, v[x].y-spherepos.y, v[x].z-spherepos.z); Vertex pd2=new_v(v[x].x-spherepos2.x, v[x].y-spherepos2.y, v[x].z-spherepos2.z); normalize(&pd); normalize(&pd2); v[x].x+=push*powah*pd.x+push*powah2*pd2.x; v[x].y+=push*powah*pd.y+push*powah2*pd2.y; v[x].z+=push*powah*pd.z+push*powah2*pd2.z; // little something for normal n[x]=new_v(0.0, 0.00001, 0.0); } // calc normals for (int x=0; x<fc; x++) { Vertex fnorm; Vertex *v1, *v2, *v3; Vertex *n1, *n2, *n3; v1=&v[i[x*3+0]]; v2=&v[i[x*3+1]]; v3=&v[i[x*3+2]]; n1=&n[i[x*3+0]]; n2=&n[i[x*3+1]]; n3=&n[i[x*3+2]]; calc_fnorm_nn(v1, v2, v3, &fnorm); n1->x+=fnorm.x; n1->y+=fnorm.y; n1->z+=fnorm.z; n2->x+=fnorm.x; n2->y+=fnorm.y; n2->z+=fnorm.z; n3->x+=fnorm.x; n3->y+=fnorm.y; n3->z+=fnorm.z; } // normalize normals, for lod 0 use original normal for (int x=0; x<vc; x++) { if (lodlevels[x]==0) n[x]=loddermesh->groups[group]->normals[x]; else normalize(&n[x]); } // render arrays // glUniform1fARB(glGetUniformLocationARB(shader, "depthmult"), 1.0); glue_disableallarrays(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, v); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, n); /* Vertex *t=loddermesh->groups[group]->texcoords; if (t) { glClientActiveTexture(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, 0, t); }*/ // alkup. verteksit texturekoordinaateiks glClientActiveTexture(GL_TEXTURE1_ARB); glActiveTexture(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, 0, loddata[0]); glDrawElements(GL_TRIANGLES, fc*3, GL_UNSIGNED_INT, i); /* // wireframe //glUniform1fARB(glGetUniformLocationARB(shader, "depthmult"), 0.0); //renderflags(GLUE_BLEND_ALPHAADD|GLUE_CHECK_DEPTH); renderflags(GLUE_BLEND|GLUE_CHECK_DEPTH); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_POLYGON_OFFSET_LINE); glPolygonOffset(1.0, 1.0); //glEnable(GL_LINE_SMOOTH); glLineWidth(glueXres/320); glueDisabletexture(); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, 0, c); glDrawElements(GL_TRIANGLES, fc*3, GL_UNSIGNED_INT, i); glue_disableallarrays(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_POLYGON_OFFSET_LINE); */ glue_disableallarrays(); tmpfree(lodlevels); tmpfree(c); tmpfree(n); tmpfree(v); }
void good_ctor(std::vector<int> &v) { std::vector<int> new_v(v.cbegin(), v.cend()); // no-warning }
void bad_ctor(std::vector<int> &v1, std::vector<int> &v2) { std::vector<int> new_v(v1.cbegin(), v2.cend()); // expected-warning{{Iterators of different containers used where the same container is expected}} }
Var* ff_warp(vfuncptr func, Var* arg) { Var *obj = NULL, *xm = NULL, *oval; float ignore = FLT_MIN; int i, j; float* out; int x, y, n; int grow = 0; float m[9]; float* minverse; float xmax, xmin, ymax, ymin; float v[3]; int dsize; const char* options[] = {"nearest", "bilinear", 0}; char* interp = NULL; float (*interp_f)(float, float, Var*, float); Alist alist[6]; alist[0] = make_alist("object", ID_VAL, NULL, &obj); alist[1] = make_alist("matrix", ID_VAL, NULL, &xm); alist[2] = make_alist("ignore", DV_FLOAT, NULL, &ignore); alist[3] = make_alist("grow", DV_INT32, NULL, &grow); alist[4] = make_alist("interp", ID_ENUM, options, &interp); alist[5].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (obj == NULL) { parse_error("%s: No object specified\n", func->name); return (NULL); } if (ignore == FLT_MIN) ignore = -32768; x = GetX(obj); y = GetY(obj); n = V_SIZE(xm)[2]; for (j = 0; j < 3; j++) { for (i = 0; i < 3; i++) { m[i + j * 3] = extract_float(xm, cpos(i, j, 0, xm)); } } xmin = ymin = 0; xmax = x; ymax = y; if (grow) { /* figure out the size of the output array */ float* out; minverse = m_inverse(m); out = vxm(new_v(0, 0), minverse); xmin = out[0]; xmax = out[0]; ymin = out[1]; ymax = out[1]; free(out); out = vxm(new_v(x, 0), minverse); xmin = min(xmin, out[0]); xmax = max(xmax, out[0]); ymin = min(ymin, out[1]); ymax = max(ymax, out[1]); free(out); out = vxm(new_v(0, y), minverse); xmin = min(xmin, out[0]); xmax = max(xmax, out[0]); ymin = min(ymin, out[1]); ymax = max(ymax, out[1]); free(out); out = vxm(new_v(x, y), minverse); xmin = min(xmin, out[0]); xmax = max(xmax, out[0]); ymin = min(ymin, out[1]); ymax = max(ymax, out[1]); free(out); xmax = ceil(xmax); xmin = floor(xmin); ymax = ceil(ymax); ymin = floor(ymin); printf("new array corners:\n"); printf(" %fx%f , %fx%f\n", xmin, ymin, xmax, ymax); } if (interp == NULL || !strcmp(interp, "nearest")) { interp_f = interp_nn; } else if (!strcmp(interp, "bilinear")) { interp_f = interp_bilinear; } else { parse_error("Invalid interpolation function\n"); return (NULL); } dsize = (xmax - xmin) * (ymax - ymin); out = calloc(dsize, sizeof(float)); oval = newVal(BSQ, xmax - xmin, ymax - ymin, 1, DV_FLOAT, out); for (j = ymin; j < ymax; j++) { for (i = xmin; i < xmax; i++) { v[0] = i + 0.5; v[1] = j + 0.5; v[2] = 1; vxm(v, m); out[cpos((int)(i - xmin), (int)(j - ymin), 0, oval)] = interp_f(v[0], v[1], obj, ignore); } } return (oval); }