Beispiel #1
0
        private void AddManeuverPoint_click(object sender, RoutedEventArgs e)
        {
            VectorObject obj = new VectorObject();

            this.Data.ManeuverPoints.Add(obj);
            ManeuverExpander.IsExpanded = true;
        }
Beispiel #2
0
        private void AddImpulsePoint_click(object sender, RoutedEventArgs e)
        {
            VectorObject obj = new VectorObject();

            this.Data.ImpulsePoints.Add(obj);
            impulseExpander.IsExpanded = true;
        }
Beispiel #3
0
        private void AddEnginePort_click(object sender, RoutedEventArgs e)
        {
            VectorObject obj = new VectorObject();

            this.Data.EnginePorts.Add(obj);
            EnginePortExpander.IsExpanded = true;
        }
Beispiel #4
0
        private void AddTubePort_click(object sender, RoutedEventArgs e)
        {
            VectorObject obj = new VectorObject();

            this.Data.TorpedoTubes.Add(obj);
            torptupeExpander.IsExpanded = true;
        }
Beispiel #5
0
        public double Lp_norm(VectorObject <double> v1, VectorObject <double> v2, int p = 2)
        {
            var keys = v1.Keys.ToList();

            foreach (var key in v2.Keys)
            {
                if (!keys.Contains(key))
                {
                    keys.Add(key);
                }
            }
            return(keys.Select(k => Math.Pow(Math.Abs(v1[k] - v2[k]), p)).Sum());
        }
Beispiel #6
0
        private void DeleteManeuverPoint_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null)
            {
                VectorObject bp = btn.CommandParameter as VectorObject;
                if (btn != null)
                {
                    this.Data.ManeuverPoints.Remove(bp);
                }
            }
        }
