Ejemplo n.º 1
0
        /// <summary>
        /// Init Each Element of Collection According to StiLib Configuration, Custom Vision Stimulus Type and Parameters Object
        /// </summary>
        /// <param name="count"></param>
        /// <param name="vstype"></param>
        /// <param name="gd"></param>
        /// <param name="slconfig"></param>
        /// <param name="service"></param>
        /// <param name="path"></param>
        /// <param name="vspara"></param>
        public virtual void Init(int count, VSType vstype, GraphicsDevice gd, AssemblySettings slconfig, IServiceProvider service, string path, object vspara)
        {
            vsType temp = null;

            try
            {
                switch (vstype)
                {
                case VSType.Bar:
                    temp = new Bar(gd, slconfig, (BarPara)vspara) as vsType;
                    break;

                case VSType.Grating:
                    temp = new Grating(gd, slconfig, service, path, (GratingPara)vspara) as vsType;
                    break;

                case VSType.Image:
                    temp = new Image(gd, slconfig, service, path, (ImagePara)vspara) as vsType;
                    break;

                case VSType.Primitive:
                    temp = new Primitive(gd, slconfig, (PrimitivePara)vspara) as vsType;
                    break;

                case VSType.SLModel:
                    temp = new SLModel(gd, slconfig, service, path, (ModelPara)vspara) as vsType;
                    break;

                case VSType.SLQuad:
                    temp = new SLQuad(gd, slconfig, service, path, (Quad)vspara) as vsType;
                    break;

                case VSType.SLVideo:
                    temp = new SLVideo(gd, slconfig, service, path, (VideoPara)vspara) as vsType;
                    break;

                case VSType.Text:
                    temp = new Text(gd, slconfig, service, path, (TextPara)vspara) as vsType;
                    break;
                }

                Init(count, gd, temp);
            }
            catch (Exception e)
            {
                SLConstant.ShowException(e);
            }
        }
