示例#1
0
        public void TestStateSetting()
        {
            FlatRedBall.PositionedObject directObjectReference =
                ((FlatRedBall.PositionedObject)mElementRuntime.ContainedElements[0].DirectObjectReference);
            directObjectReference.ForceUpdateDependencies();

            float yBefore = directObjectReference.Y;

            mElementRuntime.SetState("", false);

            directObjectReference.ForceUpdateDependencies();
            float yAfter = directObjectReference.Y;


            if (yBefore != yAfter)
            {
                throw new Exception("Setting an empty state modifies the position values when it shouldn't");
            }


            mContainerElementRuntime.SetState(mContainer.States[0].Name);

            mContainerElementRuntime.ContainedElements[0].ForceUpdateDependencies();
            if (mContainerElementRuntime.ContainedElements[0].X != 10.0f)
            {
                throw new Exception("Setting a state on a container which sets the state of a contained object seems to not be actually setting the state of the contained object.");
            }

            Sprite sprite = mContainerElementRuntime.ContainedElements[0].ContainedElements[0].DirectObjectReference as Sprite;

            if (sprite.ScaleX != 4.0f)
            {
                throw new Exception("Setting a state on a container which sets the state of a contained object, and that state sets a tunneled variable on a FRB type seems to not be working properly");
            }
        }
示例#2
0
        public static void MoveToAccurate(FlatRedBall.PositionedObject positionedObject, float x, float y, float z, double secondsToTake)
        {
            if (secondsToTake != 0.0f)
            {
                positionedObject.XVelocity = (x - positionedObject.X) / (float)secondsToTake;
                positionedObject.YVelocity = (y - positionedObject.Y) / (float)secondsToTake;
                positionedObject.ZVelocity = (z - positionedObject.Z) / (float)secondsToTake;

                double timeToExecute = TimeManager.CurrentTime + secondsToTake;

                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "XVelocity", 0, timeToExecute));
                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "YVelocity", 0, timeToExecute));
                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "ZVelocity", 0, timeToExecute));

                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "X", x, timeToExecute));
                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "Y", y, timeToExecute));
                positionedObject.Instructions.Add(
                    new Instruction <FlatRedBall.PositionedObject, float>(positionedObject, "Z", z, timeToExecute));
            }
            else
            {
                positionedObject.X = x;
                positionedObject.Y = y;
                positionedObject.Z = z;
            }
        }
        public void TestFluentInterface()
        {
            PositionedObject positionedObject = new PositionedObject();

            // Make sure it doesn't crash:
            positionedObject.Set("XVelocity").To(4.3f).After(1.1f);            

        }
示例#4
0
        public void ApplyChangeVariables(PositionedObject objectToResize, float cursorXChange, float cursorYChange,
            float xChangeCoef, float yChangeCoef)
        {
            //IScalable
            if (objectToResize is IScalable)
            {
                IScalable scalable = (IScalable)objectToResize;
                //Scale
                if (scalable.ScaleX + cursorXChange < 0)
                {
                    scalable.ScaleX = 0;
                    xChangeCoef = 0;
                }
                else
                {
                    scalable.ScaleX += cursorXChange;
                }

                if (scalable.ScaleY + cursorYChange < 0)
                {
                    scalable.ScaleY = 0;
                    yChangeCoef = 0;
                }
                else
                {
                    scalable.ScaleY += cursorYChange;
                }
            }
            else if (objectToResize is ElementRuntime &&
                ((ElementRuntime)objectToResize).AssociatedNamedObjectSave != null &&
                ((ElementRuntime)objectToResize).AssociatedNamedObjectSave.GetIsScalableEntity())
            {
                ElementRuntime currentElement = objectToResize as ElementRuntime;
                float scaleX = (float)currentElement.AssociatedNamedObjectSave.GetEffectiveValue("ScaleX");
                float scaleY = (float)currentElement.AssociatedNamedObjectSave.GetEffectiveValue("ScaleY");

                IElement entitySave = currentElement.AssociatedIElement;
                CustomVariable variable = entitySave.GetCustomVariable("ScaleX").Clone();

                variable.DefaultValue = scaleX + cursorXChange;
                currentElement.AssociatedNamedObjectSave.GetCustomVariable("ScaleX").Value = scaleX + cursorXChange;
                currentElement.SetCustomVariable(variable);


                variable = entitySave.GetCustomVariable("ScaleY").Clone();
                variable.DefaultValue = scaleY + cursorYChange;
                currentElement.AssociatedNamedObjectSave.GetCustomVariable("ScaleY").Value = variable.DefaultValue;
                currentElement.SetCustomVariable(variable);

            }

            AdjustPositionsAfterScaling(objectToResize, cursorXChange, cursorYChange, xChangeCoef, yChangeCoef);

        }
