int main() { static char s1[1024], s2[1024]; int i, m, r, t, x, y, dep, arr, len; for (freelist = i = 1; i < MAXC; i++) next[i] = i + 1; memset(adj0, 0, sizeof(adj0)); memset(adj1, 0, sizeof(adj1)); for (scanf("%d", &r), t = 1; t <= r && scanf("%d", &m) == 1; t++) { for (ncities = 0; m-- > 0;) { scanf(" %s %s %d %d", s1, s2, &dep, &len); x = get(s1); y = get(s2); if (len > 12) continue; dep %= 24; arr = (dep + len) % 24; if ((6 < dep && dep < 18) || (6 < arr && arr < 18)) continue; insert(&adj0[VERTEX(x, dep)], VERTEX(y, arr)); } scanf(" %s %s", s1, s2); x = get(s1); y = get(s2); for (m = 0; m < ncities; m++) { for (i = 18; i != 6; i = (i + 1) % 24) insert(&adj0[VERTEX(m, i)], VERTEX(m, (i + 1) % 24)); insert(&adj1[VERTEX(m, 6)], VERTEX(m, 18)); } search(VERTEX(x, 18)); for (m = dist[VERTEX(y, 0)], i = 1; i < 24; i++) if (dist[VERTEX(y, i)] < m) m = dist[VERTEX(y, i)]; printf("Test Case %d.\n", t); if (m >= INF) printf("There is no route Vladimir can take.\n"); else printf("Vladimir needs %d litre(s) of blood.\n", m); for (m = ncities * 24, i = 0; i < m; i++) { if (adj0[i]) release(&adj0[i]); if (adj1[i]) release(&adj1[i]); } } return 0; }
void SkinnedMesh::RenderSkeleton(Bone* bone, Bone *parent, D3DXMATRIX world) { //Temporary function to render the bony hierarchy if (world == NULL)return; if (bone == NULL)bone = (Bone*)m_pRootBone; //Draw line between bones if (parent != NULL && bone->Name != NULL && parent->Name != NULL) { //Draw Sphere g_pDevice->SetRenderState(D3DRS_LIGHTING, true); g_pDevice->SetTransform(D3DTS_WORLD, &(bone->CombinedTransformationMatrix * world)); m_pSphereMesh->DrawSubset(0); D3DXMATRIX w1 = bone->CombinedTransformationMatrix; D3DXMATRIX w2 = parent->CombinedTransformationMatrix; //Extract translation D3DXVECTOR3 thisBone = D3DXVECTOR3(w1(3, 0), w1(3, 1), w1(3, 2)); D3DXVECTOR3 ParentBone = D3DXVECTOR3(w2(3, 0), w2(3, 1), w2(3, 2)); if (D3DXVec3Length(&(thisBone - ParentBone)) < 2.0f) { g_pDevice->SetTransform(D3DTS_WORLD, &world); VERTEX vert[] = {VERTEX(ParentBone, 0xffff0000), VERTEX(thisBone, 0xff00ff00)}; g_pDevice->SetRenderState(D3DRS_LIGHTING, false); g_pDevice->SetFVF(VERTEX::FVF); g_pDevice->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, &vert[0], sizeof(VERTEX)); } } if (bone->pFrameSibling)RenderSkeleton((Bone*)bone->pFrameSibling, parent, world); if (bone->pFrameFirstChild)RenderSkeleton((Bone*)bone->pFrameFirstChild, bone, world); }
// iterate over vertices of face, compute u&v coords, compute min & max void get_face_extent(int face, int *u0, int *v0, int *u1, int *v1) { float uv[32][2], u[4],v[4], umin,umax,vmin,vmax; int tex = dfaces[face].texinfo; int i,n = dfaces[face].numedges; int se = dfaces[face].firstedge; vector *loc; memcpy(u, texinfo[tex].vecs[0], sizeof(u)); memcpy(v, texinfo[tex].vecs[1], sizeof(v)); for (i=0; i < n; ++i) { int j = dsurfedges[se+i]; if (j < 0) loc = (vector *) VERTEX(dedges[-j].v[1]); else loc = (vector *) VERTEX(dedges[ j].v[0]); uv[i][0] = loc->x*u[0] + loc->y*u[1] + loc->z*u[2] + u[3]; uv[i][1] = loc->x*v[0] + loc->y*v[1] + loc->z*v[2] + v[3]; } umin = umax = uv[0][0]; vmin = vmax = uv[0][1]; for (i=1; i < n; ++i) { if (uv[i][0] < umin) umin = uv[i][0]; else if (uv[i][0] > umax) umax = uv[i][0]; if (uv[i][1] < vmin) vmin = uv[i][1]; else if (uv[i][1] > vmax) vmax = uv[i][1]; } *u0 = FLOAT_TO_INT(umin) & ~15; *v0 = FLOAT_TO_INT(vmin) & ~15; *u1 = FLOAT_TO_INT(ceil(umax/16)) << 4; *v1 = FLOAT_TO_INT(ceil(vmax/16)) << 4; }
status topological_sort( graph G, int vertex_cnt, status ( *p_func_f )()) { edge *p_edge = NULL ; int i, index, sum, *local_par ; i = 0 ; local_par = ( int* )malloc( sizeof( int ) * ( G -> number_of_vertices )) ; sum = vertex_cnt ; for( i = 0 ; i < vertex_cnt ; i++ ) local_par[i] = 0 ; for( i = 0 ; i < vertex_cnt ; i++ ) while(( p_edge = edge_iterator( G, i, p_edge )) != NULL ) local_par[VERTEX( p_edge )]++ ; while( sum > 0 ) { for( i = 0 ; ( vertex )i < vertex_cnt ; i++ ) if( local_par[i] == 0 ) index = i ; p_edge = NULL ; while(( p_edge = edge_iterator( G, ( vertex )index, p_edge )) != NULL ) local_par[VERTEX(p_edge)]-- ; ( *p_func_f )( index ) ; local_par[index] = -1 ; sum-- ; } return OK; }
int o_face( /* determine if face intersects cube */ OBJREC *o, CUBE *cu ) { FVECT cumin, cumax; FVECT v1, v2; double d1, d2; int vloc; register FACE *f; register int i, j; /* get face arguments */ f = getface(o); if (f->area == 0.0) /* empty face */ return(O_MISS); /* compute cube boundaries */ for (j = 0; j < 3; j++) cumax[j] = (cumin[j] = cu->cuorg[j]-FTINY) + cu->cusize + 2.0*FTINY; vloc = ABOVE | BELOW; /* check vertices */ for (i = 0; i < f->nv; i++) if ( (j = plocate(VERTEX(f,i), cumin, cumax)) ) vloc &= j; else return(O_HIT); /* vertex inside */ if (vloc) /* all to one side */ return(O_MISS); for (i = 0; i < f->nv; i++) { /* check edges */ if ((j = i + 1) >= f->nv) j = 0; /* wrap around */ VCOPY(v1, VERTEX(f,i)); /* clip modifies */ VCOPY(v2, VERTEX(f,j)); /* the vertices! */ if (clip(v1, v2, cumin, cumax)) return(O_HIT); /* edge inside */ } /* see if cube cuts plane */ for (j = 0; j < 3; j++) if (f->norm[j] > 0.0) { v1[j] = cumin[j]; v2[j] = cumax[j]; } else { v1[j] = cumax[j]; v2[j] = cumin[j]; } if ((d1 = DOT(v1, f->norm) - f->offset) > FTINY) return(O_MISS); if ((d2 = DOT(v2, f->norm) - f->offset) < -FTINY) return(O_MISS); /* intersect face */ for (j = 0; j < 3; j++) v1[j] = (v1[j]*d2 - v2[j]*d1)/(d2 - d1); if (inface(v1, f)) return(O_HIT); return(O_MISS); /* no intersection */ }
void spot(int c1, int c2, int w, int h) { GFX_BEGIN = QUAD; GFX_COLOR = c1; GFX_VERTEX10 = VERTEX(-64, h, 0); GFX_VERTEX10 = VERTEX( 64, h, 0); GFX_COLOR = c2; GFX_VERTEX10 = VERTEX( 64+w, 64, 0); GFX_VERTEX10 = VERTEX(-64-w, 64, 0); }
Vertices * MST(Vertices * graph) { HeapP * heap; Vertices * vertex; Edges * edge; ; InitFHeap(); /* * key(s) = 0; * key(v) = infty for v != s; * init heap; * make a heap; * put s in heap; */ vertex = graph; KEY(vertex) = 0; heap = MakeHeap(); (void)Insert(&heap, (Item *)vertex); vertex = NEXT_VERTEX(vertex); while(vertex != graph) { KEY(vertex) = PLUS_INFINITY; vertex = NEXT_VERTEX(vertex); } while(vertex != graph); vertex = FindMin(heap); while(vertex != NULL_VERTEX) { heap = DeleteMin(heap); KEY(vertex) = MINUS_INFINITY; edge = EDGES(vertex); while(edge != NULL_EDGE) { if(WEIGHT(edge) < KEY(VERTEX(edge))) { KEY(VERTEX(edge)) = WEIGHT(edge); CHOSEN_EDGE(VERTEX(edge)) = edge; (void)Insert(&heap, VERTEX(edge)); } edge = NEXT_EDGE(edge); } vertex = FindMin(heap); } ; return(graph); }
Vertices * GenTree(int nVertex) { int i; int weight; Vertices * vertex; Vertices * graph; Edges * edge; graph = NewVertex(); NEXT_VERTEX(graph) = graph; for(i = 1; i < nVertex; i++) { vertex = NewVertex(); edge = NewEdge(); /* * The newly created vertex has one edge ... */ EDGES(vertex) = edge; /* * ... which is connected to the graph so far generated. The connection * point in the graph is picked at random. */ VERTEX(edge) = PickVertex(graph, random() % i); weight = GET_WEIGHT; WEIGHT(edge) = weight; SOURCE(edge) = vertex; /* * Link the new vertex into the graph. */ NEXT_VERTEX(vertex) = NEXT_VERTEX(graph); NEXT_VERTEX(graph) = vertex; /* * Add an edge to the vertex randomly picked as the connection point. */ edge = NewEdge(); WEIGHT(edge) = weight; SOURCE(edge) = VERTEX(EDGES(vertex)); VERTEX(edge) = vertex; NEXT_EDGE(edge) = EDGES(VERTEX(EDGES(vertex))); EDGES(VERTEX(EDGES(vertex))) = edge; } return(graph); }
static void do_draw_polyline(ALLEGRO_PRIM_VERTEX_CACHE* cache, const float* vertices, int vertex_stride, int vertex_count, int join_style, int cap_style, ALLEGRO_COLOR color, float thickness, float miter_limit) { if (thickness > 0.0f) { _al_prim_cache_init(cache, ALLEGRO_PRIM_VERTEX_CACHE_TRIANGLE, color); emit_polyline(cache, vertices, vertex_stride, vertex_count, join_style, cap_style, thickness, miter_limit); _al_prim_cache_term(cache); } else { # define VERTEX(index) ((const float*)(((uint8_t*)vertices) + vertex_stride * ((vertex_count + (index)) % vertex_count))) int i; _al_prim_cache_init(cache, ALLEGRO_PRIM_VERTEX_CACHE_LINE_STRIP, color); for (i = 0; i < vertex_count; ++i) { if (cache->size >= (ALLEGRO_VERTEX_CACHE_SIZE - 2)) _al_prim_cache_flush(cache); _al_prim_cache_push_point(cache, VERTEX(i)); } _al_prim_cache_term(cache); # undef VERTEX } }
void CD3DCG::setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer, D3DXVECTOR2 inputSize,D3DXVECTOR2 textureSize,D3DXVECTOR2 outputSize) { float tX = inputSize.x / textureSize.x; float tY = inputSize.y / textureSize.y; VERTEX vertexStream[4]; /* vertex is POSITION, TEXCOORD, LUT TEXCOORD */ vertexStream[0] = VERTEX(0.0f,0.0f,0.0f, 0.0f,tY, 0.0f,1.0f); vertexStream[1] = VERTEX(0.0f,1.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f); vertexStream[2] = VERTEX(1.0f,0.0f,0.0f, tX,tY, 1.0f,1.0f); vertexStream[3] = VERTEX(1.0f,1.0f,0.0f, tX,0.0f, 1.0f,0.0f); // offset coordinates to correct pixel/texture alignment for(int i=0;i<4;i++) { vertexStream[i].x -= 0.5f / outputSize.x; vertexStream[i].y += 0.5f / outputSize.y; } void *pLockedVertexBuffer; HRESULT hr = vertexBuffer->Lock(0,0,&pLockedVertexBuffer,NULL); memcpy(pLockedVertexBuffer,vertexStream,sizeof(vertexStream)); vertexBuffer->Unlock(); /* set vertex to stream 0-3, for POSITION,TEXCOORD0,TEXCOORD1,COLOR if stream is used in parameter, this will be set in setShaderVars */ pDevice->SetStreamSource(0,vertexBuffer,0,sizeof(VERTEX)); pDevice->SetStreamSource(1,vertexBuffer,0,sizeof(VERTEX)); pDevice->SetStreamSource(2,vertexBuffer,0,sizeof(VERTEX)); pDevice->SetStreamSource(3,vertexBuffer,0,sizeof(VERTEX)); }
/* CDirect3D::SetupVertices calculates the vertex coordinates (respecting the stretch and aspect ratio settings) */ void CDirect3D::SetupVertices() { void *pLockedVertexBuffer; float tX = (float)afterRenderWidth / (float)quadTextureSize; float tY = (float)afterRenderHeight / (float)quadTextureSize; vertexStream[0] = VERTEX(0.0f,0.0f,0.0f,0.0f,tY,0.0f,0.0f); vertexStream[1] = VERTEX(0.0f,1.0f,0.0f,0.0f,0.0f,0.0f,0.0f); vertexStream[2] = VERTEX(1.0f,0.0f,0.0f,tX,tY,0.0f,0.0f); vertexStream[3] = VERTEX(1.0f,1.0f,0.0f,tX,0.0f,0.0f,0.0f); for(int i=0;i<4;i++) { vertexStream[i].x -= 0.5f / (float)dPresentParams.BackBufferWidth; vertexStream[i].y += 0.5f / (float)dPresentParams.BackBufferHeight; } HRESULT hr = vertexBuffer->Lock(0,0,&pLockedVertexBuffer,NULL); memcpy(pLockedVertexBuffer,vertexStream,sizeof(vertexStream)); vertexBuffer->Unlock(); }
status depth_first_search( graph G, vertex vertex_number, bool visited[], status (*p_func_f)()){ edge *p_edge = NULL ; status rc ; visited[vertex_number] = TRUE; if(( *p_func_f )( vertex_number ) == ERROR ) return ERROR; while(( p_edge = edge_iterator( G, vertex_number, p_edge )) != NULL ) if( visited[VERTEX( p_edge )] == FALSE ) { rc = depth_first_search( G, VERTEX( p_edge ), visited, p_func_f ) ; if( rc == ERROR ) return ERROR; } return OK ; }
void PrintNeighbors(Vertices * vertex) { Edges * edge; edge = EDGES(vertex); while(edge != NULL) { printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge))); edge = NEXT_EDGE(edge); } }
void Connect(Vertices * vertex1, Vertices * vertex2) { int weight; Edges * edge; weight = GET_WEIGHT; edge = NewEdge(); WEIGHT(edge) = weight; SOURCE(edge) = vertex1; VERTEX(edge) = vertex2; NEXT_EDGE(edge) = EDGES(vertex1); EDGES(vertex1) = edge; edge = NewEdge(); WEIGHT(edge) = weight; SOURCE(edge) = vertex2; VERTEX(edge) = vertex1; NEXT_EDGE(edge) = EDGES(vertex2); EDGES(vertex2) = edge; }
void draw_face(int face) { int n = dfaces[face].numedges; int se = dfaces[face].firstedge; int i,codes_or=0,codes_and=0xff; point_3d **vlist; for (i=0; i < n; ++i) { int edge = dsurfedges[se+i]; if (edge < 0) transform_point(&pts[i], (vector *) VERTEX(dedges[-edge].v[1])); else transform_point(&pts[i], (vector *) VERTEX(dedges[ edge].v[0])); codes_or |= pts[i].ccodes; codes_and &= pts[i].ccodes; } if (codes_and) return; // abort if poly outside frustrum if (codes_or) { // poly crosses frustrum, so clip it n = clip_poly(n, default_vlist, codes_or, &vlist); } else vlist = default_vlist; if (n) { bitmap bm; float u,v; int tex = dfaces[face].texinfo; int mip = compute_mip_level(face); get_tmap(&bm, face, texinfo[tex].miptex, mip, &u, &v); qmap_set_texture(&bm); compute_texture_gradients(face, tex, mip, u, v); draw_poly(n, vlist); } }
void sonic(int t) { int i = 0; int y, x; rotateX(-1024); if ( t < 256 ) t = 0; else t = -(t*2)&127; for ( y = -7*64+t ; y < 6*64+t ; y += 64 ) { for ( x = -7*64 ; x < 6*64 ; x += 64 ) { GFX_VERTEX10 = VERTEX(x, f(x, y), y); GFX_VERTEX10 = VERTEX(x, f(x, y+64), y+64); GFX_VERTEX10 = VERTEX(x+64, f(x+64, y+64), y+64); GFX_VERTEX10 = VERTEX(x+64, f(x+64, y), y); GFX_COLOR = (i&1) ? RGB15(29, 15, 4) : RGB15(4, 11, 28); i++; } //i++; } }
static BOOL IntEngIsNULLTriangle(TRIVERTEX *pVertex, GRADIENT_TRIANGLE *gt) { if(COMPAREVERTEX(VERTEX(Vertex1), VERTEX(Vertex2))) return TRUE; if(COMPAREVERTEX(VERTEX(Vertex1), VERTEX(Vertex3))) return TRUE; if(COMPAREVERTEX(VERTEX(Vertex2), VERTEX(Vertex3))) return TRUE; return FALSE; }
Edges * NewEdge() { Edges * edge; edge = (Edges *)malloc(sizeof(Edges)); if(edge == NULL) { fprintf(stderr, "Could not malloc\n"); exit(1); } WEIGHT(edge) = 0; VERTEX(edge) = NULL; NEXT_EDGE(edge) = NULL; return(edge); }
int Duplicate(Vertices * vertex1, Vertices * vertex2) { Edges * edge; edge = EDGES(vertex1); while(edge != NULL_EDGE) { if(VERTEX(edge) == vertex2) { return(TRUE); } edge = NEXT_EDGE(edge); } return(FALSE); }
edge *edge_iterator ( graph G, vertex vertex_number , edge *p_last_return ) { vertex other_vertex ; if( vertex_number < 0 || vertex_number >= G -> number_of_vertices ) return NULL ; if ( p_last_return == NULL ) other_vertex = 0 ; else other_vertex = VERTEX(p_last_return) + 1 ; for( ; other_vertex < G -> number_of_vertices ; other_vertex++ ) { if( G -> matrix[vertex_number][other_vertex].weight != UNUSED_WEIGHT ) return &G -> matrix[vertex_number][other_vertex] ; } return NULL ; }
/* Function: al_draw_polygon_with_holes */ void al_draw_polygon_with_holes(const float *vertices, int vertex_count, const int *holes, int hole_count, ALLEGRO_LINE_JOIN join_style, ALLEGRO_COLOR color, float thickness, float miter_limit) { # define VERTEX(index) ((const float*)(((uint8_t*)vertices) + (sizeof(float) * 2) * ((vertex_count + (index)) % vertex_count))) # define HOLE(index) (*((int*)(((uint8_t*)holes) + sizeof(int) * ((hole_count + index) % hole_count)))) int i; if (hole_count <= 0) return; al_draw_polyline(vertices, HOLE(0), join_style, ALLEGRO_LINE_CAP_CLOSED, color, thickness, miter_limit); for (i = 1; i < hole_count; ++i) al_draw_polyline_ex(VERTEX(HOLE(i) - 1), -(int)(sizeof(float) * 2), HOLE(i) - HOLE(i - 1), join_style, ALLEGRO_LINE_CAP_CLOSED, color, thickness, miter_limit); # undef VERTEX # undef HOLE }
PyObject* draw_path_fill( PyObject* self, PyObject* args ) { PyObject* pobj; PyObject* plist = NULL; PyObject* cacheobj; int displaylist; int i; int size; PyObject* item; static GLUtesselator* tess = NULL; static double* v = NULL; static int alloc = 0; int used = 0; int cset = 0; // is there a current point? double sx, sy; // start of subpath double cx, cy; // current point double c[8]; int j, k; double *xy; static double** blocks = NULL; static int block_alloc = 0; int block_used = 0; if ( !PyArg_ParseTuple( args, "O", &pobj ) ) return NULL; delete_invalid_lists( pobj ); cacheobj = PyObject_GetAttrString( pobj, "_fill_list" ); if ( cacheobj && PyInt_Check(cacheobj) ) { displaylist = PyInt_AsLong( cacheobj ); glCallList( displaylist ); } else { PyErr_Clear(); // don't care if attribute was not found // generate and store triangulation plist = PyObject_GetAttrString( pobj, "raw" ); if ( plist == NULL || !PyList_Check( plist ) ) { Py_XDECREF( plist ); PyErr_SetString( DrawError, "bad path object" ); return NULL; } displaylist = glGenLists( 1 ); glNewList( displaylist, GL_COMPILE_AND_EXECUTE ); if ( tess == NULL ) tess = gluNewTess(); #ifdef SHOW_TRIANGULATION glPushAttrib( GL_LIGHTING_BIT ); glShadeModel( GL_FLAT ); gluTessCallback( tess, GLU_TESS_VERTEX, random_color_vertex ); #else gluTessCallback( tess, GLU_TESS_VERTEX, glVertex2dv ); #endif gluTessCallback( tess, GLU_TESS_BEGIN, glBegin ); gluTessCallback( tess, GLU_TESS_END, glEnd ); gluTessCallback( tess, GLU_TESS_COMBINE, combine_cb ); gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE ); size = PyList_Size( plist ); if ( size > alloc ) { alloc = size + VERTEX_ALLOC_CHUNK; v = realloc( v, alloc * 3 * sizeof( double ) ); } memset( v, 0, alloc * 3 * sizeof( double ) ); #define VERTEX(x,y) {v[used*3+0]=(x);v[used*3+1]=(y);gluTessVertex(tess,v+used*3,v+used*3);++used;} gluTessBeginPolygon( tess, NULL ); for ( i = 0; i < size; ++i ) { item = PyList_GetItem( plist, i ); switch( PyInt_AsLong( PyList_GetItem( item, 0 ) ) ) { case S_CLOSE: VERTEX( sx, sy ); gluTessEndContour( tess ); cset = 0; break; case S_MOVE: if ( cset ) gluTessEndContour( tess ); gluTessBeginContour( tess ); sx = cx = PyFloat_AsDouble( PyList_GetItem( item, 1 ) ); sy = cy = PyFloat_AsDouble( PyList_GetItem( item, 2 ) ); VERTEX( cx, cy ); cset = 1; break; case S_LINE: cx = PyFloat_AsDouble( PyList_GetItem( item, 1 ) ); cy = PyFloat_AsDouble( PyList_GetItem( item, 2 ) ); VERTEX( cx, cy ); break; case S_CURVE: if ( block_used + 1 > block_alloc ) { block_alloc += BLOCK_ALLOC_CHUNK; blocks = realloc( blocks, block_alloc * sizeof( double* ) ); } c[0] = cx; c[1] = cy; for ( j = 0; j < 6; ++j ) c[j+2] = PyFloat_AsDouble( PyList_GetItem( item, j+1 ) ); xy = bezier_points( &k, 4, c, 0.0001, 0 ); cx = c[6]; cy = c[7]; blocks[block_used] = malloc( (k-1) * 3 * sizeof( double ) ); for ( j = 1; j < k; ++j ) { blocks[block_used][(j-1)*3+0] = xy[j*2]; blocks[block_used][(j-1)*3+1] = xy[j*2+1]; blocks[block_used][(j-1)*3+2] = 0.0; } for ( j = 0; j < k-1; ++j ) gluTessVertex( tess, blocks[block_used] + j*3, blocks[block_used] + j*3 ); ++block_used; break; case S_QCURVE: if ( block_used + 1 > block_alloc ) { block_alloc += BLOCK_ALLOC_CHUNK; blocks = realloc( blocks, block_alloc * sizeof( double* ) ); } c[0] = cx; c[1] = cy; for ( j = 0; j < 4; ++j ) c[j+2] = PyFloat_AsDouble( PyList_GetItem( item, j+1 ) ); xy = bezier_points( &k, 3, c, 0.0001, 0 ); cx = c[4]; cy = c[5]; blocks[block_used] = malloc( (k-1) * 3 * sizeof( double ) ); for ( j = 1; j < k; ++j ) { blocks[block_used][(j-1)*3+0] = xy[j*2]; blocks[block_used][(j-1)*3+1] = xy[j*2+1]; blocks[block_used][(j-1)*3+2] = 0.0; } for ( j = 0; j < k-1; ++j ) gluTessVertex( tess, blocks[block_used] + j*3, blocks[block_used] + j*3 ); ++block_used; break; } } if ( cset ) gluTessEndContour( tess ); gluTessEndPolygon( tess ); for ( i = 0; i < block_used; ++i ) free( blocks[i] ); #ifdef SHOW_TRIANGULATION glPopAttrib(); #endif glEndList(); PyObject_SetAttrString( pobj, "_fill_list", PyInt_FromLong( displaylist ) ); } Py_XDECREF( cacheobj ); Py_XDECREF( plist ); Py_INCREF( Py_None ); return Py_None; }
* H H : M M */ #define VX1(x) ((x * SZ_GRID) + SZ_LED) #define VY1(y) ((y * SZ_GRID) + SZ_LED) #define VX2(x) (x * SZ_GRID) #define VY2(y) ((y * SZ_GRID) + SZ_LED) #define VX3(x) (x * SZ_GRID) #define VY3(y) (y * SZ_GRID) #define VX4(x) ((x * SZ_GRID) + SZ_LED) #define VY4(y) (y * SZ_GRID) #define VERTEX(x, y) VX1(x), VY1(y), VX2(x), VY2(y), VX3(x), VY3(y), VX4(x), VY4(y) float leds[14][8] = { {VERTEX(0, 0)}, {VERTEX(1, 0)}, {VERTEX(1, 1)}, {VERTEX(1, 2)}, {VERTEX(1, 3)}, {VERTEX(3, 0)}, {VERTEX(3, 1)}, {VERTEX(3, 2)}, {VERTEX(4, 0)}, {VERTEX(4, 1)}, {VERTEX(4, 2)}, {VERTEX(4, 3)}, {VERTEX(0, 5)}, {VERTEX(0, 6)} };
void do_display (void) { int i,j,s,t, tmp; cum_al = 0.0; metaal_texture(); for (s=0;s<24;s += 2) { t = s+2; if (!(t&7)) t=t-8; if (s == 16) rood_texture(); glBegin(GL_QUADS); for (i=0;i<tot;i=j) { tmp = 0; for (j=i+1;j<tot;j++) if ((tmp=tmp+tmp+opt[j]) > 4000 || (!(j%(3*DIST)))) break; if (j>=tot) j = 0; rr++; VERTEX(s, j); VERTEX(s, i); VERTEX(t, i); VERTEX(t, j); if (!j) break; } glEnd(); } printf("Split up to %d parts.\n", rr); rood_texture(); for (i=0;i<tot-2;i+=DIST) { if (!(i%(DIST*5))) continue; glBegin(GL_QUADS); glNormal3fv(bnormal[0][i]); glVertex3fv(strips[24][i]); glVertex3fv(strips[24][i+5]); glVertex3fv(strips[26][i+5]); glVertex3fv(strips[26][i]); glNormal3fv(bnormal[1][i]); glVertex3fv(strips[25][i]); glVertex3fv(strips[25][i+5]); glVertex3fv(strips[26][i+5]); glVertex3fv(strips[26][i]); glEnd(); } wit_texture(); for (i=0;i<tot-2;i+=DIST) { if (i%(DIST*5)) continue; glBegin(GL_QUADS); glNormal3fv(bnormal[0][i]); glVertex3fv(strips[24][i]); glVertex3fv(strips[24][i+5]); glVertex3fv(strips[26][i+5]); glVertex3fv(strips[26][i]); glNormal3fv(bnormal[1][i]); glVertex3fv(strips[25][i]); glVertex3fv(strips[25][i+5]); glVertex3fv(strips[26][i+5]); glVertex3fv(strips[26][i]); glEnd(); } groen_texture(); glBegin(GL_QUADS); for (i=0;i<tot;i+=90) { if (dy[i]<0.2) continue; glNormal3f(-1.0, 0.0, 0.0); glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7); glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2); glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2); glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7); glNormal3f(0.0, 0.0, 1.0); glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7); glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2); glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2); glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7); glNormal3f(0.0, 0.0, -1.0); glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7); glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2); glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2); glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7); glNormal3f(1.0, 0.0, 0.0); glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7); glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2); glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2); glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7); } glEnd(); }
static gear_t* gear( const GLfloat inner_radius, const GLfloat outer_radius, const GLfloat width, const GLint teeth, const GLfloat tooth_depth, const GLfloat color[]) { GLint i, j; GLfloat r0, r1, r2; GLfloat ta, da; GLfloat u1, v1, u2, v2, len; GLfloat cos_ta, cos_ta_1da, cos_ta_2da, cos_ta_3da, cos_ta_4da; GLfloat sin_ta, sin_ta_1da, sin_ta_2da, sin_ta_3da, sin_ta_4da; GLshort ix0, ix1, ix2, ix3, ix4; vertex_t *vt, *nm, *tx; GLshort *ix; gear_t *gear = calloc(1, sizeof(gear_t)); gear->nvertices = teeth * 38; gear->nindices = teeth * 64 * 3; gear->vertices = calloc(gear->nvertices, sizeof(vertex_t)); gear->indices = calloc(gear->nindices, sizeof(GLshort)); memcpy(&gear->color[0], &color[0], sizeof(GLfloat) * 4); r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0; r2 = outer_radius + tooth_depth / 2.0; da = 2.0 * M_PI / teeth / 4.0; vt = gear->vertices; nm = gear->vertices; tx = gear->vertices; ix = gear->indices; #define VERTEX(x,y,z) ((vt->pos[0] = x),(vt->pos[1] = y),(vt->pos[2] = z), \ (tx->texCoords[0] = x / r2 * 0.8 + 0.5),(tx->texCoords[1] = y / r2 * 0.8 + 0.5), (tx++), \ (vt++ - gear->vertices)) #define NORMAL(x,y,z) ((nm->norm[0] = x),(nm->norm[1] = y),(nm->norm[2] = z), \ (nm++)) #define INDEX(a,b,c) ((*ix++ = a),(*ix++ = b),(*ix++ = c)) for (i = 0; i < teeth; i++) { ta = i * 2.0 * M_PI / teeth; cos_ta = cos(ta); cos_ta_1da = cos(ta + da); cos_ta_2da = cos(ta + 2 * da); cos_ta_3da = cos(ta + 3 * da); cos_ta_4da = cos(ta + 4 * da); sin_ta = sin(ta); sin_ta_1da = sin(ta + da); sin_ta_2da = sin(ta + 2 * da); sin_ta_3da = sin(ta + 3 * da); sin_ta_4da = sin(ta + 4 * da); u1 = r2 * cos_ta_1da - r1 * cos_ta; v1 = r2 * sin_ta_1da - r1 * sin_ta; len = sqrt(u1 * u1 + v1 * v1); u1 /= len; v1 /= len; u2 = r1 * cos_ta_3da - r2 * cos_ta_2da; v2 = r1 * sin_ta_3da - r2 * sin_ta_2da; /* front face */ ix0 = VERTEX(r1 * cos_ta, r1 * sin_ta, width * 0.5); ix1 = VERTEX(r0 * cos_ta, r0 * sin_ta, width * 0.5); ix2 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, width * 0.5); ix3 = VERTEX(r0 * cos_ta_4da, r0 * sin_ta_4da, width * 0.5); ix4 = VERTEX(r1 * cos_ta_4da, r1 * sin_ta_4da, width * 0.5); for (j = 0; j < 5; j++) { NORMAL(0.0, 0.0, 1.0); } INDEX(ix0, ix2, ix1); INDEX(ix1, ix2, ix3); INDEX(ix2, ix4, ix3); /* front sides of teeth */ ix0 = VERTEX(r1 * cos_ta, r1 * sin_ta, width * 0.5); ix1 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, width * 0.5); ix2 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, width * 0.5); ix3 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, width * 0.5); for (j = 0; j < 4; j++) { NORMAL(0.0, 0.0, 1.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); /* back face */ ix0 = VERTEX(r1 * cos_ta, r1 * sin_ta, -width * 0.5); ix1 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, -width * 0.5); ix2 = VERTEX(r0 * cos_ta, r0 * sin_ta, -width * 0.5); ix3 = VERTEX(r1 * cos_ta_4da, r1 * sin_ta_4da, -width * 0.5); ix4 = VERTEX(r0 * cos_ta_4da, r0 * sin_ta_4da, -width * 0.5); for (j = 0; j < 5; j++) { NORMAL(0.0, 0.0, -1.0); } INDEX(ix0, ix2, ix1); INDEX(ix1, ix2, ix3); INDEX(ix2, ix4, ix3); /* back sides of teeth */ ix0 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, -width * 0.5); ix1 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, -width * 0.5); ix2 = VERTEX(r1 * cos_ta, r1 * sin_ta, -width * 0.5); ix3 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, -width * 0.5); for (j = 0; j < 4; j++) { NORMAL(0.0, 0.0, -1.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); /* draw outward faces of teeth */ ix0 = VERTEX(r1 * cos_ta, r1 * sin_ta, width * 0.5); ix1 = VERTEX(r1 * cos_ta, r1 * sin_ta, -width * 0.5); ix2 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, width * 0.5); ix3 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, -width * 0.5); for (j = 0; j < 4; j++) { NORMAL(v1, -u1, 0.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); ix0 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, width * 0.5); ix1 = VERTEX(r2 * cos_ta_1da, r2 * sin_ta_1da, -width * 0.5); ix2 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, width * 0.5); ix3 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, -width * 0.5); for (j = 0; j < 4; j++) { NORMAL(cos_ta, sin_ta, 0.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); ix0 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, width * 0.5); ix1 = VERTEX(r2 * cos_ta_2da, r2 * sin_ta_2da, -width * 0.5); ix2 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, width * 0.5); ix3 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, -width * 0.5); for (j = 0; j < 4; j++) { NORMAL(v2, -u2, 0.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); ix0 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, width * 0.5); ix1 = VERTEX(r1 * cos_ta_3da, r1 * sin_ta_3da, -width * 0.5); ix2 = VERTEX(r1 * cos_ta_4da, r1 * sin_ta_4da, width * 0.5); ix3 = VERTEX(r1 * cos_ta_4da, r1 * sin_ta_4da, -width * 0.5); for (j = 0; j < 4; j++) { NORMAL(cos_ta, sin_ta, 0.0); } INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); /* draw inside radius cylinder */ ix0 = VERTEX(r0 * cos_ta, r0 * sin_ta, -width * 0.5); ix1 = VERTEX(r0 * cos_ta, r0 * sin_ta, width * 0.5); ix2 = VERTEX(r0 * cos_ta_4da, r0 * sin_ta_4da, -width * 0.5); ix3 = VERTEX(r0 * cos_ta_4da, r0 * sin_ta_4da, width * 0.5); NORMAL(-cos_ta, -sin_ta, 0.0); NORMAL(-cos_ta, -sin_ta, 0.0); NORMAL(-cos_ta_4da, -sin_ta_4da, 0.0); NORMAL(-cos_ta_4da, -sin_ta_4da, 0.0); INDEX(ix0, ix1, ix2); INDEX(ix1, ix3, ix2); } // setup pointers/offsets for draw operations if (state->useVBO) { // for VBO use offsets into the buffer object gear->vertex_p = 0; gear->normal_p = (GLvoid *)sizeof(gear->vertices[0].pos); gear->texCoords_p = (GLvoid *)(sizeof(gear->vertices[0].pos) + sizeof(gear->vertices[0].norm)); gear->index_p = 0; } else { // for Vertex Array use pointers to where the buffer starts gear->vertex_p = gear->vertices[0].pos; gear->normal_p = gear->vertices[0].norm; gear->texCoords_p = gear->vertices[0].texCoords; gear->index_p = gear->indices; } gear->tricount = gear->nindices / 3; return gear; }
#if FADES #define BRIGHT (1<<14) #define DARK (2<<14) int fade_current = 31 << 2; // starts white int fade_target = 16 << 2; #endif u32 cubelist[] = { COMMAND(CDIFAMB, CBEGIN, CNORMAL, CVERTEX), DIFAMB(RGB15(16, 16, 16), RGB15(8, 8, 8)), QUAD, NORMAL(0, 512, 0), VERTEX(-64,-64,-64), COMMAND(CVERTEX, CVERTEX, CVERTEX, CNORMAL), VERTEX( 64,-64,-64), VERTEX( 64,-64, 64), VERTEX(-64,-64, 64), NORMAL(0, 511, 0), COMMAND(CVERTEX, CVERTEX, CVERTEX, CVERTEX), VERTEX(-64, 64,-64), VERTEX(-64, 64, 64), VERTEX( 64, 64, 64), VERTEX( 64, 64,-64), COMMAND(CNORMAL, CVERTEX, CVERTEX, CVERTEX), NORMAL(512, 0, 0),
void add2bbox( /* expand bounding box to fit object */ register OBJREC *o, FVECT bbmin, FVECT bbmax ) { CONE *co; FACE *fo; INSTANCE *io; MESHINST *mi; FVECT v; register int i, j; switch (o->otype) { case OBJ_SPHERE: case OBJ_BUBBLE: if (o->oargs.nfargs != 4) objerror(o, USER, "bad arguments"); for (i = 0; i < 3; i++) { VCOPY(v, o->oargs.farg); v[i] -= o->oargs.farg[3]; point2bbox(v, bbmin, bbmax); v[i] += 2.0 * o->oargs.farg[3]; point2bbox(v, bbmin, bbmax); } break; case OBJ_FACE: fo = getface(o); j = fo->nv; while (j--) point2bbox(VERTEX(fo,j), bbmin, bbmax); break; case OBJ_CONE: case OBJ_CUP: case OBJ_CYLINDER: case OBJ_TUBE: case OBJ_RING: co = getcone(o, 0); if (o->otype != OBJ_RING) circle2bbox(CO_P0(co), co->ad, CO_R0(co), bbmin, bbmax); circle2bbox(CO_P1(co), co->ad, CO_R1(co), bbmin, bbmax); break; case OBJ_INSTANCE: io = getinstance(o, IO_BOUNDS); for (j = 0; j < 8; j++) { for (i = 0; i < 3; i++) { v[i] = io->obj->scube.cuorg[i]; if (j & 1<<i) v[i] += io->obj->scube.cusize; } multp3(v, v, io->x.f.xfm); point2bbox(v, bbmin, bbmax); } break; case OBJ_MESH: mi = getmeshinst(o, IO_BOUNDS); for (j = 0; j < 8; j++) { for (i = 0; i < 3; i++) { v[i] = mi->msh->mcube.cuorg[i]; if (j & 1<<i) v[i] += mi->msh->mcube.cusize; } multp3(v, v, mi->x.f.xfm); point2bbox(v, bbmin, bbmax); } break; } }
static void emit_polyline(ALLEGRO_PRIM_VERTEX_CACHE* cache, const float* vertices, int vertex_stride, int vertex_count, int join_style, int cap_style, float thickness, float miter_limit) { # define VERTEX(index) ((const float*)(((uint8_t*)vertices) + vertex_stride * ((vertex_count + (index)) % vertex_count))) float l0[2], l1[2]; float r0[2], r1[2]; float p0[2], p1[2]; float radius; int steps; int i; ASSERT(thickness > 0.0f); /* Discard invalid lines. */ if (vertex_count < 2) return; radius = 0.5f * thickness; /* Single line cannot be closed. If user forgot to explicitly specify * most desired alternative cap style, we just disable capping at all. */ if (vertex_count == 2 && cap_style == ALLEGRO_LINE_CAP_CLOSED) cap_style = ALLEGRO_LINE_CAP_NONE; /* Prepare initial set of vertices. */ if (cap_style != ALLEGRO_LINE_CAP_CLOSED) { /* We can emit ending caps right now. * * VERTEX(-2) and similar are safe, because it at this place * it is guaranteed that there are at least two vertices * in the buffer. */ emit_end_cap(cache, cap_style, VERTEX(1), VERTEX(0), radius); emit_end_cap(cache, cap_style, VERTEX(-2), VERTEX(-1), radius); /* Compute points on the left side of the very first segment. */ compute_end_cross_points(VERTEX(1), VERTEX(0), radius, p1, p0); /* For non-closed line we have N - 1 steps, but since we iterate * from one, N is right value. */ steps = vertex_count; } else { /* Compute points on the left side of the very first segment. */ compute_cross_points(VERTEX(-1), VERTEX(0), VERTEX(1), radius, l0, l1, p0, p1, NULL, NULL, NULL); /* Closed line use N steps, because last vertex have to be * connected with first one. */ steps = vertex_count + 1; } /* Process segments. */ for (i = 1; i < steps; ++i) { /* Pick vertex and their neighbors. */ const float* v0 = VERTEX(i - 1); const float* v1 = VERTEX(i); const float* v2 = VERTEX(i + 1); /* Choose correct cross points. */ if ((cap_style == ALLEGRO_LINE_CAP_CLOSED) || (i < steps - 1)) { float middle[2]; float miter_distance; float angle; /* Compute cross points. */ compute_cross_points(v0, v1, v2, radius, l0, l1, r0, r1, middle, &angle, &miter_distance); /* Emit join. */ if (angle >= 0.0f) emit_join(cache, join_style, v1, l0, r0, radius, middle, angle, miter_distance, miter_limit); else emit_join(cache, join_style, v1, r1, l1, radius, middle, angle, miter_distance, miter_limit); } else compute_end_cross_points(v0, v1, radius, l0, l1); /* Emit triangles. */ _al_prim_cache_push_triangle(cache, v0, v1, l1); _al_prim_cache_push_triangle(cache, v0, l1, p1); _al_prim_cache_push_triangle(cache, v0, p0, l0); _al_prim_cache_push_triangle(cache, v0, l0, v1); /* Save current most right vertices. */ memcpy(p0, r0, sizeof(float) * 2); memcpy(p1, r1, sizeof(float) * 2); } # undef VERTEX }
Box::Box( const Vector &corner1, const Vector &corner2 ) : corner_min( corner1 ) , corner_max( corner2 ) { InitUnit(); draw_sequence = 3; setEnvMap( GFXFALSE ); blendSrc = ONE; blendDst = ONE; Box *oldmesh; string hash_key = string( "@@Box" )+"#"+tostring( corner1 )+"#"+tostring( corner2 ); //cerr << "hashkey: " << hash_key << endl; if ( 0 != ( oldmesh = (Box*) meshHashTable.Get( hash_key ) ) ) { *this = *oldmesh; oldmesh->refcount++; orig = oldmesh; return; } int a = 0; GFXVertex *vertices = new GFXVertex[18]; #define VERTEX( ax, ay, az ) \ do {vertices[a].x = ax; \ vertices[a].y = ay; \ vertices[a].z = az; \ vertices[a].i = ax; \ vertices[a].j = ay; \ vertices[a].k = az; \ vertices[a].s = 0; \ vertices[a].t = 0; \ a++; \ } \ while (0) VERTEX( corner_max.i, corner_min.j, corner_max.k ); VERTEX( corner_min.i, corner_min.j, corner_max.k ); VERTEX( corner_min.i, corner_min.j, corner_min.k ); VERTEX( corner_max.i, corner_min.j, corner_min.k ); VERTEX( corner_max.i, corner_max.j, corner_min.k ); VERTEX( corner_min.i, corner_max.j, corner_min.k ); VERTEX( corner_min.i, corner_max.j, corner_max.k ); VERTEX( corner_max.i, corner_max.j, corner_max.k ); a = 8; VERTEX( corner_max.i, corner_min.j, corner_max.k ); VERTEX( corner_min.i, corner_min.j, corner_max.k ); VERTEX( corner_min.i, corner_max.j, corner_max.k ); VERTEX( corner_max.i, corner_max.j, corner_max.k ); VERTEX( corner_max.i, corner_max.j, corner_min.k ); VERTEX( corner_min.i, corner_max.j, corner_min.k ); VERTEX( corner_min.i, corner_min.j, corner_min.k ); VERTEX( corner_max.i, corner_min.j, corner_min.k ); VERTEX( corner_max.i, corner_min.j, corner_max.k ); VERTEX( corner_min.i, corner_min.j, corner_max.k ); int offsets[2]; offsets[0] = 8; offsets[1] = 10; enum POLYTYPE polys[2]; polys[0] = GFXQUAD; polys[1] = GFXQUADSTRIP; vlist = new GFXVertexList( polys, 18, vertices, 2, offsets ); //quadstrips[0] = new GFXVertexList(GFXQUADSTRIP,10,vertices); delete[] vertices; meshHashTable.Put( hash_key, this ); orig = this; refcount++; draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1]; #undef VERTEX }