Beispiel #1
0
        public void Insert(T quadObject)
        {
            lock (syncLock)
            {
                if (sort & !objectSortOrder.ContainsKey(quadObject))
                {
                    objectSortOrder.Add(quadObject, objectSortId++);
                }

                var bounds = quadObject.Bounds;
                if (root == null)
                {
                    var rootSizeF = new Vector2((float)Math.Ceiling(bounds.Width / minLeafSizeF.X),
                                                (float)Math.Ceiling(bounds.Height / minLeafSizeF.Y));
                    double multiplier = Math.Max(rootSizeF.X, rootSizeF.Y);
                    rootSizeF = new Vector2((float)(minLeafSizeF.X * multiplier), (float)(minLeafSizeF.Y * multiplier));
                    var center     = new Vector2i((int)(bounds.Left + bounds.Width / 2), (int)(bounds.Top + bounds.Height / 2));
                    var rootOrigin = new Vector2i((int)(center.X - rootSizeF.X / 2), (int)(center.Y - rootSizeF.Y / 2));
                    root = new QuadNode(Box2.FromDimensions((Vector2)rootOrigin, rootSizeF));
                }

                while (!root.Bounds.Encloses(bounds))
                {
                    ExpandRoot(bounds);
                }

                InsertNodeObject(root, quadObject);
            }
        }
Beispiel #2
0
 public ParticleSystem(Sprite particleSprite, Vector2 position)
 {
     MaximumParticleCount = 200;
     //TODO start with sane defaults
     Acceleration         = new Vector2();
     AccelerationVariance = 0f;
     ColorRange           = new SS14.Shared.Utility.Range <Vector4>(Vector4.UnitX * 255, Vector4.Zero);
     ColorVariance        = 0f;
     EmissionOffset       = new Vector2();
     EmissionRadiusRange  = new SS14.Shared.Utility.Range <float>(0f, 0f);
     Emit                           = false;
     EmitRate                       = 1;
     EmitterPosition                = position;
     Lifetime                       = 1.0f;
     LifetimeVariance               = 0f;
     ParticleSprite                 = particleSprite;
     RadialAcceleration             = 0f;
     RadialAccelerationVariance     = 0f;
     RadialVelocity                 = 0f;
     RadialVelocityVariance         = 0f;
     SizeRange                      = new SS14.Shared.Utility.Range <float>(1, 0);
     SizeVariance                   = 0.1f;
     SpinVelocity                   = new SS14.Shared.Utility.Range <float>(0f, 0f);
     SpinVelocityVariance           = 0f;
     TangentialAcceleration         = 0;
     TangentialAccelerationVariance = 0;
     TangentialVelocity             = 0;
     TangentialVelocityVariance     = 0;
     Velocity                       = new Vector2();
     VelocityVariance               = 0;
 }