示例#5
0
        private void CreateHandles(PositionedObject pObj, float scaleX, float scaleY)
        {
			AddHandle(pObj.X - (scaleX), pObj.Y + (scaleY), pObj.Z, mHandleSize, -0.5f, 0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X, pObj.Y + (scaleY), pObj.Z, mHandleSize, 0f, 0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X + (scaleX), pObj.Y + (scaleY), pObj.Z, mHandleSize, 0.5f, 0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X + (scaleX), pObj.Y, pObj.Z, mHandleSize, 0.5f, 0f).AttachTo(pObj, true);
			AddHandle(pObj.X + (scaleX), pObj.Y - (scaleY), pObj.Z, mHandleSize, 0.5f, -0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X, pObj.Y - (scaleY), pObj.Z, mHandleSize, 0f, -0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X - (scaleX), pObj.Y - (scaleY), pObj.Z, mHandleSize, -0.5f, -0.5f).AttachTo(pObj, true);
			AddHandle(pObj.X - (scaleX), pObj.Y, pObj.Z, mHandleSize, -0.5f, 0f).AttachTo(pObj, true);
        }
        private void CreateRotationHandleForPositionedObject(PositionedObject posObj)
        {
            float size = 10;

            Circle circ = new Circle();
            circ.Radius = size / SpriteManager.Camera.PixelsPerUnitAt(posObj.Z);
            circ.Position = new Vector3(posObj.X, posObj.Y + 2, posObj.Z);
            circ.Color = Color.LightBlue;

            Handle handle = new Handle(Layer, circ);

            circ.AttachTo(posObj, true);
        }
示例#7
0
 public static void IgnorePausingFor(FlatRedBall.PositionedObject positionedObject)
 {
     // This function needs to tolerate
     // the same object being added multiple
     // times.  The reason is that an Entity in
     // Glue may set one of its objects to be ignored
     // in pausing, but then the object itself may also
     // be set to be ignored.
     if (!PositionedObjectsIgnoringPausing.Contains(positionedObject))
     {
         PositionedObjectsIgnoringPausing.Add(positionedObject);
     }
 }
        protected override void InitializeEntity(bool addToManagers)
        {
            LoadStaticContent(ContentManagerName);
            SpriteInstance                     = new FlatRedBall.Sprite();
            SpriteInstance.Name                = "SpriteInstance";
            mAxisAlignedRectangleInstance      = new FlatRedBall.Math.Geometry.AxisAlignedRectangle();
            mAxisAlignedRectangleInstance.Name = "mAxisAlignedRectangleInstance";
            LightSpriteInstance                = new FlatRedBall.Sprite();
            LightSpriteInstance.Name           = "LightSpriteInstance";
            AimSpriteInstance                  = new FlatRedBall.Sprite();
            AimSpriteInstance.Name             = "AimSpriteInstance";
            PivotPoint      = new FlatRedBall.PositionedObject();
            PivotPoint.Name = "PivotPoint";

            base.InitializeEntity(addToManagers);
        }
