Esempio n. 1
0
        static void Main(string[] args)
        {
            using (var space = new Space())
            {

            }
        }
Esempio n. 2
0
 /// <summary>
 /// Called before an object is removed from its space.
 /// </summary>
 public override void OnRemovalFromSpace(Space oldSpace)
 {
     for (int i = 0; i < solverUpdateables.Count; i++)
     {
         solverUpdateables[i].OnRemovalFromSpace(oldSpace);
     }
 }
 public override void Reset()
 {
     gameObject = null;
     moveVector = new FsmVector3 {UseVariable = true};
     space = Space.World;
     perSecond = true;
 }
Esempio n. 4
0
        public void AttachGO(Transform dest, Transform source, Vector3 position, Quaternion rotation, Vector3 scale,
            Space space = Space.Self)
        {
            if (source == null)
                return;

            if (dest == null)
            {
                source.parent = null;
            }
            else
            {
                source.parent = dest.transform;
            }
            if (space == Space.Self)
            {
                source.transform.localPosition = position;
                source.transform.localRotation = rotation;
            }
            else
            {
                source.transform.position = position;
                source.transform.rotation = rotation;
            }
            source.transform.localScale = scale;
        }
Esempio n. 5
0
 public override void OnReset()
 {
     if (translation != null) {
         translation.Value = Vector3.zero;
     }
     relativeTo = Space.Self;
 }
		public override void Reset()
		{
			transformRotation = new FsmGameObject { UseVariable = true};
			vectorRotation = new FsmVector3 { UseVariable = true };
			time = 1f;
			space = Space.World;
		}
Esempio n. 7
0
 public override void Reset()
 {
     base.Reset();
     this.id = new FsmString
     {
         UseVariable = true
     };
     this.time = 1f;
     this.delay = 0f;
     this.loopType = iTween.LoopType.none;
     this.vector = new FsmVector3
     {
         UseVariable = true
     };
     this.speed = new FsmFloat
     {
         UseVariable = true
     };
     this.space = Space.World;
     this.orientToPath = false;
     this.lookAtObject = new FsmGameObject
     {
         UseVariable = true
     };
     this.lookAtVector = new FsmVector3
     {
         UseVariable = true
     };
     this.lookTime = 0f;
     this.axis = iTweenFsmAction.AxisRestriction.none;
 }
Esempio n. 8
0
 public override void Reset()
 {
     this.gameObject = null;
     this.space = Space.World;
     this.storePosition = null;
     this.everyFrame = false;
 }
Esempio n. 9
0
 /// <summary>
 /// Called after the object is added to a space.
 /// </summary>
 /// <param name="newSpace"></param>
 public override void OnAdditionToSpace(Space newSpace)
 {
     for (int i = 0; i < solverUpdateables.Count; i++)
     {
         solverUpdateables[i].OnAdditionToSpace(newSpace);
     }
 }
    /// <summary>
    /// Function for applying a specific type of force to a Rigidbody2D (since the default functionality is incomplete)
    /// </summary>
    /// <param name="rb2d">Rigidbody2D to apply the force to</param>
    /// <param name="force">The amount of force to apply</param>
    /// <param name="mode">What type of force to apply</param>
    /// <param name="relativeTo">Should the force be applied in the rigidbody's local space, or world space?</param>
    public static void AddForce2D(this Rigidbody2D rb2d, Vector2 force, ForceMode mode = ForceMode.Force, Space relativeTo = Space.World)
    {
        ForceMode2D mode2D = ForceMode2D.Force;
        Vector2 forceApplied = force;
        switch (mode)
        {
            case ForceMode.Impulse:
                mode2D = ForceMode2D.Impulse;
                break;
            case ForceMode.Acceleration:
                forceApplied *= rb2d.mass;
                break;
            case ForceMode.VelocityChange:
                forceApplied = force * rb2d.mass / Time.fixedDeltaTime;
                break;
            case ForceMode.Force:
                //nothing special
                break;
        }

        if (relativeTo == Space.Self)
            rb2d.AddRelativeForce(forceApplied, mode2D);
        else if (relativeTo == Space.World)
            rb2d.AddForce(forceApplied, mode2D);
    }
 public override void OnReset()
 {
     if (eulerAngles != null) {
         eulerAngles.Value = Vector3.zero;
     }
     relativeTo = Space.Self;
 }
 public static void SetX(this Transform transform, float x, Space space = Space.Self)
 {
     if (space == Space.Self)
         transform.localPosition = transform.localPosition.ScaleBy(0, 1, 1) + x*Vector3.right;
     else
         transform.position = transform.position.ScaleBy(0, 1, 1) + x*Vector3.right;
 }
		public override void Reset()
		{
			gameObject = null;
			space = Space.World;
			storePosition = null;
			everyFrame = false;
		}