Beispiel #7
0
        private void DeleteTubePort_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null)
            {
                VectorObject bp = btn.CommandParameter as VectorObject;
                if (btn != null)
                {
                    this.Data.TorpedoTubes.Remove(bp);
                }
            }
        }
    public VectorObject GameObjectPosition(Vector3 ObjectSize, ObjectDetails objectDetails)
    {
        //Objects with Y set at ZERO should have the Y value updated to the top of terrain at that position
        //Items below or above ZERO are left to that position.  YEA, ZERO denotes on Terrain.  Got a better idea?

        VectorObject position = new VectorObject();

        try
        {
            float   x;
            float   y;
            float   z;
            float   y2      = 0;
            bool    isFound = false;
            Vector3 ObjectPositionToCheck;
            bool    isIntersected = false;
            byte    bAttempts     = 0;


            do
            {
                y2 = 0; //Reset
                x  = Random.Range(objectDetails.MinimumPosition.x, objectDetails.MaximumPosition.x);
                y  = Random.Range(objectDetails.MinimumPosition.y, objectDetails.MaximumPosition.y);
                z  = Random.Range(objectDetails.MinimumPosition.z, objectDetails.MaximumPosition.z);
                ObjectPositionToCheck = new Vector3(x, y, z);


                if (objectDetails.avoidObjects)
                {
                    //If y is zero, then it should be placed on the ground, aka top level of the terrain
                    if (y == 0 && this.currentTerrain != null)
                    {
                        //Find the top Y postion for the terrain
                        y  = currentTerrain.SampleHeight(ObjectPositionToCheck);
                        y2 = y;
                    }

                    //While this seems like the same call as above, the terrain location y value could still come back as zero,
                    //if so it is in water, at least in that location.
                    if (y > 0 || objectDetails.PercentInWater > 0)
                    {
                        ObjectSize.y += objectDetails.toTheSky;

                        ObjectPositionToCheck = new Vector3(x, y + (ObjectSize.y / 2) + 0.2f, z);

                        isIntersected = Physics.CheckBox(ObjectPositionToCheck, (ObjectSize / 2));

                        ObjectPositionToCheck.y -= (objectDetails.toTheSky / 2);

                        if (isIntersected == false)
                        {
                            //Remove this value before moving to check if it's in water.
                            //No need to do it above as it saves running this line if the object was intersected
                            ObjectSize.y -= objectDetails.toTheSky;

                            if (IsInWater(ObjectPositionToCheck, ObjectSize, objectDetails.PercentInWater) == false)
                            {
                                isFound = true;
                            }
                        }
                    }
                }
                else
                {
                    //Since the AvoidObjects flag is false, we only need to check if it is within water
                    if (IsInWater(ObjectPositionToCheck, ObjectSize, objectDetails.PercentInWater) == false)
                    {
                        isFound = true;
                    }
                }

                //To avoid infinite loop
                bAttempts++;
                if (bAttempts > 250)
                {
                    //It is possible that the object was found during the last cycle.  So set the "IsFound" to whatever it is, true or false.
                    position.IsFound = isFound; //This is used in the function PopulateExperience() in case no position is found
                    isFound          = true;    //Not necessarily true, but we need to get out of this loop.
                }
            } while (isFound == false);


            if (y2 > 0)
            {
                //Setting the Y value to the top of the terrain.
                ObjectPositionToCheck.y = y2;
            }

            //Adjusting this just a little to insure that if an object is at ground level then it is burried a tiny bit to avoid floating.
            //Yes this is a hack.  It would be better to find the lowest point of the object.  Someday.
            ObjectPositionToCheck.y += objectDetails.yVariance;

            position.Vector = ObjectPositionToCheck;
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }

        return(position);
    }
    public VectorObject AdjustObject(GameObject gameObject, ObjectDetails objectDetails)
    {
        //The return object allows this function use outside this class
        //when there is a desire to place Other objects near it.
        VectorObject VectorReturn = new VectorObject();

        try
        {
            float        x;
            float        y;
            float        z;
            VectorObject position;
            Vector3      objectSize = gameObject.transform.localScale;


            //If the terrain is used as the Min/Max of the area that can be used for placing the object
            if (objectDetails.useTerrainSize)
            {
                if (currentTerrain != null)
                {
                    objectDetails.MinimumPosition = currentTerrain.GetPosition();
                    objectDetails.MaximumPosition = currentTerrain.terrainData.size; //TODO: should the Y value be reset to zero or...?
                }
            }

            //Game Object's Size
            if (objectDetails.isScaled)
            {
                x = Random.Range(objectDetails.MinimumScale.x, objectDetails.MaximumScale.x);

                //This option allows for all values to be scaled evenly, I choose X as it was first.  Deal with it.
                if (objectDetails.isEvenlyScaled)
                {
                    y = x;
                    z = x;
                }
                else
                {
                    y = Random.Range(objectDetails.MinimumScale.y, objectDetails.MaximumScale.y);
                    z = Random.Range(objectDetails.MinimumScale.z, objectDetails.MaximumScale.z);
                }
                gameObject.transform.localScale = new Vector3(x, y, z);
            }

            //Game Object's Rotation
            x = Random.Range(objectDetails.MinimumRotation.x, objectDetails.MaximumRotation.x);
            y = Random.Range(objectDetails.MinimumRotation.y, objectDetails.MaximumRotation.y);
            z = Random.Range(objectDetails.MinimumRotation.z, objectDetails.MaximumRotation.z);
            gameObject.transform.rotation = Quaternion.Euler(x, y, z);

            //Some objects do not have a renderer, so in those cases use the original scale
            if (gameObject.GetComponent <Renderer>() != null)
            {
                objectSize = gameObject.GetComponent <Renderer>().bounds.size;
            }

            //Game Object's Position
            position = GameObjectPosition(
                objectSize,
                objectDetails);

            //Only place if the a position was found within GameObjectPosition.
            //There is a possibility that there is no room or other reason why a position is not found
            if (position.IsFound)
            {
                gameObject.transform.localPosition = position.Vector;
                VectorReturn.Vector = position.Vector;
            }
            else
            {
                Destroy(gameObject);
                VectorReturn.IsFound = false;
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }

        return(VectorReturn);
    }
Beispiel #10
0
 // makes-life-easier stub for adding objects
 public void addObject(string uid, VectorObject _object)
 {
     objects[uid] = _object;
 }
Beispiel #11
0
 public Action(string uid, ActionType type, VectorObject obj)
 {
     this.uid  = uid;
     this.type = type;
     this.obj  = obj;
 }