public static Text AddText(string displayText, BitmapFont bitmapFont, string contentManagerName) { Text text = new Text(bitmapFont); text.ContentManager = contentManagerName; text.DisplayText = displayText; text.AdjustPositionForPixelPerfectDrawing = true; #if DEBUG if (mDrawnTexts.Contains(text)) { throw new InvalidOperationException("Can't add the text to the Drawn Text list because it's already there. This error is here to prevent you from double-adding Texts."); } if (mAutomaticallyUpdatedTexts.Contains(text)) { throw new InvalidOperationException("Can't add the text to the Automatically Updated (Managed) Text list because it's already there. This error is here to prevent you from double-adding Texts."); } #endif mDrawnTexts.Add(text); mAutomaticallyUpdatedTexts.Add(text); text.SetPixelPerfectScale(SpriteManager.Camera); return(text); }
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); } }
public static void MouseRotateObject <T>(T objectToMove, MovementStyle movementStyle) where T : IRotatable { Cursor cursor = GuiManager.Cursor; if (cursor.YVelocity != 0) { cursor.StaticPosition = true; } float movementAmount = cursor.YVelocity / 8.0f; switch (movementStyle) { case MovementStyle.Group: objectToMove.RotationZ += movementAmount; break; case MovementStyle.Hierarchy: objectToMove.RotationZ += movementAmount; if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null) { (objectToMove as PositionedObject).SetRelativeFromAbsolute(); } break; case MovementStyle.IgnoreAttachments: objectToMove.RotationZ += movementAmount; if (objectToMove is PositionedObject) { PositionedObject asPositionedObject = objectToMove as PositionedObject; if (asPositionedObject.Parent != null) { asPositionedObject.SetRelativeFromAbsolute(); } foreach (PositionedObject child in asPositionedObject.Children) { //child.Position -= movementVector; if (mObjectsToIgnore.Contains(child) == false) { child.SetRelativeFromAbsolute(); } } } break; } }
void RotatePrivateSpritesAboutAxis(Vector3 axisVector, Cursor cursor) { if (CurrentObject != null) { PositionedObject s = CurrentObject; #region no parent if (s.Parent == null && !spritesAlreadyChanged.Contains(s)) { spritesAlreadyChanged.AddOneWay(s); #if FRB_MDX s.RotationMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f); #else s.RotationMatrix *= Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f); #endif // Fixes accumulation error: s.RotationZ = s.RotationZ; //if (s is ISpriteEditorObject) //{ // float temporaryRotX = 0; // float temporaryRotY = 0; // float temporaryRotationZ = 0; // MathFunctions.ExtractRotationValuesFromMatrix(tempMatrix, // ref temporaryRotX, // ref temporaryRotY, // ref temporaryRotationZ); // (s).RotationX = temporaryRotX; // (s).RotationY = temporaryRotY; // (s).RotationZ = temporaryRotationZ; //} //else //{ //} } #endregion #region has parent, group hierarchy is pressed (so in hierarchy (NOT GROUP) mode ) else if (HierarchyControl) { spritesAlreadyChanged.AddOneWay(s); #if FRB_MDX s.RotationMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f); #else s.RotationMatrix *= Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f); #endif s.SetRelativeFromAbsolute(); } #endregion #region rotation logic for the entire group - ONLY do on topparents else { Sprite parentSprite = (Sprite)(s.TopParent); spritesAlreadyChanged.AddOneWay(parentSprite); Vector3 positionFromOrigin = new Vector3((float)(parentSprite.X - origin.X), (float)(parentSprite.Y - origin.Y), (float)(parentSprite.Z - origin.Z)); #if FRB_MDX Matrix rotationMatrixToUse = Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f); #else Matrix rotationMatrixToUse = Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f); #endif parentSprite.RotationMatrix *= rotationMatrixToUse; MathFunctions.TransformVector(ref positionFromOrigin, ref rotationMatrixToUse); (parentSprite).X = (float)(positionFromOrigin.X + origin.X); (parentSprite).Y = (float)(positionFromOrigin.Y + origin.Y); (parentSprite).Z = (float)(positionFromOrigin.Z + origin.Z); float temporaryRotX = 0; float temporaryRotY = 0; float temporaryRotationZ = 0; MathFunctions.ExtractRotationValuesFromMatrix(parentSprite.RotationMatrix, ref temporaryRotX, ref temporaryRotY, ref temporaryRotationZ); (s).RotationX = temporaryRotX; (s).RotationY = temporaryRotY; (s).RotationZ = temporaryRotationZ; } #endregion } //foreach (SpriteFrame sf in GameData.EditorLogic.CurrentSpriteFrames) //{ // Matrix tempMatrix = sf.RotationMatrix; // tempMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f); // float RotationX = 0; // float RotationY = 0; // float RotationZ = 0; // MathFunctions.ExtractRotationValuesFromMatrix(tempMatrix, ref RotationX, // ref RotationY, // ref RotationZ); // sf.RotationX = RotationX; // sf.RotationY = RotationY; // sf.RotationZ = RotationZ; //} }
public static void MouseMoveObject <T>(T objectToMove, MovementStyle movementStyle) where T : IStaticPositionable { Cursor cursor = GuiManager.Cursor; if (cursor.PrimaryPush) { return; } if (GuiManager.Cursor.ActualXVelocityAt(objectToMove.Z) == 0 && GuiManager.Cursor.ActualYVelocityAt(objectToMove.Z) == 0) { return; } #region Store the movement in the movementVector Vector3 movementVector = new Vector3(); #region If doing shift movement, then consider original position #if FRB_MDX bool isShiftDown = InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.LeftShift) || InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.RightShift); #elif FRB_XNA bool isShiftDown = InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) || InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift); #endif if (isShiftDown && HasValidStartPosition) { float xDistanceFromStart = Math.Abs((cursor.WorldXAt(0) - mGrabOffset.X) - mOriginalGrabPosition.X); float yDistanceFromStart = Math.Abs((cursor.WorldYAt(0) - mGrabOffset.Y) - mOriginalGrabPosition.Y); if (xDistanceFromStart > yDistanceFromStart) { movementVector.X = (cursor.WorldXAt(0) - mGrabOffset.X) - objectToMove.X; movementVector.Y = (mOriginalGrabPosition.Y) - objectToMove.Y; } else { movementVector.X = (mOriginalGrabPosition.X) - objectToMove.X; movementVector.Y = (cursor.WorldYAt(0) - mGrabOffset.Y) - objectToMove.Y; } } #endregion #region Else, just accumulate normally else { if (cursor.PrimaryDown) { movementVector.X = GuiManager.Cursor.WorldXChangeAt(objectToMove.Z); movementVector.Y = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z); } else if (cursor.SecondaryDown && mAllowZMovement) { movementVector.Z = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z); cursor.StaticPosition = true; } } #endregion #endregion #region Apply the movement vector according to the movementStyle switch (movementStyle) { case MovementStyle.Group: if (objectToMove is PositionedObject) { PositionedObject topParent = (objectToMove as PositionedObject).TopParent; topParent.X += movementVector.X; topParent.Y += movementVector.Y; topParent.Z += movementVector.Z; } else { objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; } break; case MovementStyle.Hierarchy: objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null) { (objectToMove as PositionedObject).SetRelativeFromAbsolute(); } break; case MovementStyle.IgnoreAttachments: objectToMove.X += movementVector.X; objectToMove.Y += movementVector.Y; objectToMove.Z += movementVector.Z; if (objectToMove is PositionedObject) { PositionedObject asPositionedObject = objectToMove as PositionedObject; if (asPositionedObject.Parent != null) { asPositionedObject.SetRelativeFromAbsolute(); } foreach (PositionedObject child in asPositionedObject.Children) { //child.Position -= movementVector; if (mObjectsToIgnore.Contains(child) == false) { child.SetRelativeFromAbsolute(); } } } break; } #endregion }