⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mesh.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Mesh.java * Copyright (C) 2003 * * $Id: Mesh.java,v 1.10 2005/05/08 00:42:22 cawe Exp $ *//* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package jake2.render.jogl;import jake2.Defines;import jake2.client.VID;import jake2.client.entity_t;import jake2.qcommon.qfiles;import jake2.render.image_t;import jake2.util.Math3D;import java.nio.FloatBuffer;import net.java.games.jogl.GL;import net.java.games.jogl.util.BufferUtils;/** * Mesh *  * @author cwei */public abstract class Mesh extends Light {    // g_mesh.c: triangle model functions    /*     * =============================================================     *      * ALIAS MODELS     *      * =============================================================     */    static final int NUMVERTEXNORMALS = 162;    float[][] r_avertexnormals = Anorms.VERTEXNORMALS;    float[][] s_lerped = new float[qfiles.MAX_VERTS][4];    float[] shadevector = { 0, 0, 0 };    float[] shadelight = { 0, 0, 0 };    // precalculated dot products for quantized angles    static final int SHADEDOT_QUANT = 16;    float[][] r_avertexnormal_dots = Anorms.VERTEXNORMAL_DOTS;    float[] shadedots = r_avertexnormal_dots[0];    void GL_LerpVerts(int nverts, int[] ov, int[] v,            float[][] lerp, float[] move, float[] frontv, float[] backv) {        int i;        int lerpIndex = 0;                int ovv, vv;        //PMM -- added RF_SHELL_DOUBLE, RF_SHELL_HALF_DAM        if ((currententity.flags & (Defines.RF_SHELL_RED                | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE                | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {            float[] normal;            for (i = 0; i < nverts; i++ /* , v++, ov++, lerp+=4 */            ) {                vv = v[i];                normal = r_avertexnormals[(vv >>> 24) & 0xFF];                ovv = ov[i];                lerp[i][0] = move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF)                        * frontv[0] + normal[0] * Defines.POWERSUIT_SCALE;                lerp[i][1] = move[1] + ((ovv >>> 8) & 0xFF) * backv[1] + ((vv >>> 8) & 0xFF)                        * frontv[1] + normal[1] * Defines.POWERSUIT_SCALE;                lerp[i][2] = move[2] + ((ovv >>> 16) & 0xFF) * backv[2] + ((vv >>> 16) & 0xFF)                        * frontv[2] + normal[2] * Defines.POWERSUIT_SCALE;            }        } else {            for (i = 0; i < nverts; i++ /* , v++, ov++, lerp+=4 */            ) {                vv = v[i];                ovv = ov[i];                lerp[i][0] = move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF)                        * frontv[0];                lerp[i][1] = move[1] + ((ovv >>> 8) & 0xFF) * backv[1] + ((vv >>> 8) & 0xFF)                        * frontv[1];                lerp[i][2] = move[2] + ((ovv >>> 16) & 0xFF) * backv[2] + ((vv >>> 16) & 0xFF)                        * frontv[2];            }        }    }    void GL_LerpVerts(int nverts, int[] ov, int[] v, float[] move,            float[] frontv, float[] backv) {        int lerpIndex = 0;        int ovv, vv;        FloatBuffer lerp = vertexArrayBuf;        //PMM -- added RF_SHELL_DOUBLE, RF_SHELL_HALF_DAM        if ((currententity.flags & (Defines.RF_SHELL_RED                | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE                | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {            float[] normal;            int j = 0;            for (int i = 0; i < nverts; i++ /* , v++, ov++, lerp+=4 */            ) {                vv = v[i];                normal = r_avertexnormals[(v[i] >>> 24) & 0xFF];                ovv = ov[i];                lerp.put(j, move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF) * frontv[0]                        + normal[0] * Defines.POWERSUIT_SCALE);                lerp.put(j + 1, move[1] + ((ovv >>> 8) & 0xFF) * backv[1] + ((vv >>> 8) & 0xFF) * frontv[1]                        + normal[1] * Defines.POWERSUIT_SCALE);                lerp.put(j + 2, move[2] + ((ovv >>> 16) & 0xFF) * backv[2] + ((vv >>> 16) & 0xFF) * frontv[2]                        + normal[2] * Defines.POWERSUIT_SCALE);                j += 3;            }        } else {            int j = 0;            for (int i = 0; i < nverts; i++ /* , v++, ov++, lerp+=4 */            ) {                ovv = ov[i];                vv = v[i];                lerp.put(j, move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF) * frontv[0]);                lerp.put(j + 1, move[1] + ((ovv >>> 8) & 0xFF) * backv[1] + ((vv >>> 8) & 0xFF) * frontv[1]);                lerp.put(j + 2, move[2] + ((ovv >>> 16) & 0xFF) * backv[2] + ((vv >>> 16) & 0xFF) * frontv[2]);                j += 3;            }        }    }    FloatBuffer colorArrayBuf = BufferUtils            .newFloatBuffer(qfiles.MAX_VERTS * 4);    FloatBuffer vertexArrayBuf = BufferUtils            .newFloatBuffer(qfiles.MAX_VERTS * 3);    boolean isFilled = false;    float[] tmpVec = { 0, 0, 0 };    /*     * ============= GL_DrawAliasFrameLerp     *      * interpolates between two frames and origins FIXME: batch lerp all     * vertexes =============     */    void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, float backlerp) {        float l;        qfiles.daliasframe_t frame, oldframe;        int[] v, ov;        int[] order;        int orderIndex = 0;        int count;        float frontlerp;        float alpha;        float[] move = { 0, 0, 0 }; // vec3_t        float[][] vectors = { { 0, 0, 0 }, { 0, 0, 0 }, { 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[currententity.frame];        v = frame.verts;        oldframe = paliashdr.aliasFrames[currententity.oldframe];        ov = oldframe.verts;        order = paliashdr.glCmds;        if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0)            alpha = currententity.alpha;        else            alpha = 1.0f;        // PMM - added double shell        if ((currententity.flags & (Defines.RF_SHELL_RED                | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE                | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)            gl.glDisable(GL.GL_TEXTURE_2D);        frontlerp = 1.0f - backlerp;        // move should be the delta back to the previous frame * backlerp        Math3D.VectorSubtract(currententity.oldorigin, currententity.origin,                frontv);        Math3D.AngleVectors(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 (gl_vertex_arrays.value != 0.0f) {            GL_LerpVerts(paliashdr.num_xyz, ov, v, move, frontv, backv);            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);            gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArrayBuf);            // PMM - added double damage shell            if ((currententity.flags & (Defines.RF_SHELL_RED                    | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE                    | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {            	                gl.glDisableClientState(GL.GL_COLOR_ARRAY);                gl.glColor4f(shadelight[0], shadelight[1], shadelight[2], alpha);            } else {                gl.glEnableClientState(GL.GL_COLOR_ARRAY);                gl.glColorPointer(4, GL.GL_FLOAT, 0, colorArrayBuf);                //                // pre light everything                //                FloatBuffer color = colorArrayBuf;                int j = 0;                for (i = 0; i < paliashdr.num_xyz; i++) {                    // light normal index                    l = shadedots[(v[i] >>> 24) & 0xFF];                    color.put(j++, l * shadelight[0]);                    color.put(j++, l * shadelight[1]);                    color.put(j++, l * shadelight[2]);                    color.put(j++, alpha);                }            }            if (qglLockArraysEXT)                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;                    gl.glBegin(GL.GL_TRIANGLE_FAN);                } else {                    gl.glBegin(GL.GL_TRIANGLE_STRIP);                }                // PMM - added double damage shell                if ((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 );                         */                        gl.glArrayElement(index_xyz);                    } while (--count != 0);                } else {                    do {                        // texture coordinates come from the draw list                        gl.glTexCoord2f(Float                                .intBitsToFloat(order[orderIndex + 0]), Float                                .intBitsToFloat(order[orderIndex + 1]));                        index_xyz = order[orderIndex + 2];                        orderIndex += 3;                        // normals and vertexes come from the frame list                        gl.glArrayElement(index_xyz);                    } while (--count != 0);                }                gl.glEnd();            }            if (qglLockArraysEXT)                gl.glUnlockArraysEXT();        } else {            GL_LerpVerts(paliashdr.num_xyz, ov, v, 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;                    gl.glBegin(GL.GL_TRIANGLE_FAN);                } else {                    gl.glBegin(GL.GL_TRIANGLE_STRIP);                }                if ((currententity.flags & (Defines.RF_SHELL_RED                        | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE)) != 0) {                    do {                        index_xyz = order[orderIndex + 2];                        orderIndex += 3;                        gl.glColor4f(shadelight[0], shadelight[1],                                shadelight[2], alpha);                        tmp = s_lerped[index_xyz];                        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]);                        gl.glTexCoord2f(Float                                .intBitsToFloat(order[orderIndex + 0]), Float                                .intBitsToFloat(order[orderIndex + 1]));                        index_xyz = order[orderIndex + 2];                        orderIndex += 3;                        // normals and vertexes come from the frame list                        l = shadedots[(v[index_xyz] >>> 24) & 0xFF];                        gl.glColor4f(l * shadelight[0], l * shadelight[1], l                                * shadelight[2], alpha);                        tmp = s_lerped[index_xyz];                        gl.glVertex3f(tmp[0], tmp[1], tmp[2]);                    } while (--count != 0);                }                gl.glEnd();            }        }        // PMM - added double damage shell        if ((currententity.flags & (Defines.RF_SHELL_RED                | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE                | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)            gl.glEnable(GL.GL_TEXTURE_2D);    }    /*     * ============= GL_DrawAliasShadow =============     */    void GL_DrawAliasShadow(qfiles.dmdl_t paliashdr, int posenum) {        float[] point = { 0, 0, 0 };        int count;        qfiles.daliasframe_t frame;        float lheight = currententity.origin[2] - lightspot[2];        frame = paliashdr.aliasFrames[currententity.frame];        int[] order = paliashdr.glCmds;        float height = -lheight + 1.0f;        int orderIndex = 0;        int index = 0;        while (true) {            // get the vertex count and primitive type            count = order[orderIndex++];            if (count == 0)                break; // done            if (count < 0) {                count = -count;                gl.glBegin(GL.GL_TRIANGLE_FAN);            } else                gl.glBegin(GL.GL_TRIANGLE_STRIP);            do {                // normals and vertexes come from the frame list                /*                 * point[0] = verts[order[2]].v[0] * frame.scale[0] +

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -