/* * to_b: Converts decimal to binary * Input: integer d * Output: integer */ int to_b(int d) { int b; // Using Recursive Method if ( d == 0 ) { return 0; } else { b = d%2 + to_b(d/2)*10; return b; } }
int main() { int i; printf("| Dec | Bin | Oct | Hex |\n| --------- | --------- | --------- | --------- |\n"); for ( i=1; i<=256; i++ ) { printf("| %9d | %9d | %9o | %9X |\n", i, to_b(i), i, i); } return 0; }
void GridMap::_update_areas() { //clear the portals for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... Area &a = *E->get(); a.portals.clear(); if (a.instance.is_valid()) { VisualServer::get_singleton()->free(a.instance); a.instance = RID(); } } //test all areas against all areas and create portals - this sucks (slow :( ) for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { Area &a = *E->get(); if (a.exterior_portal) //that's pretty much all it does... yes it is continue; Vector3 from_a(a.from.x, a.from.y, a.from.z); Vector3 to_a(a.to.x, a.to.y, a.to.z); for (Map<int, Area *>::Element *F = area_map.front(); F; F = F->next()) { Area &b = *F->get(); Vector3 from_b(b.from.x, b.from.y, b.from.z); Vector3 to_b(b.to.x, b.to.y, b.to.z); // initially test intersection and discards int axis = -1; float sign = 0; bool valid = true; Vector3 axmin, axmax; for (int i = 0; i < 3; i++) { if (from_a[i] == to_b[i]) { if (axis != -1) { valid = false; break; } axis = i; sign = -1; } else if (from_b[i] == to_a[i]) { if (axis != -1) { valid = false; break; } axis = i; sign = +1; } if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) { valid = false; break; } else { axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i]; axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i]; } } if (axis == -1 || !valid) continue; Transform xf; for (int i = 0; i < 3; i++) { int ax = (axis + i) % 3; Vector3 axis_vec; float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size); axis_vec[ax] = scale; xf.basis.set_axis((2 + i) % 3, axis_vec); xf.origin[i] = axmin[i] * cell_size; } Area::Portal portal; portal.xform = xf; a.portals.push_back(portal); } } _update_area_instances(); }