예제 #1
0
 static s_mtrl()
 {
     default_mtrl = new s_mtrl();
     {
         default_mtrl.m_d = new float[4] {
             0.8f, 0.8f, 0.8f, 1.0f
         };
         default_mtrl.m_a = new float[4] {
             0.2f, 0.2f, 0.2f, 1.0f
         };
         default_mtrl.m_s = new float[4] {
             0.0f, 0.0f, 0.0f, 1.0f
         };
         default_mtrl.m_e = new float[4] {
             0.0f, 0.0f, 0.0f, 1.0f
         };
         default_mtrl.m_h = new float[1] {
             0.0f
         };
         default_mtrl.m_angle           = 0;
         default_mtrl.m_fl              = Solid.M_OPAQUE;
         default_mtrl.m_o               = 0;
         default_mtrl.m_TextureFileName = null;
     }
 }
예제 #2
0
        void fp_bv_i_rl_draw(s_file fp)
        {
            s_mtrl mp = s_mtrl.default_mtrl;

            mp = fp.sol_draw_body(this, mp, Solid.M_REFLECTIVE, 0);

            mp = s_mtrl.default_mtrl.sol_draw_mtrl(mp);
        }
예제 #3
0
        public void sol_bill(float[] M, float t)
        {
            s_mtrl mp = s_mtrl.default_mtrl;

            int ri;

            for (ri = 0; ri < m_rc; ++ri)
            {
                s_bill rp = m_rv[ri];

                float T = rp.m_t * t;
                float S = (float)System.Math.Sin(T);

                float w  = rp.m_w[0] + rp.m_w[1] * T + rp.m_w[2] * S;
                float h  = rp.m_h[0] + rp.m_h[1] * T + rp.m_h[2] * S;
                float rx = rp.m_rx[0] + rp.m_rx[1] * T + rp.m_rx[2] * S;
                float ry = rp.m_ry[0] + rp.m_ry[1] * T + rp.m_ry[2] * S;
                float rz = rp.m_rz[0] + rp.m_rz[1] * T + rp.m_rz[2] * S;

                mp = m_mv[rp.m_mi].sol_draw_mtrl(mp);

                Video.MODELVIEW_PushMatrix();
                {
                    Video.MODELVIEW_Translate(rp.m_p[0], rp.m_p[1], rp.m_p[2]);

                    if (M != null &&
                        ((rp.m_fl & Solid.B_NOFACE) == 0))
                    {
                        Video.MODELVIEW_MultMatrix(M);
                    }

                    if (System.Math.Abs(rx) > 0.0f)
                    {
                        Video.MODELVIEW_Rotate(rx, 1.0f, 0.0f, 0.0f);
                    }
                    if (System.Math.Abs(ry) > 0.0f)
                    {
                        Video.MODELVIEW_Rotate(ry, 0.0f, 1.0f, 0.0f);
                    }
                    if (System.Math.Abs(rz) > 0.0f)
                    {
                        Video.MODELVIEW_Rotate(rz, 0.0f, 0.0f, 1.0f);
                    }

                    Video.Begin(Video.TRIANGLE_FAN);//GL_QUADS);
                    {
                        Video.TexCoord2(0.0f, 0.0f); Video.Vertex2(-w / 2, -h / 2);
                        Video.TexCoord2(1.0f, 0.0f); Video.Vertex2(+w / 2, -h / 2);
                        Video.TexCoord2(1.0f, 1.0f); Video.Vertex2(+w / 2, +h / 2);
                        Video.TexCoord2(0.0f, 1.0f); Video.Vertex2(-w / 2, +h / 2);
                    }
                    Video.End();
                }
                Video.MODELVIEW_PopMatrix();
            }

            mp = s_mtrl.default_mtrl.sol_draw_mtrl(mp);
        }
예제 #4
0
        void fp_bv_i_tl_draw(s_file fp)
        {
            s_mtrl mp = s_mtrl.default_mtrl;

            mp = fp.sol_draw_body(this, mp, Solid.M_TRANSPARENT, Solid.M_DECAL);
            mp = fp.sol_draw_body(this, mp, Solid.M_TRANSPARENT, 0);

            mp = s_mtrl.default_mtrl.sol_draw_mtrl(mp);
        }
