/// <summary>
        /// Resolves overlap between this and another CHull by moving on the minimum penetration depth vector
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public double Project(IHull other)
        {
            var v  = other as CvxHull;
            var vc = v as ClusterConvexHull;
            var c  = this as ClusterConvexHull;

            if (c != null && c.Contains(v))
            {
                return(0);
            }
            if (vc != null && vc.Contains(this))
            {
                return(0);
            }
            Debug.Assert(v != null);
            Point pd = PenetrationDepth.PenetrationDepthForPolylines(TranslatedBoundary(), v.TranslatedBoundary());

            if (pd.Length > 0)
            {
                Point wpd = pd / (Weight + v.Weight);
                MoveCenter(v.Weight * wpd);
                v.MoveCenter(-Weight * wpd);
            }
            return(pd.Length);
        }
Exemplo n.º 2
0
        private void InitializeGraph(GeneratingMethodEnum generatingMethod)
        {
            Graphs.Add(new Graph {
                Origin = _graph.Origin, Points = _graph.Points
            });

            IHull hull = null;

            switch (generatingMethod)
            {
            case GeneratingMethodEnum.SerialQuickHull:
                hull = new SerialQuickHull((Graph)Graphs.Last());
                break;

            case GeneratingMethodEnum.OneThreadPerSplitQuickHull:
                hull = new OneThreadPerSplitQuickHull((Graph)Graphs.Last());
                break;

            case GeneratingMethodEnum.OneThreadSplitQuickHull:
                hull = new OneThreadSplitQuickHull((Graph)Graphs.Last());
                break;

            case GeneratingMethodEnum.SerialGiftWrapping:
                hull = new SerialGiftWrapping((Graph)Graphs.Last());
                break;

            default:
                break;
            }

            _graph.Name = generatingMethod.ToString();
            hull.Done  += Done;
            hull.Execute();
            Hulls.Add(hull);
        }
        /// <summary>
        /// Uses Lev's fast proximity query to find pairs of nodes/clusters with overlapping bounding boxes.
        /// When such are found, they are projected apart.
        /// </summary>
        public double Project()
        {
            double displacement = 0;

            if (hulls.Count < AllPairsComputationLimit)
            {
                // if there are only a few nodes then do it the most straightforward n^2 way
                for (int i = 0; i < hulls.Count - 1; ++i)
                {
                    IHull u = hulls[i];
                    for (int j = i + 1; j < hulls.Count; ++j)
                    {
                        displacement += u.Project(hulls[j]);
                    }
                }
            }
            else
            {
                var pq = new ProximityQuery(hulls);
                List <Tuple <IHull, IHull> > closePairs = pq.GetAllIntersections();
                //shuffle(ref closePairs);
                foreach (var k in closePairs)
                {
                    displacement += k.Item1.Project(k.Item2);
                }
            }
            return(displacement);
        }
Exemplo n.º 4
0
        public static IDesign Create(IHull hull)
        {
            var d = Create(hull.VehicleType);

            d.Hull = hull;
            return(d);
        }
Exemplo n.º 5
0
    private void CreateNewHulls(UvMapper uvMapper, Vector3[] points, Vector3[] normals, out IList <IHull> newHulls)
    {
        newHulls = new List <IHull>();

        // Add the starting hull
        newHulls.Add(hull);

        for (int j = 0; j < points.Length; j++)
        {
            int previousHullCount = newHulls.Count;

            for (int i = 0; i < previousHullCount; i++)
            {
                IHull previousHull = newHulls[0];

                // Split the previous hull
                IHull a, b;

                previousHull.Split(points[j], normals[j], fillCut, uvMapper, out a, out b);

                // Update the list
                newHulls.Remove(previousHull);

                if (!a.IsEmpty)
                {
                    newHulls.Add(a);
                }

                if (!b.IsEmpty)
                {
                    newHulls.Add(b);
                }
            }
        }
    }
Exemplo n.º 6
0
        public MountPickerForm(IHull hull)
        {
            InitializeComponent();
            this.hull = hull;
            Bind();

            try { this.Icon = new Icon(FrEee.WinForms.Properties.Resources.FrEeeIcon); } catch { }
        }
