Example #1
0
        /// <summary>
        /// Creates a flat-ended cylindrical mass of the specified parameters and
        /// density, with center at the origin of the body frame.
        /// </summary>
        /// <param name="density">The density of the cylinder.</param>
        /// <param name="direction">The orientation of the cylinder's long axis.</param>
        /// <param name="radius">The radius of the cylinder.</param>
        /// <param name="length">The length of the cylinder.</param>
        /// <returns>The created mass.</returns>
        public static Mass CreateCylinder(dReal density, DirectionAxis direction, dReal radius, dReal length)
        {
            Mass result;

            CreateCylinder(density, direction, radius, length, out result);
            return(result);
        }
Example #2
0
        public static void AlignTransformToCollision(this Transform trans,
                                                     Vector3 collisionPoint, Vector3 collisionNormal,
                                                     bool alignToNormal          = true, DirectionAxis axis = DirectionAxis.UP,
                                                     DirectionAxis globalForward = DirectionAxis.FORWARD)
        {
            trans.position = collisionPoint;
            if (alignToNormal && axis != DirectionAxis.NONE)
            {
                //  trans.rotation = Quaternion.LookRotation(GlobalAxisToVector(globalForward), collisionNormal);
                trans.rotation = Quaternion.FromToRotation(trans.AxisToVector(axis, true),
                                                           collisionNormal) * trans.rotation;

                Vector3 projectedGlobal = Vector3.ProjectOnPlane(GlobalAxisToVector(globalForward), collisionNormal);

                if (Mathf.Approximately(projectedGlobal.magnitude, 0))
                {
                    projectedGlobal = Vector3.ProjectOnPlane(
                        GlobalAxisToVector(NextDirection(globalForward)), collisionNormal);
                }
                var projectedSelf = Vector3.ProjectOnPlane(trans.AxisToVector(globalForward, true), collisionNormal);

                trans.rotation = Quaternion.FromToRotation(projectedSelf, projectedGlobal)
                                 /*Quaternion.AngleAxis(Vector3.Angle(projectedGlobal, projectedSelf), collisionNormal)*/
                                 * trans.rotation;
            }
        }
Example #3
0
        //Blasting
        public void BlockBreaker(Vector3i Pos, Vector3 Dir) // consider making this a bool to facilitate feedback?
        {
            //get collar position and facing direction
            Vector3i rung   = Pos;
            Vector3i facing = StyleSet(this.style, Dir);



            //determine blast radius and depth
            if (this.Explosive.Fuel < 5)
            {
                //ChatManager.ServerMessageToAll("Column Mode", false);
                //step to next block until reach bottom - may want to invert this so that it blasts from the bottom up
                for (int a = 0; a < this.blastingDepth; a = a + 1)
                {
                    rung = rung + facing;
                    //break if mineable and replace with rubble
                    Block block = World.GetBlock(rung);
                    if (block.Is <Minable>())
                    {
                        World.DeleteBlock(rung);
                        RubbleObject.TrySpawnFromBlock(block.GetType(), rung);
                    }
                }
            }
            else if (this.Explosive.Fuel > 5)
            {
                //ChatManager.ServerMessageToAll("cylinder Mode", false);
                DirectionAxis dir = LookupDirectionAxis(facing);


                for (int a = 0; a < this.blastingDepth; a = a + 1)
                {
                    rung = rung + facing;
                    Vector3i[] ring = DirectionExtensions.Get8Edges(dir);
                    //break if mineable and replace with rubble
                    Block block = World.GetBlock(rung);
                    if (block.Is <Minable>())
                    {
                        World.DeleteBlock(rung);
                        RubbleObject.TrySpawnFromBlock(block.GetType(), rung);
                    }
                    foreach (Vector3i neighbour in ring)
                    {
                        // ChatManager.ServerMessageToAll("neighbour mode", false);
                        Vector3i tar = rung + neighbour;
                        block = World.GetBlock(tar);
                        if (block.Is <Minable>())
                        {
                            World.DeleteBlock(tar);
                            RubbleObject.TrySpawnFromBlock(block.GetType(), tar);
                        }
                    }
                }
            }
            else
            {
                return;
            }
        }
