コード例 #1
0
ファイル: QuadRender.cs プロジェクト: LeonXJ/Catsland-XNA
        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);
        }
コード例 #2
0
        public void SetObserve(CatTexture _texture)
        {
            m_texture = _texture;
            // test
            if (_texture.value == null)
            {
                textureBox.Image = new Bitmap(1, 1);
                return;
            }

            // copy from texture2D to bitmap
            int srcWidth  = _texture.value.Width;
            int srcHeight = _texture.value.Height;
            int resWidth  = textureBox.Width;
            int resHeight = textureBox.Height;

            Bitmap bitmap = new Bitmap(resWidth, resHeight);

            Byte4[] data = new Byte4[srcWidth * srcHeight];
            _texture.value.GetData <Byte4>(data);

            float jStep = (float)srcWidth / textureBox.Width;
            float iStep = (float)srcHeight / textureBox.Height;

            for (int i = 0; i < resHeight; ++i)
            {
                for (int j = 0; j < resWidth; ++j)
                {
                    Vector4 vec = data[(int)(i * iStep) * srcWidth + (int)(j * jStep)].ToVector4();
                    bitmap.SetPixel(j, i,
                                    System.Drawing.Color.FromArgb((int)(vec.W),
                                                                  (int)(vec.X),
                                                                  (int)(vec.Y),
                                                                  (int)(vec.Z)));
                }
            }

            textureBox.Image = bitmap;
        }