Exemplo n.º 7
0
        private void AddSensorAbility(IHull hull, string sightType, int level)
        {
            var a = new Ability(hull);

            hull.Abilities.Add(a);
            a.Rule = Mod.Current.AbilityRules.FindByName("Sensor Level");
            a.Values.Add(sightType);
            a.Values.Add(level.ToString());
        }
Exemplo n.º 8
0
        public VehicleDesignForm(IHull <IVehicle> hull)
        {
            InitializeComponent();
            ShowComponentDetails(null);
            Design = FrEee.Game.Objects.Vehicles.Design.Create(hull);

            try { this.Icon = new Icon(FrEee.WinForms.Properties.Resources.FrEeeIcon); }
            catch { }
        }
Exemplo n.º 9
0
        public void SetUp()
        {
            // create galaxy
            TestUtilities.CreateGalaxyWithMod();

            // create star system
            sys = new(0);
            Galaxy.Current.StarSystemLocations.Add(new(sys, new Point()));

            // create stuff
            emp    = TestUtilities.CreateEmpire();
            design = TestUtilities.CreateDesign <Ship>(emp);
            hull   = TestUtilities.CreateHull(design);
            ship   = TestUtilities.CreateVehicle(design, emp);
        }
Exemplo n.º 10
0
        internal Ship(string name, Vector2 position, float radius, Color color, IGraphicsFactory graphicsFactory, IShipComponentFactory shipComponentFactory)
            : base(position, radius, 1)
        {
            Name = name;
            Color = color;

            _controller = new NullShipController();

            _energyStore = shipComponentFactory.CreateEnergyStore();
            _shield = shipComponentFactory.CreateShield(this);
            _hull = shipComponentFactory.CreateHull(this);
            _thrusterArray = shipComponentFactory.CreateThrusterArray(this);

            _graphicsFactory = graphicsFactory;
            _arrows = new List<IArrow>();
        }
Exemplo n.º 11
0
        public void Start()
        {
            Mesh sharedMesh = GetComponent <MeshFilter>().sharedMesh;

            // Initialize the first generation hull
            if (hull == null)
            {
                if (internalHullType == HullType.FastHull)
                {
                    hull = new FastHull(sharedMesh);
                }
                else if (internalHullType == HullType.LegacyHull)
                {
                    hull = new LegacyHull(sharedMesh);
                }
            }
            // Update properties
            CalculateCenter();
        }
 /// <summary>
 /// Resolves overlap between this and another CHull by moving on the minimum penetration depth vector
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public double Project(IHull other) {
     var v = other as CvxHull;
     var vc = v as ClusterConvexHull;
     var c = this as ClusterConvexHull;
     if (c!=null && c.Contains(v)) {
         return 0;
     }
     if (vc != null && vc.Contains(this)) {
         return 0;
     }
     Debug.Assert(v != null);
     Point pd = PenetrationDepth.PenetrationDepthForPolylines(TranslatedBoundary(), v.TranslatedBoundary());
     if (pd.Length > 0) {
         Point wpd = pd / (Weight + v.Weight);
         MoveCenter(v.Weight * wpd);
         v.MoveCenter(-Weight * wpd);
     }
     return pd.Length;
 }
Exemplo n.º 13
0
    public void Start()
    {
        mf         = gameObject.GetComponent <MeshFilter> ();
        uvMapper   = Camera.main.GetComponent <UvMapper> ();
        sharedMesh = mf.sharedMesh;

        // Initialize the first generation hull
        if (hull == null)
        {
            if (internalHullType == HullType.FastHull)
            {
                hull = new FastHull(sharedMesh);
            }
            else if (internalHullType == HullType.LegacyHull)
            {
                hull = new LegacyHull(sharedMesh);
            }
        }

        // Update properties
        CalculateCenter();
    }