Ejemplo n.º 2
0
Archivo: Main.cs Proyecto: babaq/StiLib
        protected override void Initialize()
        {
            logger = new SLLogger();
            frameinfo = new FrameInfo();
            audio = new SLAudio(SLConfig["content"] + "StiLib", SLConfig["content"] + "SLMWB", SLConfig["content"] + "SLSWB", SLConfig["content"] + "SLSB");
            audio.Update();
            audio.StartBgMusic("BgMusic");

            BarPara bpara = BarPara.Default;
            bpara.width = 4.0f;
            bpara.height = 1.0f;
            bpara.BasePara.direction = 0.0f;
            bpara.BasePara.speed = 10.0f;
            bpara.BasePara.space = 10.0f;
            bpara.BasePara.center = new Vector3(-2.0f, -2.0f, 0.0f);
            bpara.BasePara.color = Color.SeaGreen;
            bar = new Bar(GraphicsDevice, SLConfig, bpara);

            GratingPara gpara = GratingPara.Default;
            gpara.shape = Shape.Circle;
            gpara.gratingtype = GratingType.Sinusoidal;
            gpara.BasePara.center = new Vector3(2.0f, 2.0f, 0.0f);
            gpara.lhcolor = Color.OrangeRed;
            gpara.rlcolor = new Color(0f, 1f, 0f, 1f);
            gpara.BasePara.diameter = 7.0f;
            gpara.sf = 0.5f;
            gpara.contrast = 0.8f;
            gpara.luminance = 0.3f;
            gpara.maskpara.BasePara.diameter = 1.2f;
            grating = new Grating(GraphicsDevice, Services, "Content", gpara);

            text = new Text(GraphicsDevice, Services, "Content", "Arial");
            image = new Image(GraphicsDevice, Services, "Content", "Turtle");
            quad = new SLQuad(GraphicsDevice, Services, "Content", "StiLib_Logo");
            model = new SLModel(GraphicsDevice, Services, "Content", "earth");
            video = new SLVideo(GraphicsDevice, Services, "Content", "Butterfly");

            point = new Primitive(GraphicsDevice, PrimitivePara.Default);
            circle = new Primitive(GraphicsDevice, PrimitivePara.Circle(5f, Color.Azure, false));
            disk = new Primitive(GraphicsDevice, PrimitivePara.Circle(0.3f, Color.DarkBlue, 4 * Vector3.UnitY,Color.DarkBlue, 100, true));
            cross = new Primitive(GraphicsDevice, PrimitivePara.Cross(3f, Color.Green, 4 * Vector3.UnitX));
            arrow = new Primitive(GraphicsDevice, PrimitivePara.Arrow(4f, Color.Red, -4 * Vector3.UnitX, 60f, 1f));
            radialcircle = new Primitive(GraphicsDevice, PrimitivePara.Circle(5f, new Color(0f, 0f, 0f, 0.5f),Vector3.Zero, new Color(0f, 0f, 0f, 0.0f),100,true));
            gaussian = new Primitive(GraphicsDevice, PrimitivePara.Gaussian(10, 1.5f, Color.Gray, Vector3.Zero));

            disk.Para.BasePara.space = 10;
            model.Para.BasePara.rotationspeed3D = Vector3.UnitY;
            model.ProjectionType = ProjectionType.Perspective;
            //model.globalCamera.NearPlane = 0.1f;

            CollectionPara cpara = CollectionPara.Default;
            cpara.BasePara.center = Vector3.UnitX * 5;
            cpara.CollectionCenter = new Vector3(2f, 3f, 0.0f);
            cpara.CollectionSpeed = new Vector3(0.02f, 0.03f, 0.0f);
            vsc = new VSCollection<Primitive>(50, GraphicsDevice, cross, cpara);
            //vscp = new vscPrimitive(100, GraphicsDevice, disk, Services, "Content",cpara);

            timer = new SLTimer();
            timer.Start();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Optimized Batch Draw
        /// </summary>
        /// <param name="gd"></param>
        public virtual void BatchDraw(GraphicsDevice gd)
        {
            switch (Collection[0].VSType)
            {
            case VSType.Bar:
            case VSType.Primitive:
                PrimitiveType ptype  = Collection[0].BasePara.primitivetype;
                int           vexn   = Collection[0].VertexArray.Length;
                int           pcount = VisionStimulus.CheckPrimitiveCount(ptype, Collection[0].IndexArray.Length, Collection[0].IndexArray.Length);

                gd.VertexDeclaration = Collection[0].vertexDeclaration;
                gd.Vertices[0].SetSource(Collection[0].vertexBuffer, 0, VertexPositionColor.SizeInBytes);
                gd.Indices = Collection[0].indexBuffer;
                gd.RenderState.CullMode = CullMode.None;

                // Begin Draw
                Collection[0].basicEffect.Begin();
                Collection[0].basicEffect.CurrentTechnique.Passes[0].Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        Collection[0].basicEffect.World = Collection[i].Ori3DMatrix * Collection[i].WorldMatrix;
                        Collection[0].basicEffect.CommitChanges();
                        gd.DrawIndexedPrimitives(ptype, 0, 0, vexn, 0, pcount);
                    }
                }
                Collection[0].basicEffect.CurrentTechnique.Passes[0].End();
                Collection[0].basicEffect.End();
                break;

            case VSType.Grating:
                ptype  = Collection[0].BasePara.primitivetype;
                vexn   = Collection[0].VertexArray.Length;
                pcount = VisionStimulus.CheckPrimitiveCount(ptype, Collection[0].IndexArray.Length, Collection[0].IndexArray.Length);

                gd.VertexDeclaration = Collection[0].vertexDeclaration;
                gd.Vertices[0].SetSource(Collection[0].vertexBuffer, 0, VertexPositionColor.SizeInBytes);
                gd.Indices = Collection[0].indexBuffer;
                gd.RenderState.CullMode = CullMode.None;

                Grating grating = Collection[0] as Grating;
                // Begin Draw
                grating.gratingeffect.Begin();
                grating.gratingeffect.CurrentTechnique.Passes[0].Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        grating.eWorld.SetValue(Collection[i].Ori3DMatrix * Collection[i].WorldMatrix);
                        grating.gratingeffect.CommitChanges();
                        gd.DrawIndexedPrimitives(ptype, 0, 0, vexn, 0, pcount);
                    }
                }
                grating.gratingeffect.CurrentTechnique.Passes[0].End();
                grating.gratingeffect.End();
                break;

            case VSType.Image:
                Vector3 Center;
                float   unitFactor = Collection[0].unitFactor;
                Image   image      = Collection[0] as Image;
                // Begin Draw
                image.spriteBatch.Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        Center = Collection[i].Center;
                        image.spriteBatch.Draw(image.texture, new Vector2(Center.X * unitFactor + gd.Viewport.Width / 2 - image.texture.Width / 2, gd.Viewport.Height / 2 - Center.Y * unitFactor - image.texture.Height / 2), Collection[i].BasePara.color);
                    }
                }
                image.spriteBatch.End();
                break;

            case VSType.SLModel:
                SLModel model = Collection[0] as SLModel;
                foreach (ModelMesh mesh in model.Model.Meshes)
                {
                    for (int i = 0; i < Collection.Count; i++)
                    {
                        if (Collection[i].Visible)
                        {
                            foreach (BasicEffect effect in mesh.Effects)
                            {
                                effect.EnableDefaultLighting();
                                effect.GraphicsDevice.RenderState.DepthBufferEnable = true;

                                effect.World      = Collection[i].Ori3DMatrix * model.BoneTransforms[mesh.ParentBone.Index] * Collection[i].WorldMatrix;
                                effect.View       = model.ViewMatrix;
                                effect.Projection = model.ProjectionMatrix;
                            }
                            mesh.Draw();
                        }
                    }
                }
                break;

            case VSType.SLQuad:
                SLQuad quad = Collection[0] as SLQuad;
                ptype  = Collection[0].BasePara.primitivetype;
                vexn   = quad.Para.vertices.Length;
                pcount = VisionStimulus.CheckPrimitiveCount(ptype, Collection[0].IndexArray.Length, Collection[0].IndexArray.Length);

                gd.VertexDeclaration = quad.vertexDeclaration;
                gd.Vertices[0].SetSource(quad.vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                gd.Indices = quad.indexBuffer;
                gd.RenderState.CullMode         = CullMode.None;
                gd.RenderState.AlphaBlendEnable = true;
                gd.RenderState.AlphaTestEnable  = true;
                gd.RenderState.AlphaFunction    = CompareFunction.Greater;

                // Begin Draw
                quad.basicEffect.Begin();
                quad.basicEffect.CurrentTechnique.Passes[0].Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        quad.basicEffect.World = Collection[i].Ori3DMatrix * Collection[i].WorldMatrix;
                        quad.basicEffect.CommitChanges();
                        gd.DrawIndexedPrimitives(ptype, 0, 0, vexn, 0, pcount);
                    }
                }
                quad.basicEffect.CurrentTechnique.Passes[0].End();
                quad.basicEffect.End();
                break;

            case VSType.SLVideo:
                SLVideo video = Collection[0] as SLVideo;
                unitFactor = Collection[0].unitFactor;
                // Begin Draw
                video.spriteBatch.Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        Center = Collection[i].Center;
                        if (video.MediaState == MediaState.Stopped)
                        {
                            video.Play();
                        }
                        if (video.MediaState != MediaState.Stopped)
                        {
                            video.texture = video.Player.GetTexture();
                        }
                        if (video.texture != null)
                        {
                            video.spriteBatch.Draw(video.texture, new Vector2(Center.X * unitFactor + gd.Viewport.Width / 2 - video.texture.Width / 2, gd.Viewport.Height / 2 - Center.Y * unitFactor - video.texture.Height / 2), Collection[i].BasePara.color);
                        }
                    }
                }
                video.spriteBatch.End();
                break;

            case VSType.Text:
                Text    text = Collection[0] as Text;
                Vector2 size = text.spriteFont.MeasureString(SLConstant.Help);
                unitFactor = Collection[0].unitFactor;
                // Begin Draw
                text.spriteBatch.Begin();
                for (int i = 0; i < Collection.Count; i++)
                {
                    if (Collection[i].Visible)
                    {
                        Center = Collection[i].Center;
                        text.spriteBatch.DrawString(text.spriteFont, SLConstant.Help, new Vector2(Center.X * unitFactor + gd.Viewport.Width / 2 - size.X / 2, gd.Viewport.Height / 2 - Center.Y * unitFactor - size.Y / 2), Collection[i].BasePara.color);
                    }
                }
                text.spriteBatch.End();
                break;
            }
        }