Beispiel #1
0
 /// <summary>
 /// Registers a callback for converting a <see cref="Render"/> component to an <see cref="Engine"/> representation.
 /// </summary>
 /// <typeparam name="TComponent">The specific type of <see cref="Render"/> component to handle.</typeparam>
 /// <param name="create">The callback for mapping a <see cref="Render"/> component to an <see cref="Engine"/> representation.</param>
 protected void RegisterRenderComponent <TComponent>(RenderCompononentToEngine <TComponent> create)
     where TComponent : Render
 {
     RenderablesSync.RegisterMultiple <Entity, PositionableRenderable>(
         element => element.TemplateData.Render.OfType <TComponent>().Select(component => create(element, component)),
         UpdateRepresentation);
 }
Beispiel #2
0
 /// <summary>
 /// Registers a callback for converting a <see cref="Water"/>s to <see cref="OmegaEngine.Graphics.Renderables.Water"/> representations.
 /// </summary>
 private void RegisterWater()
 {
     RenderablesSync.Register <Water, OmegaEngine.Graphics.Renderables.Water>(
         element =>
     {
         var representation = new OmegaEngine.Graphics.Renderables.Water(Engine, new SizeF(element.Size.X, element.Size.Y))
         {
             Name = element.Name,
             // NOTE: Height must be set before child views are initialized
             Position = Terrain.Position + new DoubleVector3(0, element.Height, 0)
         };
         representation.SetupChildViews(View);
         return(representation);
     },
         (element, representation) => representation.Position = Terrain.Position + element.EnginePosition);
 }
        public virtual void Click(MouseEventArgs e, bool accumulate)
        {
            #region Sanity checks
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            #endregion

            // Determine the Engine object the user clicked on
            DoubleVector3 intersectPosition;
            var           pickedObject = View.Pick(e.Location, out intersectPosition);
            if (pickedObject == null)
            {
                return;
            }

            switch (e.Button)
            {
            case MouseButtons.Left:
                if (pickedObject is Terrain)
                {     // Action: Left-click on terrain to select one nearby entity
                    PickPositionables(
                        Universe.Positionables.OfType <Entity>().Where(entity => entity.CollisionTest(intersectPosition.Flatten())).Take(1).Cast <Positionable <Vector2> >(),
                        accumulate);
                }
                else
                {     // Action: Left-click on entity to select it
                    try
                    {
                        PickPositionables(new[] { RenderablesSync.Lookup(pickedObject) }, accumulate);
                    }
                    catch (KeyNotFoundException)
                    {}
                }
                break;

            case MouseButtons.Right:
                if (SelectedPositionables.Count != 0 && pickedObject is OmegaEngine.Graphics.Renderables.Terrain)
                {     // Action: Right-click on terrain to move
                    // Depending on the actual presenter type this may invoke pathfinding or teleportation
                    MovePositionables(SelectedPositionables, intersectPosition.Flatten());
                }
                break;
            }
        }
        /// <inheritdoc/>
        protected override void RegisterRenderablesSync()
        {
            base.RegisterRenderablesSync();

            RenderablesSync.Register(
                (Waypoint waypoint) => new Model(XMesh.Get(Engine, "Engine/Waypoint.x"))
            {
                Scale = new Vector3(100)
            },
                UpdateRepresentation);
            RenderablesSync.Register(
                (Trigger trigger) =>
            {
                var area      = Model.Cylinder(Engine, XTexture.Get(Engine, "flag.png"), radiusBottom: trigger.Range, radiusTop: trigger.Range, length: 150);
                area.Rotation = Quaternion.RotationYawPitchRoll(0, (float)Math.PI / 2, 0);
                area.Alpha    = 160;
                return(area);
            },
                UpdateRepresentation);
        }