示例#1
0
        public void Draw(int timeLastFrame)
        {
            if (!Enable)
            {
                return;
            }

            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).ToString());

            Mgr <GraphicsDevice> .Singleton.SetVertexBuffer(m_vertexBuffer);

            // configure effect

            Effect effect = null;

            if (modelComponent != null && modelComponent.Model != null)
            {
                CatMaterial material = modelComponent.GetCatModelInstance().GetMaterial();
                material.SetParameter("World", new CatMatrix(m_gameObject.AbsTransform));
                material.SetParameter("View", new CatMatrix(Mgr <Camera> .Singleton.View));
                material.SetParameter("Projection", new CatMatrix(Mgr <Camera> .Singleton.m_projection));
                if (material.HasParameter("LightMap") && Mgr <Scene> .Singleton.m_shadowSystem != null)
                {
                    material.SetParameter("LightMap", new CatTexture(Mgr <Scene> .Singleton.m_shadowSystem.AccumulateLight));
                }
                effect = material.ApplyMaterial();
            }
            else
            {
                effect = Mgr <DebugTools> .Singleton.DrawEffect;
                ((BasicEffect)effect).Alpha              = 1.0f;
                ((BasicEffect)effect).DiffuseColor       = new Vector3(1.0f, 0.0f, 1.0f);
                ((BasicEffect)effect).View               = Mgr <Camera> .Singleton.View;
                ((BasicEffect)effect).Projection         = Mgr <Camera> .Singleton.m_projection;
                ((BasicEffect)effect).VertexColorEnabled = false;
                ((BasicEffect)effect).World              = m_gameObject.AbsTransform;
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Mgr <GraphicsDevice> .Singleton.DrawUserPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleStrip, m_vertex, 0, 2);
            }
        }
示例#2
0
        public void Draw(int timeLastFrame)
        {
            if (m_lifeInMS <= 0)
            {
                return;
            }

            // now just take it as basic effect
            Mgr <GraphicsDevice> .Singleton.SetVertexBuffer(m_emitter.m_vertexBuffer);

            ModelComponent modelComponent = (ModelComponent)m_emitter.GameObject.
                                            GetComponent(typeof(ModelComponent));
            Effect effect      = null;
            Matrix matPosition = Matrix.CreateTranslation(position);
            Matrix matRotation = Matrix.CreateRotationZ(m_rotationZ);
            Matrix matScale    = Matrix.CreateScale(m_size.X, m_size.Y, 1.0f);
            Matrix transform   = Matrix.Multiply(Matrix.Multiply(matScale, matRotation), matPosition);

            if (modelComponent != null && modelComponent.Model != null)
            {
                CatMaterial material = modelComponent.GetCatModelInstance().GetMaterial();
                material.SetParameter("Alpha", new CatFloat((float)m_lifeInMS / m_emitter.ParticleLifetimeInMS));
                material.SetParameter("World", new CatMatrix(transform));
                material.SetParameter("View", new CatMatrix(Mgr <Camera> .Singleton.View));
                material.SetParameter("Projection", new CatMatrix(Mgr <Camera> .Singleton.m_projection));
                effect = material.ApplyMaterial();
            }
            else
            {
                effect = Mgr <DebugTools> .Singleton.DrawEffect;
                ((BasicEffect)effect).Alpha              = (float)m_lifeInMS / m_emitter.ParticleLifetimeInMS;
                ((BasicEffect)effect).DiffuseColor       = new Vector3(1.0f, 0.0f, 1.0f);
                ((BasicEffect)effect).View               = Mgr <Camera> .Singleton.View;
                ((BasicEffect)effect).Projection         = Mgr <Camera> .Singleton.m_projection;
                ((BasicEffect)effect).VertexColorEnabled = false;
                ((BasicEffect)effect).World              = transform;
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Mgr <GraphicsDevice> .Singleton.DrawUserPrimitives <VertexPositionTexture>(
                    PrimitiveType.TriangleStrip, m_emitter.m_vertex, 0, 2);
            }
        }
示例#3
0
        public void Draw(int timeLastFrame)
        {
            if (!Enable)
            {
                return;
            }

            ModelComponent modelComponent = m_gameObject.GetComponent(
                typeof(ModelComponent).ToString()) as ModelComponent;
            GraphicsDevice gd = Mgr <GraphicsDevice> .Singleton;

            gd.SetVertexBuffer(m_vertexBuffer);
            Effect  effect        = null;
            Vector3 finalPosition = new Vector3(m_position.X - m_offset.X,
                                                m_position.Y - m_offset.Y,
                                                m_depth);

            if (modelComponent != null && modelComponent.Model != null)
            {
                CatMaterial material = modelComponent.GetCatModelInstance().GetMaterial();
                material.SetParameter("World", new CatMatrix(Matrix.CreateTranslation(
                                                                 finalPosition)));
                material.SetParameter("View", new CatMatrix(Matrix.Identity));
                material.SetParameter("Projection", new CatMatrix(Matrix.Identity));
                effect = material.ApplyMaterial();
            }
            else
            {
                effect = Mgr <DebugTools> .Singleton.DrawEffect;
                ((BasicEffect)effect).Alpha              = 1.0f;
                ((BasicEffect)effect).DiffuseColor       = new Vector3(1.0f, 0.0f, 1.0f);
                ((BasicEffect)effect).View               = Matrix.Identity;
                ((BasicEffect)effect).Projection         = Matrix.Identity;
                ((BasicEffect)effect).VertexColorEnabled = false;
                ((BasicEffect)effect).World              = Matrix.CreateTranslation(finalPosition);
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawUserPrimitives <VertexPositionTexture>(
                    PrimitiveType.TriangleStrip, m_vertex, 0, 2);
            }
        }
示例#4
0
        public void RunScript()
        {
            if (Mgr <CatProject> .Singleton == null)
            {
                return;
            }
            // ask for model
            string modelName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Model,
                                                                     "");

            if (modelName == "")
            {
                return;
            }
            CatModel model = Mgr <CatProject> .Singleton.modelList1.GetModel(modelName);

            if (model != null)
            {
                CatMaterial material = model.GetMaterial();
                if (material == null || !material.HasParameter("DiffuseMap"))
                {
                    // TODO: give warning
                    return;
                }
            }
            else
            {
                return;
            }
            // ask for texture
            string textureName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Texture,
                                                                       "");

            if (textureName == "")
            {
                return;
            }
            Texture2D texture = Mgr <CatProject> .Singleton.contentManger.Load <Texture2D>("image\\" + textureName);

            if (texture == null)
            {
                return;
            }

            GameObject newGameObject = new GameObject();

            if (Mgr <Camera> .Singleton != null)
            {
                newGameObject.Position = new Vector3(Mgr <Camera> .Singleton.TargetPosition.X,
                                                     Mgr <Camera> .Singleton.TargetPosition.Y,
                                                     0.0f);
            }
            else
            {
                newGameObject.Position = Vector3.Zero;
            }
            ModelComponent modelComponent = new ModelComponent(newGameObject);

            newGameObject.AddComponent(modelComponent);
            modelComponent.Model = model;
            modelComponent.GetCatModelInstance().GetMaterial().SetParameter("DiffuseMap",
                                                                            new CatTexture(texture));
            QuadRender quadRender = new QuadRender(newGameObject);

            newGameObject.AddComponent(quadRender);
            quadRender.OptimalSize = true;
            Mgr <Scene> .Singleton._gameObjectList.AddGameObject(newGameObject);
        }
示例#5
0
 public void SetObserve(CatMaterial _material)
 {
     m_material = _material;
     UpdateShowValue();
 }