示例#9
0
        public static void MoveThrough <T>(FlatRedBall.PositionedObject positionedObject, IList <T> list, float velocity) where T : IPositionable
        {
            double time = TimeManager.CurrentTime;

            float lastX = positionedObject.X;
            float lastY = positionedObject.Y;
            float lastZ = positionedObject.Z;

            float distanceX = 0;
            float distanceY = 0;
            float distanceZ = 0;

            double totalDistance = 0;

            Vector3 newVelocity = new Vector3();

            foreach (IPositionable positionable in list)
            {
                distanceX = positionable.X - lastX;
                distanceY = positionable.Y - lastY;
                distanceZ = positionable.Z - lastZ;

                totalDistance = (float)System.Math.Sqrt(
                    distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ);

                newVelocity.X = distanceX;
                newVelocity.Y = distanceY;
                newVelocity.Z = distanceZ;

                newVelocity.Normalize();
                newVelocity *= velocity;

                positionedObject.Instructions.Add(new Instruction <FlatRedBall.PositionedObject, Vector3>(
                                                      positionedObject, "Velocity", newVelocity, time));


                lastX = positionable.X;
                lastY = positionable.Y;
                lastZ = positionable.Z;

                time += totalDistance / velocity;
            }

            positionedObject.Instructions.Add(new Instruction <FlatRedBall.PositionedObject, Vector3>(
                                                  positionedObject, "Velocity", new Vector3(), time));
        }
        void TestRotationY(float yValue, PositionedObject positionedObject)
        {

            positionedObject.RotationX = 0;
            positionedObject.RotationY = yValue;
            positionedObject.RotationZ = 0;

            positionedObject.RotationMatrix = positionedObject.RotationMatrix;

            float epsilon = .001f;
            
            if (Math.Abs( positionedObject.RotationY - yValue) > epsilon)
            {
                throw new Exception("There seems to be a bug with setting rotation matrices when RotationY is set");
            }

        }
        public void TestRotations()
        {
            PositionedObject first = new PositionedObject();
            PositionedObject second = new PositionedObject();

            first.RotationZ = 1.7f;

            second.RotationMatrix = first.RotationMatrix;

            if (second.RotationZ != 1.7f)
            {
                throw new Exception("There seems to be a bug with setting rotation matrices when RotationY is set");
            }

            TestRotationY(0, first);
            TestRotationY(.5f, first);
            TestRotationY(1, first);
            TestRotationY(1.5f, first);
            TestRotationY(2, first);
            TestRotationY(2.5f, first);
            TestRotationY(3, first);
            TestRotationY(3.5f, first);
        }
示例#12
0
 public void AttachTo(PositionedObject newParent, bool changeRelative)
 {
     this._sprite.AttachTo(newParent, changeRelative);
 }
示例#13
0
 public void AttachTo(PositionedObject obj, bool changeRelative)
 {
     _sprite.AttachTo(obj, changeRelative);
 }
示例#14
0
 public void AttachObject(PositionedObject obj, bool changeRelative)
 {
     obj.AttachTo(_sprite, changeRelative);
 }
        public void UpdateToEmitter(Emitter currentEmitter)
        {
            #region Update All Visibility

            if (currentEmitter == null)
            {
                if (mCurrentVisibleRepresentation != null)
                {
                    MakeAllInvisible();


                    mCurrentVisibleRepresentation = null;

                }
            }
            else
            {
                object shapeThatShouldBeVisible = mVisibleRepresentations[currentEmitter.AreaEmission];

                if (shapeThatShouldBeVisible != ((object)mCurrentVisibleRepresentation))
                {
                    MakeAllInvisible();

                    object visibleRepresentation = mVisibleRepresentations[currentEmitter.AreaEmission];

                    LateBinder.GetInstance(visibleRepresentation.GetType()).SetValue(visibleRepresentation, "Visible", true);


                    mCurrentVisibleRepresentation = mVisibleRepresentations[currentEmitter.AreaEmission] as PositionedObject;
                }
            }

            #endregion

            #region Update the current Shape's properties

            if (mCurrentVisibleRepresentation != null)
            {
                switch (currentEmitter.AreaEmission)
                {
                    case Emitter.AreaEmissionType.Point:
                        // We do nothing here since we're not showing anything
                        break;
                    case Emitter.AreaEmissionType.Cube:
                        AxisAlignedCube asAxisAlignedCube = mCurrentVisibleRepresentation as AxisAlignedCube;

                        asAxisAlignedCube.ScaleX = currentEmitter.ScaleX;
                        asAxisAlignedCube.ScaleY = currentEmitter.ScaleY;
                        asAxisAlignedCube.ScaleZ = currentEmitter.ScaleZ;

                        asAxisAlignedCube.Position = currentEmitter.Position;

                        break;
                    case Emitter.AreaEmissionType.Rectangle:
                        AxisAlignedRectangle asAxisAlignedRectangle = mCurrentVisibleRepresentation as AxisAlignedRectangle;
                        asAxisAlignedRectangle.ScaleX = currentEmitter.ScaleX;
                        asAxisAlignedRectangle.ScaleY = currentEmitter.ScaleY;
                        asAxisAlignedRectangle.Position = currentEmitter.Position;

                        break;
                }

            }

            #endregion
        }
