public void SetPosition(Vector2 position) { _checkDisposed(); var(x, y) = position; AL.Source(SourceHandle, ALSource3f.Position, x, y, 0); _checkAlError(); }
/// <summary> /// Calculates the texture coordinate offsets corresponding to the /// calculated Gaussian blur filter kernel. Each of these offset values /// are added to the current pixel's texture coordinates in order to /// obtain the neighboring texture coordinates that are affected by the /// Gaussian blur filter kernel. This implementation has been adapted /// from chapter 17 of "Filthy Rich Clients: Developing Animated and /// Graphical Effects for Desktop Java". /// </summary> public void ComputeOffsets() { float textureWidth = Size.X; float textureHeight = Size.Y; if (Kernel == null) { ComputeKernel(); } WeightsOffsetsX = null; WeightsOffsetsY = null; WeightsOffsetsX = new Vector2[Radius * 2 + 1]; WeightsOffsetsY = new Vector2[Radius * 2 + 1]; float xOffset = 1.0f / textureWidth; float yOffset = 1.0f / textureHeight; for (int i = -Radius; i <= Radius; ++i) { int index = i + Radius; WeightsOffsetsX[index] = new Vector2(Kernel[index], i * xOffset); WeightsOffsetsY[index] = new Vector2(Kernel[index], i * yOffset); } }
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) { MouseCoords = ScreenToPlayerGrid(mouseScreen); CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (pManager.CurrentPermission.IsTile) { return; } var nodes = new List <Vector2>(); if (pManager?.CurrentPrototype.MountingPoints != null) { nodes.AddRange( pManager.CurrentPrototype.MountingPoints.Select( current => new Vector2(MouseCoords.X, CurrentTile.Y + current))); } else { nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 0.5f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.0f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.5f)); } Vector2 closestNode = (from Vector2 node in nodes orderby(node - MouseCoords.Position).LengthSquared ascending select node).First(); MouseCoords = new GridCoordinates(closestNode + new Vector2(pManager.PlacementOffset.X, pManager.PlacementOffset.Y), MouseCoords.Grid); }
public LightArea(ShadowmapSize shadowmapSize, SFML.Graphics.Sprite mask) { var baseSize = 2 << (int)shadowmapSize; LightAreaSize = new Vector2(baseSize, baseSize); RenderTarget = new RenderImage("LightArea" + shadowmapSize, (uint)baseSize, (uint)baseSize); Mask = mask; }
public virtual void Render(Vector2 topLeft, Vector2 bottomRight) { ScreenCoordinates renderPos = CluwneLib.WorldToScreen(Owner.GetComponent <ITransformComponent>().LocalPosition); foreach (KeyValuePair <string, ParticleSystem> particleSystem in _emitters) { particleSystem.Value.Move(renderPos.Position); particleSystem.Value.Render(); } }
public void OnMove(object sender, VectorEventArgs args) { var offset = new Vector2(args.VectorTo.X, args.VectorTo.Y) - new Vector2(args.VectorFrom.X, args.VectorFrom.Y); foreach (KeyValuePair <string, ParticleSystem> particleSystem in _emitters) { particleSystem.Value.MoveEmitter(particleSystem.Value.EmitterPosition + offset); } }
public void OnMove(object sender, MoveEventArgs args) { var offset = new Vector2(args.NewPosition.Position.X, args.NewPosition.Position.Y) - new Vector2(args.OldPosition.Position.X, args.OldPosition.Position.Y); foreach (KeyValuePair <string, ParticleSystem> particleSystem in _emitters) { particleSystem.Value.MoveEmitter(particleSystem.Value.EmitterPosition + offset); } MapID = args.NewPosition.MapID; }
/// <summary> /// Default constructor for the GaussianBlur class. This constructor /// should be called if you don't want the GaussianBlur class to use /// its GaussianBlur.fx effect file to perform the two pass Gaussian /// blur operation. /// </summary> public GaussianBlur(IResourceCache resourceCache) { _resourceCache = resourceCache; targetName = "gaussTarget" + IoCManager.Resolve <IRand>().Next(0, 1000000000); //Set Defaults Radius = 7; Amount = 2.5f; Size = new Vector2(256.0f, 256.0f); LoadShaders(); }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (!RangeCheck()) { return(false); } var nodes = new List <Vector2>(); if (pManager.CurrentPrototype.MountingPoints != null) { nodes.AddRange( pManager.CurrentPrototype.MountingPoints.Select( current => new Vector2(MouseCoords.X, CurrentTile.Y + current))); } else { nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 0.5f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.0f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.5f)); } Vector2 closestNode = (from Vector2 node in nodes orderby(node - MouseCoords.Position).LengthSquared ascending select node).First(); MouseCoords = new LocalCoordinates(closestNode + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid); MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); return(true); }
public void SetSize(Vector2 size) { Size = size; ComputeOffsets(); }
public Vector2 ToRelativePosition(Vector2 worldPosition) { return(worldPosition - (CluwneLib.WorldToScreen(LightPosition) - LightAreaSize * 0.5f)); }
public override void Render(Vector2 topLeft, Vector2 bottomRight) { if (IsCurrentlyWorn && currentSprite == baseSprite) { base.Render(topLeft, bottomRight); return; } else if (IsCurrentlyCarried && currentSprite != CarriedSprite) { SetSprite(CarriedSprite); base.Render(topLeft, bottomRight); return; } //Render slaves beneath IEnumerable <SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth < DrawDepth select c; foreach (SpriteComponent component in renderablesBeneath.ToList()) { component.Render(topLeft, bottomRight); } //Render this sprite if (!visible) { return; } if (NotWornSprite == null) { return; } Sprite spriteToRender = NotWornSprite; var bounds = spriteToRender.GetLocalBounds(); ScreenCoordinates renderPos = CluwneLib.WorldToScreen(Owner.GetComponent <ITransformComponent>().LocalPosition); spriteToRender.Position = new Vector2f(renderPos.X - (bounds.Width / 2), renderPos.Y - (bounds.Height / 2)); if (Owner.GetComponent <ITransformComponent>().WorldPosition.X + bounds.Left + bounds.Width < topLeft.X || Owner.GetComponent <ITransformComponent>().WorldPosition.X > bottomRight.X || Owner.GetComponent <ITransformComponent>().WorldPosition.Y + bounds.Top + bounds.Height < topLeft.Y || Owner.GetComponent <ITransformComponent>().WorldPosition.Y > bottomRight.Y) { return; } spriteToRender.Scale = new Vector2f(HorizontalFlip ? -1 : 1, 1); spriteToRender.Draw(); //Render slaves above IEnumerable <SpriteComponent> renderablesAbove = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth >= DrawDepth select c; foreach (SpriteComponent component in renderablesAbove.ToList()) { component.Render(topLeft, bottomRight); } //Draw AABB var aabb = LocalAABB; if (CluwneLib.Debug.DebugColliders) { CluwneLib.drawRectangle((int)(renderPos.X - aabb.Width / 2), (int)(renderPos.Y - aabb.Height / 2), aabb.Width, aabb.Height, Color4.Blue); } }
public override void Render(Vector2 topLeft, Vector2 bottomRight) { if (IsCurrentlyWorn && currentSprite == baseSprite) { base.Render(topLeft, bottomRight); return; } else if (IsCurrentlyCarried && currentSprite != CarriedSprite) { SetSprite(CarriedSprite); base.Render(topLeft, bottomRight); return; } //Render slaves beneath IEnumerable <SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth < DrawDepth select c; foreach (SpriteComponent component in renderablesBeneath.ToList()) { component.Render(topLeft, bottomRight); } //Render this sprite if (!visible) { return; } if (NotWornSprite == null) { return; } Sprite spriteToRender = NotWornSprite; var bounds = spriteToRender.LocalBounds; var renderPos = Owner.GetComponent <ITransformComponent>().WorldPosition *CluwneLib.Camera.PixelsPerMeter; spriteToRender.Position = new Vector2(renderPos.X - (bounds.Width / 2), renderPos.Y - (bounds.Height / 2)); if (Owner.GetComponent <ITransformComponent>().WorldPosition.X + bounds.Left + bounds.Width < topLeft.X || Owner.GetComponent <ITransformComponent>().WorldPosition.X > bottomRight.X || Owner.GetComponent <ITransformComponent>().WorldPosition.Y + bounds.Top + bounds.Height < topLeft.Y || Owner.GetComponent <ITransformComponent>().WorldPosition.Y > bottomRight.Y) { return; } spriteToRender.Scale = new Vector2(HorizontalFlip ? -1 : 1, 1); spriteToRender.Draw(); //Render slaves above IEnumerable <SpriteComponent> renderablesAbove = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth >= DrawDepth select c; foreach (SpriteComponent component in renderablesAbove.ToList()) { component.Render(topLeft, bottomRight); } }