Esempio n. 14
0
    void Update()
    {
        if (!Application.isEditor)
        {
            Destroy(this);
            return;
        }

        if (FreezePosition)
        {
            // Save current position if enabled
            if ((FreezePosition != m_OldFreezePosition) || (space != m_OldSpace))
                m_Position = (space == Space.World) ? transform.position : transform.localPosition;
            // Freeze the position
            if (space == Space.World)
                transform.position = m_Position;
            else
                transform.localPosition = m_Position;
        }

        if (FreezeRotation)
        {
            // Save current rotation if enabled
            if ((FreezeRotation != m_OldFreezeRotation) || (space != m_OldSpace))
                m_Rotation = (space == Space.World) ? transform.rotation : transform.localRotation;
            // Freeze the rotation
            if (space == Space.World)
                transform.rotation = m_Rotation;
            else
                transform.localRotation = m_Rotation;
        }
        m_OldSpace = space;
        m_OldFreezePosition = FreezePosition;
        m_OldFreezeRotation = FreezeRotation;
    }
        public void AddChildNodes()
        {
            var building = new Space { Name = "Science Building", SquareFeet = 30000 };
            var storage = building.Children.Add(new Space { Name = "Storage", SquareFeet = 1200 });
            var bin = storage.Children.Add(new Space { Name = "Bin", SquareFeet = 4 });

            Assert.AreEqual(0, building.Ancestors.Count());
            Assert.AreEqual(1, building.Children.Count);
            Assert.AreEqual(1, building.ChildNodes.Count());
            Assert.AreEqual(2, building.Descendants.Count());
            Assert.AreEqual(2, building.Height);
            Assert.AreEqual(0, building.Depth);
            Assert.IsNull(building.Parent);

            Assert.AreEqual(1, storage.Ancestors.Count());
            Assert.AreEqual(1, storage.Children.Count);
            Assert.AreEqual(1, storage.ChildNodes.Count());
            Assert.AreEqual(1, storage.Descendants.Count());
            Assert.AreEqual(1, storage.Height);
            Assert.AreEqual(1, storage.Depth);
            Assert.AreSame(storage.Parent, building);

            Assert.AreEqual(2, bin.Ancestors.Count());
            Assert.AreEqual(0, bin.Children.Count);
            Assert.AreEqual(0, bin.ChildNodes.Count());
            Assert.AreEqual(0, bin.Descendants.Count());
            Assert.AreEqual(0, bin.Height);
            Assert.AreEqual(2, bin.Depth);
            Assert.AreSame(bin.Parent, storage);
        }
 public static void SetZ(this Transform transform, float z, Space space = Space.Self)
 {
     if (space == Space.Self)
         transform.localPosition = transform.localPosition.ScaleBy(1, 1, 0) + z*Vector3.forward;
     else
         transform.position = transform.position.ScaleBy(1, 1, 0) + z*Vector3.forward;
 }
 public static void SetY(this Transform transform, float y, Space space = Space.Self)
 {
     if (space == Space.Self)
         transform.localPosition = transform.localPosition.ScaleBy(1, 0, 1) + y*Vector3.up;
     else
         transform.position = transform.position.ScaleBy(1, 0, 1) + y*Vector3.up;
 }
Esempio n. 18
0
    void Awake()
    {
        InputHandler.OnZoom += this.Zoom;               // Subscribe to Zoom Event
        InputHandler.OnTouchMove += this.OnTouchMove;   // Subscribe to OnTouchMove Event

        var spaceGO = GameObject.Find("Space");
        if (spaceGO == null) {
            throw new MissingComponentException("Unable to find Space GameObject. This should be a global GO that contains the Space script.");
        }
        _map = spaceGO.GetComponent<Space>();
        if (_map == null) {
            throw new MissingComponentException("Unable to find space script. This component should be attached to the Space GameObject.");
        }

        _cameraWidthHalf = Camera.main.orthographicSize * Camera.main.aspect;
        _cameraHeightHalf = Camera.main.orthographicSize;

        _smallestPlanetDiameter = 25; // _map.GetSmallestDiameter();

        RecalculateCameraMinAndMaxSize();

        float cameraInitOrthoSize = Mathf.Max(_cameraMaxOrthoSize, _cameraMinOrthoSize) * 2 / 3; // max function is needed when the map returns a size of 0
        Camera.main.orthographicSize = cameraInitOrthoSize;
        _moveToPosition = _map.transform.position;

        _cameraOrthoSizeTo = Camera.main.orthographicSize; // needed? yes otherwise the first scroll is using zero as startpoint
        //_moveToPosition = FindHomePlanet();
    }
