// Preview rendering of this function is non-trivial, since ephemeral edges only work for the most recent edge.
        public static PlanetariaShape create_equilateral(PlanetariaShape shape, Vector3 center, Vector3 vertex, int faces,
                                                         PlanetariaShape.AppendMode permanence = PlanetariaShape.AppendMode.OverwriteWithPermanent)
        {
            if (faces > 0 && center != vertex)
            {
                if (faces >= 2)
                {
                    Vector3 forward = center.normalized;
                    Vector3 right   = Vector3.ProjectOnPlane(vertex, forward).normalized;
                    Vector3 up      = Vector3.Cross(forward, right).normalized;

                    float phi = Vector3.Angle(vertex, center) * Mathf.Deg2Rad;

                    List <Vector3> vertices = new List <Vector3>();
                    for (float face_index = 0; face_index < faces; ++face_index)
                    {
                        Vector3 equatorial_position = PlanetariaMath.spherical_linear_interpolation(right, up, -(face_index / faces) * (Mathf.PI * 2));
                        Vector3 final_position      = PlanetariaMath.spherical_linear_interpolation(forward, equatorial_position, phi);
                        vertices.Add(final_position);
                    }

                    List <SerializedArc> polygon = new List <SerializedArc>();
                    for (int face_index = 0; face_index < faces; ++face_index)
                    {
                        Vector3 start_point = vertices[face_index];
                        Vector3 end_point   = vertices[(face_index + 1) % faces];
                        polygon.Add(ArcFactory.line(start_point, end_point));
                    }
                    shape.append(polygon, permanence);
                    return(shape);
                }
                else // create a circle with given radius
                {
                    // first_vertex is circle start
                    Vector3 right         = Vector3.Cross(center, vertex).normalized;
                    Vector3 mirror        = Vector3.Cross(center, right).normalized;
                    Vector3 hidden_vertex = Vector3.Reflect(vertex, mirror).normalized; // opposite end of circle start

                    Vector3 first_up      = Vector3.Cross(vertex, right).normalized;
                    Vector3 first_tangent = -Vector3.Cross(first_up, vertex).normalized;

                    Vector3 second_up      = -Vector3.Cross(hidden_vertex, right).normalized;
                    Vector3 second_tangent = -Vector3.Cross(second_up, hidden_vertex).normalized;

                    SerializedArc upper_circle = ArcFactory.curve(vertex, first_tangent, hidden_vertex);
                    SerializedArc lower_circle = ArcFactory.curve(hidden_vertex, second_tangent, vertex);


                    // TODO: this entire function can be replaced now (with the circle generator)
                    shape.append(new List <SerializedArc>()
                    {
                        upper_circle, lower_circle
                    }, permanence);
                    return(shape);
                }
            }
            shape.append(new List <SerializedArc>(), permanence);
            return(shape);
        }
Beispiel #2
0
        /// <summary>
        /// Inspector - Draw an extruded radial arc at a particular angle of the specified arc (i.e. the extrusion is its own arc).
        /// </summary>
        /// <param name="arc">The arc that will be rendered.</param>
        /// <param name="angle">The angle along the original Arc at which the extruded radius is drawn.</param>
        /// <param name="local_angle">The angle at which the ray is "refracting" from the surface. 0=>right; PI/2=>up.</param>
        /// <param name="extrusion">The distance (radius) to extrude the radial arc.</param>
        /// <param name="color">The color of the drawn radial arc.</param>
        /// <param name="orientation">The Transform's rotation (for moving platforms). For static objects, use Quaternion.identity.</param>
        public static void draw_ray(Arc arc, float angle, float local_angle, float extrusion, Color color, Quaternion orientation)
        {
            Vector3 from = arc.position(angle);
            Vector3 to   = ArcUtility.relative_point(arc, angle, local_angle, extrusion);

            Arc composite = ArcFactory.line(from, to);

            draw_arc(composite, 0.0f, color, orientation);
        }
Beispiel #3
0
        /// <summary>
        /// Inspector - Draw a fraction of the given arc segment.
        /// </summary>
        /// <param name="arc">The arc that will be rendered.</param>
        /// <param name="begin_angle">The angle (along the arc) at which the partial arc begins.</param>
        /// <param name="end_angle">The angle (along the arc) at which the partial arc ends.</param>
        /// <param name="extrusion">The distance (radius) to extrude the radial arc.</param>
        /// <param name="color">The color of the drawn radial arc.</param>
        /// <param name="orientation">The Transform's rotation (for moving platforms). For static objects, use Quaternion.identity.</param>
        public static void draw_partial_arc(Arc arc, float begin_angle, float end_angle, float extrusion, Color color, Quaternion orientation)
        {
            if (arc.curvature >= ArcType.ConvexCorner && extrusion == 0)
            {
                return;
            }
            Vector3 from = arc.position(begin_angle, extrusion);
            Vector3 to   = arc.position(end_angle, extrusion);

            Arc composite = ArcFactory.line(from, to);

            draw_arc(composite, 0.0f, color, orientation);
        }
Beispiel #4
0
 public void receive_vector(Vector3 vector)
 {
     if (state == CreationState.SetSlope)
     {
         slope = vector;
         shape.append(ArcFactory.line(point, slope), PlanetariaShape.AppendMode.OverwriteWithEphemeral);
     }
     else // CreationState.SetPoint
     {
         point = vector;
         shape.append(ArcFactory.curve(previous_point, slope, point), PlanetariaShape.AppendMode.OverwriteWithEphemeral);
     }
 }