private bool Draw3DStretched(Batcher2D batcher, Vector3 position, MouseOverList objectList) { Texture.Ticks = Engine.Ticks; int z = Z * 4; if (Engine.Profile.Current.HighlightGameObjects) { if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } } Vector3.Add(ref position, ref _vertex0_yOffset, out _vertex[0].Position); Vector3.Add(ref position, ref _vertex1_yOffset, out _vertex[1].Position); Vector3.Add(ref position, ref _vertex2_yOffset, out _vertex[2].Position); Vector3.Add(ref position, ref _vertex3_yOffset, out _vertex[3].Position); _vertex[0].Position.Y += z; _vertex[1].Position.Y += z; _vertex[2].Position.Y += z; _vertex[3].Position.Y += z; //HueVector.Z = 1f - (AlphaHue / 255f); if (HueVector != _vertex[0].Hue) { _vertex[0].Hue = HueVector; _vertex[1].Hue = HueVector; _vertex[2].Hue = HueVector; _vertex[3].Hue = HueVector; } if (!batcher.DrawSprite(Texture, _vertex)) { return(false); } if (objectList.IsMouseInObjectIsometric(_vertex)) { objectList.Add(this, _vertex[0].Position); } return(true); }
private unsafe bool Draw3DStretched(Batcher2D batcher, Vector3 position, MouseOverList objectList) { Texture.Ticks = Engine.Ticks; int z = GameObject.Position.Z * 4; if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } fixed(SpriteVertex *ptr = _vertex) { ptr[0].Position = position + _vertex0_yOffset; ptr[1].Position = position + _vertex1_yOffset; ptr[2].Position = position + _vertex2_yOffset; ptr[3].Position = position + _vertex3_yOffset; ptr[0].Position.Y += z; ptr[1].Position.Y += z; ptr[2].Position.Y += z; ptr[3].Position.Y += z; if (HueVector != ptr[0].Hue) { ptr[0].Hue = HueVector; ptr[1].Hue = HueVector; ptr[2].Hue = HueVector; ptr[3].Hue = HueVector; } } if (!batcher.DrawSprite(Texture, _vertex)) { return(false); } if (objectList.IsMouseInObjectIsometric(_vertex)) { objectList.Add(GameObject, _vertex[0].Position); } return(true); }
public virtual bool Draw(Batcher2D batcher, Vector3 position, MouseOverList list) { SpriteVertex[] vertex; bool hasShadow = HasShadow && position.Z >= 1000; if (hasShadow) { position.Z -= 1000; } if (Rotation != 0.0f) { float w = Bounds.Width / 2f; float h = Bounds.Height / 2f; Vector3 center = position; center.X -= Bounds.X - 44 + w; center.Y -= Bounds.Y + h; float sinx = (float)Math.Sin(Rotation) * w; float cosx = (float)Math.Cos(Rotation) * w; float siny = (float)Math.Sin(Rotation) * h; float cosy = (float)Math.Cos(Rotation) * h; vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = center; vertex[0].Position.X += cosx - -siny; vertex[0].Position.Y -= sinx + -cosy; vertex[1].Position = center; vertex[1].Position.X += cosx - siny; vertex[1].Position.Y += -sinx + -cosy; vertex[2].Position = center; vertex[2].Position.X += -cosx - -siny; vertex[2].Position.Y += sinx + cosy; vertex[3].Position = center; vertex[3].Position.X += -cosx - siny; vertex[3].Position.Y += sinx + -cosy; } else if (IsFlipped) { vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = position; vertex[0].Position.X += Bounds.X + 44f; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.Y += Bounds.Height; vertex[2].Position = vertex[0].Position; vertex[2].Position.X -= Bounds.Width; vertex[2].TextureCoordinate.Y = 0; vertex[3].Position = vertex[1].Position; vertex[3].Position.X -= Bounds.Width; } else { vertex = SpriteVertex.PolyBuffer; vertex[0].Position = position; vertex[0].Position.X -= Bounds.X; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.X += Bounds.Width; vertex[1].TextureCoordinate.Y = 0; vertex[2].Position = vertex[0].Position; vertex[2].Position.Y += Bounds.Height; vertex[3].Position = vertex[1].Position; vertex[3].Position.Y += Bounds.Height; } bool isTransparent = false; if (DrawTransparent) { int dist = Distance; int maxDist = Engine.Profile.Current.CircleOfTransparencyRadius + 1; if (dist <= maxDist) { isTransparent = dist <= 3; HueVector.Z = MathHelper.Lerp(1f, 1f - (dist / (float)maxDist), 0.5f); //HueVector.Z = 1f - (dist / (float)maxDist); } else { HueVector.Z = 1f - AlphaHue / 255f; } } else { HueVector.Z = 1f - AlphaHue / 255f; } if (Engine.Profile.Current.HighlightGameObjects) { if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } } if (vertex[0].Hue != HueVector) { vertex[0].Hue = vertex[1].Hue = vertex[2].Hue = vertex[3].Hue = HueVector; } if (hasShadow) { SpriteVertex[] vertexS = { vertex[0], vertex[1], vertex[2], vertex[3] }; vertexS[0].Hue = vertexS[1].Hue = vertexS[2].Hue = vertexS[3].Hue = ShaderHuesTraslator.GetHueVector(0, ShadersEffectType.Shadow); batcher.DrawShadow(Texture, vertexS, new Vector2(position.X + 22, position.Y + Offset.Y - Offset.Z + 22), IsFlipped, 0); } if (!batcher.DrawSprite(Texture, vertex)) { return(false); } MousePick(list, vertex, isTransparent); Texture.Ticks = Engine.Ticks; return(true); }
//private static readonly Lazy<BlendState> _checkerBlend = new Lazy<BlendState>(() => //{ // BlendState state = new BlendState(); // state.AlphaSourceBlend = state.ColorSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.SourceAlpha; // state.AlphaDestinationBlend = state.ColorDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.InverseSourceAlpha; // return state; //}); public virtual bool Draw(Batcher2D batcher, Vector3 position, MouseOverList list) { Texture.Ticks = Engine.Ticks; SpriteVertex[] vertex; if (Rotation != 0.0f) { float w = Bounds.Width / 2f; float h = Bounds.Height / 2f; Vector3 center = position - new Vector3(Bounds.X - 44 + w, Bounds.Y + h, 0); float sinx = (float)Math.Sin(Rotation) * w; float cosx = (float)Math.Cos(Rotation) * w; float siny = (float)Math.Sin(Rotation) * h; float cosy = (float)Math.Cos(Rotation) * h; vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = center; vertex[0].Position.X += cosx - -siny; vertex[0].Position.Y -= sinx + -cosy; vertex[1].Position = center; vertex[1].Position.X += cosx - siny; vertex[1].Position.Y += -sinx + -cosy; vertex[2].Position = center; vertex[2].Position.X += -cosx - -siny; vertex[2].Position.Y += sinx + cosy; vertex[3].Position = center; vertex[3].Position.X += -cosx - siny; vertex[3].Position.Y += sinx + -cosy; } else if (IsFlipped) { vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = position; vertex[0].Position.X += Bounds.X + 44f; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.Y += Bounds.Height; vertex[2].Position = vertex[0].Position; vertex[2].Position.X -= Bounds.Width; vertex[2].TextureCoordinate.Y = 0; vertex[3].Position = vertex[1].Position; vertex[3].Position.X -= Bounds.Width; } else { vertex = SpriteVertex.PolyBuffer; vertex[0].Position = position; vertex[0].Position.X -= Bounds.X; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.X += Bounds.Width; vertex[1].TextureCoordinate.Y = 0; vertex[2].Position = vertex[0].Position; vertex[2].Position.Y += Bounds.Height; vertex[3].Position = vertex[1].Position; vertex[3].Position.Y += Bounds.Height; } if (DrawTransparent) { int dist = Distance; int maxDist = Engine.Profile.Current.CircleOfTransparencyRadius + 1; if (dist <= maxDist) { HueVector.Z = 1f - (dist / (float)maxDist); } else { HueVector.Z = 1f - AlphaHue / 255f; } } else { HueVector.Z = 1f - AlphaHue / 255f; } if (Engine.Profile.Current.HighlightGameObjects) { if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } } if (vertex[0].Hue != HueVector) { vertex[0].Hue = vertex[1].Hue = vertex[2].Hue = vertex[3].Hue = HueVector; } //if (HasShadow) //{ // SpriteVertex[] vertexS = new SpriteVertex[4] // { // vertex[0], // vertex[1], // vertex[2], // vertex[3] // }; // batcher.DrawShadow(Texture, vertexS, new Vector2(position.X + 22, position.Y + GameObject.Offset.Y - GameObject.Offset.Z + 22), IsFlipped, ShadowZDepth); //} //if (DrawTransparent) //{ // batcher.SetBlendState(_checkerBlend.Value); // batcher.DrawSprite(Texture, vertex); // batcher.SetBlendState(null, true); // batcher.SetStencil(_stencil.Value); // batcher.DrawSprite(Texture, vertex); // batcher.SetStencil(null); //} //else //{ // batcher.DrawSprite(Texture, vertex); //} //if (DrawTransparent) //{ // vertex[0].Hue.Z = vertex[1].Hue.Z = vertex[2].Hue.Z = vertex[3].Hue.Z = 0.5f; // batcher.SetStencil(_stencil.Value); // batcher.DrawSprite(Texture, vertex); // batcher.SetStencil(null); //} if (!batcher.DrawSprite(Texture, vertex)) { return(false); } MousePick(list, vertex); return(true); }
public virtual unsafe bool Draw(Batcher2D batcher, Vector3 position, MouseOverList list) { //if (Texture == null || Texture.IsDisposed || !AllowedToDraw || GameObject.IsDisposed) return false; Texture.Ticks = Engine.Ticks; SpriteVertex[] vertex; if (Rotation != 0.0f) { float w = Bounds.Width / 2f; float h = Bounds.Height / 2f; Vector3 center = position - new Vector3(Bounds.X - 44 + w, Bounds.Y + h, 0); float sinx = (float)Math.Sin(Rotation) * w; float cosx = (float)Math.Cos(Rotation) * w; float siny = (float)Math.Sin(Rotation) * h; float cosy = (float)Math.Cos(Rotation) * h; vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = center; vertex[0].Position.X += cosx - -siny; vertex[0].Position.Y -= sinx + -cosy; vertex[1].Position = center; vertex[1].Position.X += cosx - siny; vertex[1].Position.Y += -sinx + -cosy; vertex[2].Position = center; vertex[2].Position.X += -cosx - -siny; vertex[2].Position.Y += sinx + cosy; vertex[3].Position = center; vertex[3].Position.X += -cosx - siny; vertex[3].Position.Y += sinx + -cosy; } else if (IsFlipped) { vertex = SpriteVertex.PolyBufferFlipped; vertex[0].Position = position; vertex[0].Position.X += Bounds.X + 44f; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.Y += Bounds.Height; vertex[2].Position = vertex[0].Position; vertex[2].Position.X -= Bounds.Width; vertex[2].TextureCoordinate.Y = 0; vertex[3].Position = vertex[1].Position; vertex[3].Position.X -= Bounds.Width; } else { vertex = SpriteVertex.PolyBuffer; vertex[0].Position = position; vertex[0].Position.X -= Bounds.X; vertex[0].Position.Y -= Bounds.Y; vertex[0].TextureCoordinate.Y = 0; vertex[1].Position = vertex[0].Position; vertex[1].Position.X += Bounds.Width; vertex[1].TextureCoordinate.Y = 0; vertex[2].Position = vertex[0].Position; vertex[2].Position.Y += Bounds.Height; vertex[3].Position = vertex[1].Position; vertex[3].Position.Y += Bounds.Height; } if (Engine.Profile.Current.HighlightGameObjects) { if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } } if (CanProcessAlpha) { long ticks = Engine.Ticks; if (_processAlphaTime == -1) { _processAlphaTime = ticks + Constants.ALPHA_OBJECT_TIME; } else { ticks -= Constants.ALPHA_OBJECT_TIME; } if (_processAlphaTime < ticks) // finished! { _processAlpha = 0; CanProcessAlpha = false; } else { _processAlpha = ((_processAlphaTime - Engine.Ticks) / Constants.ALPHA_OBJECT_VALUE); } if (HueVector.Z < _processAlpha) { HueVector.Z = _processAlpha; } } if (vertex[0].Hue != HueVector) { vertex[0].Hue = vertex[1].Hue = vertex[2].Hue = vertex[3].Hue = HueVector; } //if (HasShadow) //{ // SpriteVertex[] vertexS = new SpriteVertex[4] // { // vertex[0], // vertex[1], // vertex[2], // vertex[3] // }; // batcher.DrawShadow(Texture, vertexS, new Vector2(position.X + 22, position.Y + GameObject.Offset.Y - GameObject.Offset.Z + 22), IsFlipped, ShadowZDepth); //} if (!batcher.DrawSprite(Texture, vertex)) { return(false); } MousePick(list, vertex); return(true); }
public virtual unsafe bool Draw(Batcher2D batcher, Vector3 position, MouseOverList list) { if (Texture == null || Texture.IsDisposed || !AllowedToDraw || GameObject.IsDisposed) { return(false); } Texture.Ticks = Engine.Ticks; SpriteVertex[] vertex; if (Rotation != 0.0f) { float w = Bounds.Width / 2f; float h = Bounds.Height / 2f; Vector3 center = position - new Vector3(Bounds.X - 44 + w, Bounds.Y + h, 0); float sinx = (float)Math.Sin(Rotation) * w; float cosx = (float)Math.Cos(Rotation) * w; float siny = (float)Math.Sin(Rotation) * h; float cosy = (float)Math.Cos(Rotation) * h; vertex = SpriteVertex.PolyBufferFlipped; fixed(SpriteVertex *ptr = vertex) { ptr[0].Position = center; ptr[0].Position.X += cosx - -siny; ptr[0].Position.Y -= sinx + -cosy; ptr[1].Position = center; ptr[1].Position.X += cosx - siny; ptr[1].Position.Y += -sinx + -cosy; ptr[2].Position = center; ptr[2].Position.X += -cosx - -siny; ptr[2].Position.Y += sinx + cosy; ptr[3].Position = center; ptr[3].Position.X += -cosx - siny; ptr[3].Position.Y += sinx + -cosy; } } else if (IsFlipped) { vertex = SpriteVertex.PolyBufferFlipped; fixed(SpriteVertex *ptr = vertex) { ptr[0].Position = position; ptr[0].Position.X += Bounds.X + 44f; ptr[0].Position.Y -= Bounds.Y; ptr[0].TextureCoordinate.Y = 0; ptr[1].Position = vertex[0].Position; ptr[1].Position.Y += Bounds.Height; ptr[2].Position = vertex[0].Position; ptr[2].Position.X -= Bounds.Width; ptr[2].TextureCoordinate.Y = 0; ptr[3].Position = vertex[1].Position; ptr[3].Position.X -= Bounds.Width; } } else { vertex = SpriteVertex.PolyBuffer; fixed(SpriteVertex *ptr = vertex) { ptr[0].Position = position; ptr[0].Position.X -= Bounds.X; ptr[0].Position.Y -= Bounds.Y; ptr[0].TextureCoordinate.Y = 0; ptr[1].Position = vertex[0].Position; ptr[1].Position.X += Bounds.Width; ptr[1].TextureCoordinate.Y = 0; ptr[2].Position = vertex[0].Position; ptr[2].Position.Y += Bounds.Height; ptr[3].Position = vertex[1].Position; ptr[3].Position.Y += Bounds.Height; } } if (IsSelected) { if (_storedHue == Vector3.Zero) { _storedHue = HueVector; } HueVector = ShaderHuesTraslator.SelectedHue; } else if (_storedHue != Vector3.Zero) { HueVector = _storedHue; _storedHue = Vector3.Zero; } if (vertex[0].Hue != HueVector) { vertex[0].Hue = vertex[1].Hue = vertex[2].Hue = vertex[3].Hue = HueVector; } //if (HasShadow) //{ // SpriteVertex[] vertexS = new SpriteVertex[4] // { // vertex[0], // vertex[1], // vertex[2], // vertex[3] // }; // batcher.DrawShadow(Texture, vertexS, new Vector2(position.X + 22, position.Y + GameObject.Offset.Y - GameObject.Offset.Z + 22), IsFlipped, ShadowZDepth); //} if (!batcher.DrawSprite(Texture, vertex)) { return(false); } MousePick(list, vertex); return(true); }