void Bumper::GenerateSocketMesh(Vertex3D_NoTex2 *buf) { const float scalexy = m_d.m_radius*2.0f; for (int i = 0; i < bumperSocketNumVertices; i++) { Vertex3Ds vert(bumperSocket[i].x, bumperSocket[i].y, bumperSocket[i].z); vert = m_fullMatrix.MultiplyVector(vert); buf[i].x = vert.x*scalexy + m_d.m_vCenter.x; buf[i].y = vert.y*scalexy + m_d.m_vCenter.y; // scale z by 0.6 to make the skirt a bit more flat buf[i].z = (0.6f*vert.z*m_d.m_heightScale)*m_ptable->m_BG_scalez[m_ptable->m_BG_current_set] + m_baseHeight; vert = Vertex3Ds(bumperSocket[i].nx, bumperSocket[i].ny, bumperSocket[i].nz); vert = m_fullMatrix.MultiplyVectorNoTranslate(vert); buf[i].nx = vert.x; buf[i].ny = vert.y; buf[i].nz = vert.z; buf[i].tu = bumperSocket[i].tu; buf[i].tv = bumperSocket[i].tv; } }
/* Loads a curve from a ".vert" file, which is constructed as such: * 2 //First line is the number of vec3f's to read (call this 'n') * 1.0 1.0 1.0 // Second line is always the colour to render the curve * -1.0 1.0 0.0 // The remaining n -1 lines are the vertices of the curve */ void FileHelper::loadCurveFromFile(const char* file, Renderable & curve){ char buffer[50]; FILE* fp; int numPoints; fp = fopen(file, "r"); fgets(buffer, 50, fp); numPoints = atoi(buffer); std::vector<Vec3f> verts; for(int i = 0; i < numPoints; i++){ float temp1, temp2, temp3; fgets(buffer, 50, fp); sscanf(buffer, "%f %f %f\n", &temp1, &temp2, &temp3); Vec3f vert(temp1, temp2, temp3); // First point is the colour if(i == 0) { curve.setColour(vert); } // Remaining points are the vertices else { verts.push_back(vert); } } curve.setVerts(verts); fclose(fp); printf("Loaded %s!\n", file); }
double start(FILE* in){ double f, R, t, r, g; //f : 파리 반지름, R : 라켓 바깥 반지름, t : 라켓 두께, r : 줄 두께, g : 줄 간격 double s; //누적 fscanf(in, "%lf", &f); fscanf(in, "%lf", &R); fscanf(in, "%lf", &t); fscanf(in, "%lf", &r); fscanf(in, "%lf", &g); if(2*f >= g) { //gap이 좁을 경우 종료 return 1.0; } t = t + f; // 유효면적(?) r = r + f; g = g - 2*f; coordinate d; d.x = r; d.y = r; s = 0; while(d.y*d.y + d.x*d.x < (R-t)*(R-t)){ s += vert(d, f, R, t, r, g); d.x += g+2*r; d.y += g+2*r; } s *= 8; return 1.0-s/(acos(-1)*R*R); }
bool CPath::getShape(CGeomProxy* geomObj[1],CShape* shapeObj[1]) { bool retVal=false; if (_shapingEnabled&&(_pathShapeVertices.size()!=0)) { std::vector<float> vert(_pathShapeVertices); C7Vector tr(getCumulativeTransformation()); for (int i=0;i<int(vert.size()/3);i++) { C3Vector v(&vert[3*i]); v=tr*v; vert[3*i+0]=v(0); vert[3*i+1]=v(1); vert[3*i+2]=v(2); } std::vector<int> ind(_pathShapeIndices); geomObj[0]=new CGeomProxy(NULL,vert,ind,NULL,NULL); shapeObj[0]=new CShape(); shapeObj[0]->setLocalTransformation(geomObj[0]->getCreationTransformation()); geomObj[0]->setCreationTransformation(C7Vector::identityTransformation); retVal=true; } return(retVal); }
int AssimpScene::uncompress_recursive_old(float * arr, float arr_size, float vertex_size, int arr_index_start, const aiScene * sc, const aiNode * nd, aiMatrix4x4 * matrix_before) { aiMatrix4x4 m = (*matrix_before) * nd->mTransformation; int arr_index = arr_index_start; int count_vertex = 0; //combined sum is returned at the end for (int n = 0; n < nd->mNumMeshes; ++n) { const aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]]; for (int t = 0; t < mesh->mNumFaces; ++t) { const struct aiFace* face = &mesh->mFaces[t]; bool isNormal = mesh->mNormals != NULL; for (int i = 0; i < face->mNumIndices; i++) { count_vertex++; int index = face->mIndices[i]; aiVector3D vert(m*mesh->mVertices[index]), normal((isNormal)? aiVector3D (mesh->mNormals[index]): aiVector3D()); adjust_scene_roperty(vert.x, vert.y, vert.z); arr[arr_index] = vert.x; arr[arr_index + 1] = vert.y; arr[arr_index + 2] = vert.z; arr[arr_index + 3] = normal.x; arr[arr_index + 4] = normal.y; arr[arr_index + 5] = normal.z; arr_index += vertex_size; } } } for (int n = 0; n < nd->mNumChildren; ++n) { count_vertex += uncompress_recursive_old(arr, arr_size, vertex_size, arr_index, sc, nd, &m); } return count_vertex; }
int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { int size = 1, i, j, data_blocks; char datagrid[136][120]; int row, col; int sub_version = 0; if((symbol->option_2 < 0) || (symbol->option_2 > 10)) { strcpy(symbol->errtxt, "Invalid symbol size"); return ERROR_INVALID_OPTION; } if(symbol->option_2 == 9) { /* Version S */ int codewords; short int elreg[112]; unsigned int data[15], ecc[15]; int stream[30]; int block_width; if(length > 18) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; } if(is_sane(NEON, source, length) == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)"); return ERROR_INVALID_DATA; } sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */ if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */ if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */ binary_load(elreg, (char *)source, length); hex_dump(elreg); for(i = 0; i < 15; i++) { data[i] = 0; ecc[i] = 0; } for(i = 0; i < codewords; i++) { data[codewords - i - 1] += 1 * elreg[(i * 5)]; data[codewords - i - 1] += 2 * elreg[(i * 5) + 1]; data[codewords - i - 1] += 4 * elreg[(i * 5) + 2]; data[codewords - i - 1] += 8 * elreg[(i * 5) + 3]; data[codewords - i - 1] += 16 * elreg[(i * 5) + 4]; } rs_init_gf(0x25); rs_init_code(codewords, 1); rs_encode_long(codewords, data, ecc); rs_free(); for(i = 0; i < codewords; i++) { stream[i] = data[i]; stream[i + codewords] = ecc[codewords - i - 1]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < 2; row++) { for(col = 0; col < block_width; col++) { if(stream[i] & 0x10) { datagrid[row * 2][col * 5] = '1'; } if(stream[i] & 0x08) { datagrid[row * 2][(col * 5) + 1] = '1'; } if(stream[i] & 0x04) { datagrid[row * 2][(col * 5) + 2] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][col * 5] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 1] = '1'; } if(stream[i + 1] & 0x10) { datagrid[row * 2][(col * 5) + 3] = '1'; } if(stream[i + 1] & 0x08) { datagrid[row * 2][(col * 5) + 4] = '1'; } if(stream[i + 1] & 0x04) { datagrid[(row * 2) + 1][(col * 5) + 2] = '1'; } if(stream[i + 1] & 0x02) { datagrid[(row * 2) + 1][(col * 5) + 3] = '1'; } if(stream[i + 1] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 4] = '1'; } i += 2; } } size = 9; symbol->rows = 8; symbol->width = 10 * sub_version + 1; } if(symbol->option_2 == 10) { /* Version T */ unsigned int data[40], ecc[25]; unsigned int stream[65]; int data_length; int data_cw, ecc_cw, block_width; for(i = 0; i < 40; i++) { data[i] = 0; } data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; } if(data_length > 38) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; } size = 10; sub_version = 3; data_cw = 38; ecc_cw = 22; block_width = 12; if(data_length <= 24) { sub_version = 2; data_cw = 24; ecc_cw = 16; block_width = 8; } if(data_length <= 10) { sub_version = 1; data_cw = 10; ecc_cw = 10; block_width = 4; } for(i = data_length; i < data_cw; i++) { data[i] = 129; /* Pad */ } /* Calculate error correction data */ rs_init_gf(0x12d); rs_init_code(ecc_cw, 1); rs_encode_long(data_cw, data, ecc); rs_free(); /* "Stream" combines data and error correction data */ for(i = 0; i < data_cw; i++) { stream[i] = data[i]; } for(i = 0; i < ecc_cw; i++) { stream[data_cw + i] = ecc[ecc_cw - i - 1]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < 5; row++) { for(col = 0; col < block_width; col++) { if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; } if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; } if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; } if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; } if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; } if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; } i++; } } symbol->rows = 16; symbol->width = (sub_version * 16) + 1; } if((symbol->option_2 != 9) && (symbol->option_2 != 10)) { /* Version A to H */ unsigned int data[1500], ecc[600]; unsigned int sub_data[190], sub_ecc[75]; unsigned int stream[2100]; int data_length; for(i = 0; i < 1500; i++) { data[i] = 0; } data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; } for(i = 7; i >= 0; i--) { if(c1_data_length[i] >= data_length) { size = i + 1; } } if(symbol->option_2 > size) { size = symbol->option_2; } for(i = data_length; i < c1_data_length[size - 1]; i++) { data[i] = 129; /* Pad */ } /* Calculate error correction data */ data_length = c1_data_length[size - 1]; for(i = 0; i < 190; i++) { sub_data[i] = 0; } for(i = 0; i < 75; i++) { sub_ecc[i] = 0; } data_blocks = c1_blocks[size - 1]; rs_init_gf(0x12d); rs_init_code(c1_ecc_blocks[size - 1], 0); for(i = 0; i < data_blocks; i++) { for(j = 0; j < c1_data_blocks[size - 1]; j++) { sub_data[j] = data[j * data_blocks + i]; } rs_encode_long(c1_data_blocks[size - 1], sub_data, sub_ecc); for(j = 0; j < c1_ecc_blocks[size - 1]; j++) { ecc[c1_ecc_length[size - 1] - (j * data_blocks + i) - 1] = sub_ecc[j]; } } rs_free(); /* "Stream" combines data and error correction data */ for(i = 0; i < data_length; i++) { stream[i] = data[i]; } for(i = 0; i < c1_ecc_length[size - 1]; i++) { stream[data_length + i] = ecc[i]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < c1_grid_height[size - 1]; row++) { for(col = 0; col < c1_grid_width[size - 1]; col++) { if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; } if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; } if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; } if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; } if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; } if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; } i++; } } /* for(i = 0; i < (c1_grid_height[size - 1] * 2); i++) { for(j = 0; j < (c1_grid_width[size - 1] * 4); j++) { printf("%c", datagrid[i][j]); } printf("\n"); } */ symbol->rows = c1_height[size - 1]; symbol->width = c1_width[size - 1]; } switch(size) { case 1: /* Version A */ central_finder(symbol, 6, 3, 1); vert(symbol, 4, 6, 1); vert(symbol, 12, 5, 0); set_module(symbol, 5, 12); spigot(symbol, 0); spigot(symbol, 15); block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2); block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0); block_copy(symbol, datagrid, 5, 12, 5, 4, 6, 2); break; case 2: /* Version B */ central_finder(symbol, 8, 4, 1); vert(symbol, 4, 8, 1); vert(symbol, 16, 7, 0); set_module(symbol, 7, 16); spigot(symbol, 0); spigot(symbol, 21); block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2); block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0); block_copy(symbol, datagrid, 7, 16, 7, 4, 8, 2); break; case 3: /* Version C */ central_finder(symbol, 11, 4, 2); vert(symbol, 4, 11, 1); vert(symbol, 26, 13, 1); vert(symbol, 4, 10, 0); vert(symbol, 26, 10, 0); spigot(symbol, 0); spigot(symbol, 27); block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4); block_copy(symbol, datagrid, 10, 0, 10, 4, 8, 0); block_copy(symbol, datagrid, 10, 4, 10, 20, 8, 2); block_copy(symbol, datagrid, 10, 24, 10, 4, 8, 4); break; case 4: /* Version D */ central_finder(symbol, 16, 5, 1); vert(symbol, 4, 16, 1); vert(symbol, 20, 16, 1); vert(symbol, 36, 16, 1); vert(symbol, 4, 15, 0); vert(symbol, 20, 15, 0); vert(symbol, 36, 15, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 27); spigot(symbol, 39); block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2); block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4); block_copy(symbol, datagrid, 0, 32, 15, 4, 0, 6); block_copy(symbol, datagrid, 15, 0, 15, 4, 10, 0); block_copy(symbol, datagrid, 15, 4, 15, 14, 10, 2); block_copy(symbol, datagrid, 15, 18, 15, 14, 10, 4); block_copy(symbol, datagrid, 15, 32, 15, 4, 10, 6); break; case 5: /* Version E */ central_finder(symbol, 22, 5, 2); vert(symbol, 4, 22, 1); vert(symbol, 26, 24, 1); vert(symbol, 48, 22, 1); vert(symbol, 4, 21, 0); vert(symbol, 26, 21, 0); vert(symbol, 48, 21, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 39); spigot(symbol, 51); block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4); block_copy(symbol, datagrid, 0, 44, 21, 4, 0, 6); block_copy(symbol, datagrid, 21, 0, 21, 4, 10, 0); block_copy(symbol, datagrid, 21, 4, 21, 20, 10, 2); block_copy(symbol, datagrid, 21, 24, 21, 20, 10, 4); block_copy(symbol, datagrid, 21, 44, 21, 4, 10, 6); break; case 6: /* Version F */ central_finder(symbol, 31, 5, 3); vert(symbol, 4, 31, 1); vert(symbol, 26, 35, 1); vert(symbol, 48, 31, 1); vert(symbol, 70, 35, 1); vert(symbol, 4, 30, 0); vert(symbol, 26, 30, 0); vert(symbol, 48, 30, 0); vert(symbol, 70, 30, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 45); spigot(symbol, 57); spigot(symbol, 69); block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4); block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6); block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8); block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0); block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2); block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4); block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6); block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8); break; case 7: /* Version G */ central_finder(symbol, 47, 6, 2); vert(symbol, 6, 47, 1); vert(symbol, 27, 49, 1); vert(symbol, 48, 47, 1); vert(symbol, 69, 49, 1); vert(symbol, 90, 47, 1); vert(symbol, 6, 46, 0); vert(symbol, 27, 46, 0); vert(symbol, 48, 46, 0); vert(symbol, 69, 46, 0); vert(symbol, 90, 46, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 36); spigot(symbol, 67); spigot(symbol, 79); spigot(symbol, 91); spigot(symbol, 103); block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0); block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2); block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4); block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6); block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8); block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10); block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0); block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2); block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4); block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6); block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8); block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10); break; case 8: /* Version H */ central_finder(symbol, 69, 6, 3); vert(symbol, 6, 69, 1); vert(symbol, 26, 73, 1); vert(symbol, 46, 69, 1); vert(symbol, 66, 73, 1); vert(symbol, 86, 69, 1); vert(symbol, 106, 73, 1); vert(symbol, 126, 69, 1); vert(symbol, 6, 68, 0); vert(symbol, 26, 68, 0); vert(symbol, 46, 68, 0); vert(symbol, 66, 68, 0); vert(symbol, 86, 68, 0); vert(symbol, 106, 68, 0); vert(symbol, 126, 68, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 36); spigot(symbol, 48); spigot(symbol, 60); spigot(symbol, 87); spigot(symbol, 99); spigot(symbol, 111); spigot(symbol, 123); spigot(symbol, 135); spigot(symbol, 147); block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0); block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2); block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4); block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6); block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8); block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10); block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12); block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14); block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0); block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2); block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4); block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6); block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8); block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10); block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12); block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14); break; case 9: /* Version S */ horiz(symbol, 5, 1); horiz(symbol, 7, 1); set_module(symbol, 6, 0); set_module(symbol, 6, symbol->width - 1); unset_module(symbol, 7, 1); unset_module(symbol, 7, symbol->width - 2); switch(sub_version) { case 1: /* Version S-10 */ set_module(symbol, 0, 5); block_copy(symbol, datagrid, 0, 0, 4, 5, 0, 0); block_copy(symbol, datagrid, 0, 5, 4, 5, 0, 1); break; case 2: /* Version S-20 */ set_module(symbol, 0, 10); set_module(symbol, 4, 10); block_copy(symbol, datagrid, 0, 0, 4, 10, 0, 0); block_copy(symbol, datagrid, 0, 10, 4, 10, 0, 1); break; case 3: /* Version S-30 */ set_module(symbol, 0, 15); set_module(symbol, 4, 15); set_module(symbol, 6, 15); block_copy(symbol, datagrid, 0, 0, 4, 15, 0, 0); block_copy(symbol, datagrid, 0, 15, 4, 15, 0, 1); break; } break; case 10: /* Version T */ horiz(symbol, 11, 1); horiz(symbol, 13, 1); horiz(symbol, 15, 1); set_module(symbol, 12, 0); set_module(symbol, 12, symbol->width - 1); set_module(symbol, 14, 0); set_module(symbol, 14, symbol->width - 1); unset_module(symbol, 13, 1); unset_module(symbol, 13, symbol->width - 2); unset_module(symbol, 15, 1); unset_module(symbol, 15, symbol->width - 2); switch(sub_version) { case 1: /* Version T-16 */ set_module(symbol, 0, 8); set_module(symbol, 10, 8); block_copy(symbol, datagrid, 0, 0, 10, 8, 0, 0); block_copy(symbol, datagrid, 0, 8, 10, 8, 0, 1); break; case 2: /* Version T-32 */ set_module(symbol, 0, 16); set_module(symbol, 10, 16); set_module(symbol, 12, 16); block_copy(symbol, datagrid, 0, 0, 10, 16, 0, 0); block_copy(symbol, datagrid, 0, 16, 10, 16, 0, 1); break; case 3: /* Verion T-48 */ set_module(symbol, 0, 24); set_module(symbol, 10, 24); set_module(symbol, 12, 24); set_module(symbol, 14, 24); block_copy(symbol, datagrid, 0, 0, 10, 24, 0, 0); block_copy(symbol, datagrid, 0, 24, 10, 24, 0, 1); break; } break; } for(i = 0; i < symbol->rows; i++) { symbol->row_height[i] = 1; } return 0; }
bool QChain::testPoint(const QPointF &point) const { QPointF p = mapFromItem(world(), point); std::vector<Vector2d> vert(m_vertices.begin(), m_vertices.end() - 1); return Geometry::pointInPolygon(vert.begin(), vert.end(), Vector2d(p)); }
static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, PoolVector<Face3> &p_faces) { ERR_FAIL_INDEX(x, len_x); ERR_FAIL_INDEX(y, len_y); ERR_FAIL_INDEX(z, len_z); if (p_cell_status[x][y][z] & _CELL_EXTERIOR) return; /* static const Vector3 vertices[8]={ Vector3(0,0,0), Vector3(0,0,1), Vector3(0,1,0), Vector3(0,1,1), Vector3(1,0,0), Vector3(1,0,1), Vector3(1,1,0), Vector3(1,1,1), }; */ #define vert(m_idx) Vector3((m_idx & 4) >> 2, (m_idx & 2) >> 1, m_idx & 1) static const uint8_t indices[6][4] = { { 7, 6, 4, 5 }, { 7, 3, 2, 6 }, { 7, 5, 1, 3 }, { 0, 2, 3, 1 }, { 0, 1, 5, 4 }, { 0, 4, 6, 2 }, }; /* {0,1,2,3}, {0,1,4,5}, {0,2,4,6}, {4,5,6,7}, {2,3,7,6}, {1,3,5,7}, {0,2,3,1}, {0,1,5,4}, {0,4,6,2}, {7,6,4,5}, {7,3,2,6}, {7,5,1,3}, */ for (int i = 0; i < 6; i++) { Vector3 face_points[4]; int disp_x = x + ((i % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); int disp_y = y + (((i - 1) % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); int disp_z = z + (((i - 2) % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); bool plot = false; if (disp_x < 0 || disp_x >= len_x) plot = true; if (disp_y < 0 || disp_y >= len_y) plot = true; if (disp_z < 0 || disp_z >= len_z) plot = true; if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR)) plot = true; if (!plot) continue; for (int j = 0; j < 4; j++) face_points[j] = vert(indices[i][j]) + Vector3(x, y, z); p_faces.push_back( Face3( face_points[0], face_points[1], face_points[2])); p_faces.push_back( Face3( face_points[2], face_points[3], face_points[0])); } }
typename property_traits<CoreMap>::value_type core_numbers_impl(Graph& g, CoreMap c, PositionMap pos, Visitor vis) { typedef typename graph_traits<Graph>::vertices_size_type size_type; typedef typename graph_traits<Graph>::degree_size_type degree_type; typedef typename graph_traits<Graph>::vertex_descriptor vertex; typename graph_traits<Graph>::vertex_iterator vi,vi_end; // store the vertex core numbers typename property_traits<CoreMap>::value_type v_cn = 0; // compute the maximum degree (degrees are in the coremap) typename graph_traits<Graph>::degree_size_type max_deg = 0; for (boost::tie(vi,vi_end) = vertices(g); vi!=vi_end; ++vi) { max_deg = (std::max<typename graph_traits<Graph>::degree_size_type>)(max_deg, get(c,*vi)); } // store the vertices in bins by their degree // allocate two extra locations to ease boundary cases std::vector<size_type> bin(max_deg+2); for (boost::tie(vi,vi_end) = vertices(g); vi!=vi_end; ++vi) { ++bin[get(c,*vi)]; } // this loop sets bin[d] to the starting position of vertices // with degree d in the vert array for the bucket sort size_type cur_pos = 0; for (degree_type cur_deg = 0; cur_deg < max_deg+2; ++cur_deg) { degree_type tmp = bin[cur_deg]; bin[cur_deg] = cur_pos; cur_pos += tmp; } // perform the bucket sort with pos and vert so that // pos[0] is the vertex of smallest degree std::vector<vertex> vert(num_vertices(g)); for (boost::tie(vi,vi_end) = vertices(g); vi!=vi_end; ++vi) { vertex v=*vi; size_type p=bin[get(c,v)]; put(pos,v,p); vert[p]=v; ++bin[get(c,v)]; } // we ``abused'' bin while placing the vertices, now, // we need to restore it std::copy(boost::make_reverse_iterator(bin.end()-2), boost::make_reverse_iterator(bin.begin()), boost::make_reverse_iterator(bin.end()-1)); // now simulate removing the vertices for (size_type i=0; i < num_vertices(g); ++i) { vertex v = vert[i]; vis.examine_vertex(v,g); v_cn = get(c,v); typename graph_traits<Graph>::out_edge_iterator oi,oi_end; for (boost::tie(oi,oi_end) = out_edges(v,g); oi!=oi_end; ++oi) { vis.examine_edge(*oi,g); vertex u = target(*oi,g); // if c[u] > c[v], then u is still in the graph, if (get(c,u) > v_cn) { degree_type deg_u = get(c,u); degree_type pos_u = get(pos,u); // w is the first vertex with the same degree as u // (this is the resort operation!) degree_type pos_w = bin[deg_u]; vertex w = vert[pos_w]; if (u!=v) { // swap u and w put(pos,u,pos_w); put(pos,w,pos_u); vert[pos_w] = u; vert[pos_u] = w; } // now, the vertices array is sorted assuming // we perform the following step // start the set of vertices with degree of u // one into the future (this now points at vertex // w which we swapped with u). ++bin[deg_u]; // we are removing v from the graph, so u's degree // decreases put(c,u,get(c,u)-1); } } vis.finish_vertex(v,g); } return v_cn; }
int main(int argc, char **argv) { if (argc != 3) { std::cout << "Usage: XO_tester <program1> <program2>\n"; return 1; } const char *program1 = argv[1]; const char *program2 = argv[2]; //initLog(program1, program2); // save field and score before the first move saveField(); ExecutionResult result = ER_OK; for (int move = 0 ; move < size * size ; ++move) { bool first = move % 2 == 0; std::ostringstream outs; outs << !first + 1 << "\n"; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { outs << field[i][j] << " "; } outs << "\n"; } std::string output; result = runProcess(first ? program1 : program2, outs.str(), output, 1000, 64000); if (result == ER_OK) { std::istringstream ins(output); int x, y; ins >> y >> x; if (x >= 1 && x <= size && y >= 1 && y <= size && !field[y-1][x-1]) { printLog(first, result, output); int xo = first ? 1 : 2; field[y-1][x-1] = xo; saveField(); // check win if (diag1(xo) || diag2(xo) || horz(xo, y - 1) || vert(xo, x - 1)) { result = ER_WIN; printLog(first, result, output); break; } } else { result = ER_IM; printLog(first, result, output); break; } } else {
/* * ellipsoidGate does not follow the regular transforming process * for historical reason, it is defined in 256 * 256 scale, and we don't know * how to translate it to the transformed scale yet, thus simply throw exception * for the EllipsoidGate defined on the non-linear data channel * for linear channels, we will do the same rescaling here. */ void ellipsoidGate::transforming(trans_local & trans){ if(!Transformed()) { /* * get channel names to select respective transformation functions */ string channel_x=param.xName(); string channel_y=param.yName(); //get vertices in valarray format vertices_valarray vert(antipodal_vertices); transformation * trans_x=trans.getTran(channel_x); transformation * trans_y=trans.getTran(channel_y); /* * we don't know the exact scaling rules for ellipsoidGate of non-linear space yet * so simply throws error for now */ string err="Don't know how to scale the ellipsoidGate on the non-linear data space: "; if(trans_x==NULL) { //do the special scaling first for linear ellipsoidGate scaleTrans scale_f(1024);//assuming the max value is always 262144, thus 262144/256 = 1024 if(g_loglevel>=POPULATION_LEVEL) COUT<<"scaling: "<<channel_x<<endl;; scale_f.transforming(vert.x); for(unsigned i=0;i<antipodal_vertices.size();i++) antipodal_vertices.at(i).x=vert.x[i]; } else { err.append(channel_x); throw(domain_error(err)); } if(trans_y==NULL) { //do the special scaling first for linear ellipsoidGate scaleTrans scale_f(1024);//assuming the max value is always 262144, thus 262144/256 = 1024 if(g_loglevel>=POPULATION_LEVEL) COUT<<"scaling: "<<channel_y<<endl;; scale_f.transforming(vert.y); for(unsigned i=0;i<antipodal_vertices.size();i++) antipodal_vertices.at(i).y=vert.y[i]; } else { err.append(channel_y); throw(domain_error(err)); } if(g_loglevel>=POPULATION_LEVEL) COUT<<endl; computeCov(); isTransformed=true; } }
void RoadGraph::_generateMeshVerticesDefault(VBORenderManager& renderManager, const QString &linesN, const QString &pointsN) { ////////////////////////////////////// // EDGES { RoadEdgeIter ei, eend; for (boost::tie(ei, eend) = boost::edges(graph); ei != eend; ++ei) { if (!graph[*ei]->valid) continue; int num = graph[*ei]->polyline3D.size(); if (num <= 1) continue; float halfWidth = graph[*ei]->getWidth()*0.5f;//it should not have /2.0f (but compensated below) std::vector<Vertex> vert(4*(num - 1)); std::vector<Vertex> vertBg(4*(num - 1)); // Type QColor color;// = graph[*ei]->color; QColor colorO; float heightOffset = 0.0f; float heightOffsetO=0.0f; switch (graph[*ei]->type) { case RoadEdge::TYPE_HIGHWAY: heightOffset = 0.8f; heightOffsetO = 0.3f; color=QColor(0xfa,0x9e,0x25); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xdf,0x9c,0x13); halfWidth*=1.4f; break; case RoadEdge::TYPE_BOULEVARD: heightOffset = 0.5f; heightOffsetO = 0.2f; color=QColor(0xff,0xe1,0x68); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xe5,0xbd,0x4d); halfWidth*=1.4f; break; case RoadEdge::TYPE_AVENUE: heightOffset = 0.6f; heightOffsetO = 0.1f; color=QColor(0xff,0xe1,0x68); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xe5,0xbd,0x4d); halfWidth*=1.4f; break; case RoadEdge::TYPE_STREET: heightOffset = 0.4f; heightOffsetO = 0.1f; color=QColor(0xff,0xff,0xff); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xd7,0xd1,0xc7); halfWidth*=1.8f; break; } halfWidth+= G::global().getFloat("2DroadsExtraWidth"); heightOffset+=0.45f;//to have park below heightOffsetO+=0.45f;//to have park below float halfWidthBg = halfWidth + G::global().getFloat("2DroadsStroke");//it should not depend on the type 3.5f QVector3D p0, p1, p2, p3; QVector3D p0Bg, p1Bg, p2Bg, p3Bg; for (int i = 0; i < num - 1; ++i) { QVector3D pt1 = graph[*ei]->polyline3D[i]; QVector3D pt2 = graph[*ei]->polyline3D[i + 1]; QVector3D perp = pt2 - pt1; perp = QVector3D(-perp.y(), perp.x(), 0.0f); perp.normalize(); if (i == 0) { p0 = pt1 + perp * halfWidth; p1 = pt1 - perp * halfWidth; p0Bg = pt1 + perp * halfWidthBg; p1Bg = pt1 - perp * halfWidthBg; } p2 = pt2 - perp * halfWidth; p3 = pt2 + perp * halfWidth; p2Bg = pt2 - perp * halfWidthBg; p3Bg = pt2 + perp * halfWidthBg; QVector3D normal = Util::calculateNormal(p0, p1, p2); if (i < num - 2) { QVector3D pt3 = graph[*ei]->polyline3D[i + 2]; Util::getIrregularBisector(pt1, pt2, pt3, halfWidth, halfWidth, p3); Util::getIrregularBisector(pt1, pt2, pt3, -halfWidth, -halfWidth, p2); Util::getIrregularBisector(pt1, pt2, pt3, halfWidthBg, halfWidthBg, p3Bg); Util::getIrregularBisector(pt1, pt2, pt3, -halfWidthBg, -halfWidthBg, p2Bg); } vert[i*4+0]=Vertex(p0,QVector3D(),QVector3D(0,0,1.0f),QVector3D(0,0,0));// pos color normal texture vert[i*4+1]=Vertex(p1,QVector3D(),QVector3D(0,0,1.0f),QVector3D(1,0,0));// pos color normal texture vert[i*4+2]=Vertex(p2,QVector3D(),QVector3D(0,0,1.0f),QVector3D(1,1,0));// pos color normal texture vert[i*4+2]=Vertex(p3,QVector3D(),QVector3D(0,0,1.0f),QVector3D(0,1,0));// pos color normal texture /* vert[i*4+0]=Vertex(p0.x(),p0.y(),p0.z()+heightOffset,color.redF(),color.greenF(),color.blueF(),0,0,1.0f,0,0,0);// pos color normal texture vert[i*4+1]=Vertex(p1.x(),p1.y(),p1.z()+heightOffset,color.redF(),color.greenF(),color.blueF(),0,0,1.0f,1,0,0);// pos color normal texture vert[i*4+2]=Vertex(p2.x(),p2.y(),p2.z()+heightOffset,color.redF(),color.greenF(),color.blueF(),0,0,1.0f,1,1,0);// pos color normal texture vert[i*4+3]=Vertex(p3.x(),p3.y(),p3.z()+heightOffset,color.redF(),color.greenF(),color.blueF(),0,0,1.0f,0,1,0);// pos color normal texture */ vertBg[i*4+0]=Vertex(p0Bg.x(),p0Bg.y(),p0Bg.z()+heightOffsetO,colorO.redF(),colorO.greenF(),colorO.blueF(),0,0,1.0f,0,0,0);// pos color normal texture vertBg[i*4+1]=Vertex(p1Bg.x(),p1Bg.y(),p1Bg.z()+heightOffsetO,colorO.redF(),colorO.greenF(),colorO.blueF(),0,0,1.0f,0,0,0);// pos color normal texture vertBg[i*4+2]=Vertex(p2Bg.x(),p2Bg.y(),p2Bg.z()+heightOffsetO,colorO.redF(),colorO.greenF(),colorO.blueF(),0,0,1.0f,0,0,0);// pos color normal texture vertBg[i*4+3]=Vertex(p3Bg.x(),p3Bg.y(),p3Bg.z()+heightOffsetO,colorO.redF(),colorO.greenF(),colorO.blueF(),0,0,1.0f,0,0,0);// pos color normal texture p0 = p3; p1 = p2; p0Bg = p3Bg; p1Bg = p2Bg; } //renderManager.addStaticGeometry(linesN, vert, "", GL_QUADS, 1);//MODE=1 color //renderManager.addStaticGeometry(linesN, vertBg, "", GL_QUADS, 1);//MODE=1 color renderManager.addStaticGeometry(linesN, vert, "../data/extures/roads/road_2lines.jpg", GL_QUADS, 2|mode_AdaptTerrain); } } ///////////////////////////////////////////////////// // INTERSECTIONS { RoadVertexIter vi, vend; for (boost::tie(vi, vend) = boost::vertices(graph); vi != vend; ++vi) { if (!graph[*vi]->valid) continue; // get the largest width of the outing edges QColor color;// = graph[*ei]->color; QColor colorO; float heightOffset = 0.0f; float heightOffsetO=0.0f; bool render = false; int maxType=-1; float halfWidth; RoadOutEdgeIter oei, oeend; for (boost::tie(oei, oeend) = boost::out_edges(*vi, graph); oei != oeend; ++oei) { if (!graph[*oei]->valid) continue; //printf("type %d\n",graph[*oei]->type); if(maxType>graph[*oei]->type) continue; maxType=graph[*oei]->type; halfWidth=graph[*oei]->getWidth()*0.5f;//it should not have /2.0f (but compensated below) switch (graph[*oei]->type) { case RoadEdge::TYPE_HIGHWAY: render = true; heightOffset = 0.6f; heightOffsetO = 0.3f; color=QColor(0xfa,0x9e,0x25); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xdf,0x9c,0x13); halfWidth*=1.4f; continue; case RoadEdge::TYPE_BOULEVARD: heightOffset = 0.5f; heightOffsetO = 0.2f; color=QColor(0xff,0xe1,0x68); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xe5,0xbd,0x4d); halfWidth*=1.4f; continue; case RoadEdge::TYPE_AVENUE: render = true; heightOffset = 0.5f; heightOffsetO = 0.2f; color=QColor(0xff,0xe1,0x68); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xe5,0xbd,0x4d); halfWidth*=1.4f; continue; case RoadEdge::TYPE_STREET: render = true; heightOffset = 0.4f; heightOffsetO = 0.2f; color=QColor(0xff,0xff,0xff); colorO=QColor(0x00, 0x00, 0x00);//QColor(0xd7,0xd1,0xc7); halfWidth*=1.8f; continue; } } halfWidth+= G::global().getFloat("2DroadsExtraWidth"); heightOffset+=0.45f;//to have park below heightOffsetO+=0.45f;//to have park below float max_r=halfWidth; float max_rO=halfWidth + G::global().getFloat("2DroadsStroke");//it should not depend on the type 3.5f std::vector<Vertex> vert(3*20); std::vector<Vertex> vertBg(3*20); for (int i = 0; i < 20; ++i) { float angle1 = 2.0 * M_PI * i / 20.0f; float angle2 = 2.0 * M_PI * (i + 1) / 20.0f; vert[i*3+0]=Vertex(graph[*vi]->pt3D.x(), graph[*vi]->pt3D.y(), graph[*vi]->pt3D.z() + heightOffset, color.redF(), color.greenF(), color.blueF(), 0, 0, 1.0f, 0, 0, 0); vert[i*3+1]=Vertex(graph[*vi]->pt3D.x() + max_r * cosf(angle1), graph[*vi]->pt3D.y() + max_r * sinf(angle1), graph[*vi]->pt3D.z() + heightOffset, color.redF(), color.greenF(), color.blueF(), 0, 0, 1.0f, 0, 0, 0); vert[i*3+2]=Vertex(graph[*vi]->pt3D.x() + max_r * cosf(angle2), graph[*vi]->pt3D.y() + max_r * sinf(angle2), graph[*vi]->pt3D.z() + heightOffset, color.redF(), color.greenF(), color.blueF(), 0, 0, 1.0f, 0, 0, 0); vertBg[i*3+0]=Vertex(graph[*vi]->pt3D.x(), graph[*vi]->pt3D.y(), graph[*vi]->pt3D.z() + heightOffsetO, colorO.redF(), colorO.greenF(), colorO.blueF(), 0, 0, 1.0f, 0, 0, 0); vertBg[i*3+1]=Vertex(graph[*vi]->pt3D.x() + max_rO * cosf(angle1), graph[*vi]->pt3D.y() + max_rO * sinf(angle1), graph[*vi]->pt3D.z() + heightOffsetO, colorO.redF(), colorO.greenF(), colorO.blueF(), 0, 0, 1.0f, 0, 0, 0); vertBg[i*3+2]=Vertex(graph[*vi]->pt3D.x() + max_rO * cosf(angle2), graph[*vi]->pt3D.y() + max_rO * sinf(angle2), graph[*vi]->pt3D.z() + heightOffsetO, colorO.redF(), colorO.greenF(), colorO.blueF(), 0, 0, 1.0f, 0, 0, 0); } //renderManager.addStaticGeometry(pointsN, vert, "", GL_TRIANGLES, 1);//MODE=1 color //renderManager.addStaticGeometry(pointsN, vertBg, "", GL_TRIANGLES, 1);//MODE=1 color } } }
void ZoneDefaultInteraction::onProximityUpdate(QPointF const& mouse_pos, InteractionState& interaction) { m_screenMousePos = mouse_pos; QTransform const to_screen(m_rContext.imageView().imageToWidget()); QTransform const from_screen(m_rContext.imageView().widgetToImage()); QPointF const image_mouse_pos(from_screen.map(mouse_pos)); m_ptrNearestVertex.reset(); m_ptrNearestVertexSpline.reset(); m_nearestSegment = SplineSegment(); m_ptrNearestSegmentSpline.reset(); Proximity best_vertex_proximity; Proximity best_segment_proximity; bool has_zone_under_mouse = false; BOOST_FOREACH(EditableZoneSet::Zone const& zone, m_rContext.zones()) { EditableSpline::Ptr const& spline = zone.spline(); if (!has_zone_under_mouse) { QPainterPath path; path.setFillRule(Qt::WindingFill); path.addPolygon(spline->toPolygon()); has_zone_under_mouse = path.contains(image_mouse_pos); } // Process vertices. for (SplineVertex::Ptr vert(spline->firstVertex()); vert; vert = vert->next(SplineVertex::NO_LOOP)) { Proximity const proximity(mouse_pos, to_screen.map(vert->point())); if (proximity < best_vertex_proximity) { m_ptrNearestVertex = vert; m_ptrNearestVertexSpline = spline; best_vertex_proximity = proximity; } } // Process segments. for (EditableSpline::SegmentIterator it(*spline); it.hasNext(); ) { SplineSegment const segment(it.next()); QLineF const line(to_screen.map(segment.toLine())); QPointF point_on_segment; Proximity const proximity(Proximity::pointAndLineSegment(mouse_pos, line, &point_on_segment)); if (proximity < best_segment_proximity) { m_nearestSegment = segment; m_ptrNearestSegmentSpline = spline; best_segment_proximity = proximity; m_screenPointOnSegment = point_on_segment; } } } interaction.updateProximity(m_vertexProximity, best_vertex_proximity, 1); interaction.updateProximity(m_segmentProximity, best_segment_proximity, 0); if (has_zone_under_mouse) { Proximity const zone_area_proximity(std::min(best_vertex_proximity, best_segment_proximity)); interaction.updateProximity(m_zoneAreaProximity, zone_area_proximity, -1, zone_area_proximity); } }
TessellationExample(void) : prog() , projection_matrix(prog, "ProjectionMatrix") , camera_matrix(prog, "CameraMatrix") { VertexShader vert(ObjectDesc("Vertex")); vert.Source( "#version 330\n" "uniform mat4 CameraMatrix;" "in vec4 Position;" "out vec4 vertPosition;" "void main(void)" "{" " vertPosition = CameraMatrix * Position;" "}" ); vert.Compile(); prog << vert; TessControlShader teco(ObjectDesc("TessControl")); teco.Source( "#version 330\n" "#extension ARB_tessellation_shader: enable\n" "layout(vertices = 16) out;" "in vec4 vertPosition[];" "patch out vec3 tecoPosition[16];" "void main(void)" "{" " if(gl_InvocationID == 0)" " {" " int tl = 1-int(100.0 / vertPosition[gl_InvocationID].z);" " gl_TessLevelInner[0] = tl;" " gl_TessLevelInner[1] = tl;" " gl_TessLevelOuter[0] = tl;" " gl_TessLevelOuter[1] = tl;" " gl_TessLevelOuter[2] = tl;" " gl_TessLevelOuter[3] = tl;" " }" " tecoPosition[gl_InvocationID] = " " vertPosition[gl_InvocationID].xyz;" "}" ); teco.Compile(); prog << teco; TessEvaluationShader teev(ObjectDesc("TessEvaluation")); teev.Source( "#version 330\n" "#extension ARB_tessellation_shader: enable\n" "layout(quads, equal_spacing, ccw) in;" "uniform mat4 ProjectionMatrix;" "patch in vec3 tecoPosition[16];" "const mat4 B = mat4(" " -1, 3,-3, 1," " 3,-6, 3, 0," " -3, 3, 0, 0," " 1, 0, 0, 0 " ");" "mat4 Px, Py, Pz;" "void main(void)" "{" " float u = gl_TessCoord.x, v = gl_TessCoord.y;" " for(int j=0; j!=4; ++j)" " for(int i=0; i!=4; ++i)" " {" " int k = j*4+i;" " Px[j][i] = tecoPosition[k].x;" " Py[j][i] = tecoPosition[k].y;" " Pz[j][i] = tecoPosition[k].z;" " }" " mat4 Cx = B * Px * B;" " mat4 Cy = B * Py * B;" " mat4 Cz = B * Pz * B;" " vec4 up = vec4(u*u*u, u*u, u, 1);" " vec4 vp = vec4(v*v*v, v*v, v, 1);" " vec4 tempPosition = vec4(dot(Cx * vp, up), dot(Cy * vp, up), dot(Cz * vp, up), 1.0);" " gl_Position = ProjectionMatrix * tempPosition;" "}" ); teev.Compile(); prog << teev; FragmentShader frag(ObjectDesc("Fragment")); frag.Source( "#version 330\n" "out vec3 fragColor;" "void main(void)" "{" " fragColor = vec3(0.1, 0.1, 0.1);" "}" ); frag.Compile(); prog << frag; prog.Link(); prog.Use(); vao.Bind(); GLfloat patch_cp_pos[16*3] = { -2.0f, 0.0f, -2.0f, -1.0f, 0.0f, -3.0f, 1.0f, 0.0f, -5.0f, 2.0f, 0.0f, -2.0f, -1.0f, 0.0f, -1.0f, 0.0f, 4.0f, -1.0f, 1.0f, 4.0f, -1.0f, 3.0f, 0.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 4.0f, 1.0f, 0.0f, 4.0f, 1.0f, 1.0f, 0.0f, 1.0f, -2.0f, 0.0f, 2.0f, -1.0f, 0.0f, 5.0f, 1.0f, 0.0f, 3.0f, 2.0f, 0.0f, 2.0f }; positions.Bind(Buffer::Target::Array); Buffer::Data(Buffer::Target::Array, 16*3, patch_cp_pos); VertexArrayAttrib position_attr(prog, "Position"); position_attr.Setup<Vec3f>(); position_attr.Enable(); gl.ClearColor(0.9f, 0.9f, 0.9f, 0.0f); gl.ClearDepth(1.0f); gl.PolygonMode(PolygonMode::Line); gl.PatchParameter(PatchParameter::PatchVertices, 16); }
void AsymmetricUnit::SetSpaceGroup(const SpaceGroup &spg) { VFN_DEBUG_MESSAGE("AsymmetricUnit::SetSpaceGroup(SpGroup)",5) tmp_C_Numeric_locale tmploc; # if 0 TAU_PROFILE("(AsymmetricUnit::SetSpaceGroup)","void (SpaceGroup)",TAU_DEFAULT); mXmin=0.; mYmin=0.; mZmin=0.; mXmax=1.; mYmax=1.; mZmax=1.; if(1==spg.GetSpaceGroupNumber()) return;//no need to search an asymmetric unit // Test points=reular grid of points inside the unit cell // All points must be or have at least a symmetric in the asymmetric unit const long nbPoints=13; CrystMatrix_REAL testPoints(nbPoints*nbPoints*nbPoints,3); { long l=0; for(long i=0;i<nbPoints;i++) for(long j=0;j<nbPoints;j++) for(long k=0;k<nbPoints;k++) { testPoints(l ,0)=i/(REAL)nbPoints; testPoints(l ,1)=j/(REAL)nbPoints; testPoints(l++,2)=k/(REAL)nbPoints; } } testPoints += 0.01; CrystVector_REAL vert(8);//vertices limits vert(0)=1/8.; vert(1)=1/6.; vert(2)=1/4.; vert(3)=1/3.; vert(4)=1/2.; vert(5)=2/3.; vert(6)=3/4.; vert(7)=1.; const int NbStep=vert.numElements(); CrystMatrix_REAL coords; double junk; REAL minVolume=1.; bool allPtsInAsym,tmp; for(long nx=0;nx<NbStep;nx++) for(long ny=0;ny<NbStep;ny++) for(long nz=0;nz<NbStep;nz++) { if(minVolume<(vert(nx)*vert(ny)*vert(nz)-.0001)) break; allPtsInAsym=true; for(int i=0;i<testPoints.rows();i++) { coords=spg.GetAllSymmetrics(testPoints(i,0),testPoints(i,1),testPoints(i,2)); for(long j=0;j<coords.numElements();j++) coords(j)=modf(coords(j)+10.,&junk) ; tmp=false; for(long j=0;j<coords.rows();j++) {//Test if at least one of the symmetrics is in the parallelepiped if( (coords(j,0) < vert(nx)) &&(coords(j,1) < vert(ny)) &&(coords(j,2) < vert(nz))) { //cout << modf(coords(j,0)+10.,junk) << " " // << modf(coords(j,1)+10.,junk) << " " // << modf(coords(j,2)+10.,junk) << endl; tmp=true; break; } } if(false==tmp) { //cout << " Rejected:"<<vert(nx)<<" "<<vert(ny)<<" "<<vert(nz)<<" "<<i<<endl; //cout << coords <<endl; allPtsInAsym=false; break; } } if( (true==allPtsInAsym)) { mXmax=vert(nx); mYmax=vert(ny); mZmax=vert(nz); VFN_DEBUG_MESSAGE("->ACCEPTED:" << mXmax <<" "<< mYmax <<" "<< mZmax <<endl,2) //cout << "->ACCEPTED:" << mXmax <<" "<< mYmax <<" "<< mZmax <<endl; minVolume=vert(nx)*vert(ny)*vert(nz); break;//no need to grow any more along z } } cout<<"->Finished Generating (pseudo) Asymmetric Unit, with:"<<endl <<" 0 <= x <= "<< mXmax<<endl <<" 0 <= y <= "<< mYmax<<endl <<" 0 <= z <= "<< mZmax<<endl<<endl; #else const cctbx::sgtbx::brick b(spg.GetCCTbxSpg().type()); #ifdef __DEBUG__ cout<<"->>Parallelepipedic Asymmetric Unit, from cctbx::sgtbx::brick:"<<endl <<b.as_string()<<endl; #endif mXmin=boost::rational_cast<REAL,int>(b(0,0).value()); mYmin=boost::rational_cast<REAL,int>(b(1,0).value()); mZmin=boost::rational_cast<REAL,int>(b(2,0).value()); mXmax=boost::rational_cast<REAL,int>(b(0,1).value()); mYmax=boost::rational_cast<REAL,int>(b(1,1).value()); mZmax=boost::rational_cast<REAL,int>(b(2,1).value()); #endif }
gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face& F, const SMDS_MeshNode* n, const SMDS_MeshNode* n2) const { gp_Pnt2d uv( 1e100, 1e100 ); const SMDS_PositionPtr Pos = n->GetPosition(); if(Pos->GetTypeOfPosition()==SMDS_TOP_FACE) { // node has position on face const SMDS_FacePosition* fpos = static_cast<const SMDS_FacePosition*>(n->GetPosition().get()); uv = gp_Pnt2d(fpos->GetUParameter(),fpos->GetVParameter()); } else if(Pos->GetTypeOfPosition()==SMDS_TOP_EDGE) { // node has position on edge => it is needed to find // corresponding edge from face, get pcurve for this // edge and recieve value from this pcurve const SMDS_EdgePosition* epos = static_cast<const SMDS_EdgePosition*>(n->GetPosition().get()); SMESHDS_Mesh* meshDS = GetMeshDS(); int edgeID = Pos->GetShapeId(); TopoDS_Edge E = TopoDS::Edge(meshDS->IndexToShape(edgeID)); double f, l; Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); uv = C2d->Value( epos->GetUParameter() ); // for a node on a seam edge select one of UVs on 2 pcurves if ( n2 && IsSeamShape( edgeID ) ) uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 )); } else if(Pos->GetTypeOfPosition()==SMDS_TOP_VERTEX) { if ( int vertexID = n->GetPosition()->GetShapeId() ) { bool ok = true; const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID)); try { uv = BRep_Tool::Parameters( V, F ); } catch (Standard_Failure& exc) { ok = false; } if ( !ok ) { for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() ) ok = ( V == vert.Current() ); if ( !ok ) { #ifdef _DEBUG_ MESSAGE ( "SMESH_MesherHelper::GetNodeUV(); Vertex " << vertexID << " not in face " << GetMeshDS()->ShapeToIndex( F ) ); #endif // get UV of a vertex closest to the node double dist = 1e100; gp_Pnt pn ( n->X(),n->Y(),n->Z() ); for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() ) { TopoDS_Vertex curV = TopoDS::Vertex( vert.Current() ); gp_Pnt p = BRep_Tool::Pnt( curV ); double curDist = p.SquareDistance( pn ); if ( curDist < dist ) { dist = curDist; uv = BRep_Tool::Parameters( curV, F ); if ( dist < DBL_MIN ) break; } } } else { TopTools_ListIteratorOfListOfShape it( myMesh->GetAncestors( V )); for ( ; it.More(); it.Next() ) { if ( it.Value().ShapeType() == TopAbs_EDGE ) { const TopoDS_Edge & edge = TopoDS::Edge( it.Value() ); double f,l; Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, F, f, l); if ( !C2d.IsNull() ) { double u = ( V == TopExp::FirstVertex( edge ) ) ? f : l; uv = C2d->Value( u ); break; } } } } } if ( n2 && IsSeamShape( vertexID ) ) uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 )); } } return uv.XY(); }
int main(int argc, char **argv) { if (argc != 3) { std::cout << "Usage: tester <program1> <program2>\n"; return 1; } const char *program1 = argv[1]; const char *program2 = argv[2]; ExecutionResult result = ER_OK; for (int move = 0 ; move < size * size ; ++move) { bool first = move % 2 == 0; std::ostringstream outs; outs << !first + 1 << "\n"; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { outs << field[i][j] << " "; } outs << "\n"; } std::string output; result = runProcess(first ? program1 : program2, outs.str(), output, 1000, 64000); if (result == ER_OK) { std::istringstream ins(output); int x, y; ins >> y >> x; if (x >= 1 && x <= size && y >= 1 && y <= size && !field[y-1][x-1]) { printLog(first, result, output); int xo = first ? 1 : 2; field[y-1][x-1] = xo; score[0] = score[1] = 0; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { horz(i, j); vert(i, j); diag1(i, j); diag2(i, j); } } std::ostringstream outs; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) outs << field[i][j] << " "; outs << "\n"; } outs << score[0] << " " << score[1] << "\n"; printField(outs.str()); } else { result = ER_IM; printLog(first, result, output); break; } } else {
void TreeSegGeo::constructGeometryData(Quaternion orient, bool topPlane, bool bottomPlane) { int numVerts = mSegmentsW * (mSegmentsH + 1) + 2; // positionData mGeoData.posData.push_back(Vector3::Zero); mGeoData.posData.push_back(Vector3(0, mLength, 0)); float heightDelta = mLength / mSegmentsH; float deltaTheta = 2*PI / mSegmentsW; for(int i = 0; i <= mSegmentsH; ++i) { float circleHeight = i * heightDelta; float circleRadius = mRadius[i]; for(int j = 0; j < mSegmentsW; ++j) { float x = circleRadius * cos(j*deltaTheta); float z = circleRadius * sin(j*deltaTheta); Vector3 vertPos(x, circleHeight, z); if(i == 0) vertPos = vertPos * orient.Conjugate(); mGeoData.posData.push_back(vertPos); } } // verts for(size_t i = 0; i < mGeoData.posData.size(); ++i) { Vert vert(i); mGeoData.verts.push_back(vert); } // triangles if(bottomPlane) { for(int i = 0; i < mSegmentsW; ++i) // 底圆面 { // 顶点索引为2 ~ sw+1 Triangle triangle(0, 2+i, 2 + (i + 1) % mSegmentsW); mGeoData.tris.push_back(triangle); } } if(topPlane) { for(int i = 0; i < mSegmentsW; ++i) // 顶圆面 { // 顶点索引为sw*sh + 2 ~ sw*(sh + 1) + 1 Triangle triangle(1, mSegmentsW*mSegmentsH + 2 + (i + 1) % mSegmentsW, mSegmentsW*mSegmentsH + 2 + i); mGeoData.tris.push_back(triangle); } } for(int i = 0; i < mSegmentsH; ++i) // 柱面 { for(int j = 0; j < mSegmentsW; ++j) { Triangle tri1; Triangle tri2; tri1.vertexIndex[0] = mSegmentsW * i + j + 2; tri1.vertexIndex[1] = mSegmentsW * (i + 1) + j + 2; tri1.vertexIndex[2] = mSegmentsW * i + (j + 1)%mSegmentsW + 2; tri2.vertexIndex[0] = mSegmentsW * (i + 1) + j + 2; tri2.vertexIndex[1] = mSegmentsW * (i + 1) + (j + 1)%mSegmentsW + 2; tri2.vertexIndex[2] = mSegmentsW * i + (j + 1)%mSegmentsW + 2; _Assert(tri1.vertexIndex[0] < mSegmentsW * (mSegmentsH + 1) + 2); _Assert(tri1.vertexIndex[1] < mSegmentsW * (mSegmentsH + 1) + 2); _Assert(tri1.vertexIndex[2] < mSegmentsW * (mSegmentsH + 1) + 2); _Assert(tri2.vertexIndex[0] < mSegmentsW * (mSegmentsH + 1) + 2); _Assert(tri2.vertexIndex[1] < mSegmentsW * (mSegmentsH + 1) + 2); _Assert(tri2.vertexIndex[2] < mSegmentsW * (mSegmentsH + 1) + 2); mGeoData.tris.push_back(tri1); mGeoData.tris.push_back(tri2); } } }
MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationProjectionMatrixUniform(0), viewportSizeUniform(1), colorUniform(2), wireframeColorUniform(3), wireframeWidthUniform(4), smoothnessUniform(5) { #ifndef MAGNUM_TARGET_GLES if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4); #elif defined(MAGNUM_TARGET_GLES2) if(flags & Flag::Wireframe) MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::standard_derivatives); #endif Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES const Version v = Context::current()->supportedVersion({Version::GL320, Version::GL310, Version::GL210}); #else const Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif Shader vert(v, Shader::Type::Vertex); vert.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") .addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "") .addSource(rs.get("compatibility.glsl")) .addSource(rs.get("MeshVisualizer.vert")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); vert.compile(); attachShader(vert); #ifndef MAGNUM_TARGET_GLES if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) { Shader geom(v, Shader::Type::Geometry); geom.addSource(rs.get("compatibility.glsl")) .addSource(rs.get("MeshVisualizer.geom")); CORRADE_INTERNAL_ASSERT_OUTPUT(geom.compile()); geom.compile(); attachShader(geom); } #endif Shader frag(v, Shader::Type::Fragment); frag.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") .addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "") .addSource(rs.get("compatibility.glsl")) .addSource(rs.get("MeshVisualizer.frag")); CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); frag.compile(); attachShader(frag); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() || Context::current()->version() == Version::GL210) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif { bindAttributeLocation(Position::Location, "position"); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isVersionSupported(Version::GL310)) #endif { bindAttributeLocation(VertexIndex::Location, "vertexIndex"); } } CORRADE_INTERNAL_ASSERT_OUTPUT(link()); link(); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) #endif { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); colorUniform = uniformLocation("color"); if(flags & Flag::Wireframe) { wireframeColorUniform = uniformLocation("wireframeColor"); wireframeWidthUniform = uniformLocation("wireframeWidth"); smoothnessUniform = uniformLocation("smoothness"); if(!(flags & Flag::NoGeometryShader)) viewportSizeUniform = uniformLocation("viewportSize"); } } /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ #ifdef MAGNUM_TARGET_GLES setColor(Color3<>(1.0f)); if(flags & Flag::Wireframe) { setWireframeColor(Color3<>(0.0f)); setWireframeWidth(1.0f); setSmoothness(2.0f); } #endif }
bool MeshMod_FixPipe::apply(Mesh *mesh) { int i, j; rvfloat minHeights[8] = { -1e9,-1e9,-1e9,-1e9,-1e9,-1e9,-1e9,-1e9 }; Polygon *newPolys [8] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; Vector polyCenters[8]; bool pipe = false; for (i = 0; i < mesh->data.num_polys; i++) { if (mesh->poly[i]->detTEPart() & TEP_PIPE) { pipe = true; break; } } if (!pipe) { return true; } rvfloat meshMinX = mesh->verts[0]->pos.coord[0]; rvfloat meshMaxX = mesh->verts[0]->pos.coord[0]; rvfloat meshMinZ = mesh->verts[0]->pos.coord[2]; rvfloat meshMaxZ = mesh->verts[0]->pos.coord[2]; for (i = 1; i < mesh->data.num_vecs; i++) { Vertex *v = mesh->verts[i]; if (meshMinX > v->pos.coord[0] - 0.5) { meshMinX = v->pos.coord[0]; } if (meshMaxX < v->pos.coord[0] + 0.5) { meshMaxX = v->pos.coord[0]; } if (meshMinZ > v->pos.coord[2] - 0.5) { meshMinZ = v->pos.coord[2]; } if (meshMaxZ < v->pos.coord[2] + 0.5) { meshMaxZ = v->pos.coord[2]; } } Vector meshCenter( floor((meshMinX + meshMaxX) / 2000 + 0.5) * 1000, 0.0f, floor((meshMinZ + meshMaxZ) / 2000 + 0.5) * 1000); for (i = 0; i < mesh->data.num_polys; i++) { Polygon *p = mesh->poly[i]; if (p->detTEPart() & (TEP_PWALL | TEP_PIPE)) { rvfloat minHeight = -1e9; Vector polyCenter(0.0, 0.0, 0.0); for (j = 0; j < p->numverts(); j++) { Vertex *v = mesh->verts[p->vertidx(j)]; polyCenter = polyCenter + v->pos; if (minHeight < v->pos.coord[1]) { minHeight = v->pos.coord[1]; } } Vector polyCoord = polyCenter * 0.25; polyCenter = polyCoord - meshCenter; int octant = (int) ((atan2(polyCenter.z(), polyCenter.x()) + M_PI) / (M_PI / 4)); if (p->detTEPart() & TEP_PIPE) { if (minHeights[octant] < minHeight) { minHeights[octant] = minHeight; } } if ((p->detTEPart() & TEP_PWALL) && p->numverts() == 4) { Vector& v0 = mesh->verts[p->vertidx(0)]->pos; Vector& v1 = mesh->verts[p->vertidx(1)]->pos; Vector& v2 = mesh->verts[p->vertidx(2)]->pos; rvfloat w = (v0 - v1).length(); rvfloat h = (v2 - v1).length(); if (fabs(w - 125.0) < 0.5 && fabs(h - 125.0) < 0.5) { // Check if we've encountered an indentical polygon before, // and if so, delete the current one so we don't end up with // duplicates bool found = false; for (j = 0; j < polyList.size(); j++) { if ((polyList[j].center - polyCoord).length() < 1.0) { found = true; break; } } if (found) { delete mesh->poly[i]; mesh->poly[i] = NULL; } else { polyList.push_back(PolyInfo(p, polyCoord)); } } } } } for (i = 0; i < mesh->data.num_polys; i++) { Polygon *p = mesh->poly[i]; if (p->isInTexture(0, 0.5,1.0, 0.0,0.375)) { rvfloat minX = 1.0e9f, maxX = -1.0e9f; rvfloat minZ = 1.0e9f, maxZ = -1.0e9f; Vector polyCenter(0.0, 0.0, 0.0); for (j = 0; j < p->numverts(); j++) { Vertex *v = mesh->verts[p->vertidx(j)]; polyCenter = polyCenter + v->pos; if (minX > v->pos.coord[0]) { minX = v->pos.coord[0]; } if (maxX < v->pos.coord[0]) { maxX = v->pos.coord[0]; } if (minZ > v->pos.coord[2]) { minZ = v->pos.coord[2]; } if (maxZ < v->pos.coord[2]) { maxZ = v->pos.coord[2]; } } Vector polyCoord = polyCenter / (rvfloat) p->numverts(); polyCenter = polyCoord - meshCenter; int octant = (int) ((atan2(polyCenter.z(), polyCenter.x()) + M_PI) / (M_PI / 4)); if (newPolys[octant] == NULL && (fabs(maxX - minX) < 0.5 || fabs(maxZ - minZ) < 0.5) && fabs(polyCenter.x()) > 10.0 && fabs(polyCenter.z()) > 10.0) { Vector p[4]; Vector norm; // Find the corners of the new polygon switch (octant) { case 0: p[3] = Vector(-500, minHeights[octant] + 125, -500); p[2] = Vector(-500, minHeights[octant] , -500); p[1] = Vector(-500, minHeights[octant] , -375); p[0] = Vector(-500, minHeights[octant] + 125, -375); norm = Vector(-1.0, 0.0, 0.0); break; case 1: p[0] = Vector(-375, minHeights[octant] , -500); p[1] = Vector(-375, minHeights[octant] + 125, -500); p[2] = Vector(-500, minHeights[octant] + 125, -500); p[3] = Vector(-500, minHeights[octant] , -500); norm = Vector(0.0, 0.0, -1.0); break; case 2: p[3] = Vector(375, minHeights[octant] , -500); p[2] = Vector(375, minHeights[octant] + 125, -500); p[1] = Vector(500, minHeights[octant] + 125, -500); p[0] = Vector(500, minHeights[octant] , -500); norm = Vector(0.0, 0.0, -1.0); break; case 3: p[0] = Vector(500, minHeights[octant] + 125, -500); p[1] = Vector(500, minHeights[octant] , -500); p[2] = Vector(500, minHeights[octant] , -375); p[3] = Vector(500, minHeights[octant] + 125, -375); norm = Vector(-1.0, 0.0, 0.0); break; case 4: p[3] = Vector(500, minHeights[octant] + 125, 500); p[2] = Vector(500, minHeights[octant] , 500); p[1] = Vector(500, minHeights[octant] , 375); p[0] = Vector(500, minHeights[octant] + 125, 375); norm = Vector(-1.0, 0.0, 0.0); break; case 5: p[0] = Vector(375, minHeights[octant] , 500); p[1] = Vector(375, minHeights[octant] + 125, 500); p[2] = Vector(500, minHeights[octant] + 125, 500); p[3] = Vector(500, minHeights[octant] , 500); norm = Vector(0.0, 0.0, -1.0); break; case 6: p[3] = Vector(-375, minHeights[octant] , 500); p[2] = Vector(-375, minHeights[octant] + 125, 500); p[1] = Vector(-500, minHeights[octant] + 125, 500); p[0] = Vector(-500, minHeights[octant] , 500); norm = Vector(0.0, 0.0, -1.0); break; case 7: p[0] = Vector(-500, minHeights[octant] + 125, 500); p[1] = Vector(-500, minHeights[octant] , 500); p[2] = Vector(-500, minHeights[octant] , 375); p[3] = Vector(-500, minHeights[octant] + 125, 375); norm = Vector(-1.0, 0.0, 0.0); break; } for (j = 0; j < 4; j++) { // Translate to the mesh position p[j] = p[j] + meshCenter; // Add the vertex Vertex vert(p[j], norm); mesh->add(new Vertex(&vert)); } // add a new polygon RV_Poly polyData = { 1, 0, { mesh->data.num_vecs - 4, mesh->data.num_vecs - 3, mesh->data.num_vecs - 2, mesh->data.num_vecs - 1 }, { {0xFFFFFF}, {0xFFFFFF}, {0xFFFFFF}, {0xFFFFFF} }, { { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } } }; polyCenter = (p[0] + p[1] + p[2] + p[3]) / 4; // Check if we've encountered an indentical polygon before, // and if so, use that instead of creating a new one bool found = false; for (j = 0; j < polyList.size(); j++) { if ((polyList[j].center - polyCenter).length() < 1.0) { found = true; break; } } if (found) { newPolys[octant] = polyList[j].poly; } else { newPolys[octant] = new Polygon(mesh, &polyData); mesh->add(newPolys[octant]); polyList.push_back(PolyInfo(newPolys[octant], polyCenter)); } polyCenters[octant] = polyCenter; } } } // Finally, put textures on the "missing pieces" for (i = 0; i < 8; i++) { if (newPolys[i]) { Polygon *p = newPolys[i]; p->data.texture = 0; for (int j = 0; j < p->numverts(); j++) { Vertex *v = mesh->verts[p->vertidx(j)]; Vector relPos = v->pos - Vector(meshMinX, 0, meshMinZ); rvfloat x = relPos.lengthXZ(); rvfloat y = relPos.y(); if ((relPos.x() < 0.5 || relPos.x() > 999.5) && (relPos.z() < 0.5 || relPos.z() > 999.5)) { p->data.texcoord[j].u = 0.504f; } else { p->data.texcoord[j].u = 0.625f; } if (relPos.y() > polyCenters[i].y() + 0.5) { p->data.texcoord[j].v = 0.371f; } else { p->data.texcoord[j].v = 0.250f; } p->data.color[j].value = 0xFFFFFF; } } } return true; }
btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix) { btCollisionShape* shape = 0; switch (collision->m_geometry.m_type) { case URDF_GEOM_CYLINDER: { btScalar cylRadius = collision->m_geometry.m_cylinderRadius; btScalar cylLength = collision->m_geometry.m_cylinderLength; btAlignedObjectArray<btVector3> vertices; //int numVerts = sizeof(barrel_vertices)/(9*sizeof(float)); int numSteps = 32; for (int i=0;i<numSteps;i++) { btVector3 vert(cylRadius*btSin(SIMD_2_PI*(float(i)/numSteps)),cylRadius*btCos(SIMD_2_PI*(float(i)/numSteps)),cylLength/2.); vertices.push_back(vert); vert[2] = -cylLength/2.; vertices.push_back(vert); } btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3)); cylZShape->setMargin(0.001); cylZShape->initializePolyhedralFeatures(); //btConvexShape* cylZShape = new btConeShapeZ(cyl->radius,cyl->length);//(vexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3)); //btVector3 halfExtents(cyl->radius,cyl->radius,cyl->length/2.); //btCylinderShapeZ* cylZShape = new btCylinderShapeZ(halfExtents); shape = cylZShape; break; } case URDF_GEOM_BOX: { btVector3 extents = collision->m_geometry.m_boxSize; btBoxShape* boxShape = new btBoxShape(extents*0.5f); //btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5); shape = boxShape; shape ->setMargin(0.001); break; } case URDF_GEOM_SPHERE: { btScalar radius = collision->m_geometry.m_sphereRadius; btSphereShape* sphereShape = new btSphereShape(radius); shape = sphereShape; shape ->setMargin(0.001); break; break; } case URDF_GEOM_MESH: { if (collision->m_name.length()) { //b3Printf("collision->name=%s\n",collision->m_name.c_str()); } if (1) { if (collision->m_geometry.m_meshFileName.length()) { const char* filename = collision->m_geometry.m_meshFileName.c_str(); //b3Printf("mesh->filename=%s\n",filename); char fullPath[1024]; int fileType = 0; sprintf(fullPath,"%s%s",urdfPathPrefix,filename); b3FileUtils::toLower(fullPath); char tmpPathPrefix[1024]; int maxPathLen = 1024; b3FileUtils::extractPath(filename,tmpPathPrefix,maxPathLen); char collisionPathPrefix[1024]; sprintf(collisionPathPrefix,"%s%s",urdfPathPrefix,tmpPathPrefix); if (strstr(fullPath,".dae")) { fileType = FILE_COLLADA; } if (strstr(fullPath,".stl")) { fileType = FILE_STL; } if (strstr(fullPath,".obj")) { fileType = FILE_OBJ; } sprintf(fullPath,"%s%s",urdfPathPrefix,filename); FILE* f = fopen(fullPath,"rb"); if (f) { fclose(f); GLInstanceGraphicsShape* glmesh = 0; switch (fileType) { case FILE_OBJ: { glmesh = LoadMeshFromObj(fullPath,collisionPathPrefix); break; } case FILE_STL: { glmesh = LoadMeshFromSTL(fullPath); break; } case FILE_COLLADA: { btAlignedObjectArray<GLInstanceGraphicsShape> visualShapes; btAlignedObjectArray<ColladaGraphicsInstance> visualShapeInstances; btTransform upAxisTrans;upAxisTrans.setIdentity(); float unitMeterScaling=1; int upAxis = 2; LoadMeshFromCollada(fullPath, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, upAxis ); glmesh = new GLInstanceGraphicsShape; // int index = 0; glmesh->m_indices = new b3AlignedObjectArray<int>(); glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>(); for (int i=0;i<visualShapeInstances.size();i++) { ColladaGraphicsInstance* instance = &visualShapeInstances[i]; GLInstanceGraphicsShape* gfxShape = &visualShapes[instance->m_shapeIndex]; b3AlignedObjectArray<GLInstanceVertex> verts; verts.resize(gfxShape->m_vertices->size()); int baseIndex = glmesh->m_vertices->size(); for (int i=0;i<gfxShape->m_vertices->size();i++) { verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0]; verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1]; verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2]; verts[i].uv[0] = gfxShape->m_vertices->at(i).uv[0]; verts[i].uv[1] = gfxShape->m_vertices->at(i).uv[1]; verts[i].xyzw[0] = gfxShape->m_vertices->at(i).xyzw[0]; verts[i].xyzw[1] = gfxShape->m_vertices->at(i).xyzw[1]; verts[i].xyzw[2] = gfxShape->m_vertices->at(i).xyzw[2]; verts[i].xyzw[3] = gfxShape->m_vertices->at(i).xyzw[3]; } int curNumIndices = glmesh->m_indices->size(); int additionalIndices = gfxShape->m_indices->size(); glmesh->m_indices->resize(curNumIndices+additionalIndices); for (int k=0;k<additionalIndices;k++) { glmesh->m_indices->at(curNumIndices+k)=gfxShape->m_indices->at(k)+baseIndex; } //compensate upAxisTrans and unitMeterScaling here btMatrix4x4 upAxisMat; upAxisMat.setIdentity(); //upAxisMat.setPureRotation(upAxisTrans.getRotation()); btMatrix4x4 unitMeterScalingMat; unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling,unitMeterScaling,unitMeterScaling)); btMatrix4x4 worldMat = unitMeterScalingMat*instance->m_worldTransform*upAxisMat; //btMatrix4x4 worldMat = instance->m_worldTransform; int curNumVertices = glmesh->m_vertices->size(); int additionalVertices = verts.size(); glmesh->m_vertices->reserve(curNumVertices+additionalVertices); for(int v=0;v<verts.size();v++) { btVector3 pos(verts[v].xyzw[0],verts[v].xyzw[1],verts[v].xyzw[2]); pos = worldMat*pos; verts[v].xyzw[0] = float(pos[0]); verts[v].xyzw[1] = float(pos[1]); verts[v].xyzw[2] = float(pos[2]); glmesh->m_vertices->push_back(verts[v]); } } glmesh->m_numIndices = glmesh->m_indices->size(); glmesh->m_numvertices = glmesh->m_vertices->size(); //glmesh = LoadMeshFromCollada(fullPath); break; } default: { b3Warning("Unsupported file type in Collision: %s\n",fullPath); btAssert(0); } } if (glmesh && (glmesh->m_numvertices>0)) { //b3Printf("extracted %d verticed from STL file %s\n", glmesh->m_numvertices,fullPath); //int shapeId = m_glApp->m_instancingRenderer->registerShape(&gvertices[0].pos[0],gvertices.size(),&indices[0],indices.size()); //convex->setUserIndex(shapeId); btAlignedObjectArray<btVector3> convertedVerts; convertedVerts.reserve(glmesh->m_numvertices); for (int i=0;i<glmesh->m_numvertices;i++) { convertedVerts.push_back(btVector3(glmesh->m_vertices->at(i).xyzw[0],glmesh->m_vertices->at(i).xyzw[1],glmesh->m_vertices->at(i).xyzw[2])); } //btConvexHullShape* cylZShape = new btConvexHullShape(&glmesh->m_vertices->at(0).xyzw[0], glmesh->m_numvertices, sizeof(GLInstanceVertex)); btConvexHullShape* cylZShape = new btConvexHullShape(&convertedVerts[0].getX(), convertedVerts.size(), sizeof(btVector3)); //cylZShape->initializePolyhedralFeatures(); //btVector3 halfExtents(cyl->radius,cyl->radius,cyl->length/2.); //btCylinderShapeZ* cylZShape = new btCylinderShapeZ(halfExtents); cylZShape->setMargin(0.001); shape = cylZShape; } else { b3Warning("issue extracting mesh from STL file %s\n", fullPath); } delete glmesh; } else { b3Warning("mesh geometry not found %s\n",fullPath); } } } break; } default: { b3Warning("Error: unknown visual geometry type\n"); } } return shape; }
void MeshLoader::loadScene(const aiScene *scene) { m_entity = std::make_shared<Entity>(); for (int i = 0; i < scene->mNumMeshes; i++) { const aiMesh *model = scene->mMeshes[i]; std::vector<Vertex> vertices; std::vector<unsigned int> indices; const aiVector3D aiZeroVector(0.0f, 0.0f, 0.0f); for (unsigned int i = 0; i < model->mNumVertices; i++) { const aiVector3D *pPos = &(model->mVertices[i]); const aiVector3D *pNormal = &(model->mNormals[i]); const aiVector3D *pTexCoord = model->HasTextureCoords(0) ? &(model->mTextureCoords[0][i]) : &aiZeroVector; const aiVector3D *pTangent = model->HasTangentsAndBitangents() ? &(model->mTangents[i]) : &aiZeroVector; Vertex vert(glm::vec3(pPos->x, pPos->y, pPos->z), glm::vec2(pTexCoord->x, pTexCoord->y), glm::vec3(pNormal->x, pNormal->y, pNormal->z), glm::vec3(pTangent->x, pTangent->y, pTangent->z)); vertices.push_back(vert); } for (unsigned int i = 0; i < model->mNumFaces; i++) { const aiFace &face = model->mFaces[i]; indices.push_back(face.mIndices[0]); indices.push_back(face.mIndices[1]); indices.push_back(face.mIndices[2]); } const aiMaterial *pMaterial = scene->mMaterials[model->mMaterialIndex]; log_info("tex num: %i", model->mMaterialIndex); std::shared_ptr<Texture> diffuseMap; std::shared_ptr<Texture> normalMap; std::shared_ptr<Texture> specularMap; aiString Path; if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0 && pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { diffuseMap = std::make_shared<Texture>(Asset(Path.data)); } else { diffuseMap = std::make_shared<Texture>(Asset("default_normal.jpg")); } if (pMaterial->GetTextureCount(aiTextureType_HEIGHT) > 0 && pMaterial->GetTexture(aiTextureType_HEIGHT, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { normalMap = std::make_shared<Texture>(Asset(Path.data)); } else { normalMap = std::make_shared<Texture>(Asset("default_normal.jpg")); } if (pMaterial->GetTextureCount(aiTextureType_SPECULAR) > 0 && pMaterial->GetTexture(aiTextureType_SPECULAR, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { specularMap = std::make_shared<Texture>(Asset(Path.data)); } else { specularMap = std::make_shared<Texture>(Asset("default_specular.jpg")); } MeshRendererData meshRenderData; meshRenderData.mesh = std::make_shared<Mesh>(m_fileName + std::string(model->mName.C_Str()), &vertices[0], vertices.size(), &indices[0], indices.size()); meshRenderData.material = std::make_shared<Material>(diffuseMap, normalMap, specularMap); MeshLoader::sceneMeshRendererDataCache[m_fileName].push_back(meshRenderData); m_entity->addComponent<MeshRenderer>(meshRenderData.mesh, meshRenderData.material); } }
bool Tessellation(int& OutputVertNum, int& OutputIndiceNum) { if (ExtRingCoords == NULL) { return false; } #ifdef _DEBUG //test std::cout<<"EXT"<<std::endl; std::cout<<ExtRingVertNum<<std::endl; for (int i = 0; i < ExtRingVertNum; i++) { std::cout<<ExtRingCoords[i][0]<<ExtRingCoords[i][1]<<ExtRingCoords[i][2]<<std::endl; } std::cout<<"INT"<<std::endl; std::cout<<IntRingCoordsNum.size()<<std::endl; std::vector<int>::iterator itr = IntRingCoordsNum.begin(); std::vector<Vec3*>::iterator itr2 = IntRingCoords.begin(); for (;itr != IntRingCoordsNum.end(); itr++, itr2++) { std::cout<<*itr<<std::endl; for (int i = 0 ; i <*itr; i ++ ) { std::cout<<(*itr2)[i][0]<<(*itr2)[i][1]<<(*itr2)[i][2]<<std::endl; } } std::cout<<"good1"<<std::endl; #endif int IntRingNum = IntRingCoords.size(); //calculate the normal Vec3 pNorm; pNorm[0] = 0.0; pNorm[1] = 0.0; pNorm[2] = 0.0; Vec3 lVert; lVert[0] = ExtRingCoords[ExtRingVertNum - 1][0]; lVert[1] = ExtRingCoords[ExtRingVertNum - 1][1]; lVert[2] = ExtRingCoords[ExtRingVertNum - 1][2]; for (int i = 0 ; i < ExtRingVertNum; i++) { Vec3 pStep; pStep[0] = (lVert[2] + ExtRingCoords[i][2]) * (lVert[1] - ExtRingCoords[i][1]); pStep[1] = (lVert[0] + ExtRingCoords[i][0]) * (lVert[2] - ExtRingCoords[i][2]); pStep[2] = (lVert[1] + ExtRingCoords[i][1]) * (lVert[0] - ExtRingCoords[i][0]); pNorm[0] = pNorm[0] + pStep[0]; pNorm[1] = pNorm[1] + pStep[1]; pNorm[2] = pNorm[2] + pStep[2]; lVert[0] = ExtRingCoords[i][0]; lVert[1] = ExtRingCoords[i][1]; lVert[2] = ExtRingCoords[i][2]; } #ifdef _DEBUG //test std::cout<<"good2"<<std::endl; #endif //do tessellation //verts number int VertNum = ExtRingVertNum; for (int i = 0; i < IntRingCoordsNum.size(); i++) VertNum += IntRingCoordsNum[i]; // #ifdef _DEBUG //test std::cout<<"good2.1"<<std::endl; std::cout<<"VertNum: "<<VertNum<<std::endl; std::cout<<pNorm[0]<<pNorm[1]<<pNorm[2]<<std::endl; #endif tess.init(VertNum, TVec3d(pNorm[0], pNorm[1], pNorm[2])); std::vector<TVec3d> ring; std::vector<TVec2f> tag;//no use //add ExtierRing for (int i = 0; i < ExtRingVertNum; i++) { TVec3d vert(ExtRingCoords[i][0], ExtRingCoords[i][1], ExtRingCoords[i][2]); ring.push_back(vert); } #ifdef _DEBUG //test std::cout<<"good2.2"<<std::endl; std::cout<<ring.size()<<std::endl; #endif tess.addContour(ring, tag); ring.clear(); //add InteriorRings for (int i = 0; i < IntRingNum; i++) { for (int j = 0 ; j < IntRingCoordsNum[i]; j++) { TVec3d vert(IntRingCoords[i][j][0], IntRingCoords[i][j][1], IntRingCoords[i][j][2]); ring.push_back(vert); } tess.addContour(ring, tag); ring.clear(); } #ifdef _DEBUG //test std::cout<<"good2.3"<<std::endl; #endif tess.compute(); //return results if (tess.getIndices().size() == 0) { return false; } #ifdef _DEBUG //test std::cout<<"good3"<<std::endl; #endif //return coordsSAT OutputVertNum = tess.getVertices().size(); OutputIndiceNum = tess.getIndices().size()/3; // { delete[] ExtRingCoords; ExtRingCoords = NULL; std::vector<Vec3*>::iterator itr = IntRingCoords.begin(); for (; itr != IntRingCoords.end(); itr++) { delete[] *itr; *itr = NULL; } } #ifdef _DEBUG //test std::cout<<"good4"<<std::endl; #endif return true; }
void RTriangleMesh::init(const std::tr1::shared_ptr<magnet::thread::TaskQueue>& systemQueue) { RTriangles::init(systemQueue); //Send the data we already have setGLPositions(_vertices); setGLElements(_elements); {//Calculate the normal vectors std::vector<float> VertexNormals(_vertices.size(), 0); //For every triangle, add the cross product of the two edges. We //then renormalize the normal to get a //"weighted-by-the-triangle-size" normal. for (size_t triangle(0); triangle < _elements.size() / 3; ++triangle) { //Grab the vertex IDs size_t v1(_elements[3 * triangle + 0]), v2(_elements[3 * triangle + 1]), v3(_elements[3 * triangle + 2]); Vector V1(_vertices[3 * v1 + 0], _vertices[3 * v1 + 1], _vertices[3 * v1 + 2]), V2(_vertices[3 * v2 + 0], _vertices[3 * v2 + 1], _vertices[3 * v2 + 2]), V3(_vertices[3 * v3 + 0], _vertices[3 * v3 + 1], _vertices[3 * v3 + 2]); Vector norm = (V2-V1)^(V3-V2); for (size_t i(0); i < 3; ++i) { VertexNormals[3 * v1 + i] += norm[i]; VertexNormals[3 * v2 + i] += norm[i]; VertexNormals[3 * v3 + i] += norm[i]; } } //Now normalize those vertices for (size_t vert(0); vert < _vertices.size() / 3; ++vert) { double norm = VertexNormals[3 * vert + 0] * VertexNormals[3 * vert + 0] + VertexNormals[3 * vert + 1] * VertexNormals[3 * vert + 1] + VertexNormals[3 * vert + 2] * VertexNormals[3 * vert + 2]; if (norm) { double factor = 1 / std::sqrt(norm); VertexNormals[3 * vert + 0] *= factor; VertexNormals[3 * vert + 1] *= factor; VertexNormals[3 * vert + 2] *= factor; } else { VertexNormals[3 * vert + 0] = 1; VertexNormals[3 * vert + 1] = 0; VertexNormals[3 * vert + 2] = 0; } } setGLNormals(VertexNormals); } //Reclaim some memory _vertices.clear(); _elements.clear(); }
void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPrefix, const btTransform& visualTransform, btAlignedObjectArray<GLInstanceVertex>& verticesOut, btAlignedObjectArray<int>& indicesOut, btAlignedObjectArray<MyTexture2>& texturesOut) { GLInstanceGraphicsShape* glmesh = 0; btConvexShape* convexColShape = 0; switch (visual->m_geometry.m_type) { case URDF_GEOM_CYLINDER: { btAlignedObjectArray<btVector3> vertices; //int numVerts = sizeof(barrel_vertices)/(9*sizeof(float)); int numSteps = 32; for (int i = 0; i<numSteps; i++) { btScalar cylRadius = visual->m_geometry.m_cylinderRadius; btScalar cylLength = visual->m_geometry.m_cylinderLength; btVector3 vert(cylRadius*btSin(SIMD_2_PI*(float(i) / numSteps)), cylRadius*btCos(SIMD_2_PI*(float(i) / numSteps)), cylLength / 2.); vertices.push_back(vert); vert[2] = -cylLength / 2.; vertices.push_back(vert); } btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3)); cylZShape->setMargin(0.001); convexColShape = cylZShape; break; } case URDF_GEOM_BOX: { btVector3 extents = visual->m_geometry.m_boxSize; btBoxShape* boxShape = new btBoxShape(extents*0.5f); //btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5); convexColShape = boxShape; convexColShape->setMargin(0.001); break; } case URDF_GEOM_SPHERE: { btScalar radius = visual->m_geometry.m_sphereRadius; btSphereShape* sphereShape = new btSphereShape(radius); convexColShape = sphereShape; convexColShape->setMargin(0.001); break; break; } case URDF_GEOM_MESH: { if (visual->m_name.length()) { //b3Printf("visual->name=%s\n", visual->m_name.c_str()); } if (1)//visual->m_geometry) { if (visual->m_geometry.m_meshFileName.length()) { const char* filename = visual->m_geometry.m_meshFileName.c_str(); //b3Printf("mesh->filename=%s\n", filename); char fullPath[1024]; int fileType = 0; char tmpPathPrefix[1024]; std::string xml_string; int maxPathLen = 1024; b3FileUtils::extractPath(filename,tmpPathPrefix,maxPathLen); char visualPathPrefix[1024]; sprintf(visualPathPrefix,"%s%s",urdfPathPrefix,tmpPathPrefix); sprintf(fullPath, "%s%s", urdfPathPrefix, filename); b3FileUtils::toLower(fullPath); if (strstr(fullPath, ".dae")) { fileType = MY_FILE_COLLADA; } if (strstr(fullPath, ".stl")) { fileType = MY_FILE_STL; } if (strstr(fullPath,".obj")) { fileType = MY_FILE_OBJ; } sprintf(fullPath, "%s%s", urdfPathPrefix, filename); FILE* f = fopen(fullPath, "rb"); if (f) { fclose(f); switch (fileType) { case MY_FILE_OBJ: { //glmesh = LoadMeshFromObj(fullPath,visualPathPrefix); b3ImportMeshData meshData; if (b3ImportMeshUtility::loadAndRegisterMeshFromFileInternal(fullPath, meshData)) { if (meshData.m_textureImage) { MyTexture2 texData; texData.m_width = meshData.m_textureWidth; texData.m_height = meshData.m_textureHeight; texData.textureData = meshData.m_textureImage; texturesOut.push_back(texData); } glmesh = meshData.m_gfxShape; } break; } case MY_FILE_STL: { glmesh = LoadMeshFromSTL(fullPath); break; } case MY_FILE_COLLADA: { btAlignedObjectArray<GLInstanceGraphicsShape> visualShapes; btAlignedObjectArray<ColladaGraphicsInstance> visualShapeInstances; btTransform upAxisTrans; upAxisTrans.setIdentity(); float unitMeterScaling = 1; int upAxis = 2; LoadMeshFromCollada(fullPath, visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, upAxis); glmesh = new GLInstanceGraphicsShape; // int index = 0; glmesh->m_indices = new b3AlignedObjectArray<int>(); glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>(); for (int i = 0; i<visualShapeInstances.size(); i++) { ColladaGraphicsInstance* instance = &visualShapeInstances[i]; GLInstanceGraphicsShape* gfxShape = &visualShapes[instance->m_shapeIndex]; b3AlignedObjectArray<GLInstanceVertex> verts; verts.resize(gfxShape->m_vertices->size()); int baseIndex = glmesh->m_vertices->size(); for (int i = 0; i<gfxShape->m_vertices->size(); i++) { verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0]; verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1]; verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2]; verts[i].uv[0] = gfxShape->m_vertices->at(i).uv[0]; verts[i].uv[1] = gfxShape->m_vertices->at(i).uv[1]; verts[i].xyzw[0] = gfxShape->m_vertices->at(i).xyzw[0]; verts[i].xyzw[1] = gfxShape->m_vertices->at(i).xyzw[1]; verts[i].xyzw[2] = gfxShape->m_vertices->at(i).xyzw[2]; verts[i].xyzw[3] = gfxShape->m_vertices->at(i).xyzw[3]; } int curNumIndices = glmesh->m_indices->size(); int additionalIndices = gfxShape->m_indices->size(); glmesh->m_indices->resize(curNumIndices + additionalIndices); for (int k = 0; k<additionalIndices; k++) { glmesh->m_indices->at(curNumIndices + k) = gfxShape->m_indices->at(k) + baseIndex; } //compensate upAxisTrans and unitMeterScaling here btMatrix4x4 upAxisMat; upAxisMat.setIdentity(); // upAxisMat.setPureRotation(upAxisTrans.getRotation()); btMatrix4x4 unitMeterScalingMat; unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling, unitMeterScaling, unitMeterScaling)); btMatrix4x4 worldMat = unitMeterScalingMat*upAxisMat*instance->m_worldTransform; //btMatrix4x4 worldMat = instance->m_worldTransform; int curNumVertices = glmesh->m_vertices->size(); int additionalVertices = verts.size(); glmesh->m_vertices->reserve(curNumVertices + additionalVertices); for (int v = 0; v<verts.size(); v++) { btVector3 pos(verts[v].xyzw[0], verts[v].xyzw[1], verts[v].xyzw[2]); pos = worldMat*pos; verts[v].xyzw[0] = float(pos[0]); verts[v].xyzw[1] = float(pos[1]); verts[v].xyzw[2] = float(pos[2]); glmesh->m_vertices->push_back(verts[v]); } } glmesh->m_numIndices = glmesh->m_indices->size(); glmesh->m_numvertices = glmesh->m_vertices->size(); //glmesh = LoadMeshFromCollada(fullPath); break; } default: { b3Warning("Error: unsupported file type for Visual mesh: %s\n", fullPath); btAssert(0); } } if (glmesh && glmesh->m_vertices && (glmesh->m_numvertices>0)) { //apply the geometry scaling for (int i=0;i<glmesh->m_vertices->size();i++) { glmesh->m_vertices->at(i).xyzw[0] *= visual->m_geometry.m_meshScale[0]; glmesh->m_vertices->at(i).xyzw[1] *= visual->m_geometry.m_meshScale[1]; glmesh->m_vertices->at(i).xyzw[2] *= visual->m_geometry.m_meshScale[2]; } } else { b3Warning("issue extracting mesh from COLLADA/STL file %s\n", fullPath); } } else { b3Warning("mesh geometry not found %s\n", fullPath); } } } break; } default: { b3Warning("Error: unknown visual geometry type\n"); } } //if we have a convex, tesselate into localVertices/localIndices if ((glmesh==0) && convexColShape) { btShapeHull* hull = new btShapeHull(convexColShape); hull->buildHull(0.0); { // int strideInBytes = 9*sizeof(float); int numVertices = hull->numVertices(); int numIndices = hull->numIndices(); glmesh = new GLInstanceGraphicsShape; // int index = 0; glmesh->m_indices = new b3AlignedObjectArray<int>(); glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>(); for (int i = 0; i < numVertices; i++) { GLInstanceVertex vtx; btVector3 pos = hull->getVertexPointer()[i]; vtx.xyzw[0] = pos.x(); vtx.xyzw[1] = pos.y(); vtx.xyzw[2] = pos.z(); vtx.xyzw[3] = 1.f; pos.normalize(); vtx.normal[0] = pos.x(); vtx.normal[1] = pos.y(); vtx.normal[2] = pos.z(); vtx.uv[0] = 0.5f; vtx.uv[1] = 0.5f; glmesh->m_vertices->push_back(vtx); } btAlignedObjectArray<int> indices; for (int i = 0; i < numIndices; i++) { glmesh->m_indices->push_back(hull->getIndexPointer()[i]); } glmesh->m_numvertices = glmesh->m_vertices->size(); glmesh->m_numIndices = glmesh->m_indices->size(); } delete hull; delete convexColShape; convexColShape = 0; } if (glmesh && glmesh->m_numIndices>0 && glmesh->m_numvertices >0) { int baseIndex = verticesOut.size(); for (int i = 0; i < glmesh->m_indices->size(); i++) { indicesOut.push_back(glmesh->m_indices->at(i) + baseIndex); } for (int i = 0; i < glmesh->m_vertices->size(); i++) { GLInstanceVertex& v = glmesh->m_vertices->at(i); btVector3 vert(v.xyzw[0],v.xyzw[1],v.xyzw[2]); btVector3 vt = visualTransform*vert; v.xyzw[0] = vt[0]; v.xyzw[1] = vt[1]; v.xyzw[2] = vt[2]; btVector3 triNormal(v.normal[0],v.normal[1],v.normal[2]); triNormal = visualTransform.getBasis()*triNormal; v.normal[0] = triNormal[0]; v.normal[1] = triNormal[1]; v.normal[2] = triNormal[2]; verticesOut.push_back(v); } } delete glmesh; }
void StochasticPointRenderer::initializeShader( void ) { const std::string vert_code = "StochasticShader/point.vert"; const std::string frag_code = "StochasticShader/point.frag"; kvs::glew::ShaderSource vert( vert_code ); kvs::glew::ShaderSource frag( frag_code ); if ( BaseClass::isEnabledShading() ) { switch ( BaseClass::m_shader->type() ) { case kvs::Shader::LambertShading: frag.define("ENABLE_LAMBERT_SHADING"); break; case kvs::Shader::PhongShading: frag.define("ENABLE_PHONG_SHADING"); break; case kvs::Shader::BlinnPhongShading: frag.define("ENABLE_BLINN_PHONG_SHADING"); break; default: /* NO SHADING */ break; } } this->create_shaders( m_shader_program, vert, frag ); m_loc_identifier = m_shader_program.attributeLocation( "identifier" ); if ( BaseClass::isEnabledShading() ) { m_shader_program.bind(); switch ( BaseClass::m_shader->type() ) { case kvs::Shader::LambertShading: { const GLfloat Ka = ((kvs::Shader::Lambert*)(BaseClass::m_shader))->Ka; const GLfloat Kd = ((kvs::Shader::Lambert*)(BaseClass::m_shader))->Kd; m_shader_program.setUniformValuef( "shading.Ka", Ka ); m_shader_program.setUniformValuef( "shading.Kd", Kd ); break; } case kvs::Shader::PhongShading: { const GLfloat Ka = ((kvs::Shader::Phong*)(BaseClass::m_shader))->Ka; const GLfloat Kd = ((kvs::Shader::Phong*)(BaseClass::m_shader))->Kd; const GLfloat Ks = ((kvs::Shader::Phong*)(BaseClass::m_shader))->Ks; const GLfloat S = ((kvs::Shader::Phong*)(BaseClass::m_shader))->S; m_shader_program.setUniformValuef( "shading.Ka", Ka ); m_shader_program.setUniformValuef( "shading.Kd", Kd ); m_shader_program.setUniformValuef( "shading.Ks", Ks ); m_shader_program.setUniformValuef( "shading.S", S ); break; } case kvs::Shader::BlinnPhongShading: { const GLfloat Ka = ((kvs::Shader::BlinnPhong*)(BaseClass::m_shader))->Ka; const GLfloat Kd = ((kvs::Shader::BlinnPhong*)(BaseClass::m_shader))->Kd; const GLfloat Ks = ((kvs::Shader::BlinnPhong*)(BaseClass::m_shader))->Ks; const GLfloat S = ((kvs::Shader::BlinnPhong*)(BaseClass::m_shader))->S; m_shader_program.setUniformValuef( "shading.Ka", Ka ); m_shader_program.setUniformValuef( "shading.Kd", Kd ); m_shader_program.setUniformValuef( "shading.Ks", Ks ); m_shader_program.setUniformValuef( "shading.S", S ); break; } default: /* NO SHADING */ break; } m_shader_program.unbind(); } }
bool Map::LoadV2(FILE *f) { uint32 data_size; if (fread(&data_size, sizeof(data_size), 1, f) != 1) { return false; } uint32 buffer_size; if (fread(&buffer_size, sizeof(buffer_size), 1, f) != 1) { return false; } std::vector<char> data; data.resize(data_size); if (fread(&data[0], data_size, 1, f) != 1) { return false; } std::vector<char> buffer; buffer.resize(buffer_size); uint32 v = InflateData(&data[0], data_size, &buffer[0], buffer_size); char *buf = &buffer[0]; uint32 vert_count; uint32 ind_count; uint32 nc_vert_count; uint32 nc_ind_count; uint32 model_count; uint32 plac_count; uint32 plac_group_count; uint32 tile_count; uint32 quads_per_tile; float units_per_vertex; vert_count = *(uint32*)buf; buf += sizeof(uint32); ind_count = *(uint32*)buf; buf += sizeof(uint32); nc_vert_count = *(uint32*)buf; buf += sizeof(uint32); nc_ind_count = *(uint32*)buf; buf += sizeof(uint32); model_count = *(uint32*)buf; buf += sizeof(uint32); plac_count = *(uint32*)buf; buf += sizeof(uint32); plac_group_count = *(uint32*)buf; buf += sizeof(uint32); tile_count = *(uint32*)buf; buf += sizeof(uint32); quads_per_tile = *(uint32*)buf; buf += sizeof(uint32); units_per_vertex = *(float*)buf; buf += sizeof(float); std::vector<Vertex> verts; std::vector<uint32> indices; for (uint32 i = 0; i < vert_count; ++i) { float x; float y; float z; x = *(float*)buf; buf += sizeof(float); y = *(float*)buf; buf += sizeof(float); z = *(float*)buf; buf += sizeof(float); Vertex vert(x, y, z); verts.push_back(vert); } for (uint32 i = 0; i < ind_count; ++i) { uint32 index; index = *(uint32*)buf; buf += sizeof(uint32); indices.push_back(index); } for (uint32 i = 0; i < nc_vert_count; ++i) { buf += sizeof(float) * 3; } for (uint32 i = 0; i < nc_ind_count; ++i) { buf += sizeof(uint32); } std::map<std::string, std::shared_ptr<ModelEntry>> models; for (uint32 i = 0; i < model_count; ++i) { std::shared_ptr<ModelEntry> me(new ModelEntry); std::string name = buf; buf += name.length() + 1; uint32 vert_count = *(uint32*)buf; buf += sizeof(uint32); uint32 poly_count = *(uint32*)buf; buf += sizeof(uint32); me->verts.resize(vert_count); for (uint32 j = 0; j < vert_count; ++j) { float x = *(float*)buf; buf += sizeof(float); float y = *(float*)buf; buf += sizeof(float); float z = *(float*)buf; buf += sizeof(float); me->verts[j] = Vertex(x, y, z); } me->polys.resize(poly_count); for (uint32 j = 0; j < poly_count; ++j) { uint32 v1 = *(uint32*)buf; buf += sizeof(uint32); uint32 v2 = *(uint32*)buf; buf += sizeof(uint32); uint32 v3 = *(uint32*)buf; buf += sizeof(uint32); uint8 vis = *(uint8*)buf; buf += sizeof(uint8); ModelEntry::Poly p; p.v1 = v1; p.v2 = v2; p.v3 = v3; p.vis = vis; me->polys[j] = p; } models[name] = me; } for (uint32 i = 0; i < plac_count; ++i) { std::string name = buf; buf += name.length() + 1; float x = *(float*)buf; buf += sizeof(float); float y = *(float*)buf; buf += sizeof(float); float z = *(float*)buf; buf += sizeof(float); float x_rot = *(float*)buf; buf += sizeof(float); float y_rot = *(float*)buf; buf += sizeof(float); float z_rot = *(float*)buf; buf += sizeof(float); float x_scale = *(float*)buf; buf += sizeof(float); float y_scale = *(float*)buf; buf += sizeof(float); float z_scale = *(float*)buf; buf += sizeof(float); if (models.count(name) == 0) continue; auto model = models[name]; auto &mod_polys = model->polys; auto &mod_verts = model->verts; for (uint32 j = 0; j < mod_polys.size(); ++j) { auto ¤t_poly = mod_polys[j]; auto v1 = mod_verts[current_poly.v1]; auto v2 = mod_verts[current_poly.v2]; auto v3 = mod_verts[current_poly.v3]; RotateVertex(v1, x_rot, y_rot, z_rot); RotateVertex(v2, x_rot, y_rot, z_rot); RotateVertex(v3, x_rot, y_rot, z_rot); ScaleVertex(v1, x_scale, y_scale, z_scale); ScaleVertex(v2, x_scale, y_scale, z_scale); ScaleVertex(v3, x_scale, y_scale, z_scale); TranslateVertex(v1, x, y, z); TranslateVertex(v2, x, y, z); TranslateVertex(v3, x, y, z); float t = v1.x; v1.x = v1.y; v1.y = t; t = v2.x; v2.x = v2.y; v2.y = t; t = v3.x; v3.x = v3.y; v3.y = t; if (current_poly.vis != 0) { verts.push_back(v1); verts.push_back(v2); verts.push_back(v3); indices.push_back((uint32)verts.size() - 3); indices.push_back((uint32)verts.size() - 2); indices.push_back((uint32)verts.size() - 1); } } } for (uint32 i = 0; i < plac_group_count; ++i) { float x = *(float*)buf; buf += sizeof(float); float y = *(float*)buf; buf += sizeof(float); float z = *(float*)buf; buf += sizeof(float); float x_rot = *(float*)buf; buf += sizeof(float); float y_rot = *(float*)buf; buf += sizeof(float); float z_rot = *(float*)buf; buf += sizeof(float); float x_scale = *(float*)buf; buf += sizeof(float); float y_scale = *(float*)buf; buf += sizeof(float); float z_scale = *(float*)buf; buf += sizeof(float); float x_tile = *(float*)buf; buf += sizeof(float); float y_tile = *(float*)buf; buf += sizeof(float); float z_tile = *(float*)buf; buf += sizeof(float); uint32 p_count = *(uint32*)buf; buf += sizeof(uint32); for (uint32 j = 0; j < p_count; ++j) { std::string name = buf; buf += name.length() + 1; float p_x = *(float*)buf; buf += sizeof(float); float p_y = *(float*)buf; buf += sizeof(float); float p_z = *(float*)buf; buf += sizeof(float); float p_x_rot = *(float*)buf * 3.14159f / 180; buf += sizeof(float); float p_y_rot = *(float*)buf * 3.14159f / 180; buf += sizeof(float); float p_z_rot = *(float*)buf * 3.14159f / 180; buf += sizeof(float); float p_x_scale = *(float*)buf; buf += sizeof(float); float p_y_scale = *(float*)buf; buf += sizeof(float); float p_z_scale = *(float*)buf; buf += sizeof(float); if (models.count(name) == 0) continue; auto &model = models[name]; for (size_t k = 0; k < model->polys.size(); ++k) { auto &poly = model->polys[k]; Vertex v1, v2, v3; v1 = model->verts[poly.v1]; v2 = model->verts[poly.v2]; v3 = model->verts[poly.v3]; ScaleVertex(v1, p_x_scale, p_y_scale, p_z_scale); ScaleVertex(v2, p_x_scale, p_y_scale, p_z_scale); ScaleVertex(v3, p_x_scale, p_y_scale, p_z_scale); TranslateVertex(v1, p_x, p_y, p_z); TranslateVertex(v2, p_x, p_y, p_z); TranslateVertex(v3, p_x, p_y, p_z); RotateVertex(v1, x_rot * 3.14159f / 180.0f, 0, 0); RotateVertex(v2, x_rot * 3.14159f / 180.0f, 0, 0); RotateVertex(v3, x_rot * 3.14159f / 180.0f, 0, 0); RotateVertex(v1, 0, y_rot * 3.14159f / 180.0f, 0); RotateVertex(v2, 0, y_rot * 3.14159f / 180.0f, 0); RotateVertex(v3, 0, y_rot * 3.14159f / 180.0f, 0); Vertex correction(p_x, p_y, p_z); RotateVertex(correction, x_rot * 3.14159f / 180.0f, 0, 0); TranslateVertex(v1, -correction.x, -correction.y, -correction.z); TranslateVertex(v2, -correction.x, -correction.y, -correction.z); TranslateVertex(v3, -correction.x, -correction.y, -correction.z); RotateVertex(v1, p_x_rot, 0, 0); RotateVertex(v2, p_x_rot, 0, 0); RotateVertex(v3, p_x_rot, 0, 0); RotateVertex(v1, 0, -p_y_rot, 0); RotateVertex(v2, 0, -p_y_rot, 0); RotateVertex(v3, 0, -p_y_rot, 0); RotateVertex(v1, 0, 0, p_z_rot); RotateVertex(v2, 0, 0, p_z_rot); RotateVertex(v3, 0, 0, p_z_rot); TranslateVertex(v1, correction.x, correction.y, correction.z); TranslateVertex(v2, correction.x, correction.y, correction.z); TranslateVertex(v3, correction.x, correction.y, correction.z); RotateVertex(v1, 0, 0, z_rot * 3.14159f / 180.0f); RotateVertex(v2, 0, 0, z_rot * 3.14159f / 180.0f); RotateVertex(v3, 0, 0, z_rot * 3.14159f / 180.0f); ScaleVertex(v1, x_scale, y_scale, z_scale); ScaleVertex(v2, x_scale, y_scale, z_scale); ScaleVertex(v3, x_scale, y_scale, z_scale); TranslateVertex(v1, x_tile, y_tile, z_tile); TranslateVertex(v2, x_tile, y_tile, z_tile); TranslateVertex(v3, x_tile, y_tile, z_tile); TranslateVertex(v1, x, y, z); TranslateVertex(v2, x, y, z); TranslateVertex(v3, x, y, z); float t = v1.x; v1.x = v1.y; v1.y = t; t = v2.x; v2.x = v2.y; v2.y = t; t = v3.x; v3.x = v3.y; v3.y = t; if (poly.vis != 0) { verts.push_back(v1); verts.push_back(v2); verts.push_back(v3); indices.push_back((uint32)verts.size() - 3); indices.push_back((uint32)verts.size() - 2); indices.push_back((uint32)verts.size() - 1); } } } } uint32 ter_quad_count = (quads_per_tile * quads_per_tile); uint32 ter_vert_count = ((quads_per_tile + 1) * (quads_per_tile + 1)); std::vector<uint8> flags; std::vector<float> floats; flags.resize(ter_quad_count); floats.resize(ter_vert_count); for (uint32 i = 0; i < tile_count; ++i) { bool flat; flat = *(bool*)buf; buf += sizeof(bool); float x; x = *(float*)buf; buf += sizeof(float); float y; y = *(float*)buf; buf += sizeof(float); if (flat) { float z; z = *(float*)buf; buf += sizeof(float); float QuadVertex1X = x; float QuadVertex1Y = y; float QuadVertex1Z = z; float QuadVertex2X = QuadVertex1X + (quads_per_tile * units_per_vertex); float QuadVertex2Y = QuadVertex1Y; float QuadVertex2Z = QuadVertex1Z; float QuadVertex3X = QuadVertex2X; float QuadVertex3Y = QuadVertex1Y + (quads_per_tile * units_per_vertex); float QuadVertex3Z = QuadVertex1Z; float QuadVertex4X = QuadVertex1X; float QuadVertex4Y = QuadVertex3Y; float QuadVertex4Z = QuadVertex1Z; uint32 current_vert = (uint32)verts.size() + 3; verts.push_back(Vertex(QuadVertex1X, QuadVertex1Y, QuadVertex1Z)); verts.push_back(Vertex(QuadVertex2X, QuadVertex2Y, QuadVertex2Z)); verts.push_back(Vertex(QuadVertex3X, QuadVertex3Y, QuadVertex3Z)); verts.push_back(Vertex(QuadVertex4X, QuadVertex4Y, QuadVertex4Z)); indices.push_back(current_vert); indices.push_back(current_vert - 2); indices.push_back(current_vert - 1); indices.push_back(current_vert); indices.push_back(current_vert - 3); indices.push_back(current_vert - 2); } else { //read flags for (uint32 j = 0; j < ter_quad_count; ++j) { uint8 f; f = *(uint8*)buf; buf += sizeof(uint8); flags[j] = f; } //read floats for (uint32 j = 0; j < ter_vert_count; ++j) { float f; f = *(float*)buf; buf += sizeof(float); floats[j] = f; } int row_number = -1; std::map<std::tuple<float, float, float>, uint32> cur_verts; for (uint32 quad = 0; quad < ter_quad_count; ++quad) { if ((quad % quads_per_tile) == 0) { ++row_number; } if (flags[quad] & 0x01) continue; float QuadVertex1X = x + (row_number * units_per_vertex); float QuadVertex1Y = y + (quad % quads_per_tile) * units_per_vertex; float QuadVertex1Z = floats[quad + row_number]; float QuadVertex2X = QuadVertex1X + units_per_vertex; float QuadVertex2Y = QuadVertex1Y; float QuadVertex2Z = floats[quad + row_number + quads_per_tile + 1]; float QuadVertex3X = QuadVertex1X + units_per_vertex; float QuadVertex3Y = QuadVertex1Y + units_per_vertex; float QuadVertex3Z = floats[quad + row_number + quads_per_tile + 2]; float QuadVertex4X = QuadVertex1X; float QuadVertex4Y = QuadVertex1Y + units_per_vertex; float QuadVertex4Z = floats[quad + row_number + 1]; uint32 i1, i2, i3, i4; std::tuple<float, float, float> t = std::make_tuple(QuadVertex1X, QuadVertex1Y, QuadVertex1Z); auto iter = cur_verts.find(t); if (iter != cur_verts.end()) { i1 = iter->second; } else { i1 = (uint32)verts.size(); verts.push_back(Vertex(QuadVertex1X, QuadVertex1Y, QuadVertex1Z)); cur_verts[std::make_tuple(QuadVertex1X, QuadVertex1Y, QuadVertex1Z)] = i1; } t = std::make_tuple(QuadVertex2X, QuadVertex2Y, QuadVertex2Z); iter = cur_verts.find(t); if (iter != cur_verts.end()) { i2 = iter->second; } else { i2 = (uint32)verts.size(); verts.push_back(Vertex(QuadVertex2X, QuadVertex2Y, QuadVertex2Z)); cur_verts[std::make_tuple(QuadVertex2X, QuadVertex2Y, QuadVertex2Z)] = i2; } t = std::make_tuple(QuadVertex3X, QuadVertex3Y, QuadVertex3Z); iter = cur_verts.find(t); if (iter != cur_verts.end()) { i3 = iter->second; } else { i3 = (uint32)verts.size(); verts.push_back(Vertex(QuadVertex3X, QuadVertex3Y, QuadVertex3Z)); cur_verts[std::make_tuple(QuadVertex3X, QuadVertex3Y, QuadVertex3Z)] = i3; } t = std::make_tuple(QuadVertex4X, QuadVertex4Y, QuadVertex4Z); iter = cur_verts.find(t); if (iter != cur_verts.end()) { i4 = iter->second; } else { i4 = (uint32)verts.size(); verts.push_back(Vertex(QuadVertex4X, QuadVertex4Y, QuadVertex4Z)); cur_verts[std::make_tuple(QuadVertex4X, QuadVertex4Y, QuadVertex4Z)] = i4; } indices.push_back(i4); indices.push_back(i2); indices.push_back(i3); indices.push_back(i4); indices.push_back(i1); indices.push_back(i2); } } } uint32 face_count = indices.size() / 3; if (imp) { imp->rm->release(); imp->rm = nullptr; } else { imp = new impl; } imp->rm = createRaycastMesh((RmUint32)verts.size(), (const RmReal*)&verts[0], face_count, &indices[0]); if (!imp->rm) { delete imp; imp = nullptr; return false; } return true; }
void Pyramid::createVAO(void) { struct pyramidVertexStride { float x; float y; float z; float s; float t; float nx; float ny; float nz; }; struct triangleList { unsigned short v1; unsigned short v2; unsigned short v3; }; pyramidVertexStride pVerts[5]; triangleList pList[6]; #if 1 FileHandle fh2; FileError ferror; ferror = File::open(fh2, "pyramid.vbo", FILE_READ); assert(ferror == FILE_SUCCESS); ferror = File::read(fh2, &pVerts, 5 * sizeof(pyramidVertexStride)); assert(ferror == FILE_SUCCESS); ferror = File::read(fh2, &pList, 6 * sizeof(triangleList)); assert(ferror == FILE_SUCCESS); ferror = File::close(fh2); assert(ferror == FILE_SUCCESS); #else // apex pVerts[0].x = 0.0f; pVerts[0].y = 1.0f; pVerts[0].z = 0.0f; pVerts[0].s = 0.5f; pVerts[0].t = 0.5f; pVerts[0].nx = 0.0f; pVerts[0].ny = 2.0f; pVerts[0].nz = 0.0f; // left front pVerts[1].x = -1.0f; pVerts[1].y = -1.0f; pVerts[1].z = 1.0f;//-1.0f; pVerts[1].s = 0.0f; pVerts[1].t = 0.0f; pVerts[1].nx = -3.0f; pVerts[1].ny = -5.0f; pVerts[1].nz = -3.0f; // right front pVerts[2].x = 1.0f; pVerts[2].y = -1.0f; pVerts[2].z = 1.0f; pVerts[2].s = 1.0f; pVerts[2].t = 0.0f; pVerts[2].nx = 3.0f; pVerts[2].ny = -5.0f; pVerts[2].nz = -3.0f; // left back pVerts[3].x = -1.0f; pVerts[3].y = -1.0f; pVerts[3].z = -1.0f; pVerts[3].s = 0.0f; pVerts[3].t = 1.0f; pVerts[3].nx = -3.0f; pVerts[3].ny = -5.0f; pVerts[3].nz = 3.0f; // right back pVerts[4].x = 1.0f; pVerts[4].y = -1.0f; pVerts[4].z = -1.0f; pVerts[4].s = 1.0f; pVerts[4].t = 1.0f; pVerts[4].nx = 3.0f; pVerts[4].ny = -5.0f; pVerts[4].nz = 3.0f; // front pList[0].v1 = 0; pList[0].v2 = 1; pList[0].v3 = 2; // left pList[1].v1 = 0; pList[1].v2 = 3; pList[1].v3 = 1; // right pList[2].v1 = 0; pList[2].v2 = 2; pList[2].v3 = 4; // back pList[3].v1 = 0; pList[3].v2 = 4; pList[3].v3 = 3; // bottom 1 pList[4].v1 = 2; pList[4].v2 = 1; pList[4].v3 = 3; // bottom 2 pList[5].v1 = 4; pList[5].v2 = 2; pList[5].v3 = 3; //Write the data to a file --------------------- FileHandle fh; FileError ferror; //-----------WRITE-------------------------------- ferror = File::open(fh, "pyramid.vbo", FILE_WRITE); assert(ferror == FILE_SUCCESS); //Write the data ferror = File::write(fh, &pVerts, 5 * sizeof(pyramidVertexStride)); assert(ferror == FILE_SUCCESS); ferror = File::write(fh, &pList, 6 * sizeof(triangleList)); assert(ferror == FILE_SUCCESS); ferror = File::close(fh); assert(ferror == FILE_SUCCESS); #endif if (test) { for( int i = 0; i<5; i++) { Matrix Trans(TRANS, 0.0f, 1.0f, 0.0f); //Matrix Scale(SCALE, 1.0f, 0.5f, 1.0f); Matrix Scale(SCALE, 0.3f, 0.1f, 0.3f); Matrix Rot( ROT_X, 90.0f * MATH_PI_180); Matrix M = Trans * Scale * Rot; Matrix Scale2( SCALE, 13.0f, 13.0f, 109.43f); Matrix Rot2; Rot2.set(ROT_ORIENT, Vect(1.0f,0.0f,0.0f), Vect( 0.0f, 1.0f, 0.0f) ); M = M * Scale2 * Rot2; //M = M * Scale2 ; Vect vert( pVerts[i].x, pVerts[i].y, pVerts[i].z); Vect vertNorm( pVerts[i].nx, pVerts[i].ny, pVerts[i].nz); Vect vout; Vect voutNorm; vout = vert * M; voutNorm = vertNorm * M; pVerts[i].x = vout[x] ; pVerts[i].y = vout[y] ; pVerts[i].z = vout[z] ; pVerts[i].nx = voutNorm[x]; pVerts[i].ny = voutNorm[y]; pVerts[i].nz = voutNorm[z]; printf(" vert[%d] %f %f %f\n",i, vout[x], vout[y], vout[z]); } } /* Allocate and assign a Vertex Array Object to our handle */ glGenVertexArrays(1, &this->vao); /* Bind our Vertex Array Object as the current used object */ glBindVertexArray(this->vao); //Create two buffers GLuint vbo[2]; /* Allocate and assign two Vertex Buffer Objects to our handle */ glGenBuffers(2, vbo); // Load the combined data: --------------------------------------------------------- /* Bind our first VBO as being the active buffer and storing vertex attributes (coordinates) */ glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); /* Copy the vertex data to our buffer */ // glBufferData(type, size in bytes, data, usage) glBufferData(GL_ARRAY_BUFFER, sizeof(pyramidVertexStride) * 5, &pVerts, GL_STATIC_DRAW); // VERTEX data: --------------------------------------------------------- // Set Attribute to 0 // WHY - 0? and not 1,2,3 (this is tied to the shader attribute, it is defined in GLShaderManager.h) // GLT_ATTRIBUTE_VERTEX = 0 // Specifies the index of the generic vertex attribute to be enabled glEnableVertexAttribArray(0); //Compute offset void *offsetVert = (void *)((unsigned int)&pVerts[0].x - (unsigned int)&pVerts); /* Specify that our coordinate data is going into attribute index 0, and contains 3 floats per vertex */ // ( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(pyramidVertexStride), offsetVert); // Texture data: --------------------------------------------------------- // Set Attribute to 3 // WHY - 3? and not 1,2,3 (this is tied to the shader attribute, it is defined in GLShaderManager.h) // GLT_ATTRIBUTE_TEXTURE0 = 3 // Specifies the index of the generic vertex attribute to be enabled glEnableVertexAttribArray(3); //Compute offset void *offsetTex = (void *)((unsigned int)&pVerts[0].s - (unsigned int)&pVerts); /* Specify that our coordinate data is going into attribute index 3, and contains 2 floats per vertex */ // ( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(pyramidVertexStride), offsetTex); // Normal data: --------------------------------------------------------- // Set Attribute to 2 // WHY - 2? and not 1,2,3 (this is tied to the shader attribute, it is defined in GLShaderManager.h) // GLT_ATTRIBUTE_NORMAL = 2 // Specifies the index of the generic vertex attribute to be enabled glEnableVertexAttribArray(2); //Compute offset void *offsetNorm = (void *)((unsigned int)&pVerts[0].nx - (unsigned int)&pVerts); /* Specify that our coordinate data is going into attribute index 3, and contains 2 floats per vertex */ // ( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(pyramidVertexStride), offsetNorm); // Load the index data: --------------------------------------------------------- /* Bind our 2nd VBO as being the active buffer and storing index ) */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); /* Copy the index data to our buffer */ // glBufferData(type, size in bytes, data, usage) glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(triangleList)*6, pList, GL_STATIC_DRAW); }
void core_numbers(const Graph& g, KCoreMap kcm, PositionMap pos) { typedef typename graph_traits<Graph>::vertex_descriptor vertex; typedef typename graph_traits<Graph>::degree_size_type size_type; BGL_FORALL_VERTICES_T(v,g,Graph) { kcm[v] = 0; } // compute the degree of all vertices BGL_FORALL_EDGES_T(e,g,Graph) { ++kcm[source(e,g)]; } size_type max_deg = 0; // compute the maximum degree BGL_FORALL_VERTICES_T(v,g,Graph) { if (kcm[v] > max_deg) { max_deg = kcm[v]; } } // now we sort vertices into bins by their degree // (we buffer this vector by 2 extra spots to make // some of the computations easier. // 1. because deg > 0, we need max_deg+1 to index w/ deg itself // 2. because we want to make things really easy, we extend // the array one past degree to make computing partial_sums // trivial std::vector<size_type> bin(max_deg+2); // compute the size of each bin BGL_FORALL_VERTICES_T(v,g,Graph) { ++bin[kcm[v]]; } // this loop sets bin[d] to the starting position of vertices // with degree d in the vert array size_type cur_pos = 0; for (size_type cur_deg = 0; cur_deg < max_deg+2; ++cur_deg) { size_type tmp = bin[cur_deg]; bin[cur_deg] = cur_pos; cur_pos += tmp; } // place the vertices std::vector<vertex> vert(num_vertices(g)); BGL_FORALL_VERTICES_T(v,g,Graph) { pos[v] = bin[kcm[v]]; vert[pos[v]] = v; ++bin[kcm[v]]; }
/*===========================================================================*/ void StochasticUniformGridRenderer::Engine::create_shader_program( const kvs::StructuredVolumeObject* volume ) { // Build bounding cube shader. { kvs::ShaderSource vert("RC_bounding_cube.vert"); kvs::ShaderSource frag("RC_bounding_cube.frag"); m_bounding_cube_shader.build( vert, frag ); } // Build ray caster. { kvs::ShaderSource vert("SR_uniform_grid.vert"); kvs::ShaderSource frag("SR_uniform_grid.frag"); if ( isEnabledShading() ) { switch ( shader().type() ) { case kvs::Shader::LambertShading: frag.define("ENABLE_LAMBERT_SHADING"); break; case kvs::Shader::PhongShading: frag.define("ENABLE_PHONG_SHADING"); break; case kvs::Shader::BlinnPhongShading: frag.define("ENABLE_BLINN_PHONG_SHADING"); break; default: /* NO SHADING */ break; } } m_ray_casting_shader.build( vert, frag ); } // Set uniform variables. const kvs::Vector3ui r = volume->resolution(); const kvs::Real32 max_ngrids = static_cast<kvs::Real32>( kvs::Math::Max( r.x(), r.y(), r.z() ) ); const kvs::Vector3f resolution( static_cast<float>(r.x()), static_cast<float>(r.y()), static_cast<float>(r.z()) ); const kvs::Vector3f ratio( r.x() / max_ngrids, r.y() / max_ngrids, r.z() / max_ngrids ); const kvs::Vector3f reciprocal( 1.0f / r.x(), 1.0f / r.y(), 1.0f / r.z() ); kvs::Real32 min_range = 0.0f; kvs::Real32 max_range = 0.0f; kvs::Real32 min_value = m_transfer_function.colorMap().minValue(); kvs::Real32 max_value = m_transfer_function.colorMap().maxValue(); const std::type_info& type = volume->values().typeInfo()->type(); if ( type == typeid( kvs::UInt8 ) ) { min_range = 0.0f; max_range = 255.0f; if ( !m_transfer_function.hasRange() ) { min_value = 0.0f; max_value = 255.0f; } } else if ( type == typeid( kvs::Int8 ) ) { min_range = static_cast<kvs::Real32>( kvs::Value<kvs::UInt8>::Min() ); max_range = static_cast<kvs::Real32>( kvs::Value<kvs::UInt8>::Max() ); if ( !m_transfer_function.hasRange() ) { min_value = -128.0f; max_value = 127.0f; } } else if ( type == typeid( kvs::UInt16 ) ) { min_range = static_cast<kvs::Real32>( kvs::Value<kvs::UInt16>::Min() ); max_range = static_cast<kvs::Real32>( kvs::Value<kvs::UInt16>::Max() ); if ( !m_transfer_function.hasRange() ) { min_value = static_cast<kvs::Real32>( volume->minValue() ); max_value = static_cast<kvs::Real32>( volume->maxValue() ); } } else if ( type == typeid( kvs::Int16 ) ) { min_range = static_cast<kvs::Real32>( kvs::Value<kvs::Int16>::Min() ); max_range = static_cast<kvs::Real32>( kvs::Value<kvs::Int16>::Max() ); if ( !m_transfer_function.hasRange() ) { min_value = static_cast<kvs::Real32>( volume->minValue() ); max_value = static_cast<kvs::Real32>( volume->maxValue() ); } } else if ( type == typeid( kvs::UInt32 ) || type == typeid( kvs::Int32 ) || type == typeid( kvs::Real32 ) ) { min_range = 0.0f; max_range = 1.0f; min_value = 0.0f; max_value = 1.0f; } else { kvsMessageError( "Not supported data type '%s'.", volume->values().typeInfo()->typeName() ); } m_ray_casting_shader.bind(); m_ray_casting_shader.setUniform( "volume.resolution", resolution ); m_ray_casting_shader.setUniform( "volume.resolution_ratio", ratio ); m_ray_casting_shader.setUniform( "volume.resolution_reciprocal", reciprocal ); m_ray_casting_shader.setUniform( "volume.min_range", min_range ); m_ray_casting_shader.setUniform( "volume.max_range", max_range ); m_ray_casting_shader.setUniform( "transfer_function.min_value", min_value ); m_ray_casting_shader.setUniform( "transfer_function.max_value", max_value ); m_ray_casting_shader.setUniform( "dt", m_step ); m_ray_casting_shader.setUniform( "shading.Ka", shader().Ka ); m_ray_casting_shader.setUniform( "shading.Kd", shader().Kd ); m_ray_casting_shader.setUniform( "shading.Ks", shader().Ks ); m_ray_casting_shader.setUniform( "shading.S", shader().S ); m_ray_casting_shader.unbind(); }