Beispiel #1
0
        private void setToOptimalSize()
        {
            // get model component and image size
            int            imageWidth     = 0;
            int            imageHeight    = 0;
            ModelComponent modelComponent =
                m_gameObject.GetComponent(typeof(ModelComponent).ToString()) as ModelComponent;
            CatModelInstance modelInstance = modelComponent.GetCatModelInstance();

            if (modelInstance == null || modelInstance.GetMaterial() == null)
            {
                return;
            }
            CatTexture texture = (CatTexture)(modelInstance.GetMaterial().GetParameter("DiffuseMap"));

            imageWidth  = texture.value.Width;
            imageHeight = texture.value.Height;

            if (modelComponent.Model.GetAnimation() != null)
            {
                imageWidth  /= modelComponent.Model.GetAnimation().m_tiltUV.X;
                imageHeight /= modelComponent.Model.GetAnimation().m_tiltUV.Y;
            }

            // get Camera Min Width
            float cameraMinWidth = Mgr <Camera> .Singleton.ViewSize.X;
            // get Screen Width
            float screenWidth = Mgr <Camera> .Singleton.targetResolutionWidth;

            // calculate optimalWidth
            Size = new Vector2(imageWidth * cameraMinWidth / screenWidth,
                               imageHeight * cameraMinWidth / screenWidth);
        }
Beispiel #2
0
        public override CatModelInstance GetModel()
        {
            ModelComponent modelComponent = (ModelComponent)m_gameObject
                                            .GetComponent(typeof(ModelComponent).ToString());

            return(modelComponent.GetCatModelInstance());
        }
Beispiel #3
0
        public override void Update(int timeLastFrame)
        {
            base.Update(timeLastFrame);

            Environment environment = m_gameObject.Scene.GetSharedObject(typeof(Environment).ToString())
                                      as Environment;
            ModelComponent modelComponent = m_gameObject.GetComponent(typeof(ModelComponent))
                                            as ModelComponent;

            if (environment != null && modelComponent != null &&
                modelComponent.GetCatModelInstance() != null &&
                modelComponent.GetCatModelInstance().GetMaterial().HasParameter("Time"))
            {
                modelComponent.GetCatModelInstance().GetMaterial()
                .SetParameter("Time", new CatFloat(environment.CurrentTimeInRatio));
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
        }