示例#16
0
 public void RemoveResource(PositionedObject p)
 {
     if (p is Sprite)
     {
         this.RemoveSprite((Sprite)p);
     }
     else if (p is Text)
     {
         this.RemoveText((Text)p);
     }
     else
     {
         throw new ArgumentException("Not sure how to remove " + p);
     }
 }
示例#17
0
        private static void AdjustPositionsAfterScaling(PositionedObject pObj, float xChange, float yChange, float xChangeCoef, float yChangeCoef)
        {
            //Move to line up with the scale properly
            if (pObj.Parent == null)
            {
                pObj.X += xChange * xChangeCoef;
                pObj.Y += yChange * yChangeCoef;

            }
            else
            {
                pObj.RelativeX += xChange * xChangeCoef;
                pObj.RelativeY += yChange * yChangeCoef;
                pObj.ForceUpdateDependencies();
            }
        }
示例#18
0
 public void Add(PositionedObject objectToAdd)
 {
     instances.Add(objectToAdd);
 }
示例#19
0
        private void ShowErrorIfObjectCanNotBeGrabbed()
        {
            if (GuiData.ToolsWindow.IsRotateButtonPressed)
            {
                if (mObjectGrabbed is Circle || mObjectGrabbed is AxisAlignedRectangle ||
                    mObjectGrabbed is AxisAlignedCube || mObjectGrabbed is Sphere)
                {
                    GuiManager.ShowMessageBox("This shape cannot be rotated", "Error rotating");

                    mObjectGrabbed = null;
                }
            }
        }