예제 #5
0
        public static void sol_load_mtrl(IntPtr fin, s_mtrl mp)
        {
            Binary.get_array(fin, mp.m_d, 4);
            Binary.get_array(fin, mp.m_a, 4);
            Binary.get_array(fin, mp.m_s, 4);
            Binary.get_array(fin, mp.m_e, 4);
            Binary.get_array(fin, mp.m_h, 1);
            Binary.get_index(fin, ref mp.m_fl);

            FileSystem.fs_read(ref mp.m_TextureFileName, Config.PATHMAX, fin);
        }
예제 #6
0
        public s_mtrl sol_back_bill(s_file fp, s_mtrl mp, float t)
        {
            float T = (m_t > 0.0f) ? (float)(System.Math.IEEERemainder(t, m_t) - m_t / 2) : 0.0f;

            float w = m_w[0] + m_w[1] * T + m_w[2] * T * T;
            float h = m_h[0] + m_h[1] * T + m_h[2] * T * T;

            if (w > 0 && h > 0)
            {
                float rx = m_rx[0] + m_rx[1] * T + m_rx[2] * T * T;
                float ry = m_ry[0] + m_ry[1] * T + m_ry[2] * T * T;
                float rz = m_rz[0] + m_rz[1] * T + m_rz[2] * T * T;

                Video.MODELVIEW_PushMatrix();
                {
                    float y0 = (m_fl & Solid.B_EDGE) != 0 ? 0 : -h / 2;
                    float y1 = (m_fl & Solid.B_EDGE) != 0 ? h : +h / 2;

                    Video.MODELVIEW_Rotate(ry, 0.0f, 1.0f, 0.0f);
                    Video.MODELVIEW_Rotate(rx, 1.0f, 0.0f, 0.0f);
                    Video.MODELVIEW_Translate(0.0f, 0.0f, -m_d);

                    if ((m_fl & Solid.B_FLAT) != 0)
                    {
                        Video.MODELVIEW_Rotate(-rx - 90.0f, 1.0f, 0.0f, 0.0f);
                        Video.MODELVIEW_Rotate(-ry, 0.0f, 0.0f, 1.0f);
                    }

                    if ((m_fl & Solid.B_EDGE) != 0)
                    {
                        Video.MODELVIEW_Rotate(-rx, 1.0f, 0.0f, 0.0f);
                    }

                    Video.MODELVIEW_Rotate(rz, 0.0f, 0.0f, 1.0f);

                    mp = fp.m_mv[m_mi].sol_draw_mtrl(mp);

                    Video.Begin(Video.TRIANGLE_FAN);
                    {
                        Video.TexCoord2(0.0f, 0.0f); Video.Vertex2(-w / 2, y0);
                        Video.TexCoord2(1.0f, 0.0f); Video.Vertex2(+w / 2, y0);
                        Video.TexCoord2(1.0f, 1.0f); Video.Vertex2(+w / 2, y1);
                        Video.TexCoord2(0.0f, 1.0f); Video.Vertex2(-w / 2, y1);
                    }
                    Video.End();
                }
                Video.MODELVIEW_PopMatrix();
            }

            return(mp);
        }
예제 #7
0
        void fp_bv_i_ol_draw(s_file fp)
        {
            //fp.bv[i].ol = Video.GenLists(1);

            //Video.NewList(fp.bv[i].ol, Video.COMPILE);
            {
                s_mtrl mp = s_mtrl.default_mtrl;

                mp = fp.sol_draw_body(this, mp, Solid.M_OPAQUE, 0);
                mp = fp.sol_draw_body(this, mp, Solid.M_OPAQUE, Solid.M_DECAL);

                mp = s_mtrl.default_mtrl.sol_draw_mtrl(mp);
            }
            //Video.EndList();
        }
예제 #8
0
        public s_mtrl sol_draw_body(s_body bp, s_mtrl mp, int fl, int decal)
        {
            int mi, li, gi;

            /* Iterate all materials of the correct opacity. */

            for (mi = 0; mi < m_mc; mi++)
            {
                if ((m_mv[mi].m_fl & fl) != 0 &&
                    (m_mv[mi].m_fl & Solid.M_DECAL) == decal)
                {
                    if (sol_enum_mtrl(bp, mi) != 0)
                    {
                        //  Set the material state.

                        mp = m_mv[mi].sol_draw_mtrl(mp);

                        /* Render all geometry of that material. */

                        Video.Begin(Video.TRIANGLES);
                        {
                            for (li = 0; li < bp.m_lc; li++)
                            {
                                sol_draw_lump(m_lv[bp.m_l0 + li], mi);
                            }

                            for (gi = 0; gi < bp.m_gc; gi++)
                            {
                                sol_draw_geom(m_gv[m_iv[bp.m_g0 + gi]], mi);
                            }
                        }
                        Video.End();
                    }
                }
            }

            return(mp);
        }
