/// <summary>
        /// Fired when the entity ticks.
        /// </summary>
        public void Tick()
        {
            Game    game = Engine3D.Source as Game;
            Matrix4 m    = Engine3D.MainView.PrimaryMatrix.Inverted();

            m.Transpose();
            float   x    = 2.0f * Engine3D.Client.MouseX / Engine3D.Window.Width - 1.0f;
            float   y    = 1.0f - 2.0f * Engine3D.Client.MouseY / Engine3D.Window.Height;
            Vector4 vIn  = new Vector4(x, y, 1, 1);
            Vector4 vOut = Vector4.Transform(m, vIn);
            float   mul  = 1.0f / vOut.W;

            BEPUutilities.Vector3 dir = new BEPUutilities.Vector3(vOut.X * mul, vOut.Y * mul, vOut.Z * mul);
            if (game.Terrain.Body.RayCast(new BEPUutilities.Ray(Engine3D.MainCamera.Position.ToBVector(), dir), 100.0, out BEPUutilities.RayHit hit))
            {
                BEPUutilities.Vector3 loc = hit.Location;
                Target = GridVertex.FromXY(loc.X, loc.Y);
                Vector2 pos = Target.ToCartesianCoords2D();
                Entity.SetPosition(new Location(pos.X, pos.Y, game.Terrain.HeightMap[Target.U, Target.V] + 0.5));
                BasicUnitAction action = game.UnitController.SelectedAction;
                if (action != null)
                {
                    action.Update();
                    Rend.Color = action.AffectedVertices.Contains(Target) ? Color4F.Red : Color4F.Blue;
                }
                Rend.IsVisible = true;
            }
            else
            {
                Rend.IsVisible = false;
            }
        }
示例#2
0
        /// <summary>
        /// Fired when entity is spawned.
        /// </summary>
        public override void OnSpawn()
        {
            Health = MaxHealth;
            Energy = MaxEnergy;
            Game   game = Engine3D.Source as Game;
            double mul  = 0.866 * Size;

            // Build the renderable property
            Renderable = new EntitySimple3DRenderableModelProperty()
            {
                EntityModel    = game.Client.Models.Cylinder,
                Scale          = new Location(mul, mul, 2 * Size),
                DiffuseTexture = game.Client.Textures.White,
                Color          = Color4F.Blue
            };
            // Build the physics body property
            Body = new ClientEntityPhysicsProperty()
            {
                Shape = new EntityCylinderShape()
                {
                    FixedOrientation = true,
                    Height           = 2 * Size,
                    Radius           = 0.5 * Size
                },
                Mass = 0
            };
            // Add properties and set position
            Entity.AddProperties(Renderable, Body);
            Vector2 pos = Coords.ToCartesianCoords2D();

            Entity.SetPosition(new Location(pos.X, pos.Y, game.Terrain.HeightMap[Coords.U, Coords.V] + Size));
            // Update the UnitFaces array with this unit's occupied faces
            foreach (GridFace face in game.UnitController.OccupiedFaces(Size, Coords))
            {
                game.UnitFaces[face.U, face.V] = this;
            }
            Entity.OnTick += Tick;
        }