示例#20
0
        private void MouseControlOverObjects()
        {
            Cursor cursor = GuiManager.Cursor;

            if (cursor.WindowOver != null)
            {
                return;
            }

            GuiManager.Cursor.StaticPosition = false;

            #region moving mEditorLogic.CurrentEmitter and its boundary
            if (AppState.Self.CurrentEmitter != null)
            {
                #region see if we pushed the mouse buttons  on a marker
                if (cursor.PrimaryPush || cursor.SecondaryPush)
                {
                    if (cursor.WindowOver == null)
                    {
                        if (cursor.IsOn(EditorData.EditorLogic.ReactiveHud.CurrentEmitterMarker))
                            mGrabbedObject = AppState.Self.CurrentEmitter;
                        else if (AppState.Self.CurrentEmitter.BoundedEmission)
                        {
                            foreach (AxisAlignedRectangle corner in EditorData.EditorLogic.ReactiveHud.CurrentEmitterBoundaryCorners)
                            {
                                if (cursor.IsOn<AxisAlignedRectangle>(corner))
                                {
                                    mGrabbedObject = corner;
                                    break;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region release emitter
                if (cursor.PrimaryClick || cursor.SecondaryClick)
                {
                    mGrabbedObject = null;
                }
                #endregion

                #region move the emitter or its boundary if we have one grabbed
                if (mGrabbedObject != null && GuiData.ToolsWindow.moveObject.IsPressed)
                {
                    PositionedObjectMover.MouseMoveObject(mGrabbedObject, MovementStyle.Hierarchy);
                    if (mGrabbedObject is AxisAlignedRectangle)
                    {
                        for (int i = 0; i < EditorData.EditorLogic.ReactiveHud.CurrentEmitterBoundaryCorners.Count; i++)
                        {
                            if (EditorData.EditorLogic.ReactiveHud.CurrentEmitterBoundaryCorners[i].Equals(mGrabbedObject))
                            {
                                AppState.Self.CurrentEmitter.EmissionBoundary.SetPoint(i, mGrabbedObject.X - AppState.Self.CurrentEmitter.X, mGrabbedObject.Y - AppState.Self.CurrentEmitter.Y);
                                if (i == 0)
                                {
                                    AppState.Self.CurrentEmitter.EmissionBoundary.SetPoint(AppState.Self.CurrentEmitter.EmissionBoundary.Points.Count - 1,
                                        mGrabbedObject.X - AppState.Self.CurrentEmitter.X, mGrabbedObject.Y - AppState.Self.CurrentEmitter.Y);
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            #endregion

            #region scnFileArray  logic for moving our scene
            if (EditorData.Scene != null && mGrabbedObject == null)
            {
                #region grabbing a sprite
                if (cursor.PrimaryPush)
                {
                    if (cursor.WindowOver == null)
                    {
                        if (cursor.GetSpriteOver(EditorData.Scene.Sprites) != null)
                            arrayGrabbed = true;
                    }
                }
                #endregion

                #region release sprite
                if (cursor.PrimaryClick)
                    arrayGrabbed = false;

                #endregion

                #region if an array is grabbed, move the entire scene by the sprite's velocity
                if (arrayGrabbed && GuiData.ToolsWindow.moveObject.IsPressed)
                {
                    EditorData.Scene.Shift(
                        new Vector3(
                            cursor.ActualXVelocityAt(0),
                            cursor.ActualYVelocityAt(0),
                            0));
                }
                #endregion
            }
            #endregion

            if (GuiData.ToolsWindow.attachObject.IsPressed && cursor.PrimaryClick)
                TryAttachEmitterToSprite();
        }
示例#21
0
 public void AttachTo(PositionedObject newParent, bool throwaway)
 {
     Parent = newParent;
 }
示例#22
0
        /// <summary>
        /// Controls selecting new Shapes and performing move, scale, and rotate (when appropriate).
        /// </summary>
        #endregion
        private void CursorControlOverShapes()
        {
            if (GuiManager.DominantWindowActive)
                return;


            Cursor cursor = GuiManager.Cursor;

            #region Pushing selects and grabs a Shape or the corner of a Polygon
            if (cursor.PrimaryPush)
            {
                #region If the user has not interacted with the corners then see check for grabbing any Shapes

                if (mReactiveHud.HasPolygonEdgeGrabbed == false)
                {

                    mObjectGrabbed = GetShapeOver(cursor.PrimaryDoublePush);

                    ShowErrorIfObjectCanNotBeGrabbed();

                    // If the object is not null store its original position.  This will be used
                    // for SHIFT+drag which allows movement only on one axis.
                    if (mObjectGrabbed != null)
                    {
                        PositionedObjectMover.SetStartPosition(mObjectGrabbed);
                    }

                    cursor.SetObjectRelativePosition(mObjectGrabbed);

                    if (PolygonGrabbed != null)
                    {
                        UndoManager.AddToWatch(PolygonGrabbed);
                        SelectPolygon(PolygonGrabbed);
                    }

                    if (AxisAlignedCubeGrabbed != null)
                    {
                        UndoManager.AddToWatch(AxisAlignedCubeGrabbed);
                        SelectAxisAlignedCube(AxisAlignedCubeGrabbed);
                    }

                    if (AxisAlignedRectangleGrabbed != null)
                    {
                        UndoManager.AddToWatch(AxisAlignedRectangleGrabbed);
                        SelectAxisAlignedRectangle(AxisAlignedRectangleGrabbed);
                    }
                    if (CircleGrabbed != null)
                    {
                        UndoManager.AddToWatch(CircleGrabbed);
                        SelectCircle(CircleGrabbed);
                    }
                    if (SphereGrabbed != null)
                    {
                        UndoManager.AddToWatch(SphereGrabbed);
                        SelectSphere(SphereGrabbed);
                    }

                    if (mObjectGrabbed == null)
                    {
                        DeselectAll();
                    }
                }

                #endregion
            }
            #endregion

            #region Holding the button down can be used to drag objects
            if (cursor.PrimaryDown)
            {
                PerformDraggingUpdate();

            }
            #endregion

            #region Clicking (releasing) the mouse lets go of grabbed Polygons

            if (cursor.PrimaryClick)
            {
                if (PolygonGrabbed != null)
                {
                    UndoManager.RecordUndos<Polygon>();
                    UndoManager.ClearObjectsWatching<Polygon>();
                }

                if (AxisAlignedRectangleGrabbed != null)
                {
                    UndoManager.RecordUndos<AxisAlignedRectangle>();
                    UndoManager.ClearObjectsWatching<AxisAlignedRectangle>();
                }

                if (AxisAlignedCubeGrabbed != null)
                {
                    UndoManager.RecordUndos<AxisAlignedCube>();
                    UndoManager.ClearObjectsWatching<AxisAlignedCube>();
                }

                if (CircleGrabbed != null)
                {
                    UndoManager.RecordUndos<Circle>();
                    UndoManager.ClearObjectsWatching<Circle>();
                }

                if (SphereGrabbed != null)
                {
                    UndoManager.RecordUndos<Sphere>();
                    UndoManager.ClearObjectsWatching<Sphere>();
                }

                mObjectGrabbed = null;

                cursor.StaticPosition = false;

                cursor.ObjectGrabbed = null;
            }

            #endregion

        }