Exemplo n.º 14
0
        public void Split(Vector3 localPointOnPlane, Vector3 localPlaneNormal, bool fillCut, UvMapper uvMapper, ColorMapper colorMapper, out IHull resultA, out IHull resultB)
        {
            if (localPlaneNormal == Vector3.zero)
            {
                localPlaneNormal = Vector3.up;
            }

            FastHull a = new FastHull(this);
            FastHull b = new FastHull(this);

            bool[] vertexAbovePlane;
            int[]  oldToNewVertexMap;

            AssignVertices(a, b, localPointOnPlane, localPlaneNormal, out vertexAbovePlane, out oldToNewVertexMap);

            IList <Vector3> cutEdges;

            AssignTriangles(a, b, vertexAbovePlane, oldToNewVertexMap, localPointOnPlane, localPlaneNormal, out cutEdges);

            if (fillCut)
            {
                if (colors != null && colorMapper == null)
                {
                    Debug.LogWarning("Fill cut failed: A ColorMapper was not provided even though the mesh has a color channel");
                }
                else if ((tangents != null || uvs != null) && uvMapper == null)
                {
                    Debug.LogWarning("Fill cut failed: A UvMapper was not provided even though the mesh has a tangent/uv channel");
                }
                else
                {
                    FillCutEdges(a, b, cutEdges, localPlaneNormal, uvMapper, colorMapper);
                }
            }

            ValidateOutput(a, b, localPlaneNormal);

            // Set output
            resultA = a;
            resultB = b;
        }
Exemplo n.º 15
0
        protected void CreateNewGameObjects(IList <IHull> newHulls, out GameObject[] newGameObjects)
        {
            // Get new meshes
            Mesh[]  newMeshes  = new Mesh[newHulls.Count];
            float[] newVolumes = new float[newHulls.Count];

            float totalVolume = 0.0f;

            for (int i = 0; i < newHulls.Count; i++)
            {
                Mesh    mesh   = newHulls[i].GetMesh();
                Vector3 size   = mesh.bounds.size;
                float   volume = size.x * size.y * size.z;

                newMeshes[i]  = mesh;
                newVolumes[i] = volume;

                totalVolume += volume;
            }

            MeshFilter   meshFilter   = GetComponent <MeshFilter>();
            MeshCollider meshCollider = GetComponent <MeshCollider>();
            Rigidbody    rigidbody    = GetComponent <Rigidbody>();

            // Remove mesh references to speed up instantiation
            //meshFilter.sharedMesh = null;

            //if (meshCollider != null)
            //{
            //    meshCollider.sharedMesh = null;
            //}

            // Create new game objects
            newGameObjects = new GameObject[newHulls.Count];

            for (int i = 0; i < newHulls.Count; i++)
            {
                IHull newHull = newHulls[i];
                Mesh  newMesh = newMeshes[i];
                float volume  = newVolumes[i];

                GameObject newGameObject = (GameObject)Instantiate(gameObject);
                newGameObject.tag = "cubeClone";
                /* Set position */
                newGameObject.transform.position = gameObject.transform.position;
                // Set shatter tool
                ShatterTool newShatterTool = newGameObject.GetComponent <ShatterTool>();

                if (newShatterTool != null)
                {
                    newShatterTool.hull = newHull;
                }

                // Set mesh filter
                MeshFilter newMeshFilter = newGameObject.GetComponent <MeshFilter>();

                if (newMeshFilter != null)
                {
                    newMeshFilter.sharedMesh = newMesh;
                }

                // Set mesh collider
                MeshCollider newMeshCollider = newGameObject.GetComponent <MeshCollider>();

                if (newMeshCollider != null)
                {
                    newMeshCollider.sharedMesh = newMesh;
                }
                // isTrigger
                //newMeshCollider.isTrigger = true;
                // Set rigidbody
                Rigidbody newRigidbody = newGameObject.GetComponent <Rigidbody>();

                if (rigidbody != null && newRigidbody != null)
                {
                    newRigidbody.mass = .1f;

                    newRigidbody.constraints = RigidbodyConstraints.None;
                    //newRigidbody.constraints = RigidbodyConstraints.FreezePositionY;
                    if (!gameObject.GetComponent <Bullet>())
                    {
                        float randomX = Random.Range(-10, 10f);
                        newRigidbody.AddForce(new Vector3(randomX, 20f, 0f));
                    }
                    else
                    {
                    }
                    //if (!newRigidbody.isKinematic)
                    //{
                    //    newRigidbody.velocity = rigidbody.GetPointVelocity(newRigidbody.worldCenterOfMass);

                    //    newRigidbody.angularVelocity = rigidbody.angularVelocity;
                    //}
                }

                //newGameObject.tag = "DestroyedSpike";

                // Update properties
                newShatterTool.CalculateCenter();

                newGameObjects[i] = newGameObject;
            }
        }
