void clipmap_ring::generate_indices() { unsigned int indices[4]; ibuf.clear(); for (int j = 0; j < PHI_STEPS; ++j) { for (int i = 0; i < THETA_STEPS; ++i) { indices[0] = static_cast<unsigned int>( (j+0) * (THETA_STEPS+1) + (i+0) ); // lower left indices[1] = static_cast<unsigned int>( (j+0) * (THETA_STEPS+1) + (i+1) ); // lower right indices[2] = static_cast<unsigned int>( (j+1) * (THETA_STEPS+1) + (i+1) ); // upper right indices[3] = static_cast<unsigned int>( (j+1) * (THETA_STEPS+1) + (i+0) ); // upper left repair_quad(indices); ibuf.append(indices[0]); ibuf.append(indices[1]); ibuf.append(indices[3]); ibuf.append(indices[2]); ibuf.append(indices[3]); ibuf.append(indices[1]); } } } // clipmap_ring::generate_indices()
void partition_table::partition(MonomialIdeal * &I, array<MonomialIdeal *> &result) // consumes and frees I { int k; reset(I->topvar()+1); // Create the sets for (Index<MonomialIdeal> i = I->first(); i.valid(); i++) if (n_sets > 1) merge_in((*I)[i]->monom().raw()); else break; if (n_sets == 1) { result.append(I); return; } int this_label = -1; n_sets = 0; for (k=0; k<n_vars; k++) if (occurs[k] && dad[k] < 0) { dad[k] = this_label--; n_sets++; } if (n_sets == 1) { result.append(I); return; } int first = result.length(); for (k=0; k<n_sets; k++) result.append(new MonomialIdeal(I->get_ring(), mi_stash)); // Now partition the monomials Bag *b; while (I->remove(b)) { const intarray &m = b->monom(); int v = varpower::topvar(m.raw()); int loc = -1-dad[representative(v)]; result[first+loc]->insert_minimal(b); } delete I; }
void clipmap_ring::repair_quad(unsigned int *indices) { int quadrant_one = 0; int quadrant_four = 0; for (int i = 0; i < 4; ++i) { double theta = cbuf[ indices[i]*2 + 1 ]; if (theta < math::PI_TIMES_2 && theta > math::PI * 0.75) quadrant_four++; else if (theta < math::PI_OVER_2) quadrant_one++; } // if (quadrant_one && quadrant_four) { for (int i = 0; i < 4; ++i) { double phi = cbuf[ indices[i]*2 + 0 ]; double theta = cbuf[ indices[i]*2 + 1 ]; if (theta > math::PI * 0.75) theta -= math::PI_TIMES_2; unsigned int orig_index = indices[i]; unsigned int new_index = vbuf.size() / 8; indices[i] = new_index; float s = static_cast<float>(theta / math::PI_TIMES_2); float t = 1.0f - static_cast<float>(phi / math::PI); vbuf.append(s); vbuf.append(t); vbuf.append( vbuf[orig_index*8 + 2] ); vbuf.append( vbuf[orig_index*8 + 3] ); vbuf.append( vbuf[orig_index*8 + 4] ); vbuf.append( vbuf[orig_index*8 + 5] ); vbuf.append( vbuf[orig_index*8 + 6] ); vbuf.append( vbuf[orig_index*8 + 7] ); } } } // clipmap_ring::repair_quad()
//returns true if tag closes itself (<tag/>); false if not (<tag>) inline bool parseHead(const char *&p) { //parse name const char *nameStart = ++p; //skip '<' while(isName(*p)) p++; const char *nameEnd = p; copy(name, nameStart, nameEnd - nameStart); if(name.empty()) throw "missing element name"; //parse attributes while(*p) { while(isWhitespace(*p)) p++; if(!*p) throw "unclosed attribute"; if(*p == '?' || *p == '/' || *p == '>') break; //parse attribute name Node *attribute = new Node; children.append(attribute); attribute->attribute = true; const char *nameStart = p; while(isName(*p)) p++; const char *nameEnd = p; copy(attribute->name, nameStart, nameEnd - nameStart); if(attribute->name.empty()) throw "missing attribute name"; //parse attribute data if(*p++ != '=') throw "missing attribute value"; char terminal = *p++; if(terminal != '\'' && terminal != '\"') throw "attribute value not quoted"; const char *dataStart = p; while(*p && *p != terminal) p++; if(!*p) throw "missing attribute data terminal"; const char *dataEnd = p++; //skip closing terminal copy(attribute->data, dataStart, dataEnd - dataStart); } //parse closure if(*p == '?' && *(p + 1) == '>') { p += 2; return true; } if(*p == '/' && *(p + 1) == '>') { p += 2; return true; } if(*p == '>') { p += 1; return false; } throw "invalid element tag"; }
//parse element and all of its child elements inline void parseElement(const char *&p) { Node *node = new Node; children.append(node); if(node->parseHead(p) == true) return; node->parse(p); }
// delit to bez tech mezer int parametrizer::tokens_get(DATA_FILE_SECTION *p_line, array<PARAM_NODE> &nodes) { assert(p_line); char *p_start = p_line->line_raw_string_get(); char *p_current = p_line->line_raw_string_get(); TOKEN_STATE state = STATE_TOKEN_START; do { switch(state) { case STATE_TOKEN_START: { assert(p_start == p_current); char c = *p_start; if(c == '\0') { state = STATE_STRING_END; } else if(isspace(c)) { p_start++; } else if(is_token_delim(c)) { state = STATE_TOKEN_END; } else { state = STATE_TOKEN_IN; } p_current++; break; } case STATE_TOKEN_IN: { char c = *p_current; if(c == '\0' || is_token_delim(c) || isspace(c)) { state = STATE_TOKEN_END; } else { p_current++; } break; } case STATE_TOKEN_END: { PARAM_NODE token; memset(&token,0,sizeof(token)); char c = *p_start; int length = p_current - p_start; assert(c != '\0' && !isspace(c)); assert(length != 0); if(is_token(p_start, length, token) || is_number(p_start, length, token)) { // It's a number or token nodes.append(token); } else { if(!is_token_delim(p_start[0])) { // We have a variable here if(p_start[length-2] == '.') { // it's a part of color variable (.r .g .b .a) // or a vector variable (.x .y .z) switch(p_start[length-1]) { case 'r': token.content_type = NODE_VAR_VARIABLE_R; length -= 2; break; case 'g': token.content_type = NODE_VAR_VARIABLE_G; length -= 2; break; case 'b': token.content_type = NODE_VAR_VARIABLE_B; length -= 2; break; case 'a': token.content_type = NODE_VAR_VARIABLE_A; length -= 2; break; case 'x': token.content_type = NODE_VAR_VARIABLE_X; length -= 2; break; case 'y': token.content_type = NODE_VAR_VARIABLE_Y; length -= 2; break; case 'z': token.content_type = NODE_VAR_VARIABLE_Z; length -= 2; break; default: p_line->ppline(); pperror(TRUE, "wrong tail .%c",p_start[length-1]); break; } } else { token.content_type = NODE_VAR_VARIABLE; } SYMBOL_TABLE_NODE *p_variable = symbol_table_get(symbol_table_get_active(), p_start, length); if(!p_variable) { p_variable = symbol_table_add(symbol_table_get_active(), p_start, length); } if(token.content_type == NODE_VAR_VARIABLE_R || token.content_type == NODE_VAR_VARIABLE_G || token.content_type == NODE_VAR_VARIABLE_B || token.content_type == NODE_VAR_VARIABLE_A) { if(p_variable->value.type == VARIABLE_UNSET) { p_variable->value.type = VARIABLE_RGBAF; } if(p_variable->value.type != VARIABLE_RGBAF) { p_line->ppline(); pperror(TRUE, "variable %s has to be a color type! (is %s)", p_variable->name, variable_type_translate(p_variable->value.type)); } } else if(token.content_type == NODE_VAR_VARIABLE_X || token.content_type == NODE_VAR_VARIABLE_Y || token.content_type == NODE_VAR_VARIABLE_Z) { if(p_variable->value.type == VARIABLE_UNSET) { p_variable->value.type = VARIABLE_VECT3DF; } if(p_variable->value.type != VARIABLE_VECT3DF) { p_line->ppline(); pperror(TRUE, "variable %s has to be a vector type! (is %s)", p_variable->name, variable_type_translate(p_variable->value.type)); } } token.node_type = NODE_VARIABLE; token.p_cvariable = p_variable; // Append it nodes.append(token); } } p_start = p_current; state = STATE_TOKEN_START; break; } default: break; } } while(state != STATE_STRING_END); return(nodes.num_get()); }
void clipmap_ring::generate_vertices() { // generate vertices (PHI_STEPS rings of THETA_STEPS+1 vertices) cbuf.clear(); vbuf.clear(); double delta_theta = 2.0 * math::PI / static_cast<double>(THETA_STEPS); for (int j = 0; j <= PHI_STEPS; ++j) { double eye_phi = 0; if (level) { double exp = static_cast<double>(-j) / static_cast<double>(PHI_STEPS); eye_phi = start_phi * ::pow(2.0, exp); } else { double delta_phi = (start_phi - end_phi) / static_cast<double>(PHI_STEPS); eye_phi = start_phi - delta_phi * static_cast<double>(j); } for (int i = 0; i <= THETA_STEPS; ++i) { double eye_theta = delta_theta * static_cast<double>(i); double eye_x = ::cos(eye_theta) * ::sin(eye_phi); double eye_y = ::sin(eye_theta) * ::sin(eye_phi); double eye_z = ::cos(eye_phi); quaternion eye_point(0, eye_x, eye_y, eye_z); quaternion yrot_point = (roty * eye_point) * roty_conj; quaternion obj_point = (rotz * yrot_point) * rotz_conj; double obj_x = obj_point.x; double obj_y = obj_point.y; double obj_z = obj_point.z; double obj_phi = ::acos(obj_z); double obj_theta = ::atan2(obj_y, obj_x) + (map_offset * math::PI_TIMES_2); if (obj_theta < 0.0) obj_theta += math::PI_TIMES_2; cbuf.append(obj_phi); cbuf.append(obj_theta); float s = static_cast<float>(obj_theta / math::PI_TIMES_2); float t = 1.0f - static_cast<float>(obj_phi / math::PI); float nx = static_cast<float>(obj_x); float ny = static_cast<float>(obj_y); float nz = static_cast<float>(obj_z); float x = parent->get_equatorial_radius() * nx; float y = parent->get_equatorial_radius() * ny; float z = parent->get_polar_radius() * nz; if (hmap) { double hval, alpha; hmap->get_data(s, t, hval, alpha); vector old_vertex(x, y, z); vector normal(nx, ny, nz); gsgl::real_t alt = static_cast<gsgl::real_t>(hval * hmap->get_altitude()); vector new_vertex = old_vertex + normal*alt; x = new_vertex[0]; y = new_vertex[1]; z = new_vertex[2]; } vbuf.append(s); vbuf.append(t); vbuf.append(nx); vbuf.append(ny); vbuf.append(nz); vbuf.append(x); vbuf.append(y); vbuf.append(z); } } } // clipmap_ring::generate_vertices()
void generate() { //entry _output.append(entry().lines()); }