public void LerpSceneItemWith(CompositeBoneTransform nextState, float amount, bool nextStateOverride) { // original is only used when bone.Interpolate is set to false, and refer to the 1st KF of the 1st anim SceneItem item = GetSceneItem(); String subItem = GetSubItem(); if (String.IsNullOrEmpty(subItem) == false && item is ISubItemCollection) { ((ISubItemCollection)item).SetCurrentSubItem(subItem); } if (item != null) { item.Update(1 / 60f); amount = MathHelper.Clamp(amount, 0, 1); CompositeEntity parentEntity = Parent.Parent.Parent; CompositeBoneTransform parentTransform = this.ParentBoneTransform; _currentVisibleState = GetVisibilityState(parentTransform); if (_currentVisibleState == false) { return; } bool nextStateVisibility = nextState.GetVisibilityState(nextState.ParentBoneTransform); // no lerping if the next state isnt visible if (nextStateVisibility == false) { nextState = this; } if (nextStateOverride == true) { _position = nextState.Position; _scale = nextState.Scale; _rotation = nextState.Rotation; } else { _position = Vector2.Lerp(this.Position, nextState.Position, amount); _scale = Vector2.Lerp(this.Scale, nextState.Scale, amount); _rotation = MathHelper.Lerp(this.Rotation, nextState.Rotation, amount); } if (this.Opacity.HasValue == true || nextState.Opacity.HasValue == true) { if (this.Opacity.HasValue == true && nextState.Opacity.HasValue == false) { _opacity = this.Opacity.Value; } else if (this.Opacity.HasValue == false && nextState.Opacity.HasValue == true) { _opacity = nextState.Opacity.Value; } else { _opacity = IceMath.Lerp(this.Opacity.Value, nextState.Opacity.Value, amount); } } else { _opacity = null; } _transformPivot = item.GetAbsolutePivot(false); item.FlipHorizontal = parentEntity.FlipHorizontal ^ this.FlipHorizontal; item.FlipVertical = parentEntity.FlipVertical ^ this.FlipVertical; if (parentEntity.FlipHorizontal == true) { _position.X = -_position.X; _transformPivot.X = item.BoundingRectSize.X - _transformPivot.X; _rotation = -_rotation; } if (parentEntity.FlipVertical == true) { _position.Y = -_position.Y; _transformPivot.Y = item.BoundingRectSize.Y - _transformPivot.Y; _rotation = -_rotation; } if (parentEntity.Scale != Vector2.One) { _position *= parentEntity.Scale; } if (parentEntity.Rotation != 0) { Vector2 offset = _position; float length = offset.Length(); double angle = Math.Atan2((float)offset.Y, (float)offset.X) + parentEntity.Rotation; offset.X = (float)(length * Math.Cos(angle)); offset.Y = (float)(length * Math.Sin(angle)); _position = offset; } if (parentTransform != null) { if (this.InheritRotation.HasValue == false && this.Bone.InheritRotation == true || this.InheritRotation.HasValue == true && this.InheritRotation == true) { _rotation += parentTransform.CurrentRotation; } if (this.InheritScale.HasValue == false && this.Bone.InheritScale == true || this.InheritScale.HasValue == true && this.InheritScale == true) { _scale *= parentTransform.CurrentScale; } if (this.InheritPosition.HasValue == false && this.Bone.InheritPosition == true || this.InheritPosition.HasValue == true && this.InheritPosition == true) { Vector2 offset = _position; float length = offset.Length(); double angle = Math.Atan2((float)offset.Y, (float)offset.X) + parentTransform._rotation; offset.X = (float)(length * Math.Cos(angle)); offset.Y = (float)(length * Math.Sin(angle)); _position = parentTransform.CurrentPosition + offset; } } } }
protected override void Draw() { DrawingManager.ViewPortSize = new Point(this.Width, this.Height); ParentEditor.ZoomBox.Camera.Update(1 / 60f); GraphicsDevice.Clear(Color.CornflowerBlue); // Use SpriteSortMode.Immediate, so we can apply custom renderstates. _spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); // Set the texture addressing mode to wrap, so we can repeat // many copies of our tiled checkerboard texture. GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap; GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap; Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height); // Draw a tiled checkerboard pattern in the background. _spriteBatch.Draw(_checkerTexture, fullRect, fullRect, new Color(64, 64, 92)); if (CompositeEntity == null) { _spriteBatch.End(); } else { _spriteBatch.End(); float gridSize = 100000; DrawingManager.DrawFilledRectangle(10, new Vector2(-gridSize, 0), new Vector2(gridSize * 2, 1), new Color(128, 128, 128, 40), DrawingBlendingType.Alpha); DrawingManager.DrawFilledRectangle(10, new Vector2(0, -gridSize), new Vector2(1, gridSize * 2), new Color(128, 128, 128, 40), DrawingBlendingType.Alpha); DrawingManager.DrawFilledRectangle(10, new Vector2(-gridSize, 213), new Vector2(gridSize * 2, 1), new Color(255, 0, 255, 0), DrawingBlendingType.Alpha); CompositeEntity.Position = new Vector2(0); if (ParentEditor.SelectedCompositeKeyFrame != null) { DrawKeyFrame(ParentEditor.SelectedCompositeKeyFrame); if (String.IsNullOrEmpty(this.HighlightedBone) == false) { DrawBoneSceneItemBoundingRect(this.HighlightedBone, Color.Gray); } foreach (String boneTransformRef in this.SelectedBones) { DrawBoneSceneItemBoundingRect(boneTransformRef, Color.Blue); } if (_refreshSceneItemProperties == true) { ParentEditor.propertyGridCompositeBoneTransform.SelectedObject = this.ParentEditor.SelectedCompositeBoneTransform; _refreshSceneItemProperties = false; } } MilkshakeForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); // draw Pivot if (String.IsNullOrEmpty(this.HighlightedBone) != true) { _spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); Vector2 offset = new Vector2(this.Width / 2f, this.Height / 2f); CompositeBoneTransform boneTransform = ParentEditor.SelectedCompositeKeyFrame.GetBoneTransformFromKeyFrame( ParentEditor.SelectedCompositeKeyFrame, this.HighlightedBone); SceneItem boneTransformSceneItem = boneTransform.GetSceneItem(); if (boneTransform.IsVisible == true && boneTransformSceneItem != null) { Rectangle boundingRect = boneTransformSceneItem.BoundingRect; Vector2 pivotPos = offset + boneTransformSceneItem.GetAbsolutePivot(true) + new Vector2(boundingRect.X, boundingRect.Y); _spriteBatch.Draw(_pivotTexture, pivotPos, null, Color.White, 0, new Vector2(6.5f), Vector2.One, SpriteEffects.None, 1); } _spriteBatch.End(); } } if (ParentEditor.UpdatePreview == true) { ParentEditor.UpdatePreview = false; ParentEditor.PreviewAnimation(); } ParentEditor.Update(1 / 60f); }