Exemplo n.º 1
0
        //プレイヤーの描画
        public void Draw()
        {
            if (ssbx_motiondata == null)
            {
                return;
            }

            //描画
            int nowframe = (int)frame_count;

            string str;

            str = string.Format("frame{0:D3}", nowframe);
            SSBX_FRAMEDATA ssbx_framedata = ssbx_motiondata.framedata[str];
            int            idx            = 0;

            for (idx = 0; idx < ssbx_framedata.framedata.Count; idx++)
            {
                str = string.Format("part{0:D3}", idx);
                SSBX_PARTDATA ssbx_partdata = ssbx_framedata.framedata[str];
                PART_STATE    state         = ssbx_partdata.partdata;


                //プレイヤーのステータスからマトリクスの変形を行う

/*
 *                              float[] mat = new float[16];
 *                              IdentityMatrix(mat);
 *                              TranslationMatrixM(mat, state.x, state.y, 0 );
 *                              TranslationMatrixM(mat, pos_x, pos_y, 0 );
 *                              RotationXYZMatrixM(mat, 0.0f, 0.0f, rot_z);
 *                              ScaleMatrixM(mat,scale_x,scale_y,1.0f);
 */
                //最終的な表示座標を取得
                state.x = pos_x + (state.x * scale_x);
                state.y = pos_y + (state.y * scale_y);

                if ((scale_x * scale_y) < 0)
                {
                    state.rotz = -state.rotz;
                }

                if (rot_z != 1.0f)
                {
                    state.rotz += rot_z;
                    get_rotation(ref state.x, ref state.y, pos_x, pos_y, rot_z);
                }

                //スプライトの描画
                sprite_draw(state);
            }
        }
Exemplo n.º 2
0
 public SSBX_PARTDATA(PART_STATE data)
 {
     this.partdata = data;
 }
Exemplo n.º 3
0
        private void sprite_draw(PART_STATE state)
        {
            if (state.tex_id == -1)
            {
                //NULLパーツ
                return;
            }
            float tex_w = tex[state.tex_id].Width;
            float tex_h = tex[state.tex_id].Height;
            float u1    = (float)state.rect_x / tex_w;
            float v1    = (float)state.rect_y / tex_h;
            float u2    = (float)(state.rect_x + state.rect_w) / tex_w;
            float v2    = (float)(state.rect_y + state.rect_h) / tex_h;

            float[] texcoords =
            {
                u1, v1,             // 0 top left.
                u1, v2,             // 1 bottom left.
                u2, v1,             // 2 top right.
                u2, v2,             // 3 bottom right.
            };
            if ((state.flip_x != 0) && (state.flip_y != 0))
            {
                texcoords[0] = u2;
                texcoords[1] = v2;
                texcoords[2] = u2;
                texcoords[3] = v1;
                texcoords[4] = u1;
                texcoords[5] = v2;
                texcoords[6] = u1;
                texcoords[7] = v1;
            }
            else if (state.flip_x != 0)
            {
                texcoords[0] = u2;
                texcoords[1] = v1;
                texcoords[2] = u2;
                texcoords[3] = v2;
                texcoords[4] = u1;
                texcoords[5] = v1;
                texcoords[6] = u1;
                texcoords[7] = v2;
            }
            else if (state.flip_y != 0)
            {
                texcoords[0] = u1;
                texcoords[1] = v2;
                texcoords[2] = u1;
                texcoords[3] = v1;
                texcoords[4] = u2;
                texcoords[5] = v2;
                texcoords[6] = u2;
                texcoords[7] = v1;
            }

            float[] colors =
            {
                1.0f, 1.0f, 1.0f, state.alpha *alpha,                      // 0 top left.
                1.0f, 1.0f, 1.0f, state.alpha *alpha,                      // 1 bottom left.
                1.0f, 1.0f, 1.0f, state.alpha *alpha,                      // 2 top right.
                1.0f, 1.0f, 1.0f, state.alpha *alpha,                      // 3 bottom right.
            };

            float w = (state.rect_w * state.scale_x * scale_x);
            float h = (state.rect_h * state.scale_y * scale_y);
            float x = (float)state.x - (w / 2.0f);
            float y = (float)state.y - (h / 2.0f);


            float[] vertices = new float[12];
            vertices[0] = x;              // x0
            vertices[1] = y;              // y0
            vertices[2] = 0.0f;           // z0
            get_rotation(ref vertices[0], ref vertices[1], (float)state.x, (float)state.y, state.rotz);

            vertices[3] = x;              // x1
            vertices[4] = y + h;          // y1
            vertices[5] = 0.0f;           // z1
            get_rotation(ref vertices[3], ref vertices[4], (float)state.x, (float)state.y, state.rotz);

            vertices[6] = x + w;          // x2
            vertices[7] = y;              // y2
            vertices[8] = 0.0f;           // z2
            get_rotation(ref vertices[6], ref vertices[7], (float)state.x, (float)state.y, state.rotz);

            vertices[9]  = x + w;            // x3
            vertices[10] = y + h;            // y3
            vertices[11] = 0.0f;             // z3
            get_rotation(ref vertices[9], ref vertices[10], (float)state.x, (float)state.y, state.rotz);


            vertexBuffer.SetVertices(0, vertices);
            vertexBuffer.SetVertices(1, texcoords);
            vertexBuffer.SetVertices(2, colors);

            vertexBuffer.SetIndices(indices);
            graphics.SetVertexBuffer(0, vertexBuffer);

            graphics.SetShaderProgram(shaderProgram);
            graphics.SetTexture(0, tex[state.tex_id]);
            shaderProgram.SetUniformValue(0, ref screenMatrix);

            //ブレンドファンクション
            switch (state.blend_func)
            {
            case 0:             //通常
                graphics.Enable(EnableMode.Blend, true);
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.One, BlendFuncFactor.OneMinusSrcAlpha);
                break;

            case 1:             //乗算
                graphics.Enable(EnableMode.Blend, true);
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.Zero, BlendFuncFactor.SrcColor);
                break;

            case 2:             //加算
                graphics.Enable(EnableMode.Blend, true);
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.One, BlendFuncFactor.One);
                break;

            case 3:             //減算
                graphics.Enable(EnableMode.Blend, true);
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.OneMinusSrcAlpha, BlendFuncFactor.OneMinusSrcColor);
                break;
            }
            graphics.DrawArrays(DrawMode.TriangleStrip, 0, indexSize);
        }