public static float evaluate(Vector3 point, corporial subject) { float distance_value = 0; for (int i = 0; i < subject.joints.Length; i++) { distance_value = distance_value + subject.joints[i].evaluated_distance(point); } return(distance_value); }
protected static corporial Centre(corporial mass) { corporial centred_mass = new corporial(); centred_mass.joints = new metaball[mass.joints.Length]; Vector3 mass_centre_of_mass = CoM(mass.joints); Vector3 difference; for (int i = 0; i < mass.joints.Length; i++) { difference = new Vector3(mass.joints[i].X, mass.joints[i].Y, mass.joints[i].Z) - mass_centre_of_mass; centred_mass.joints[i] = new metaball(difference.x, difference.y, difference.z, mass.joints[i].Radius); } return(centred_mass); }
protected static corporial mirror_in_zy(corporial mass) { var mirrored_mass = new corporial(); mirrored_mass.joints = new metaball[mass.joints.Length]; for (int i = 0; i < mass.joints.Length; i++) { mirrored_mass.joints[i] = new metaball( -mass.joints[i].X, mass.joints[i].Y, mass.joints[i].Z, mass.joints[i].Radius ); } return(mirrored_mass); }
protected static corporial anitclockwise_rotate_piontwo(corporial mass) { var rotated_mass = new corporial(); rotated_mass.joints = new metaball[mass.joints.Length]; for (int i = 0; i < mass.joints.Length; i++) { rotated_mass.joints[i] = new metaball( -mass.joints[i].Z, mass.joints[i].Y, mass.joints[i].X, mass.joints[i].Radius ); } return(rotated_mass); }
protected static float calculated_cube_size(corporial rendered_object, int target_number_of_vertices) { int number_of_metaballs = rendered_object.joints.Length; float surface_area; float sum_surface_area = 0; float sum_radius = 0; for (int i = 0; i < number_of_metaballs; i++) { surface_area = (float)(4 * System.Math.PI * System.Math.Pow(rendered_object.joints[i].Radius, 2)); sum_surface_area = sum_surface_area + surface_area; sum_radius = sum_radius + rendered_object.joints[i].Radius; } float method1 = (float)System.Math.Sqrt(sum_surface_area / target_number_of_vertices); float surface = (float)(4 * System.Math.PI * System.Math.Pow(sum_radius, 2)); float method2 = (float)System.Math.Sqrt(surface / target_number_of_vertices); // return (method1+method2)/2; return(method1); }
public key_animal_data collect_body_parts(float head_height_percentage, float neck_length, int no_legs, float leg_depth_percentage) { corpus = null; corpus = Centre(torso); find_region(); float x_ordinate_of_torso_front = top_corner.x - max_radius; float x_ordinate_of_torso_back = max_radius - bottom_corner.x; float leg_depth_factor = System.Math.Min(x_ordinate_of_torso_back, x_ordinate_of_torso_front); // float leg_depth_percentage; // code for affixing head Vector3 base_of_neck = new Vector3(corpus.joints[1].X, corpus.joints[1].Y, corpus.joints[1].Z); float radius_of_neck = corpus.joints[1].Radius; Vector3 neck = new Vector3(0, 0, 0); neck.z = 0; neck.y = ((head_height_percentage / 100) * 2 - 1) * radius_of_neck; neck.x = (float)System.Math.Sqrt(radius_of_neck * radius_of_neck - (neck.y) * (neck.y)); //NEW neck = Vector3.Normalize(neck); neck = neck * neck_length; neck = base_of_neck + neck; //NEW Vector3 chin = new Vector3(skull.joints[1].X + base_of_neck.x + neck.x, skull.joints[1].Y + base_of_neck.y + neck.y, skull.joints[1].Z + base_of_neck.z); var metalist = new List <metaball>(); for (int i = 0; i < corpus.joints.Length; i++) { metalist.Add(corpus.joints[i]); } key_animal_data results = new key_animal_data(); Vector3 connected_head_centre = new Vector3(base_of_neck.x + neck.x, base_of_neck.y + neck.y, base_of_neck.z); results.head_position = connected_head_centre; // results.head_position = new Vector3(-connected_head_centre.z, connected_head_centre.y, connected_head_centre.x); results.main_radius = skull.joints[0].Radius; results.chin_radius = skull.joints[1].Radius; results.main_chin_vertical_distance = (connected_head_centre.y - chin.y); metalist.Add(new metaball(base_of_neck.x + neck.x, base_of_neck.y + neck.y, base_of_neck.z, skull.joints[0].Radius)); metalist.Add(new metaball(chin.x, chin.y, chin.z, skull.joints[1].Radius)); if (no_legs > 0) { //shifting leg so that highest joint is at zero vector corporial new_leg = new corporial(); new_leg.joints = new metaball[hind_leg.joints.Length]; // new leg is a copy of hind_leg but shifted so that the highest joint (ie the shoulder if it had 4 joints) is at (0,0,0) Vector3 tmp = new Vector3(0, 0, 0); for (int i = 0; i < hind_leg.joints.Length; i++) { tmp = new Vector3( hind_leg.joints[i].X, hind_leg.joints[i].Y, hind_leg.joints[i].Z ) - new Vector3( hind_leg.joints[hind_leg.joints.Length - 1].X, hind_leg.joints[hind_leg.joints.Length - 1].Y, hind_leg.joints[hind_leg.joints.Length - 1].Z ); new_leg.joints[i] = new metaball( tmp.x, tmp.y, tmp.z, hind_leg.joints[i].Radius ); } new_leg = anitclockwise_rotate_piontwo(new_leg); if (no_legs < 2) { leg_depth_percentage = 0; } //finding base z ordinate for leg, based on the radius of the nearest metaball float closest_metaball_radius = 0; float distance = Single.MaxValue; float tmp_d; for (int i = 0; i < metalist.Count; i++) { tmp_d = (leg_depth_factor * (leg_depth_percentage / 100) - metalist[i].X); tmp_d = tmp_d * tmp_d; if (tmp_d < distance) { distance = tmp_d; closest_metaball_radius = metalist[i].Radius; } } Vector3 leg_connector_position = new Vector3( new_leg.joints[new_leg.joints.Length - 1].X - leg_depth_factor * (leg_depth_percentage / 100), new_leg.joints[new_leg.joints.Length - 1].Y, new_leg.joints[new_leg.joints.Length - 1].Z - closest_metaball_radius ); for (int i = 0; i < new_leg.joints.Length; i++) { new_leg.joints[i].X = new_leg.joints[i].X + leg_connector_position.x; new_leg.joints[i].Y = new_leg.joints[i].Y + leg_connector_position.y; new_leg.joints[i].Z = new_leg.joints[i].Z + leg_connector_position.z; metalist.Add(new_leg.joints[i]); } var mirror_leg = mirror_in_xy(new_leg); for (int i = 0; i < mirror_leg.joints.Length; i++) { metalist.Add(mirror_leg.joints[i]); } if (no_legs == 2) { var front_leg = mirror_in_zy(new_leg); var front_mirror_leg = mirror_in_zy(mirror_leg); for (int i = 0; i < front_leg.joints.Length; i++) { metalist.Add(front_leg.joints[i]); metalist.Add(front_mirror_leg.joints[i]); } } } corpus.joints = metalist.ToArray(); // corpus = anitclockwise_rotate_piontwo(corpus); // corpus = mirror_in_xy(corpus); return(results); }
public organism() { animal_mesh = new Mesh(); vertex_registry = new VertexArray(); subject = new corporial(); }
public bool cast(corporial subject) { // moves the ray forwards by one step and returns if the new position is inside the object current_ray_position = current_ray_position + direction_of_ray * resolution; return(evaluate(current_ray_position, subject) >= 1); }
//method 1 tends to make the cubes too big // method 2 tends to make the cubes too small private Vector3 push_to_edge(Vector3 calculated_corner, float max_radius, corporial subject, bool positive) { float distance_value = ray.evaluate(calculated_corner, subject); if (distance_value >= 1) { max_radius = max_radius * 0.1F; if (positive) { calculated_corner = calculated_corner + new Vector3(max_radius, max_radius, max_radius); } else { calculated_corner = calculated_corner - new Vector3(max_radius, max_radius, max_radius); } calculated_corner = push_to_edge(calculated_corner, max_radius, subject, positive); } return(calculated_corner); }