Esempio n. 19
0
    // Use this for initialization
    void Awake()
    {
        Debug.Assert(SaveGameEventSubscription == null && AutoSaveGameEventSubscription == null);
        SaveGameEventSubscription= MessageHub.Subscribe<SaveGameEvent>(SaveGame);
        AutoSaveGameEventSubscription = MessageHub.Subscribe<AutoSaveGameEvent>(AutoSaveGame);

        mapData = new CollectedMapData();

        space = GameObject.Find("Space").GetComponent<Space>();
        if (space == null)
        {
            throw new MissingComponentException("Unable to find Space. The big bang doesn't have enough space to happen. The 'Space' game object also needs to be added to the level and have the space script attached.");
        }

        airTrafficControl = GameObject.Find("AirTrafficControl").GetComponent<AirTrafficControl>();
        if (space == null)
        {
            throw new MissingComponentException("Unable to find AirTrafficControl. There can't be any troops flying around without an global AirTrafficControl GameObject that has an AirTrafficControl Script attached.");
        }

        gameState = GameObject.Find("2D_MainCam").GetComponent<GameState>();
        if (gameState == null)
        {
            throw new MissingComponentException("Unable to find GameState. The 'GameState' script needs to be attached to the same Gameobject as the BigBang.");
        }
        playerManager = GameObject.Find("PlayerManagement").GetComponent<PlayerManager>();
        if (playerManager == null)
        {
            throw new MissingComponentException("Unable to find playerManager.");
        }
    }