Exemplo n.º 16
0
 public long GetCurrentHull(IHull hull) => (hull.Level.Value + hull.Id) + hull.Id * 3;
Exemplo n.º 17
0
        public void SetUp()
        {
            _graphicsFactory = Substitute.For<IGraphicsFactory>();
            _graphicsDevice = Substitute.For<IGraphicsDevice>();
            _shipComponentFactory = Substitute.For<IShipComponentFactory>();

            _energyStore = Substitute.For<IEnergyStore>();
            _shield = Substitute.For<IShield>();
            _hull = Substitute.For<IHull>();
            _thrusterArray = Substitute.For<IThrusterArray>();
            _controller = Substitute.For<IShipController>();

            _shipComponentFactory.CreateEnergyStore().ReturnsForAnyArgs(_energyStore);
            _shipComponentFactory.CreateShield(Arg.Any<IShip>()).Returns(_shield);
            _shipComponentFactory.CreateHull(Arg.Any<IShip>()).Returns(_hull);
            _shipComponentFactory.CreateThrusterArray(Arg.Any<IShip>()).Returns(_thrusterArray);

            _position = new Vector2(12f, 5.5f);
            _ship = new Ship("TestShip", _position, _radius, Color.Goldenrod, _graphicsFactory, _shipComponentFactory);
            _ship.SetController(_controller);
        }
Exemplo n.º 18
0
 public void Split(Vector3 localPointOnPlane, Vector3 localPlaneNormal, bool fillCut, UvMapper uvMapper, ColorMapper colorMapper, out IHull resultA, out IHull resultB)
 {
     lock (key)
     {
         if (localPlaneNormal == Vector3.zero)
         {
             localPlaneNormal = Vector3.up;
         }
         
         LegacyHull a = new LegacyHull(this);
         LegacyHull b = new LegacyHull(this);
         
         SetIndices();
         
         bool[] pointAbovePlane;
         
         AssignPoints(a, b, localPointOnPlane, localPlaneNormal, out pointAbovePlane);
         
         int[] oldToNewVertex;
         
         AssignVertices(a, b, pointAbovePlane, out oldToNewVertex);
         
         bool[] edgeIntersectsPlane;
         EdgeHit[] edgeHits;
         
         AssignEdges(a, b, pointAbovePlane, localPointOnPlane, localPlaneNormal, out edgeIntersectsPlane, out edgeHits);
         
         IList<Edge> cutEdgesA, cutEdgesB;
         
         AssignTriangles(a, b, pointAbovePlane, edgeIntersectsPlane, edgeHits, oldToNewVertex, out cutEdgesA, out cutEdgesB);
         
         if (fillCut)
         {
             SortCutEdges(cutEdgesA, cutEdgesB);
             
             FillCutEdges(a, b, cutEdgesA, cutEdgesB, localPlaneNormal, uvMapper);
         }
         
         ValidateOutput(a, b, localPlaneNormal);
         
         Clear();
         
         // Set output
         resultA = a;
         resultB = b;
     }
 }
Exemplo n.º 19
0
 public HullViewModel(CommandBindingCollection commandBindings, IHull hull, TankViewModelBase owner)
     : base(commandBindings, hull, owner)
 {
 }
Exemplo n.º 20
0
 public void Split(Vector3 localPointOnPlane, Vector3 localPlaneNormal, bool fillCut, UvMapper uvMapper, ColorMapper colorMapper, out IHull resultA, out IHull resultB)
 {
     if (localPlaneNormal == Vector3.zero)
     {
         localPlaneNormal = Vector3.up;
     }
     
     FastHull a = new FastHull(this);
     FastHull b = new FastHull(this);
     
     bool[] vertexAbovePlane;
     int[] oldToNewVertexMap;
     
     AssignVertices(a, b, localPointOnPlane, localPlaneNormal, out vertexAbovePlane, out oldToNewVertexMap);
     
     IList<Vector3> cutEdges;
     
     AssignTriangles(a, b, vertexAbovePlane, oldToNewVertexMap, localPointOnPlane, localPlaneNormal, out cutEdges);
     
     if (fillCut)
     {
         if (colors != null && colorMapper == null)
         {
             Debug.LogWarning("Fill cut failed: A ColorMapper was not provided even though the mesh has a color channel");
         }
         else if ((tangents != null || uvs != null) && uvMapper == null)
         {
             Debug.LogWarning("Fill cut failed: A UvMapper was not provided even though the mesh has a tangent/uv channel");
         }
         else
         {
             FillCutEdges(a, b, cutEdges, localPlaneNormal, uvMapper, colorMapper);
         }
     }
     
     ValidateOutput(a, b, localPlaneNormal);
     
     // Set output
     resultA = a;
     resultB = b;
 }
