/// <summary> /// 値を複製セットする /// </summary> /// <param name="r"></param> public void Set(MCDrawSpriteBase r) { IsBillbord = r.IsBillbord; IsBillbordConstX = r.IsBillbordConstX; IsBillbordConstY = r.IsBillbordConstY; BlendState = r.BlendState; Flip = r.Flip; m_anchor = r.m_anchor; m_angle = r.m_angle; m_scale = r.m_scale; m_position = r.m_position; m_BVSphere = r.m_BVSphere; m_visible = r.m_visible; }
/// <summary> /// 任意の頂点型 pV に、頂点、UV、色のデータ化rあ作り渡す /// </summary> /// <param name="flip">フリップフラグ</param> /// <param name="sX">開始 X</param> /// <param name="sY">開始 Y</param> /// <param name="eX">終了 X</param> /// <param name="eY">終了 Y</param> /// <param name="sU">開始 U</param> /// <param name="sV">開始 V</param> /// <param name="eU">終了 U</param> /// <param name="eV">終了 V</param> /// <param name="aColor">4頂点分の色ポインタ(配列)</param> /// <param name="pV">任意の頂点型で、上記パラメータにより作られる</param> unsafe private void Sprite_V3_UV_Color( SPRITE_FLIP flip, float sX, float sY, float eX, float eY, float sU, float sV, float eU, float eV, Color4[] aColor, MC_VERTEX_PCTx *pV) { if (aColor == null) { throw new Exception(nameof(aColor)); } UV[] aUV = new UV[4]; Color4[] aTmpC = new Color4[4]; // 位置 pV[0].p.X = sX; pV[0].p.Y = sY; pV[0].p.Z = 0.0f; pV[1].p.X = sX; pV[1].p.Y = eY; pV[1].p.Z = 0.0f; pV[2].p.X = eX; pV[2].p.Y = sY; pV[2].p.Z = 0.0f; pV[3].p.X = eX; pV[3].p.Y = eY; pV[3].p.Z = 0.0f; // UV . ディフェーズ色 // 回転 if ((flip & SPRITE_FLIP.R90) != 0) { aUV[0].u = sU; aUV[0].v = eV; aUV[1].u = eU; aUV[1].v = eV; aUV[2].u = sU; aUV[2].v = sV; aUV[3].u = eU; aUV[3].v = sV; aTmpC[0] = aColor[1]; aTmpC[1] = aColor[3]; aTmpC[2] = aColor[0]; aTmpC[3] = aColor[2]; } else if ((flip & SPRITE_FLIP.R180) != 0) { aUV[0].u = eU; aUV[0].v = eV; aUV[1].u = eU; aUV[1].v = sV; aUV[2].u = sU; aUV[2].v = eV; aUV[3].u = sU; aUV[3].v = sV; aTmpC[0] = aColor[3]; aTmpC[1] = aColor[2]; aTmpC[2] = aColor[1]; aTmpC[3] = aColor[0]; } else if ((flip & SPRITE_FLIP.R270) != 0) { aUV[0].u = eU; aUV[0].v = sV; aUV[1].u = sU; aUV[1].v = sV; aUV[2].u = eU; aUV[2].v = eV; aUV[3].u = sU; aUV[3].v = eV; aTmpC[0] = aColor[2]; aTmpC[1] = aColor[0]; aTmpC[2] = aColor[3]; aTmpC[3] = aColor[1]; } else { aUV[0].u = sU; aUV[0].v = sV; aUV[1].u = sU; aUV[1].v = eV; aUV[2].u = eU; aUV[2].v = sV; aUV[3].u = eU; aUV[3].v = eV; for (int i = 0; i < 4; ++i) { aTmpC[i] = aColor[i]; } } SPRITE_FLIP tempFlip = flip & SPRITE_FLIP.V_H; if (tempFlip == SPRITE_FLIP.HORIZONTAL) { //-------------- // 左右反転 //-------------- pV[0].u = aUV[2].u; pV[0].v = aUV[2].v; pV[1].u = aUV[3].u; pV[1].v = aUV[3].v; pV[2].u = aUV[0].u; pV[2].v = aUV[0].v; pV[3].u = aUV[1].u; pV[3].v = aUV[1].v; // ディフェーズ色 pV[2].c = aTmpC[0]; pV[3].c = aTmpC[1]; pV[0].c = aTmpC[2]; pV[1].c = aTmpC[3]; } else if (tempFlip == SPRITE_FLIP.VERTICAL) { //-------------- // 上下反転 //-------------- pV[0].u = aUV[1].u; pV[0].v = aUV[1].v; pV[1].u = aUV[0].u; pV[1].v = aUV[0].v; pV[2].u = aUV[3].u; pV[2].v = aUV[3].v; pV[3].u = aUV[2].u; pV[3].v = aUV[2].v; // ディフェーズ色 pV[1].c = aTmpC[0]; pV[0].c = aTmpC[1]; pV[3].c = aTmpC[2]; pV[2].c = aTmpC[3]; } else if (tempFlip == SPRITE_FLIP.V_H) { //-------------- // 上下左右反転 //-------------- pV[0].u = aUV[3].u; pV[0].v = aUV[3].v; pV[1].u = aUV[2].u; pV[1].v = aUV[2].v; pV[2].u = aUV[1].u; pV[2].v = aUV[1].v; pV[3].u = aUV[0].u; pV[3].v = aUV[0].v; // ディフェーズ色 pV[3].c = aTmpC[0]; pV[2].c = aTmpC[1]; pV[1].c = aTmpC[2]; pV[0].c = aTmpC[3]; } else { //-------------- // 通常 //-------------- pV[0].u = aUV[0].u; pV[0].v = aUV[0].v; pV[1].u = aUV[1].u; pV[1].v = aUV[1].v; pV[2].u = aUV[2].u; pV[2].v = aUV[2].v; pV[3].u = aUV[3].u; pV[3].v = aUV[3].v; // ディフェーズ色 pV[0].c = aTmpC[0]; pV[1].c = aTmpC[1]; pV[2].c = aTmpC[2]; pV[3].c = aTmpC[3]; } }
/// <summary> /// スプライト頂点データを更新する /// </summary> /// <param name="drawSprite"></param> /// <returns></returns> public int VertexUpdate( MCDrawSquareAmountSprite drawSprite ) { int dwTmp; var pSprite = drawSprite.Sprite; int divNo = drawSprite.DivNo; float startX, startY, midX, midY, endX, endY; float startU, startV, midU, midV, endU, endV; float factorU, factorV; startX = pSprite.Anchor.X; // -0.5f; startY = pSprite.Anchor.Y; // +0.5f; if (pSprite.flags.SpriteType == (uint)MC_SPRITE_DATA.SIMPLE) { endX = pSprite.Width + startX; endY = -(pSprite.Height - startY); startU = pSprite.spl.StartU; startV = pSprite.spl.StartV; endU = pSprite.spl.EndU; endV = pSprite.spl.EndV; } else { endX = (pSprite.div.DivW_U * pSprite.Width) + startX; endY = -((pSprite.div.DivH_V * pSprite.Height) - startY); if (pSprite.div.Col == 0) { factorV = (1.0f / pSprite.div.Row); startU = 0.0f; startV = factorV * divNo; endU = 1.0f; endV = startV + factorV; } else if (pSprite.div.Row == 0) { factorU = (1.0f / pSprite.div.Col); startU = factorU * divNo; startV = 0.0f; endU = startU + factorU; endV = 1.0f; } else { dwTmp = divNo % pSprite.div.Col; startU = pSprite.div.DivW_U * dwTmp; dwTmp = divNo / pSprite.div.Col; startV = pSprite.div.DivH_V * dwTmp; endU = startU + pSprite.div.DivW_U; endV = startV + pSprite.div.DivH_V; } } midX = (startX + endX) * 0.5f; midY = (startY + endY) * 0.5f; midU = (startU + endU) * 0.5f; midV = (startV + endV) * 0.5f; //------------------------- // 中間色の作成 //------------------------- var aColor = drawSprite.Colors; Color4[] aMidColor = new Color4[5]; aMidColor[0] = Color4.Lerp(aColor[0], aColor[1], 0.5f); aMidColor[1] = Color4.Lerp(aColor[1], aColor[2], 0.5f); aMidColor[2] = Color4.Lerp(aColor[2], aColor[3], 0.5f); aMidColor[3] = Color4.Lerp(aColor[3], aColor[4], 0.5f); aMidColor[4] = Color4.Lerp(aMidColor[0], aMidColor[2], 0.5f); //------------------------------ // 頂点情報 // // 7--0--1 // | | | // 6--8--2 // | | | // 5--4--3 //------------------------------ MC_VERTEX_PCTx[] aV = new MC_VERTEX_PCTx[] { new MC_VERTEX_PCTx(new MCVector3(midX, startY, 0), aMidColor[0], midU, startV), // 0 new MC_VERTEX_PCTx(new MCVector3(endX, startY, 0), aColor[1], endU, startV), // 1 new MC_VERTEX_PCTx(new MCVector3(endX, midY, 0), aMidColor[1], endU, midV), // 2 new MC_VERTEX_PCTx(new MCVector3(endX, endY, 0), aColor[2], endU, endV), // 3 new MC_VERTEX_PCTx(new MCVector3(midX, endY, 0), aMidColor[2], midU, endV), // 4 new MC_VERTEX_PCTx(new MCVector3(startX, endY, 0), aColor[3], startU, endV), // 5 new MC_VERTEX_PCTx(new MCVector3(startX, midY, 0), aMidColor[3], startU, midV), // 6 new MC_VERTEX_PCTx(new MCVector3(startX, startY, 0), aColor[0], startU, startV), // 7 new MC_VERTEX_PCTx(new MCVector3(midX, midY, 0), aMidColor[4], midU, midV), // 8 new MC_VERTEX_PCTx(new MCVector3(midX, startY, 0), aMidColor[0], midU, startV), // 9(0), }; Action <int> SG_UV_C_9_SET = (_idx) => { aV[_idx].u = midU; aV[_idx].v = startV; aV[_idx].c = aMidColor[0]; }; Action <int> SG_UV_C_0_SET = (_idx) => { aV[_idx].u = midU; aV[_idx].v = startV; aV[_idx].c = aMidColor[0]; }; Action <int> SG_UV_C_1_SET = (_idx) => { aV[_idx].u = endU; aV[_idx].v = startV; aV[_idx].c = aColor[1]; }; Action <int> SG_UV_C_2_SET = (_idx) => { aV[_idx].u = endU; aV[_idx].v = midV; aV[_idx].c = aMidColor[1]; }; Action <int> SG_UV_C_3_SET = (_idx) => { aV[_idx].u = endU; aV[_idx].v = endV; aV[_idx].c = aColor[2]; }; Action <int> SG_UV_C_4_SET = (_idx) => { aV[_idx].u = midU; aV[_idx].v = endV; aV[_idx].c = aMidColor[2]; }; Action <int> SG_UV_C_5_SET = (_idx) => { aV[_idx].u = startU; aV[_idx].v = endV; aV[_idx].c = aColor[3]; }; Action <int> SG_UV_C_6_SET = (_idx) => { aV[_idx].u = startU; aV[_idx].v = midV; aV[_idx].c = aMidColor[3]; }; Action <int> SG_UV_C_7_SET = (_idx) => { aV[_idx].u = startU; aV[_idx].v = midV; aV[_idx].c = aColor[0]; }; Action <int> SG_UV_C_8_SET = (_idx) => { aV[_idx].u = midU; aV[_idx].v = midV; aV[_idx].c = aMidColor[4]; }; // 回転 if ((drawSprite.Flip & SPRITE_FLIP.R90) != 0) { SG_UV_C_2_SET(9); SG_UV_C_2_SET(0); SG_UV_C_3_SET(1); SG_UV_C_4_SET(2); SG_UV_C_5_SET(3); SG_UV_C_6_SET(4); SG_UV_C_7_SET(5); SG_UV_C_0_SET(6); SG_UV_C_1_SET(7); } else if ((drawSprite.Flip & SPRITE_FLIP.R180) != 0) { SG_UV_C_4_SET(9); SG_UV_C_4_SET(0); SG_UV_C_5_SET(1); SG_UV_C_6_SET(2); SG_UV_C_7_SET(3); SG_UV_C_0_SET(4); SG_UV_C_1_SET(5); SG_UV_C_2_SET(6); SG_UV_C_3_SET(7); } else if ((drawSprite.Flip & SPRITE_FLIP.R270) != 0) { SG_UV_C_6_SET(9); SG_UV_C_6_SET(0); SG_UV_C_7_SET(1); SG_UV_C_0_SET(2); SG_UV_C_1_SET(3); SG_UV_C_2_SET(4); SG_UV_C_3_SET(5); SG_UV_C_4_SET(6); SG_UV_C_5_SET(7); } SPRITE_FLIP tempFlip = (SPRITE_FLIP)(drawSprite.Flip & SPRITE_FLIP.V_H); Color4 tmpColor; float tmpUV; Action <int, int> SG_UV_C_SWAP = (_idx1, _idx2) => { tmpUV = aV[_idx2].u; aV[_idx2].u = aV[_idx1].u; aV[_idx1].u = tmpUV; tmpUV = aV[_idx2].v; aV[_idx2].v = aV[_idx1].v; aV[_idx1].v = tmpUV; tmpColor = aV[_idx2].c; aV[_idx2].c = aV[_idx1].c; aV[_idx1].c = tmpColor; }; if (tempFlip == SPRITE_FLIP.HORIZONTAL) { //-------------- // 左右反転 //-------------- SG_UV_C_SWAP(7, 1); SG_UV_C_SWAP(6, 2); SG_UV_C_SWAP(5, 3); } else if (tempFlip == SPRITE_FLIP.VERTICAL) { //-------------- // 上下反転 //-------------- SG_UV_C_SWAP(7, 5); SG_UV_C_SWAP(0, 4); SG_UV_C_4_SET(9); SG_UV_C_SWAP(1, 3); } else if (tempFlip == SPRITE_FLIP.V_H) { //-------------- // 上下左右反転 //-------------- SG_UV_C_SWAP(7, 3); SG_UV_C_SWAP(0, 4); SG_UV_C_4_SET(9); SG_UV_C_SWAP(1, 5); SG_UV_C_SWAP(6, 2); } // 頂点の変形 VertexTransformation(drawSprite, aV); DataStream MappedResource; var box = App.ImmediateContext.MapSubresource( m_vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out MappedResource); unsafe { var pV = (MC_VERTEX_PCTx *)MappedResource.DataPointer; for (int i = 0; i < VERTEX_NUM; ++i) { pV[i].Set(aV[i].p, aV[i].c, aV[i].u, aV[i].v); } } App.ImmediateContext.UnmapSubresource(m_vertexBuffer, 0); return(0); }