Esempio n. 20
0
        public void Done()
        {
            if (SpaceName != null)
                SpaceName = SpaceName.Trim();
            if (string.IsNullOrWhiteSpace(SpaceName))
            {
                MessageBox.Show("Profile name is empty", "Locality", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SpaceName.Length > 30)
            {
                MessageBox.Show("Profile name is too long", "Locality", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            foreach (var spc in App.Instance.Config.Spaces)
                if (spc.Name.Equals(SpaceName, StringComparison.InvariantCultureIgnoreCase))
                {
                    MessageBox.Show("This profile already exists", "Locality", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

            var s = new Space { Name = SpaceName, Id = Guid.NewGuid().ToString() };
            App.Instance.Config.Spaces.Add(s);
            (Parent as RootViewModel).Back();
        }
 public override void Reset()
 {
     gameObject = null;
     speed = null;
     speedVector = null;
     space = Space.World;
 }
 public override void Reset()
 {
     gameObjects = new FsmGameObject[1];
     storePositions = new FsmVector3[1];
     space = Space.World;
     everyFrame = false;
 }
    static void SetTargetRotationInternal(ConfigurableJoint joint, Quaternion targetRotation, Quaternion startRotation, Space space)
    {
        // Calculate the rotation expressed by the joint's axis and secondary axis
        var right = joint.axis;
        var forward = Vector3.Cross (joint.axis, joint.secondaryAxis).normalized;
        var up = Vector3.Cross (forward, right).normalized;
        Quaternion worldToJointSpace = Quaternion.LookRotation (forward, up);

        // Transform into world space
        Quaternion resultRotation = Quaternion.Inverse (worldToJointSpace);

        // Counter-rotate and apply the new local rotation.
        // Joint space is the inverse of world space, so we need to invert our value
        if (space == Space.World) {
            resultRotation *= startRotation * Quaternion.Inverse (targetRotation);
        } else {
            resultRotation *= Quaternion.Inverse (targetRotation) * startRotation;
        }

        // Transform back into joint space
        resultRotation *= worldToJointSpace;

        // Set target rotation to our newly calculated rotation
        joint.targetRotation = resultRotation;
    }
	public void Rotate(Vector3 rotation, Space relativeTo)
	{
		if (_focalTransform == null)
		{
			return;
		}
		_focalTransform.Rotate(rotation, relativeTo);
	}
Esempio n. 25
0
 public static void PopulatePoints(ISpaceManager sm, Space<string> space)
 {
     sm.AddPoint(space, p0, 0, 0, 0);
     sm.AddPoint(space, p1, 1, 8, 3);
     sm.AddPoint(space, p3, 5, 5, 5);
     sm.AddPoint(space, p2, 1, -1, -1);
     sm.AddPoint(space, p4, 7, 1, 1);
 }
Esempio n. 26
0
 public override void Reset () {
     gameObject = new ConcreteGameObjectVar(this.self);
     newEulerAngles = new ConcreteVector3Var();
     x = new ConcreteFloatVar();
     y = new ConcreteFloatVar();
     z = new ConcreteFloatVar();
     relativeTo = Space.Self;
 }
Esempio n. 27
0
 public AiPlayer(PlayerData playerData, Space space)
 {
     this.playerData = playerData;
     this.space = space;
     playerData.IsHumanPlayer = false;
     lastDayAtk = new AttackDictionary();
     todaysAtk = new AttackDictionary();
 }
Esempio n. 28
0
 public override void Reset () {
     gameObject = new ConcreteGameObjectVar(this.self);
     newPosition = new ConcreteVector3Var();
     newX = new ConcreteFloatVar();
     newY = new ConcreteFloatVar();
     newZ = new ConcreteFloatVar();
     relativeTo = Space.World;
 }
Esempio n. 29
0
        private void P_eValueChanged(object sender, EventArgs e) {
            inSpace = (Space)properties["inSpace"].nValue;
            outSpace = (Space)properties["outSpace"].nValue;

            setExtra(inSpace.ToString() + " to " + outSpace.ToString());

            soil();
        }
Esempio n. 30
0
 public override void Reset () {
     gameObject = new ConcreteGameObjectVar(this.self);
     storePosition = new ConcreteVector3Var();
     storeX = new ConcreteFloatVar();
     storeY = new ConcreteFloatVar();
     storeZ = new ConcreteFloatVar();
     relativeTo = Space.Self;
 }
Esempio n. 31
0
        public static void Main(string [] args)
        {
            Kary.Calculat.Expression load_expr = new Expression("23 - 23");
            var ans = load_expr.Evaluate();

            List <Space>  spaces  = new List <Space> ();
            List <string> history = new List <string> ();



            //
            // ──────────────────────────────────────────────────────────── I ─────────
            //  :::::: I N T E R F A C E : : :  :  :   :     :        :          :
            // ─────────────────────────────────────────────────────────────────────
            //

            Terminal.Title = "I N T A C T U S";
            Terminal.NewLine();
            Terminal.PrintLn(" Int, Terminal Interface for Complot and Intactus engines");
            Interface.LineWriter();
            Terminal.PrintLn(" Kary.Intactus, Kary.Foundation, Kary.Text, Kary.Calculat, and Kary.Numerica");
            Terminal.PrintLn(" Copyright (c) 2015-2016 Kary Foundation, Inc. All rights reserved.");
            Terminal.PrintLn(" http://www.karyfoundation.org/developer/kary-framework/");


            //
            // COUNTERS
            //

            int IO_counter = 1;

            while (true)
            {
                var input = Interface.Input(IO_counter).Replace(" vs ", "&");
                Terminal.PrintLn("");

                if (input == "c")
                {
                    Terminal.Clean();
                    history.Add("0");
                }
                else if (input == "e")
                {
                    history.Add("0");
                    Terminal.PrintLn();
                    Terminal.Title = "";
                    Environment.Exit(0);
                }
                else if (input.StartsWith("load "))
                {
                    try {
                        int input_number_to_load = InputToLoadNumberFromString(input, "load");
                        EvaluateWithResult(history [input_number_to_load], ref ans, IO_counter, spaces);
                        history.Add(history [input_number_to_load]);
                    } catch {
                        Interface.PrintOut("bad index number...", IO_counter);
                        history.Add("0");
                    }
                }
                else if (input.StartsWith("simple "))
                {
                    try {
                        int input_number_to_load = InputToLoadNumberFromString(input, "simple");
                        Interface.PrintOut(history [input_number_to_load].Replace("&", " vs "), IO_counter);
                        history.Add("0");
                    } catch {
                        Interface.PrintOut("bad index number...", IO_counter);
                        history.Add("0");
                    }
                }
                else if (input.Split('&').Length > 1)
                {
                    history.Add(input);
                    var parts = input.Split('&');

                    string [] results = new string [parts.Length];

                    for (int i = 0; i < parts.Length; i++)
                    {
                        results [i] = Evaluate(parts [i], ref ans, spaces).ToString();
                    }

                    Interface.PrintColumnChart(results, IO_counter);
                    ans = 0;
                }
                else if (input.StartsWith("// "))
                {
                    IO_counter--;
                    Terminal.Y--;
                }
                else if (input.Split('?').Length == 2)
                {
                    var parts = input.Split('?');                       // 0 -> name 1 -> value
                    EvaluateWithResult(parts [1], ref ans, IO_counter, spaces);
                    var space = new Space();

                    space.name  = parts [0].Replace(" ", "");
                    space.value = ans;

                    bool add_the_space = true;

                    foreach (var find_space in spaces)
                    {
                        if (find_space.name == space.name)
                        {
                            add_the_space = false;
                        }
                    }

                    if (add_the_space)
                    {
                        spaces.Add(space);
                    }
                    else
                    {
                        for (int J = 0; J < spaces.Count; J++)
                        {
                            if (spaces [J].name == space.name)
                            {
                                spaces [J] = space;
                                J          = spaces.Count;
                            }
                        }
                    }

                    history.Add(parts [1]);
                }
                else
                {
                    EvaluateWithResult(input, ref ans, IO_counter, spaces);
                    history.Add(input);
                }

                IO_counter++;
            }
        }
Esempio n. 32
0
        public static TransformFollower CreateFollower(Transform parent, Transform attached, Vector3 offset, Space offsetSpace = Space.Self)
        {
            Vector3 worldOffset, localOffset;

            if (offsetSpace == Space.Self)
            {
                worldOffset = attached.TransformDirection(offset);
                localOffset = offset;
            }
            else
            {
                worldOffset = offset;
                localOffset = attached.InverseTransformDirection(offset);
            }
            return(CreateFollower(parent, attached.position + worldOffset, new TransformTransformable(attached, localOffset)));
        }
Esempio n. 33
0
 public void Add(Space space)
 {
     SpaceCounts[space]++;
 }
Esempio n. 34
0
 public void Skip1(Space space) => Spaces.Remove(space);
Esempio n. 35
0
 private TransformTransformable(Transform transform, Vector3?offset = null, Space offsetSpace = Space.Self)
 {
     this.transform = transform;
     if (offset == null || offset.Value == Vector3.zero)
     {
         this.offset = null;
     }
     else if (offsetSpace == Space.Self)
     {
         this.offset = offset;
     }
     else
     {
         this.offset = transform.InverseTransformDirection(offset.Value);
     }
 }
Esempio n. 36
0
 public static Vector3 Rotate(this Vector3 vector, float angle, Vector3 axis, Space space = Space.Self)
 {
     return(Quaternion.Euler(vector).Rotate(angle, axis, space).eulerAngles);
 }
Esempio n. 37
0
 public static void RotateFromDefault(this Transform transform, Quaternion def, float x, float y, float z, Space space = Space.Self)
 {
     transform.localRotation = def;
     transform.Rotate(x, y, z, space);
 }
Esempio n. 38
0
        public override void Update(float dt)
        {
            #region Kapow-Shooter Input

            //Update kapow-shooter
            if (!vehicle.IsActive)
#if !WINDOWS
            { if (Game.GamePadInput.IsButtonDown(Buttons.RightTrigger))
#else
            { if (Game.MouseInput.LeftButton == ButtonState.Pressed)
#endif
              {
                  if (character.IsActive)   //Keep the ball out of the character's body if its being used.
                  {
                      kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * 3;
                  }
                  else
                  {
                      kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward;
                  }
                  kapow.AngularVelocity = Vector3.Zero;
                  kapow.LinearVelocity  = Game.Camera.WorldMatrix.Forward * 30;
              } }

            #endregion

            #region Grabber Input

            //Update grabber

#if !WINDOWS
            if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && !grabber.IsUpdating)
#else
            if (Game.MouseInput.RightButton == ButtonState.Pressed && !grabber.IsGrabbing)
#endif
            {
                //Find the earliest ray hit
                RayCastResult raycastResult;
                if (Space.RayCast(new Ray(Game.Camera.Position, Game.Camera.WorldMatrix.Forward), 1000, rayCastFilter, out raycastResult))
                {
                    var entityCollision = raycastResult.HitObject as EntityCollidable;
                    //If there's a valid ray hit, then grab the connected object!
                    if (entityCollision != null && entityCollision.Entity.IsDynamic)
                    {
                        grabber.Setup(entityCollision.Entity, raycastResult.HitData.Location);
                        grabberGraphic.IsDrawing = true;
                        grabDistance             = raycastResult.HitData.T;
                    }
                }
            }
#if !WINDOWS
            if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating)
#else
            else if (Game.MouseInput.RightButton == ButtonState.Pressed && grabber.IsUpdating)
#endif
            {
                grabber.GoalPosition = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * grabDistance;
            }
#if !WINDOWS
            if (!Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating)
#else
            else if (Game.MouseInput.RightButton == ButtonState.Released && grabber.IsUpdating)
#endif
            {
                grabber.Release();
                grabberGraphic.IsDrawing = false;
            }

            #endregion

            #region Control State Input

#if !WINDOWS
            if (!vehicle.IsActive && Game.WasButtonPressed(Buttons.LeftTrigger))
            {
                kapowMaker.Position = kapow.Position;
                kapowMaker.Explode();
            }
            if (Game.WasButtonPressed(Buttons.A))
            {//Toggle character perspective.
                if (!character.IsActive)
                {
                    vehicle.Deactivate();
                    character.Activate();
                }
                else
                {
                    character.Deactivate();
                }
            }
            if (Game.WasButtonPressed(Buttons.B))
            {//Toggle vehicle perspective.
                if (!vehicle.IsActive)
                {
                    character.Deactivate();
                    vehicle.Activate();
                }
                else
                {
                    vehicle.Deactivate();
                }
            }
#else
            if (!vehicle.IsActive && Game.WasKeyPressed(Keys.Space))
            {
                //Detonate the bomb
                kapowMaker.Position = kapow.Position;
                kapowMaker.Explode();
            }
            if (Game.WasKeyPressed(Keys.C))
            {
                //Toggle character perspective.
                if (!character.IsActive)
                {
                    vehicle.Deactivate();
                    character.Activate();
                }
                else
                {
                    character.Deactivate();
                }
            }


            if (Game.WasKeyPressed(Keys.V))
            {
                //Toggle vehicle perspective.
                if (!vehicle.IsActive)
                {
                    character.Deactivate();
                    vehicle.Activate(Game.Camera.Position);
                }
                else
                {
                    vehicle.Deactivate();
                }
            }
#endif

            #endregion

            base.Update(dt); //Base.update updates the space, which needs to be done before the camera is updated.

            character.Update(dt, Game.PreviousKeyboardInput, Game.KeyboardInput, Game.PreviousGamePadInput, Game.GamePadInput);
            vehicle.Update(dt, Game.KeyboardInput, Game.GamePadInput);
            //If neither are active, just use the default camera movement style.
            if (!character.IsActive && !vehicle.IsActive)
            {
                freeCameraControlScheme.Update(dt);
            }
        }
Esempio n. 39
0
        override internal PhysicNode Run(JoinGraph graph, BigInteger expectC1)
        {
            int ntables = graph.vertices_.Count;

            Console.WriteLine("DP_Bushy #tables: " + ntables);

            // initialization: enqueue all single tables
            InitByInsertBasicTables(graph);

            // loop through all candidates trees, CP included
            ulong c1 = 0, c2 = 0;

            for (BitVector S = 1; S < (1 << ntables); S++)
            {
                if (bestTree_[S] != null)
                {
                    continue;
                }

                // need connected subgraphs if not consider CP
                if (!graph.IsConnected(S))
                {
                    // this partition enumeration is only to record #c2
                    c2 += (ulong)(new VancePartition(S)).Next().ToArray().Length;
                    continue;
                }

                // for all S_1 subset of S do
                VancePartition partitioner = new VancePartition(S);
                foreach (var S1 in partitioner.Next())
                {
                    c2++;
                    BitVector S2 = SetOp.Substract(S, S1);

                    // requires S1 < S2 to avoid commutative duplication
                    Debug.Assert(S1 != S2);
                    if (S1 < S2)
                    {
                        // need connected subgraphs if not consider CP
                        if (!graph.IsConnected(S1) || !graph.IsConnected(S2))
                        {
                            continue;
                        }

                        // find a connected pair, get the best join tree between them
                        c1++;
                        var currTree = CreateMinimalJoinTree(bestTree_[S1], bestTree_[S2]);
                        Debug.Assert(bestTree_[S].Cost() == currTree.Cost());
                    }
                }
            }

            // verify # loops for enumeration completeness:
            // 1. mumber of bushy trees
            // 2. expectC2/c2: number of trees DP considered (P68) and number of trees generated
            // 3. expectC1/c1: number of trees considered
            //
            var nbushy   = Space.Count_General_Bushy_CP(ntables);
            var expectC2 = BigInteger.Pow(3, ntables) - BigInteger.Pow(2, ntables + 1) + 1;

            Console.WriteLine("bushy: {0}, dp: {1} == c2: {2}; expected c1: {3} == c1: {4}",
                              nbushy, expectC2, c2,
                              expectC1, c1);
            Debug.Assert(expectC2 == c2);
            if (!expectC1.IsZero)
            {
                Debug.Assert(c1 == expectC1);
            }

            var result = bestTree_[(1 << ntables) - 1];

            Console.WriteLine(result.Explain());
            return(result);
        }
Esempio n. 40
0
 public override void OnAdditionToSpace(Space newSpace)
 {
     base.OnAdditionToSpace(newSpace);
     ParallelLooper   = newSpace.ParallelLooper;
     QueryAccelerator = newSpace.BroadPhase.QueryAccelerator;
 }
Esempio n. 41
0
 public override void OnRemovalFromSpace(Space oldSpace)
 {
     base.OnRemovalFromSpace(oldSpace);
     ParallelLooper   = null;
     QueryAccelerator = null;
 }
        /// <summary>
        /// Calculates the average mesh positions out of all the meshes parented by this transform
        /// </summary>
        /// <returns>The average meshes center.</returns>
        public static Vector3 CalculateAverageBoundsCenter(this Transform rootParent, Space space)
        {
            var totalBounds   = CalculateBoundsRecursive(rootParent);
            var worldPosition = totalBounds.center;

            if (space == Space.Self)
            {
                return(rootParent.InverseTransformPoint(worldPosition));
            }
            return(worldPosition);
        }
 public void Rotate(int charIndex, Vector3 axis, float angle, Space relativeTo)
 {
     GetProxyTransform(charIndex).Target.Rotate(axis, angle, relativeTo);
     transformsChangedByProperties = true;
 }
 public void Rotate(int charIndex, Vector3 eulerAngles, Space relativeTo)
 {
     GetProxyTransform(charIndex).Target.Rotate(eulerAngles, relativeTo);
     transformsChangedByProperties = true;
 }
Esempio n. 45
0
        private void CreateLayout()
        {
            // View for the input/output wkid labels.
            LinearLayout wkidLabelsStackView = new LinearLayout(this)
            {
                Orientation = Orientation.Horizontal
            };

            wkidLabelsStackView.SetPadding(10, 10, 0, 10);

            // Create a label for the input spatial reference.
            _inWkidLabel = new TextView(this)
            {
                Text          = "In WKID = ",
                TextAlignment = TextAlignment.ViewStart
            };

            // Create a label for the output spatial reference.
            _outWkidLabel = new TextView(this)
            {
                Text          = "Out WKID = ",
                TextAlignment = TextAlignment.ViewStart
            };

            // Create some horizontal space between the labels.
            Space space = new Space(this);

            space.SetMinimumWidth(30);

            // Add the Wkid labels to the stack view.
            wkidLabelsStackView.AddView(_inWkidLabel);
            wkidLabelsStackView.AddView(space);
            wkidLabelsStackView.AddView(_outWkidLabel);

            // Create the 'use extent' switch.
            _useExtentSwitch = new Switch(this)
            {
                Checked = false,
                Text    = "Use extent"
            };

            // Handle the checked change event for the switch.
            _useExtentSwitch.CheckedChange += UseExtentSwitch_CheckedChange;

            // Create a picker (Spinner) for datum transformations.
            _transformationsPicker = new Spinner(this);
            _transformationsPicker.SetPadding(5, 10, 0, 10);

            // Handle the selection event to work with the selected transformation.
            _transformationsPicker.ItemSelected += TransformationsPicker_ItemSelected;

            // Create a text view to show messages.
            _messagesTextView = new TextView(this);

            // Create a new vertical layout for the app UI.
            LinearLayout mainLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            // Create a layout for the app tools.
            LinearLayout toolsLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            toolsLayout.SetPadding(10, 0, 0, 0);
            toolsLayout.SetMinimumHeight(320);

            // Add the transformation UI controls to the tools layout.
            toolsLayout.AddView(wkidLabelsStackView);
            toolsLayout.AddView(_useExtentSwitch);
            toolsLayout.AddView(_transformationsPicker);
            toolsLayout.AddView(_messagesTextView);

            // Add the tools layout and map view to the main layout.
            mainLayout.AddView(toolsLayout);
            mainLayout.AddView(_myMapView);

            // Show the layout in the app.
            SetContentView(mainLayout);
        }
Esempio n. 46
0
        public void RunAlgorithmEliminateTest1()
        {
            // Initialise Possible
            IPossible possibleAll = new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible(possibleAll));
            }

            // Initialise one group (top row)
            Keys <int> group = new Keys <int>();

            for (int i = 1; i < 10; i++)
            {
                group.Add(i);
            }
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            Possible values2To9 = new Possible(possibleAll);

            values2To9.Remove(1);
            Keys <int> keysInner = new Keys <int>();

            for (int j = 2; j < 10; j++)
            {
                keysInner.Add(j);
                space[j] = new Possible(values2To9);
            }
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteSetActions(keysInner, group, engine);

            Assert.AreEqual(1, engine.Count);

            // Test
            Keys <int> expectedK = new Keys <int>()
            {
                1
            };
            IPossible expectedV = new Possible()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };

            IJobFilter <int> job    = engine.Peek() as IJobFilter <int>;
            Keys <int>       actual = job.Keys;
            IPossible        filter = job.Filter;

            Assert.AreEqual(1, actual.Count(), "Algorithm Eliminate did not return 8 changes");
            Assert.IsTrue(expectedK.SetEquals(actual));
            Assert.AreEqual(8, filter.Count, "Filter value incorrect");
            Assert.IsTrue(expectedV.SetEquals(filter), "Filter values incorrect");
        }
Esempio n. 47
0
 public static Quaternion Rotate(this Quaternion quaternion, float angle, Vector3 axis, Space space = Space.Self)
 {
     if (space == Space.Self)
     {
         return(quaternion * Quaternion.AngleAxis(angle, axis));
     }
     else
     {
         return(Quaternion.AngleAxis(angle, axis) * quaternion);
     }
 }
Esempio n. 48
0
 ///<summary>
 /// Constructs the buffer.
 ///</summary>
 ///<param name="space">Space that owns the buffer.</param>
 public SpaceObjectBuffer(Space space)
 {
     Enabled    = true;
     this.space = space;
 }
Esempio n. 49
0
 public AbstractTsf(string name, Space space)
 {
     this.space = space;
     this.name  = name;
 }
Esempio n. 50
0
 public TransformTransformable(Transform transform, Vector3 offset, Space offsetSpace = Space.Self) : this(transform, (Vector3?)offset, offsetSpace)
 {
 }
Esempio n. 51
0
        public virtual void Turn(Vector3 r, Space s)
        {
            Matrix4 t = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(r.Y)) * Matrix4.CreateRotationX(MathHelper.DegreesToRadians(r.X)) * Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(r.Z));

            LocalTurn = LocalTurn * t;
        }
