Esempio n. 1
0
        /// <summary>
        /// Constructor - Creates a shape based on a list of curves (generates cached list of Arc)
        /// </summary>
        /// <param name="curves">The list of curves that uniquely defines a shape.</param>
        /// <param name="closed_shape">Is the shape closed? (i.e. does the shape draw the final arc from the last point to the first point?)</param>
        /// <param name="generate_corners">Does the shape have corners between line segments?</param>
        public static PlanetariaShape Create(List <SerializedArc> serialized_arcs, bool generate_corners) // CONSIDER: TODO: add convex option
        {
            PlanetariaShape asset = Create();

            asset.serialized_arc_list = serialized_arcs;
            asset.has_corners         = generate_corners;
            asset.initialize();
            return(asset);
        }
Esempio n. 2
0
        public static ArcBuilder arc_builder(Vector3 first_point, bool convex, bool allow_self_intersections)
        {
            GameObject game_object = new GameObject("ArcBuilder");
            ArcBuilder result      = game_object.AddComponent <ArcBuilder>();

            result.point                    = result.previous_point = result.original_point = first_point;
            result.shape                    = PlanetariaShape.Create();
            result.must_be_convex           = convex; // must be a "convex hull"
            result.allow_self_intersections = allow_self_intersections;
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor - Creates a circle (shape) of the given radius.
        /// </summary>
        /// <param name="radius">The radius of the circle.</param>
        public static PlanetariaShape Create(float radius)
        {
            PlanetariaShape asset = Create();

            asset.serialized_arc_list = new List <SerializedArc> {
                ArcFactory.circle(radius)
            };
            asset.has_corners = false;
            asset.initialize();
            return(asset);
        }
Esempio n. 4
0
        public static PlanetariaShape Create()
        {
            PlanetariaShape asset = ScriptableObject.CreateInstance <PlanetariaShape>();

            if (asset.serialized_arc_list == null)
            {
                asset.serialized_arc_list = new List <SerializedArc>();
                asset.has_corners         = true;
            }
            asset.initialize();
            return(asset);
        }
 public static void draw_shape(PlanetariaShape self, Quaternion orientation)
 {
     if (!EditorGlobal.self.hide_graphics)
     {
         if (self)
         {
             foreach (Arc arc in self.arcs)
             {
                 ArcEditor.draw_arc(arc, orientation);
             }
         }
     }
 }
Esempio n. 6
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            radius = EditorGUILayout.Slider("Radius", radius, 0, Mathf.PI);
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Generate"))
            {
                PlanetariaShape procedural_circle = PlanetariaShape.Create(radius);
                AssetDatabase.CreateAsset(procedural_circle,
                                          "Assets/Planetaria/Procedural/PlanetariaShape/planetaria_shape_circle_radius" + radius + ".asset");
                AssetDatabase.SaveAssets();
            }
        }
Esempio n. 7
0
        private void cache(PlanetariaShape shape)
        {
            PlanetariaCache.uncache(this);
            shape_variable = shape;
            if (shape != null)
            {
                PlanetariaCache.cache(this);
                PlanetariaSphereCollider sphere = shape.bounding_sphere;

                internal_collider.center = sphere.center;
                internal_collider.radius = sphere.radius;
            }
            else
            {
                internal_collider.radius = float.NegativeInfinity; // FIXME: HACK: ensure there are no collisions
            }
            internal_collider.isTrigger = true;                    // Rigidbody must be added for collisions to be detected.
        }
Esempio n. 8
0
        public List <Arc> block_collision(PlanetariaShape other, Quaternion shift_from_self_to_other) // TODO: AABB-equivalent would be nice here
        {
            List <Arc> union = new List <Arc>();

            for (int other_index = 0; other_index < other.block_list.Length; ++other_index)
            {
                PlanetariaArcCollider other_collider = other.block_list[other_index];
                foreach (PlanetariaArcCollider this_collider in this.block_list)
                {
                    if (other_collider.collides_with(this_collider, shift_from_self_to_other))
                    {
                        union.Add(other.arc_list[other_index]);
                        break; // try to see if the next arc collides (because we know this one does)
                    }
                }
            }
            return(union);
        }
Esempio n. 9
0
 public bool field_collision(PlanetariaShape other, Quaternion shift_from_self_to_other) // TODO: AABB-equivalent would be nice here
 {
     foreach (PlanetariaArcCollider arc in this.block_list)
     {
         bool colliding = true;
         foreach (PlanetariaSphereCollider sphere in other.field_list)
         {
             if (!arc.collides_with(sphere, shift_from_self_to_other))
             {
                 colliding = false;
                 break; // try to see if the next arc collides (because we know this one does)
             }
         }
         if (colliding)
         {
             return(true);
         }
     }
     return(false);
 }