Example #4
0
        public static DirectionAxis NextDirection(DirectionAxis axis)
        {
            switch (axis)
            {
            case DirectionAxis.UP:
                return(DirectionAxis.RIGHT);

            case DirectionAxis.DOWN:
                return(DirectionAxis.LEFT);

            case DirectionAxis.LEFT:
                return(DirectionAxis.BACK);

            case DirectionAxis.RIGHT:
                return(DirectionAxis.FORWARD);

            case DirectionAxis.FORWARD:
                return(DirectionAxis.UP);

            case DirectionAxis.BACK:
                return(DirectionAxis.DOWN);

            case DirectionAxis.NONE:
                return(DirectionAxis.NONE);

            default:
                throw new ArgumentOutOfRangeException(nameof(axis), axis, null);
            }
        }
Example #5
0
        public static Vector3 AxisToVector(this Transform trans, DirectionAxis axis, bool local)
        {
            switch (axis)
            {
            case DirectionAxis.RIGHT:
                return(local ? trans.right : Vector3.right);

            case DirectionAxis.LEFT:
                return(local ? -trans.right : -Vector3.right);

            case DirectionAxis.UP:
                return(local ? trans.up : Vector3.up);

            case DirectionAxis.DOWN:
                return(local ? -trans.up : -Vector3.up);

            case DirectionAxis.FORWARD:
                return(local ? trans.forward : Vector3.forward);

            case DirectionAxis.BACK:
                return(local ? -trans.forward : -Vector3.forward);

            default:
                return(Vector3.zero);
            }
        }
Example #6
0
        public static Vector3 GlobalAxisToVector(DirectionAxis axis)
        {
            switch (axis)
            {
            case DirectionAxis.RIGHT:
                return(Vector3.right);

            case DirectionAxis.LEFT:
                return(-Vector3.right);

            case DirectionAxis.UP:
                return(Vector3.up);

            case DirectionAxis.DOWN:
                return(-Vector3.up);

            case DirectionAxis.FORWARD:
                return(Vector3.forward);

            case DirectionAxis.BACK:
                return(-Vector3.forward);

            default:
                return(Vector3.zero);
            }
        }
Example #7
0
        /// <summary>
        /// Creates a flat-ended cylindrical mass of the specified parameters and
        /// total mass, with center at the origin of the body frame.
        /// </summary>
        /// <param name="totalMass">The total mass of the cylinder.</param>
        /// <param name="direction">The orientation of the cylinder's long axis.</param>
        /// <param name="radius">The radius of the cylinder.</param>
        /// <param name="length">The length of the cylinder.</param>
        /// <returns>The created mass.</returns>
        public static Mass CreateCylinderTotal(
            dReal totalMass, DirectionAxis direction,
            dReal radius, dReal length)
        {
            Mass result;

            CreateCylinderTotal(totalMass, direction, radius, length, out result);
            return(result);
        }
    public void OnSpawnMover(DirectionAxis axis, ObjecTPoolType type, Identifier identifier)
    {
        int index = Random.Range(0, GameDesignManager.blockLevelSize);

        GameObject mover = ObjectPoolManager.Instance.FindPoolObjectItem(type);

        StartCoroutine(RoutineSetPosition(mover.transform, Vector3.zero, SetTargetPosition(axis.AxisToIndex(), index)));
        StartCoroutine(RoutineSetRotation(mover.transform, Quaternion.identity, SetTargetRotation(axis.AxisToIndex(), index, identifier)));
    }
Example #9
0
        public static void RaycastDirection(bool local, Transform t, Vector3 direction,
                                            DirectionAxis axisToHitNormal)
        {
            RaycastHit hit;

            if (Physics.Raycast(t.position, local ? t.TransformDirection(direction) : direction,
                                out hit))
            {
                Undo.RecordObject(t, "movement");
                t.AlignTransformToCollision(hit.point, hit.normal, true, axisToHitNormal);
            }
        }
Example #10
0
        public static void RenderDirectionAxis(this WorldView world, DirectionAxis axis, Matrix4X4 matrix, double size)
        {
            GLHelper.PrepareFor3DLineRender(true);

            Frustum frustum = world.GetClippingFrustum();
            Vector3 length  = axis.Normal * size;
            var     color   = Agg.Color.Red;

            // draw center line
            {
                var     min   = axis.Origin - length;
                Vector3 start = Vector3Ex.Transform(min, matrix);

                var     max = axis.Origin + length;
                Vector3 end = Vector3Ex.Transform(max, matrix);

                world.Render3DLineNoPrep(frustum, start, end, color, 1);
            }

            var perpendicular = Vector3.GetPerpendicular(axis.Normal, Vector3.Zero).GetNormal();
            // draw some lines to mark the rotation plane
            int  count    = 20;
            bool first    = true;
            var  firstEnd = Vector3.Zero;
            var  lastEnd  = Vector3.Zero;
            var  center   = Vector3Ex.Transform(axis.Origin, matrix);

            for (int i = 0; i < count; i++)
            {
                var rotation = size / 4 * Vector3Ex.Transform(perpendicular, Matrix4X4.CreateRotation(axis.Normal, MathHelper.Tau * i / count));
                // draw center line
                var     max = axis.Origin + rotation;
                Vector3 end = Vector3Ex.Transform(max, matrix);

                world.Render3DLineNoPrep(frustum, center, end, color, 1);
                if (!first)
                {
                    world.Render3DLineNoPrep(frustum, end, lastEnd, color, 1);
                }
                else
                {
                    firstEnd = end;
                }

                lastEnd = end;
                first   = false;
            }

            world.Render3DLineNoPrep(frustum, firstEnd, lastEnd, color, 1);

            GL.Enable(EnableCap.Lighting);
        }
    public void OnClickVertex(ObjecTPoolType type, DirectionAxis axis, Vector3 start)
    {
        int index          = Random.Range(0, GameDesignManager.blockLevelSize);
        int axisConversion = (axis.AxisToIndex() + 2) % 3;

        GameObject mover = ObjectPoolManager.Instance.FindPoolObjectItem(type);

        Vector3 end = SetTargetPosition(axisConversion, index);

        AudioManager.Instance.PlaySFXSound(SFXSoundType.MoverSpawn);
        StartCoroutine(RoutineSetParabola(mover.transform, start, end));
        StartCoroutine(RoutineSetRotation(mover.transform, Quaternion.identity, SetTargetRotation(axisConversion, index, Identifier.Positive)));
    }
Example #12
0
            public override void DisplayParameters()
            {
                base.DisplayParameters();
                DisplayFloatOption("Collision Offset", ref Offset);
                DisplayFloatOption("Angle Offset", ref AngleOffset);
                Enum en = AlignToNormal;

                DisplayEnumOption("Up Axis", ref en);
                AlignToNormal = (DirectionAxis)en;

                en = ForwardAlign;
                DisplayEnumOption("Forward Axis", ref en);
                ForwardAlign = (DirectionAxis)en;

                DisplayBoolOption("Ignore Invisible Colliders", ref IgnoreInvisibleColliders);
            }
Example #13
0
        public static int AxisToIndex(this DirectionAxis axis)
        {
            switch (axis)
            {
            case DirectionAxis.xDirection:
                return(0);

            case DirectionAxis.yDirection:
                return(1);

            case DirectionAxis.zDirection:
                return(2);

            default:
                Debug.LogWarning("invaild axis values");
                return(-1);
            }
        }
Example #14
0
        public DirectionAxis GetDirectionByKey(string[] keys)
        {
            DirectionAxis dir = 0;

            foreach (var key in keys)
            {
                if (string.Compare(key, vertical, true) == 0)
                {
                    dir |= DirectionAxis.Vertical;
                }

                if (string.Compare(key, horizontal, true) == 0)
                {
                    dir |= DirectionAxis.Horizontal;
                }
            }

            return(dir);
        }
Example #15
0
    protected void SetParentOrigin(int origin)
    {
        switch (origin)
        {
        case 0:
            parentDirection = DirectionAxis.xDirection;
            this.transform.SetParent(LevelDesigner.Instance.xDirectionAxis);
            break;

        case 1:
            parentDirection = DirectionAxis.yDirection;
            this.transform.SetParent(LevelDesigner.Instance.yDirectionAxis);
            break;

        case 2:
            parentDirection = DirectionAxis.zDirection;
            this.transform.SetParent(LevelDesigner.Instance.zDirectionAxis);
            break;
        }
    }
Example #16
0
            public RaycastSceneCommand(GameObject[] cachedObjectsToMove, float offset,
                                       DirectionAxis alignToNormal)
            {
                //  HideGUI = true;
                ConfirmationMode         = ActionConfirmationMode.ENTER_AND_CLICK;
                SceneCommandName         = "RayCast Mouse Position";
                IgnoreInvisibleColliders = true;
                CachedObjectsToMove      = cachedObjectsToMove;
                Offset        = offset;
                AlignToNormal = alignToNormal;
                ForwardAlign  = DirectionAxis.FORWARD;
                List <Transform> allChildren = new List <Transform>();

                foreach (GameObject gameObject in cachedObjectsToMove)
                {
                    previousPosRot.Add(
                        new PositionRotation(gameObject.transform.position,
                                             gameObject.transform.rotation));
                    allChildren.AddRange(gameObject.GetComponentsInChildren <Transform>());
                }

                selfAndChildren = allChildren.ToArray();
            }
Example #17
0
        public static void RaycastDirection2D(bool local, Transform t, Vector3 direction,
                                              DirectionAxis axisToHitNormal, GameObject[] objectsToIgnore)
        {
            RaycastHit2D[] hits = Physics2D.RaycastAll(t.position, local ? t.TransformDirection(direction) : direction)
                                  .OrderByDescending(_ => (_.point - (Vector2)t.position).magnitude).ToArray();
            foreach (var hit in hits)
            {
                if (objectsToIgnore.Contains(hit.transform.gameObject) ||
                    objectsToIgnore.Any(_ => _.GetComponentsInChildren <Transform>().Contains(hit.transform)))
                {
                    continue;
                }

                if (hit)
                {
                    Undo.RecordObject(t, "movement");
                    t.AlignTransformToCollision(hit.point, hit.normal, true, axisToHitNormal);
                }
                else
                {
                    Debug.Log("Nope");
                }
            }
        }
Example #18
0
 /// <summary>
 /// Creates a flat-ended cylindrical mass of the specified parameters and
 /// density, with center at the origin of the body frame.
 /// </summary>
 /// <param name="density">The density of the cylinder.</param>
 /// <param name="direction">The orientation of the cylinder's long axis.</param>
 /// <param name="radius">The radius of the cylinder.</param>
 /// <param name="length">The length of the cylinder.</param>
 /// <param name="result">The created mass.</param>
 public static void CreateCylinder(
     dReal density, DirectionAxis direction,
     dReal radius, dReal length, out Mass result)
 {
     NativeMethods.dMassSetCylinder(out result, density, direction, radius, length);
 }
Example #19
0
        public void ProcessMesh(bool runtime = false)
        {
            if (s_srcCapsuleMesh == null)
            {
                if (runtime)
                {
                    var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                    s_srcCapsuleMesh = go.GetComponent <MeshFilter>().sharedMesh;
                    DestroyImmediate(go);
                }
#if UNITY_EDITOR
                UnityEditor.EditorApplication.delayCall += () =>
                {
                    if (this == null)
                    {
                        return;
                    }
                    var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                    s_srcCapsuleMesh = go.GetComponent <MeshFilter>().sharedMesh;
                    DestroyImmediate(go);
                    ProcessMesh();
                };
#endif
                if (!runtime)
                {
                    return;
                }
            }

            bool dirty = false;

            var mfmesh = GetComponent <MeshFilter>().sharedMesh;
            if (m_mesh != mfmesh || mfmesh == null || runtime)
            {
                m_mesh = new Mesh();
                if (runtime)
                {
                    GetComponent <MeshFilter>().sharedMesh = m_mesh;
                }
#if UNITY_EDITOR
                UnityEditor.EditorApplication.delayCall += () =>
                {
                    if (this == null)
                    {
                        return;
                    }
                    GetComponent <MeshFilter>().sharedMesh = m_mesh;
                };
#endif

                dirty = true;
            }
            dirty |= m_height != m_savedHeight ||
                     m_radius != m_savedRadius ||
                     m_axis != m_savedAxis;

            if (dirty)
            {
                Quaternion rot = Quaternion.identity;
                if (m_axis == DirectionAxis.Z)
                {
                    rot = Quaternion.Euler(90f, 0f, 0f);
                }
                else if (m_axis == DirectionAxis.X)
                {
                    rot = Quaternion.Euler(0f, 0f, 90f);
                }

                var positions = s_srcCapsuleMesh.vertices;

                for (int i = 0; i < positions.Length; i++)
                {
                    var p = positions[i];
                    if (p.y > 0f)
                    {
                        p.y -= 0.5f;
                        p   *= m_radius * 2f;
                        p.y += m_height / 2f - m_radius;
                    }
                    else
                    {
                        p.y += 0.5f;
                        p   *= m_radius * 2f;
                        p.y -= m_height / 2f - m_radius;
                    }
                    p            = rot * p;
                    positions[i] = p;
                }

                m_mesh.vertices = positions;

                if (m_axis != DirectionAxis.Y)
                {
                    var normals  = s_srcCapsuleMesh.normals;
                    var tangents = s_srcCapsuleMesh.tangents;
                    for (int i = 0; i < normals.Length; i++)
                    {
                        normals[i]  = rot * normals[i];
                        tangents[i] = rot * tangents[i];
                    }
                    m_mesh.normals  = normals;
                    m_mesh.tangents = tangents;
                }
                else
                {
                    m_mesh.normals  = s_srcCapsuleMesh.normals;
                    m_mesh.tangents = s_srcCapsuleMesh.tangents;
                }
                m_mesh.uv        = s_srcCapsuleMesh.uv;
                m_mesh.uv2       = s_srcCapsuleMesh.uv2;
                m_mesh.triangles = s_srcCapsuleMesh.triangles;

                var filter = GetComponent <MeshFilter>();

                var capCol = GetComponent <CapsuleCollider>();
                if (capCol != null)
                {
                    capCol.direction = (int)m_axis;
                    capCol.center    = Vector3.zero;
                    capCol.height    = m_height;
                    capCol.radius    = m_radius;
                }

                m_savedAxis   = m_axis;
                m_savedHeight = m_height;
                m_savedRadius = m_radius;
                char axname = m_axis == DirectionAxis.X ? 'x' : m_axis == DirectionAxis.Y ? 'y' : 'z';
                m_mesh.name = $"capsule_{axname}_{m_radius}_{m_height}";
            }
        }
Example #20
0
        /// <summary>
        /// Tries to connects close areas with the same flag
        /// </summary>
        /// <param name="row">Tile row index</param>
        /// <param name="column">Tile column index</param>
        /// <param name="rowCount">Grid row count</param>
        /// <param name="columnCount">Grid column count</param>
        /// <param name="map">Current map as flatten array</param>
        /// <param name="tileIdValue">Tile id value</param>
        /// <param name="tileFlags">Tile flags</param>
        /// <param name="distance">Maximum tile distance between areas</param>
        /// <param name="axis">Direction of connection</param>
        private void TryConnect(int row, int column, int rowCount, int columnCount, Tile[] map, ushort tileIdValue, byte tileFlags, int distance, DirectionAxis axis)
        {
            bool connectPos = false;
            bool connectNeg = false;

            int realRow    = row;
            int realColumn = column;

            for (int i = distance; i > 0; i--)
            {
                if (axis == DirectionAxis.Horizontal)
                {
                    realColumn = column + i;
                }
                else
                {
                    realRow = row + i;
                }

                if (!TileMathHelper.IsOutOfRange(realRow, realColumn, rowCount, columnCount))
                {
                    int id = TileMathHelper.ToIndex(realRow, realColumn, columnCount);
                    if (!connectPos)
                    {
                        if (map[id].Id == tileIdValue)
                        {
                            connectPos = true;
                        }
                    }
                    else
                    {
                        if (map[id].Id == 0)
                        {
                            map[id] = new Tile(tileIdValue, tileFlags);
                        }
                    }
                }

                if (axis == DirectionAxis.Horizontal)
                {
                    realColumn = column - i;
                }
                else
                {
                    realRow = row - i;
                }
                if (!TileMathHelper.IsOutOfRange(realRow, realColumn, rowCount, columnCount))
                {
                    int id = TileMathHelper.ToIndex(realRow, realColumn, columnCount);
                    if (!connectNeg)
                    {
                        if (map[id].Id == tileIdValue)
                        {
                            connectNeg = true;
                        }
                    }
                    else
                    {
                        if (map[id].Id == 0)
                        {
                            map[id] = new Tile(tileIdValue, tileFlags);
                        }
                    }
                }
            }
        }
Example #21
0
 internal static extern void dMassSetCylinder(out Mass m, dReal density, DirectionAxis direction,
                                              dReal radius, dReal length);
Example #22
0
        private void SetScrollViewDirection(Data.GroupNode node, ScrollRect scrollRect, DirectionAxis direction)
        {
            switch (direction)
            {
            case DirectionAxis.Horizontal:
                scrollRect.vertical   = false;
                scrollRect.horizontal = true;
                break;

            case DirectionAxis.Vertical:
                scrollRect.vertical   = true;
                scrollRect.horizontal = false;
                break;

            case DirectionAxis.Horizontal | DirectionAxis.Vertical:
                scrollRect.vertical   = true;
                scrollRect.horizontal = true;
                break;

            default:
                if (node.children != null)
                {
                    if (node.children.Find(x => MatchAddress((x as Data.GroupNode).displayName, vbarAddress)) != null)
                    {
                        scrollRect.vertical = true;
                    }
                    else if (node.children.Find(x => MatchAddress((x as Data.GroupNode).displayName, hbarAddress)) != null)
                    {
                        scrollRect.horizontal = true;
                    }
                }
                break;
            }
        }
Example #23
0
 /// <summary>
 /// Holds tile shift information
 /// </summary>
 /// <param name="axis">direction shift</param>
 /// <param name="value">tile shift</param>
 public Direction(DirectionAxis axis, int value)
 {
     Axis  = axis;
     Value = value;
 }
Example #24
0
 internal static extern void dMassSetCylinderTotal(out Mass m, dReal total_mass, DirectionAxis direction,
                                                   dReal radius, dReal length);
Example #25
0
 /// <summary>
 /// Creates a flat-ended cylindrical mass of the specified parameters and
 /// total mass, with center at the origin of the body frame.
 /// </summary>
 /// <param name="totalMass">The total mass of the cylinder.</param>
 /// <param name="direction">The orientation of the cylinder's long axis.</param>
 /// <param name="radius">The radius of the cylinder.</param>
 /// <param name="length">The length of the cylinder.</param>
 /// <param name="result">The created mass.</param>
 public static void CreateCylinderTotal(
     dReal totalMass, DirectionAxis direction,
     dReal radius, dReal length, out Mass result)
 {
     NativeMethods.dMassSetCylinderTotal(out result, totalMass, direction, radius, length);
 }