예제 #9
0
        public void sol_back(float n, float f, float t)
        {
            s_mtrl mp = s_mtrl.default_mtrl;

            //  Render all billboards in the given range.

            GL.Disable(EnableCap.Lighting);
            GL.DepthMask(false);
            {
                sol_back_OffsetZ = 0;
                for (int ri = 0; ri < m_rc; ri++)
                {
                    if (n <= m_rv[ri].m_d && m_rv[ri].m_d < f)
                    {
                        mp = m_rv[ri].sol_back_bill(this, mp, t);
                    }
                }

                mp = s_mtrl.default_mtrl.sol_draw_mtrl(mp);
            }
            GL.DepthMask(true);
            GL.Enable(EnableCap.Lighting);
        }
예제 #10
0
        public s_mtrl sol_draw_mtrl(s_mtrl mq)
        {
            /* Change material properties only as needed. */

            if (!color_cmp(m_a, mq.m_a))
            {
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, m_a);
            }
            if (!color_cmp(m_d, mq.m_d))
            {
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, m_d);
            }
            if (!color_cmp(m_s, mq.m_s))
            {
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, m_s);
            }
            if (!color_cmp(m_e, mq.m_e))
            {
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Emission, m_e);
            }
            if (tobyte(m_h[0]) != tobyte(mq.m_h[0]))
            {
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, m_h);
            }

            /* Bind the texture. */

            if (m_o != mq.m_o &&
                m_o != 0)
            {
                GL.BindTexture(TextureTarget.Texture2D, m_o);
            }

            /* Enable environment mapping. */

            if ((m_fl & Solid.M_ENVIRONMENT) != 0 && (mq.m_fl & Solid.M_ENVIRONMENT) == 0)
            {
                GL.Enable(EnableCap.TextureGenS);
                GL.Enable(EnableCap.TextureGenT);

                GL.TexGen(TextureCoordName.S, TextureGenParameter.TextureGenMode, (int)TextureGenMode.SphereMap);
                GL.TexGen(TextureCoordName.T, TextureGenParameter.TextureGenMode, (int)TextureGenMode.SphereMap);
            }

            /* Disable environment mapping. */

            if ((mq.m_fl & Solid.M_ENVIRONMENT) != 0 && (m_fl & Solid.M_ENVIRONMENT) == 0)
            {
                GL.Disable(EnableCap.TextureGenS);
                GL.Disable(EnableCap.TextureGenT);
            }

            /* Enable additive blending. */

            if ((m_fl & Solid.M_ADDITIVE) != 0 &&
                (mq.m_fl & Solid.M_ADDITIVE) == 0)
            {
                GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
            }

            /* Enable standard blending. */

            if ((mq.m_fl & Solid.M_ADDITIVE) != 0 && (m_fl & Solid.M_ADDITIVE) == 0)
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }

            /* Enable visibility-from-behind. */

            if ((m_fl & Solid.M_TWO_SIDED) != 0 && (mq.m_fl & Solid.M_TWO_SIDED) == 0)
            {
                GL.Disable(EnableCap.CullFace);
                GL.LightModel(LightModelParameter.LightModelTwoSide, 1);
            }

            /* Disable visibility-from-behind. */

            if ((mq.m_fl & Solid.M_TWO_SIDED) != 0 && (m_fl & Solid.M_TWO_SIDED) == 0)
            {
                GL.Enable(EnableCap.CullFace);
                GL.LightModel(LightModelParameter.LightModelTwoSide, 0);
            }

            /* Enable decal offset. */

            if ((m_fl & Solid.M_DECAL) != 0 && (mq.m_fl & Solid.M_DECAL) == 0)
            {
                GL.Enable(EnableCap.PolygonOffsetFill);
                Video.PolygonOffset(-1.0f, -2.0f);
            }

            /* Disable decal offset. */

            if ((mq.m_fl & Solid.M_DECAL) != 0 && (m_fl & Solid.M_DECAL) == 0)
            {
                GL.Disable(EnableCap.PolygonOffsetFill);
            }

            return(this);// mp;
        }