Beispiel #3
0
        public override bool MouseDown(MouseButtonEventArgs e)
        {
            if (disposing || !IsVisible())
            {
                return(false);
            }

            if (closeButton.MouseDown(e))
            {
                return(true);
            }

            if (base.MouseDown(e))
            {
                return(true);
            }

            if (titleArea.Contains((int)e.X, (int)e.Y))
            {
                draggingOffset = new Vector2(e.X, e.Y) - Position;
                dragging       = true;
                return(true);
            }

            return(false);
        }
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)Math.Round((mouseCoords.X / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize,
                (float)Math.Round((mouseCoords.Y / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize);

            //Convert back to original world and screen coordinates after applying offset
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public override bool Update(Vector2i mouseS, IMapManager currentMap)
        {
            if (currentMap == null)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseWorld  = CluwneLib.ScreenToWorld(mouseScreen);

            currentTile = currentMap.GetDefaultGrid().GetTile(mouseWorld);

            if (!RangeCheck())
            {
                return(false);
            }

            if (pManager.CurrentPermission.IsTile)
            {
                mouseWorld = new Vector2(currentTile.X + 0.5f,
                                         currentTile.Y + 0.5f);
                mouseScreen = (Vector2i)CluwneLib.WorldToScreen(mouseWorld);
            }
            else
            {
                mouseWorld = new Vector2(currentTile.X + 0.5f + pManager.CurrentPrototype.PlacementOffset.X,
                                         currentTile.Y + 0.5f + pManager.CurrentPrototype.PlacementOffset.Y);
                mouseScreen = (Vector2i)CluwneLib.WorldToScreen(mouseWorld);

//                if (CheckCollision())
//                    return false;
            }

            return(true);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="position">Position of the vertex.</param>
 /// <param name="color">Color of the vertex.</param>
 /// <param name="textureCoordinates">Texture coordinates.</param>
 public PositionDiffuse2DTexture1(Vector3 position, Color color, Vector2 textureCoordinates)
 {
     // Copy data.
     Position           = position;
     ColorValue         = ColorToInt(color);
     TextureCoordinates = textureCoordinates;
 }
        /// <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);
            }
        }
Beispiel #8
0
            public void Update(float frameTime)
            {
                Age += frameTime;
                if (Age >= Lifetime)
                {
                    Alive = false;
                }
                Velocity           += Acceleration * frameTime;
                RadialVelocity     += RadialAcceleration * frameTime;
                TangentialVelocity += TangentialAcceleration * frameTime;

                //Calculate delta p due to radial velocity
                var positionRelativeToEmitter = Position - EmitterPosition;
                var deltaRadial   = RadialVelocity * frameTime;
                var deltaPosition = positionRelativeToEmitter * (deltaRadial / positionRelativeToEmitter.Length);

                //Calculate delta p due to tangential velocity
                var radius = positionRelativeToEmitter.Length;

                if (radius > 0)
                {
                    var theta = (float)Math.Atan2(positionRelativeToEmitter.Y, positionRelativeToEmitter.X);
                    theta         += TangentialVelocity * frameTime;
                    deltaPosition += new Vector2(radius * (float)Math.Cos(theta), radius * (float)Math.Sin(theta))
                                     - positionRelativeToEmitter;
                }
                //Calculate delta p due to Velocity
                deltaPosition += Velocity * frameTime;
                Position      += deltaPosition;
                Spin          += SpinVelocity * frameTime;
                Size          += SizeDelta * frameTime;
                Color         += ColorDelta * frameTime;
            }
        private void HandleKeyChange()
        {
            var input = Owner.GetComponent <KeyBindingInputComponent>();

            // key directions are in screen coordinates
            // _moveDir is in world coordinates
            // if the camera is moved, this needs to be changed

            var x = 0;

            x -= input.GetKeyState(BoundKeyFunctions.MoveLeft) ? 1 : 0;
            x += input.GetKeyState(BoundKeyFunctions.MoveRight) ? 1 : 0;

            var y = 0;

            y += input.GetKeyState(BoundKeyFunctions.MoveDown) ? 1 : 0;
            y -= input.GetKeyState(BoundKeyFunctions.MoveUp) ? 1 : 0;

            _moveDir = new Vector2(x, y);

            // can't normalize zero length vector
            if (_moveDir.LengthSquared > 1.0e-6)
            {
                _moveDir = _moveDir.Normalized;
            }

            // players can run or walk
            _run = input.GetKeyState(BoundKeyFunctions.Run);
        }
Beispiel #10
0
        /// <inheritdoc />
        public override void Update(float frameTime)
        {
            base.Update(frameTime);

            if (sprite == null || IsSlaved())
            {
                return;
            }

            var worldRot = Owner.GetComponent <TransformComponent>().Rotation.ToVec();

            // world2screen
            worldRot = new Vector2(worldRot.X, worldRot.Y * -1);

            //If the sprite is idle, it won't try to update Direction, meaning you stay facing the way you move
            if (sprite.CurrentAnimationStateKey.Equals("idle"))
            {
                sprite.Update(frameTime);
            }
            else
            {
                sprite.Direction = worldRot.GetDir();
                sprite.Update(frameTime);
            }
        }
Beispiel #11
0
 public static Vector2 TileToWorld(Vector2 point)
 {
     return(new Vector2(
                point.X + 0.5f,
                point.Y + 0.5f
                ));
 }
Beispiel #12
0
 public static Vector2 WorldToTile(Vector2 point)
 {
     return(new Vector2(
                (float)Math.Floor(point.X),
                (float)Math.Floor(point.Y)
                ));
 }
Beispiel #13
0
        public override void Render(Vector2 topLeft, Vector2 bottomRight)
        {
            if (!visible)
            {
                return;
            }

            var position = Owner.GetComponent <ITransformComponent>().Position;

            if (position.X < topLeft.X ||
                position.X > bottomRight.X ||
                position.Y < topLeft.Y ||
                position.Y > bottomRight.Y)
            {
                return;
            }

            base.Render(topLeft, bottomRight);

            if (_speechBubble != null)
            {
                _speechBubble.Draw(CluwneLib.WorldToScreen(position),
                                   new Vector2(), currentBaseSprite);
            }
        }
        private static Vector2i GetBucketCoordinate(Vector2 coordinate)
        {
            var x = (int)Math.Floor(coordinate.X / BucketSize);
            var y = (int)Math.Floor(coordinate.Y / BucketSize);

            return(new Vector2i(x, y));
        }
Beispiel #15
0
 private Vector2 VariedPositiveVector2(Vector2 value, float variance)
 {
     return(new Vector2(
                VariedPositiveFloat(value.X, variance),
                VariedPositiveFloat(value.Y, variance)
                ));
 }
Beispiel #16
0
        public void SetSpriteCenter(Sprite sprite, Vector2 center)
        {
            var bounds = GetActiveDirectionalSprite().LocalBounds;

            sprite.Position = new Vector2(center.X - (bounds.Width / 2),
                                          center.Y - (bounds.Height / 2));
        }
        public void SetSpriteCenter(Sprite sprite, Vector2 center)
        {
            var bounds = GetActiveDirectionalSprite().GetLocalBounds();

            sprite.Position = new SFML.System.Vector2f(center.X - (bounds.Width / 2),
                                                       center.Y - (bounds.Height / 2));
        }
Beispiel #18
0
        public override bool Update(Vector2i mouseS, IMapManager currentMap)
        {
            if (currentMap == null)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseWorld  = CluwneLib.ScreenToWorld(mouseScreen);

            currentTile = currentMap.GetDefaultGrid().GetTile(mouseWorld);

            if (!RangeCheck())
            {
                return(false);
            }

            var entitymanager = IoCManager.Resolve <IClientEntityManager>();
            var failtoplace   = entitymanager.AnyEntitiesIntersecting(new Box2(new Vector2(currentTile.X, currentTile.Y), new Vector2(currentTile.X + 0.99f, currentTile.Y + 0.99f)));

            if (pManager.CurrentPermission.IsTile)
            {
                mouseWorld = new Vector2(currentTile.X + 0.5f,
                                         currentTile.Y + 0.5f);
                mouseScreen = (Vector2i)CluwneLib.WorldToScreen(mouseWorld);
            }
            else
            {
                mouseWorld = new Vector2(currentTile.X + 0.5f + pManager.CurrentPrototype.PlacementOffset.X,
                                         currentTile.Y + 0.5f + pManager.CurrentPrototype.PlacementOffset.Y);
                mouseScreen = (Vector2i)CluwneLib.WorldToScreen(mouseWorld);
            }
            return(failtoplace);
        }
        /// <inheritdoc />
        public override void HandleComponentState(ComponentState state)
        {
            var newState = (TransformComponentState)state;

            Rotation = newState.Rotation;

            if (_position != newState.Position || MapID != newState.MapID || GridID != newState.GridID)
            {
                OnMove?.Invoke(this, new MoveEventArgs(LocalPosition, new LocalCoordinates(newState.Position, newState.GridID, newState.MapID)));
                _position = newState.Position;
                MapID     = newState.MapID;
                GridID    = newState.GridID;
            }

            if (Parent?.Owner?.Uid != newState.ParentID)
            {
                DetachParent();
                if (!(newState.ParentID is int parentID))
                {
                    return;
                }
                var newParent = Owner.EntityManager.GetEntity(parentID);
                AttachParent(newParent.GetComponent <ITransformComponent>());
            }
        }
Beispiel #20
0
        private void ShowSplashScreen()
        {
            // Do nothing when we're on DEBUG builds.
            // The splash is just annoying.
            const int SIZE_X = 600;
            const int SIZE_Y = 300;
            var       Size   = new Vector2i(SIZE_X, SIZE_Y);
            // Size of the NT logo in the bottom right.
            const float NT_SIZE_X = SIZE_X / 10f;
            const float NT_SIZE_Y = SIZE_Y / 10f;
            var         NTSize    = new Vector2(NT_SIZE_X, NT_SIZE_Y);
            var         window    = CluwneLib.ShowSplashScreen(new VideoMode(SIZE_X, SIZE_Y)).Graphics;

            var logo = _resourceCache.GetSprite("ss14_logo");

            logo.Position = Size / 2 - logo.TextureRect.Size / 2;

            var background = _resourceCache.GetSprite("ss14_logo_background");

            background.Scale = (Vector2)Size / background.TextureRect.Size;

            var nanotrasen = _resourceCache.GetSprite("ss14_logo_nt");

            nanotrasen.Scale    = NTSize / nanotrasen.TextureRect.Size;
            nanotrasen.Position = Size - NTSize - 5;
            nanotrasen.Color    = Color.White.WithAlpha(64);

            window.Draw(background);
            window.Draw(logo);
            window.Draw(nanotrasen);
            window.Display();
        }
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)(Math.Round((mouseCoords.Position.X / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize,
                (float)(Math.Round((mouseCoords.Position.Y / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize);

            //Adjust mouseCoords to new calculated position
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
        /// <inheritdoc />
        public IEntity ForceSpawnEntityAt(string EntityType, Vector2 position, int argMap)
        {
            var mapmanager  = IoCManager.Resolve <IMapManager>();
            var coordinates = new LocalCoordinates(position, mapmanager.GetMap(argMap).FindGridAt(position));

            return(ForceSpawnEntityAt(EntityType, coordinates));
        }
        /// <inheritdoc />
        public bool TrySpawnEntityAt(string EntityType, Vector2 position, int argMap, out IEntity entity)
        {
            var mapmanager  = IoCManager.Resolve <IMapManager>();
            var coordinates = new LocalCoordinates(position, mapmanager.GetMap(argMap).FindGridAt(position));

            return(TrySpawnEntityAt(EntityType, coordinates, out entity));
        }
Beispiel #24
0
        private static Vector2 MatMult(Matrix3 mat, Vector2 vec)
        {
            var vecHom = new Vector3(vec.X, vec.Y, 1);

            Matrix3.Transform(ref mat, ref vecHom);
            return(vecHom.Xy);
        }
Beispiel #25
0
        /// <summary>
        /// Transforms global world coordinates to tile indices relative to grid origin.
        /// </summary>
        /// <returns></returns>
        public Indices WorldToTile(Vector2 worldPos)
        {
            var local = WorldToLocal(worldPos);
            var x     = (int)Math.Floor(local.X / _mapManager.TileSize);
            var y     = (int)Math.Floor(local.Y / _mapManager.TileSize);

            return(new Indices(x, y));
        }
        /// <summary>
        ///     Gets a bucket given a point coordinate
        /// </summary>
        /// <param name="coordinate"></param>
        /// <returns></returns>
        private CollidableBucket GetBucket(Vector2 coordinate)
        {
            var key = GetBucketCoordinate(coordinate);

            return(_bucketIndex.ContainsKey(key)
                ? _buckets[_bucketIndex[key]]
                : CreateBucket(key));
        }
Beispiel #27
0
 /// <summary>
 /// Move JUST the particles, moving the emitter to offset
 /// </summary>
 /// <remarks>
 /// This moves the particles, but not the emitter. This changes the particles positions relative to the emitter.
 /// </remarks>
 /// <param name="offset"></param>
 public void MoveParticlesOffset(Vector2 offset)
 {
     Parallel.ForEach(LiveParticles, particle =>
     {
         particle.Position        += offset;
         particle.EmitterPosition += offset;
     });
 }
Beispiel #28
0
        /// <inheritdoc />
        public IEntity ForceSpawnEntityAt(string EntityType, Vector2 position)
        {
            IEntity entity = SpawnEntity(EntityType);

            entity.GetComponent <TransformComponent>().Position = position;
            entity.Initialize();
            return(entity);
        }
Beispiel #29
0
        /// <summary>
        /// Transforms global world coordinates to chunk indices relative to grid origin.
        /// </summary>
        /// <param name="localPos">The position in the world.</param>
        /// <returns></returns>
        public Indices WorldToChunk(Vector2 localPos)
        {
            var local = localPos - WorldPosition;
            var x     = (int)Math.Floor(local.X / (_mapManager.TileSize * ChunkSize));
            var y     = (int)Math.Floor(local.Y / (_mapManager.TileSize * ChunkSize));

            return(new Indices(x, y));
        }
Beispiel #30
0
        public void RecalculateLightsInView(Vector2 point)
        {
            var lights = LightsIntersectingPoint(point);

            foreach (var l in lights)
            {
                l.LightArea.Calculated = false;
            }
        }
Beispiel #31
0
 public void SetParameter(string Parameter, Vector2[] vec2array)
 {
     for (int i = 0; i < vec2array.Length; i++)
     {
         this.SetParameter(Parameter + i, vec2array[i]);
     }
 }
Beispiel #32
0
 public void SetParameter(string Parameter, Vector2 vec2)
 {
     base.SetParameter(Parameter, vec2.X, vec2.Y);
     Debug.Write("Setting Parameter " + Parameter + " with value: " + vec2.X + " " + vec2.Y);
 }