Exemplo n.º 21
0
    public void Split(Vector3 localPointOnPlane, Vector3 localPlaneNormal, bool fillCut, UvMapper uvMapper, out IHull resultA, out IHull resultB)
    {
        if (localPlaneNormal == Vector3.zero)
        {
            localPlaneNormal = Vector3.up;
        }

        FastHull a = new FastHull(this);
        FastHull b = new FastHull(this);

        bool[] vertexAbovePlane;
        int[]  oldToNewVertexMap;

        AssignVertices(a, b, localPointOnPlane, localPlaneNormal, out vertexAbovePlane, out oldToNewVertexMap);

        IList <Vector3> cutEdges;

        AssignTriangles(a, b, vertexAbovePlane, oldToNewVertexMap, localPointOnPlane, localPlaneNormal, out cutEdges);

        if (fillCut)
        {
            FillCutEdges(a, b, cutEdges, localPlaneNormal, uvMapper);
        }

        ValidateOutput(a, b, localPlaneNormal);

        isValid = false;

        // Set output
        resultA = a;
        resultB = b;
    }
Exemplo n.º 22
0
    private void CreateNewGameObjects(IList <IHull> newHulls, out GameObject[] newGameObjects)
    {
        // Get new meshes
        Mesh[]  newMeshes  = new Mesh[newHulls.Count];
        float[] newVolumes = new float[newHulls.Count];

        float totalVolume = 0.0f;

        for (int i = 0; i < newHulls.Count; i++)
        {
            Mesh    mesh   = newHulls[i].GetMesh();
            Vector3 size   = mesh.bounds.size;
            float   volume = size.x * size.y * size.z;

            newMeshes[i]  = mesh;
            newVolumes[i] = volume;

            totalVolume += volume;
        }

        // Create new game objects
        newGameObjects = new GameObject[newHulls.Count];

        for (int i = 0; i < newHulls.Count; i++)
        {
            IHull newHull = newHulls[i];
            Mesh  newMesh = newMeshes[i];
            float volume  = newVolumes[i];

            GameObject newGameObject = (GameObject)Instantiate(gameObject);

            // Set mesh filter
            MeshFilter newMeshFilter = newGameObject.GetComponent <MeshFilter>();

            if (newMeshFilter != null)
            {
                newMeshFilter.sharedMesh = newMesh;
            }

            // Set mesh collider
            MeshCollider newMeshCollider = newGameObject.GetComponent <MeshCollider>();

            if (newMeshCollider != null)
            {
                newMeshCollider.sharedMesh = newMesh;
            }

            newGameObject.transform.position = gameObject.transform.position;
            newGameObject.transform.rotation = gameObject.transform.rotation;

            if (i == 0)
            {
                GameObject.Destroy(newGameObject);
            }
            else
            {
                if (!gameObject.name.Substring(gameObject.name.Length - 2).Equals("_C"))
                {
                    newGameObject.name = gameObject.name + "_C";
                }
                else
                {
                    newGameObject.name = gameObject.name;
                    GameObject.Destroy(gameObject);
                }
            }

            newGameObjects[i] = newGameObject;
        }
    }
Exemplo n.º 23
0
 public void Start()
 {
     Mesh sharedMesh = GetComponent<MeshFilter>().sharedMesh;
     
     // Initialize the first generation hull
     if (hull == null)
     {
         if (internalHullType == HullType.FastHull)
         {
             hull = new FastHull(sharedMesh);
         }
         else if (internalHullType == HullType.LegacyHull)
         {
             hull = new LegacyHull(sharedMesh);
         }
     }
     
     // Update properties
     CalculateCenter();
 }
