コード例 #1
0
        /*
         * ============= GL_DrawAliasShadow =============
         */
        private void GL_DrawAliasShadow(dmdl_t paliashdr, int posenum)
        {
            float[] point = { 0, 0, 0 };
            int     count;
            var     lheight = this.currententity.origin[2] - this.lightspot[2];

            var order = paliashdr.glCmds;

            var height = -lheight + 1.0f;

            var orderIndex = 0;
            var index      = 0;

            while (true)
            {
                // get the vertex count and primitive type
                count = order[orderIndex++];

                if (count == 0)
                {
                    break;                     // done
                }
                if (count < 0)
                {
                    count = -count;
                    this.gl.glBegin(OpenGL.GL_TRIANGLE_FAN);
                }
                else
                {
                    this.gl.glBegin(OpenGL.GL_TRIANGLE_STRIP);
                }

                do
                {
                    // normals and vertexes come from the frame list

                    /*
                     * point[0] = verts[order[2]].v[0] * frame.scale[0] +
                     * frame.translate[0]; point[1] = verts[order[2]].v[1] *
                     * frame.scale[1] + frame.translate[1]; point[2] =
                     * verts[order[2]].v[2] * frame.scale[2] + frame.translate[2];
                     */

                    if (this.gl_vertex_arrays.value != 0.0f)
                    {
                        index    = order[orderIndex + 2] * 3;
                        point[0] = this.vertexArrayBuf[index];
                        point[1] = this.vertexArrayBuf[index + 1];
                        point[2] = this.vertexArrayBuf[index + 2];
                    }
                    else
                    {
                        Math3D.VectorCopy(this.s_lerped[order[orderIndex + 2]], point);
                    }

                    point[0] -= this.shadevector[0] * (point[2] + lheight);
                    point[1] -= this.shadevector[1] * (point[2] + lheight);
                    point[2]  = height;
                    this.gl.glVertex3f(point[0], point[1], point[2]);

                    orderIndex += 3;
                }while (--count != 0);

                this.gl.glEnd();
            }
        }
コード例 #2
0
        public virtual void Mod_LoadAliasModel(model_t mod, ByteBuffer buffer)
        {
            Int32 i;

            qfiles.dmdl_t          pheader;
            qfiles.dstvert_t[]     poutst;
            qfiles.dtriangle_t[]   pouttri;
            qfiles.daliasframe_t[] poutframe;
            Int32[] poutcmd;
            pheader = new dmdl_t(buffer);
            if (pheader.version != qfiles.ALIAS_VERSION)
            {
                Com.Error(Defines.ERR_DROP, "%s has wrong version number (%i should be %i)", mod.name, pheader.version, qfiles.ALIAS_VERSION);
            }
            if (pheader.skinheight > MAX_LBM_HEIGHT)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has a skin taller than " + MAX_LBM_HEIGHT);
            }
            if (pheader.num_xyz <= 0)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no vertices");
            }
            if (pheader.num_xyz > qfiles.MAX_VERTS)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has too many vertices");
            }
            if (pheader.num_st <= 0)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no st vertices");
            }
            if (pheader.num_tris <= 0)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no triangles");
            }
            if (pheader.num_frames <= 0)
            {
                Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no frames");
            }
            poutst          = new qfiles.dstvert_t[pheader.num_st];
            buffer.Position = pheader.ofs_st;
            for (i = 0; i < pheader.num_st; i++)
            {
                poutst[i] = new dstvert_t(buffer);
            }

            pouttri         = new qfiles.dtriangle_t[pheader.num_tris];
            buffer.Position = pheader.ofs_tris;
            for (i = 0; i < pheader.num_tris; i++)
            {
                pouttri[i] = new dtriangle_t(buffer);
            }

            poutframe       = new qfiles.daliasframe_t[pheader.num_frames];
            buffer.Position = pheader.ofs_frames;
            for (i = 0; i < pheader.num_frames; i++)
            {
                poutframe[i]       = new daliasframe_t(buffer);
                poutframe[i].verts = new Int32[pheader.num_xyz];
                for (var k = 0; k < pheader.num_xyz; k++)
                {
                    poutframe[i].verts[k] = buffer.GetInt32();
                }
            }

            mod.type        = mod_alias;
            poutcmd         = new Int32[pheader.num_glcmds];
            buffer.Position = pheader.ofs_glcmds;
            for (i = 0; i < pheader.num_glcmds; i++)
            {
                poutcmd[i] = buffer.GetInt32();
            }
            String[] skinNames = new String[pheader.num_skins];
            Byte[]   nameBuf   = new Byte[qfiles.MAX_SKINNAME];
            buffer.Position = pheader.ofs_skins;
            for (i = 0; i < pheader.num_skins; i++)
            {
                buffer.Get(nameBuf);
                skinNames[i] = Encoding.ASCII.GetString(nameBuf).Trim();
                mod.skins[i] = GL_FindImage(skinNames[i], it_skin);
            }

            pheader.skinNames   = skinNames;
            pheader.stVerts     = poutst;
            pheader.triAngles   = pouttri;
            pheader.glCmds      = poutcmd;
            pheader.aliasFrames = poutframe;
            mod.extradata       = pheader;
            mod.mins[0]         = -32;
            mod.mins[1]         = -32;
            mod.mins[2]         = -32;
            mod.maxs[0]         = 32;
            mod.maxs[1]         = 32;
            mod.maxs[2]         = 32;
        }