Esempio n. 52
0
 public void OnAdditionToSpace(Space newSpace)
 {
     newSpace.Add(Entity);
     newSpace.DuringForcesUpdateables.Starting += Texture.GameProperties.SpaceUpdate;
 }
Esempio n. 53
0
 /// <summary>
 /// Gets the euler angles for the given space.
 /// </summary>
 public Vector3 Get(Space inSpace)
 {
     return(inSpace == Space.Self ? m_Local : m_World);
 }
Esempio n. 54
0
 protected override void CreateDataTypes() // Create all primitive data types from some specification like Enum, List or XML
 {
     Space.CreateTable(DcSchemaKind.Csv, "Root", this);
     Space.CreateTable(DcSchemaKind.Csv, "String", this);
 }
Esempio n. 55
0
 public BuildingEventArgs.BuildType GetBuildType(Space space)
 {
     return(BuildTypes.ContainsKey(space)
                     ? BuildTypes[space]
                     : BuildingEventArgs.BuildType.TownsAndCities);
 }
Esempio n. 56
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public PathFollowingDemo(DemosGame game)
            : base(game)
        {
            Entity movingEntity;

            //The moving entity can be either kinematic or dynamic; the EntityMover/Rotator works for either.
            movingEntity = new Box(new Vector3(-10, 0, -10), 3, 1, 1);

            //We're going to use a speed-controlled curve that wraps another curve.
            //This is the internal curve.
            //Speed-controlled curves let the user specify speeds at which an evaluator
            //will move along the curve.  Non-speed controlled curves can move at variable
            //rates based on the interpolation.
            var wrappedPositionCurve = new CardinalSpline3D();

            //Since the endpoints don't overlap, just reverse direction when they're hit.
            //The default is wrapping around; if there's a distance between the starting
            //and ending endpoints, the entity will jump very quickly (smashing anything in the way).
            wrappedPositionCurve.PreLoop  = CurveEndpointBehavior.Mirror;
            wrappedPositionCurve.PostLoop = CurveEndpointBehavior.Mirror;

            //Start the curve up above the blocks.
            //There's two control points because the very first and very last control points
            //aren't actually reached by the curve in a CardinalSpline3D; they are used
            //to define the tangents on the interior points.
            wrappedPositionCurve.ControlPoints.Add(-1, new Vector3(0, 30, 0));
            wrappedPositionCurve.ControlPoints.Add(0, new Vector3(0, 20, 0));
            //Add a bunch of random control points to the curve.
            var random = new Random();

            for (int i = 1; i <= 10; i++)
            {
                wrappedPositionCurve.ControlPoints.Add(i, new Vector3(
                                                           (Fix64)random.NextDouble() * 20 - 10,
                                                           (Fix64)random.NextDouble() * 12,
                                                           (Fix64)random.NextDouble() * 20 - 10));
            }

            positionPath = wrappedPositionCurve;

            //There's also a constant speed and variable speed curve type that can be used.
            //Try the following instead to move the entity at a constant rate:
            //positionPath = new ConstantLinearSpeedCurve(5, wrappedPositionCurve);

            var slerpCurve = new QuaternionSlerpCurve();

            slerpCurve.ControlPoints.Add(0, Quaternion.Identity);
            slerpCurve.ControlPoints.Add(1, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));
            slerpCurve.ControlPoints.Add(2, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi));
            slerpCurve.ControlPoints.Add(3, Quaternion.CreateFromAxisAngle(Vector3.Up, 3 * MathHelper.PiOver2));
            slerpCurve.ControlPoints.Add(4, Quaternion.Identity);

            slerpCurve.PostLoop = CurveEndpointBehavior.Mirror;
            orientationPath     = slerpCurve;


            mover = new EntityMover(movingEntity);
            //Offset the place that the mover tries to reach a little.
            //Now, when the entity spins, it acts more like a hammer swing than a saw.
            mover.LocalOffset = new Vector3(3, 0, 0);
            rotator           = new EntityRotator(movingEntity);

            //Add the entity and movers to the space.
            Space.Add(movingEntity);
            Space.Add(mover);
            Space.Add(rotator);

            //Add some extra stuff to the space.
            Space.Add(new Box(new Vector3(0, -5, 0), 25, 10, 25));

            int   numColumns = 7;
            int   numRows    = 7;
            int   numHigh    = 3;
            Fix64 xSpacing   = 2.09m;
            Fix64 ySpacing   = 2.08m;
            Fix64 zSpacing   = 2.09m;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(
                                              xSpacing * i - (numRows - 1) * xSpacing / 2,
                                              1.58m + k * (ySpacing),
                                              2 + zSpacing * j - (numColumns - 1) * zSpacing / 2),
                                          2, 2, 2, 10));
                    }
                }
            }

            game.Camera.Position = new Vector3(0, 5, 30);
        }
 public void Translate(int charIndex, Vector3 translation, Space relativeTo)
 {
     GetProxyTransform(charIndex).Target.Translate(translation, relativeTo);
     transformsChangedByProperties = true;
 }
Esempio n. 58
0
 public static TransformFollower CreateFollower(Transform attached, Vector3 offset, Space offsetSpace = Space.Self)
 {
     return(CreateFollower(null, attached, offset, offsetSpace));
 }
 public void Rotate(int charIndex, float xAngle, float yAngle, float zAngle, Space relativeTo)
 {
     GetProxyTransform(charIndex).Target.Rotate(xAngle, yAngle, zAngle, relativeTo);
     transformsChangedByProperties = true;
 }
 public void Translate(int charIndex, float x, float y, float z, Space relativeTo)
 {
     GetProxyTransform(charIndex).Target.Translate(x, y, z, relativeTo);
     transformsChangedByProperties = true;
 }