/*Si, si, it's good for you*/ MAP_SLOPE map_collide_dir(int *obj, int lines, int x1, int y1, int dir) { unsigned int section1=~0, section2=0; int i; for(i=0; i<lines; i++) { section1=MIN(section1, obj[i*2] + x1); section2=MAX(section2, obj[i*2] + x1); } section1 /= (MAP_SECTION_WIDTH*TILE_SIZE); section2 /= (MAP_SECTION_WIDTH*TILE_SIZE); for(i=0; i<map.lines[section1]; i++) { if(map.line_coord[section1][i].x1 == map.line_coord[section1][i].x2) if(collision_test((void *) &map.line_coord[section1][i], 1, 0, 1, obj, lines, x1, y1)) return map_slope_direction(dir, section1, i); } for(i=0; i<map.lines[section1]; i++) { if(collision_test((void *) &map.line_coord[section1][i], 1, 0, 0, obj, lines, x1, y1)) return map_slope_direction(dir, section1, i); } if(section1==section2) return -1; for(i=0; i<map.lines[section2]; i++) { if(map.line_coord[section2][i].x1 == map.line_coord[section2][i].x2) if(collision_test((void *) &map.line_coord[section2][i], 1, 0, 1, obj, lines, x1, y1)) return map_slope_direction(dir, section2, i); } for(i=0; i<map.lines[section2]; i++) { if(collision_test((void *) &map.line_coord[section2][i], 1, 0, 0, obj, lines, x1, y1)) return map_slope_direction(dir, section2, i); } return -1; }
int shape_copy_collides(SHAPE_COPY *shape1, int x1, int y1, SHAPE_COPY *shape2, int x2, int y2) { int i; int buf[4]; if(collision_test(shape1->rot, shape1->lines, x1/1000, y1/1000, shape2->rot, shape2->lines, x2/1000, y2/1000)) return 1; buf[0]=shape1->rot[0]; buf[1]=shape1->rot[1]; for(i=1; i<shape1->lines; i++) { buf[2]=shape1->rot[i*2]; buf[3]=shape1->rot[i*2+1]; if(collision_test(buf, 1, x1/1000, y1/1000, shape2->rot, shape2->lines, x2/1000, y2/1000)) return 1; } buf[0]=shape2->rot[0]; buf[1]=shape2->rot[1]; for(i=1; i<shape2->lines; i++) { buf[2]=shape2->rot[i*2]; buf[3]=shape2->rot[i*2+1]; if(collision_test(shape1->rot, shape1->lines, x1/1000, y1/1000, buf, 1, x2/1000, y2/1000)) return 1; } return 0; }
int map_collide(int *obj, int lines, int x1, int y1) { unsigned int section1=0, section2=0; int i; for(i=0; i<lines; i++) { section1=MIN(section1, obj[i*2] + x1); section2=MAX(section2, obj[i*2] + x1); } section1 /= (MAP_SECTION_WIDTH*TILE_SIZE); section2 /= (MAP_SECTION_WIDTH*TILE_SIZE); for(i=0; i<map.lines[section1]; i++) { if(collision_test((void *) &map.line_coord[section1][i], 1, 0, 0, obj, lines, x1, y1)) return 1; } if(section1==section2) return 0; for(i=0; i<map.lines[section2]; i++) { if(collision_test((void *) &map.line_coord[section2][i], 1, 0, 0, obj, lines, x1, y1)) return 1; } return 0; }
intersection_context surface_mobius::intersect(const ray &emission_ray) const { if (!collision_test(emission_ray)) { return null_intersect; } double ox = emission_ray.origin.x; double oy = emission_ray.origin.y; double oz = emission_ray.origin.z; double dx = emission_ray.dir.x; double dy = emission_ray.dir.y; double dz = emission_ray.dir.z; double R = radius; double coef_0 = 0, coef_1 = 0, coef_2 = 0, coef_3 = 0; coef_0 = ox * ox * oy + oy * oy * oy - 2 * ox * ox * oz - 2 * oy * oy * oz + oy * oz * oz - 2 * ox * oz * R - oy * R * R; coef_1 = dy * ox * ox - 2 * dz * ox * ox + 2 * dx * ox * oy + 3 * dy * oy * oy - 2 * dz * oy * oy - 4 * dx * ox * oz - 4 * dy * oy * oz + 2 * dz * oy * oz + dy * oz * oz - 2 * dz * ox * R - 2 * dx * oz * R - dy * R * R; coef_2 = 2 * dx * dy * ox - 4 * dx * dz * ox + dx * dx * oy + 3 * dy * dy * oy - 4 * dy * dz * oy + dz * dz * oy - 2 * dx * dx * oz - 2 * dy * dy * oz + 2 * dy * dz * oz - 2 * dx * dz * R; coef_3 = dx * dx * dy + dy * dy * dy - 2 * dx * dx * dz - 2 * dy * dy * dz + dy * dz * dz; std::vector<double> coef, result; coef.push_back(coef_0); coef.push_back(coef_1); coef.push_back(coef_2); coef.push_back(coef_3); result = equation_solve(coef, 3); for (std::vector<double>::iterator iter = result.begin(); iter != result.end(); ++iter) { if (*iter > epsilon && inside(emission_ray.at(*iter))) { return intersection_context(*iter); } } return null_intersect; }
intersection_context surface_regpolyhedron::intersect(const ray &emission_ray) const { if (!collision_test(emission_ray)) { return null_intersect; } return surface_convexhull::intersect(emission_ray); }