Exemplo n.º 24
0
        public void Split(Vector3 localPointOnPlane, Vector3 localPlaneNormal, bool fillCut, UvMapper uvMapper, ColorMapper colorMapper, out IHull resultA, out IHull resultB)
        {
            lock (key)
            {
                if (localPlaneNormal == Vector3.zero)
                {
                    localPlaneNormal = Vector3.up;
                }

                LegacyHull a = new LegacyHull(this);
                LegacyHull b = new LegacyHull(this);

                SetIndices();

                bool[] pointAbovePlane;

                AssignPoints(a, b, localPointOnPlane, localPlaneNormal, out pointAbovePlane);

                int[] oldToNewVertex;

                AssignVertices(a, b, pointAbovePlane, out oldToNewVertex);

                bool[]    edgeIntersectsPlane;
                EdgeHit[] edgeHits;

                AssignEdges(a, b, pointAbovePlane, localPointOnPlane, localPlaneNormal, out edgeIntersectsPlane, out edgeHits);

                IList <Edge> cutEdgesA, cutEdgesB;

                AssignTriangles(a, b, pointAbovePlane, edgeIntersectsPlane, edgeHits, oldToNewVertex, out cutEdgesA, out cutEdgesB);

                if (fillCut)
                {
                    SortCutEdges(cutEdgesA, cutEdgesB);

                    FillCutEdges(a, b, cutEdgesA, cutEdgesB, localPlaneNormal, uvMapper);
                }

                ValidateOutput(a, b, localPlaneNormal);

                Clear();

                // Set output
                resultA = a;
                resultB = b;
            }
        }
Exemplo n.º 25
0
    private void CreateNewGameObjects(IList <IHull> newHulls, out GameObject[] newGameObjects)
    {
        // Get new meshes
        Mesh[]  newMeshes  = new Mesh[newHulls.Count];
        float[] newVolumes = new float[newHulls.Count];

        float totalVolume = 0.0f;

        for (int i = 0; i < newHulls.Count; i++)
        {
            Mesh    mesh   = newHulls[i].GetMesh();
            Vector3 size   = mesh.bounds.size;
            float   volume = size.x * size.y * size.z;

            newMeshes[i]  = mesh;
            newVolumes[i] = volume;

            totalVolume += volume;
        }

        // Remove mesh references to speed up instantiation
        GetComponent <MeshFilter>().sharedMesh = null;

        MeshCollider meshCollider = GetComponent <MeshCollider>();

        if (meshCollider != null)
        {
            meshCollider.sharedMesh = null;
        }

        // Create new game objects
        newGameObjects = new GameObject[newHulls.Count];

        for (int i = 0; i < newHulls.Count; i++)
        {
            IHull newHull = newHulls[i];
            Mesh  newMesh = newMeshes[i];
            float volume  = newVolumes[i];

            GameObject newGameObject = (GameObject)Instantiate(gameObject);

            // Set shatter tool
            ShatterTool newShatterTool = newGameObject.GetComponent <ShatterTool>();

            if (newShatterTool != null)
            {
                newShatterTool.hull = newHull;
            }

            // Set mesh filter
            MeshFilter newMeshFilter = newGameObject.GetComponent <MeshFilter>();

            if (newMeshFilter != null)
            {
                newMeshFilter.sharedMesh = newMesh;
            }

            // Set mesh collider
            MeshCollider newMeshCollider = newGameObject.GetComponent <MeshCollider>();

            if (newMeshCollider != null)
            {
                newMeshCollider.sharedMesh = newMesh;
            }

            // Set rigidbody
            Rigidbody newRigidbody = newGameObject.GetComponent <Rigidbody>();

            if (newRigidbody != null)
            {
                newRigidbody.mass        = GetComponent <Rigidbody>().mass *(volume / totalVolume);
                newRigidbody.constraints = RigidbodyConstraints.None;

                if (!newRigidbody.isKinematic)
                {
                    newRigidbody.velocity = GetComponent <Rigidbody>().GetPointVelocity(newRigidbody.worldCenterOfMass);

                    newRigidbody.angularVelocity = GetComponent <Rigidbody>().angularVelocity;
                }
            }

            HingeJoint hinge = newGameObject.GetComponent <HingeJoint>();
            if (hinge != null)
            {
                Destroy(hinge);
            }

            // Update properties
            newShatterTool.CalculateCenter();

            newGameObjects[i] = newGameObject;
        }
    }