コード例 #3
0
        /*
         * ============= GL_DrawAliasFrameLerp
         *
         * interpolates between two frames and origins FIXME: batch lerp all
         * vertexes =============
         */
        private void GL_DrawAliasFrameLerp(dmdl_t paliashdr, float backlerp)
        {
            float         l;
            daliasframe_t frame, oldframe;

            int[] v, ov;

            int[] order;
            var   orderIndex = 0;
            int   count;

            float frontlerp;
            float alpha;

            float[] move = { 0, 0, 0 };             // vec3_t

            float[][] vectors =
            {
                new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }, new float[] { 0, 0, 0 }                 // 3 mal
                // vec3_t
            };

            float[] frontv = { 0, 0, 0 };            // vec3_t
            float[] backv  = { 0, 0, 0 };            // vec3_t

            int i;
            int index_xyz;

            //float[][] lerp;

            frame = paliashdr.aliasFrames[this.currententity.frame];

            v = frame.verts;

            oldframe = paliashdr.aliasFrames[this.currententity.oldframe];

            ov = oldframe.verts;

            order = paliashdr.glCmds;

            if ((this.currententity.flags & Defines.RF_TRANSLUCENT) != 0)
            {
                alpha = this.currententity.alpha;
            }
            else
            {
                alpha = 1.0f;
            }

            // PMM - added double shell
            if ((this.currententity.flags
                 & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM))
                != 0)
            {
                this.gl.glDisable(OpenGL.GL_TEXTURE_2D);
            }

            frontlerp = 1.0f - backlerp;

            // move should be the delta back to the previous frame * backlerp
            Math3D.VectorSubtract(this.currententity.oldorigin, this.currententity.origin, frontv);
            Math3D.AngleVectors(this.currententity.angles, vectors[0], vectors[1], vectors[2]);

            move[0] = Math3D.DotProduct(frontv, vectors[0]);             // forward
            move[1] = -Math3D.DotProduct(frontv, vectors[1]);            // left
            move[2] = Math3D.DotProduct(frontv, vectors[2]);             // up

            Math3D.VectorAdd(move, oldframe.translate, move);

            for (i = 0; i < 3; i++)
            {
                move[i]   = backlerp * move[i] + frontlerp * frame.translate[i];
                frontv[i] = frontlerp * frame.scale[i];
                backv[i]  = backlerp * oldframe.scale[i];
            }

            if (this.gl_vertex_arrays.value != 0.0f)
            {
                this.GL_LerpVerts(paliashdr.num_xyz, ov, v, move, frontv, backv);

                this.gl.glEnableClientState(OpenGL.GL_VERTEX_ARRAY);
                this.gl.glVertexPointer(3, 0, this.vertexArrayBuf);

                // PMM - added double damage shell
                if ((this.currententity.flags
                     & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM))
                    != 0)
                {
                    this.gl.glDisableClientState(OpenGL.GL_COLOR_ARRAY);
                    this.gl.glColor4f(this.shadelight[0], this.shadelight[1], this.shadelight[2], alpha);
                }
                else
                {
                    this.gl.glEnableClientState(OpenGL.GL_COLOR_ARRAY);
                    this.gl.glColorPointer(4, 0, this.colorArrayBuf);

                    //
                    // pre light everything
                    //
                    var color = this.colorArrayBuf;
                    var j     = 0;

                    for (i = 0; i < paliashdr.num_xyz; i++)
                    {
                        // light normal index
                        l          = this.shadedots[((uint)v[i] >> 24) & 0xFF];
                        color[j++] = l * this.shadelight[0];
                        color[j++] = l * this.shadelight[1];
                        color[j++] = l * this.shadelight[2];
                        color[j++] = alpha;
                    }
                }

                if (this.qglLockArraysEXT)
                {
                    this.gl.glLockArraysEXT(0, paliashdr.num_xyz);
                }

                while (true)
                {
                    // get the vertex count and primitive type
                    count = order[orderIndex++];

                    if (count == 0)
                    {
                        break;                         // done
                    }
                    if (count < 0)
                    {
                        count = -count;
                        this.gl.glBegin(OpenGL.GL_TRIANGLE_FAN);
                    }
                    else
                    {
                        this.gl.glBegin(OpenGL.GL_TRIANGLE_STRIP);
                    }

                    // PMM - added double damage shell
                    if ((this.currententity.flags
                         & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM))
                        != 0)
                    {
                        do
                        {
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;

                            /*
                             * vertexArrayBuf.position(4 * index_xyz);
                             * vertexArrayBuf.get(tmpVec); gl.glVertex3fv( tmpVec );
                             */
                            this.gl.glArrayElement(index_xyz);
                        }while (--count != 0);
                    }
                    else
                    {
                        do
                        {
                            // texture coordinates come from the draw list
                            this.gl.glTexCoord2f(
                                BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0]), 0),
                                BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1]), 0)
                                );

                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;

                            // normals and vertexes come from the frame list
                            this.gl.glArrayElement(index_xyz);
                        }while (--count != 0);
                    }

                    this.gl.glEnd();
                }

                if (this.qglLockArraysEXT)
                {
                    this.gl.glUnlockArraysEXT();
                }
            }
            else
            {
                this.GL_LerpVerts(paliashdr.num_xyz, ov, v, this.s_lerped, move, frontv, backv);

                float[] tmp;

                while (true)
                {
                    // get the vertex count and primitive type
                    count = order[orderIndex++];

                    if (count == 0)
                    {
                        break;                         // done
                    }
                    if (count < 0)
                    {
                        count = -count;
                        this.gl.glBegin(OpenGL.GL_TRIANGLE_FAN);
                    }
                    else
                    {
                        this.gl.glBegin(OpenGL.GL_TRIANGLE_STRIP);
                    }

                    if ((this.currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE)) != 0)
                    {
                        do
                        {
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;

                            this.gl.glColor4f(this.shadelight[0], this.shadelight[1], this.shadelight[2], alpha);
                            tmp = this.s_lerped[index_xyz];
                            this.gl.glVertex3f(tmp[0], tmp[1], tmp[2]);
                        }while (--count != 0);
                    }
                    else
                    {
                        do
                        {
                            // texture coordinates come from the draw list
                            // gl.glTexCoord2f (((float *)order)[0], ((float
                            // *)order)[1]);

                            this.gl.glTexCoord2f(
                                BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0]), 0),
                                BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1]), 0)
                                );

                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;

                            // normals and vertexes come from the frame list
                            l = this.shadedots[((uint)v[index_xyz] >> 24) & 0xFF];

                            this.gl.glColor4f(l * this.shadelight[0], l * this.shadelight[1], l * this.shadelight[2], alpha);
                            tmp = this.s_lerped[index_xyz];
                            this.gl.glVertex3f(tmp[0], tmp[1], tmp[2]);
                        }while (--count != 0);
                    }

                    this.gl.glEnd();
                }
            }

            // PMM - added double damage shell
            if ((this.currententity.flags
                 & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM))
                != 0)
            {
                this.gl.glEnable(OpenGL.GL_TEXTURE_2D);
            }
        }