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

📄 warp.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Warp.java * Copyright (C) 2003 * * $Id: Warp.java,v 1.7 2005/01/16 15:24:50 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.fastjogl;import jake2.Defines;import jake2.Globals;import jake2.qcommon.Com;import jake2.render.*;import jake2.util.Math3D;import jake2.util.Vec3Cache;import net.java.games.jogl.GL;/** * Warp *  * @author cwei */public abstract class Warp extends Model {    // warpsin.h    public static final float[] SIN = { 0f, 0.19633f, 0.392541f, 0.588517f,            0.784137f, 0.979285f, 1.17384f, 1.3677f, 1.56072f, 1.75281f,            1.94384f, 2.1337f, 2.32228f, 2.50945f, 2.69512f, 2.87916f,            3.06147f, 3.24193f, 3.42044f, 3.59689f, 3.77117f, 3.94319f,            4.11282f, 4.27998f, 4.44456f, 4.60647f, 4.76559f, 4.92185f,            5.07515f, 5.22538f, 5.37247f, 5.51632f, 5.65685f, 5.79398f,            5.92761f, 6.05767f, 6.18408f, 6.30677f, 6.42566f, 6.54068f,            6.65176f, 6.75883f, 6.86183f, 6.9607f, 7.05537f, 7.14579f,            7.23191f, 7.31368f, 7.39104f, 7.46394f, 7.53235f, 7.59623f,            7.65552f, 7.71021f, 7.76025f, 7.80562f, 7.84628f, 7.88222f,            7.91341f, 7.93984f, 7.96148f, 7.97832f, 7.99036f, 7.99759f, 8f,            7.99759f, 7.99036f, 7.97832f, 7.96148f, 7.93984f, 7.91341f,            7.88222f, 7.84628f, 7.80562f, 7.76025f, 7.71021f, 7.65552f,            7.59623f, 7.53235f, 7.46394f, 7.39104f, 7.31368f, 7.23191f,            7.14579f, 7.05537f, 6.9607f, 6.86183f, 6.75883f, 6.65176f,            6.54068f, 6.42566f, 6.30677f, 6.18408f, 6.05767f, 5.92761f,            5.79398f, 5.65685f, 5.51632f, 5.37247f, 5.22538f, 5.07515f,            4.92185f, 4.76559f, 4.60647f, 4.44456f, 4.27998f, 4.11282f,            3.94319f, 3.77117f, 3.59689f, 3.42044f, 3.24193f, 3.06147f,            2.87916f, 2.69512f, 2.50945f, 2.32228f, 2.1337f, 1.94384f,            1.75281f, 1.56072f, 1.3677f, 1.17384f, 0.979285f, 0.784137f,            0.588517f, 0.392541f, 0.19633f, 9.79717e-16f, -0.19633f,            -0.392541f, -0.588517f, -0.784137f, -0.979285f, -1.17384f,            -1.3677f, -1.56072f, -1.75281f, -1.94384f, -2.1337f, -2.32228f,            -2.50945f, -2.69512f, -2.87916f, -3.06147f, -3.24193f, -3.42044f,            -3.59689f, -3.77117f, -3.94319f, -4.11282f, -4.27998f, -4.44456f,            -4.60647f, -4.76559f, -4.92185f, -5.07515f, -5.22538f, -5.37247f,            -5.51632f, -5.65685f, -5.79398f, -5.92761f, -6.05767f, -6.18408f,            -6.30677f, -6.42566f, -6.54068f, -6.65176f, -6.75883f, -6.86183f,            -6.9607f, -7.05537f, -7.14579f, -7.23191f, -7.31368f, -7.39104f,            -7.46394f, -7.53235f, -7.59623f, -7.65552f, -7.71021f, -7.76025f,            -7.80562f, -7.84628f, -7.88222f, -7.91341f, -7.93984f, -7.96148f,            -7.97832f, -7.99036f, -7.99759f, -8f, -7.99759f, -7.99036f,            -7.97832f, -7.96148f, -7.93984f, -7.91341f, -7.88222f, -7.84628f,            -7.80562f, -7.76025f, -7.71021f, -7.65552f, -7.59623f, -7.53235f,            -7.46394f, -7.39104f, -7.31368f, -7.23191f, -7.14579f, -7.05537f,            -6.9607f, -6.86183f, -6.75883f, -6.65176f, -6.54068f, -6.42566f,            -6.30677f, -6.18408f, -6.05767f, -5.92761f, -5.79398f, -5.65685f,            -5.51632f, -5.37247f, -5.22538f, -5.07515f, -4.92185f, -4.76559f,            -4.60647f, -4.44456f, -4.27998f, -4.11282f, -3.94319f, -3.77117f,            -3.59689f, -3.42044f, -3.24193f, -3.06147f, -2.87916f, -2.69512f,            -2.50945f, -2.32228f, -2.1337f, -1.94384f, -1.75281f, -1.56072f,            -1.3677f, -1.17384f, -0.979285f, -0.784137f, -0.588517f,            -0.392541f, -0.19633f };    // gl_warp.c -- sky and water polygons    //extern model_t *loadmodel; // Model.java    String skyname;    float skyrotate;    float[] skyaxis = { 0, 0, 0 };    image_t[] sky_images = new image_t[6];    msurface_t warpface;    static final int SUBDIVIDE_SIZE = 64;    void BoundPoly(int numverts, float[][] verts, float[] mins, float[] maxs) {        int i, j;        float[] v;        mins[0] = mins[1] = mins[2] = 9999;        maxs[0] = maxs[1] = maxs[2] = -9999;        for (i = 0; i < numverts; i++) {            v = verts[i];            for (j = 0; j < 3; j++) {                if (v[j] < mins[j])                    mins[j] = v[j];                if (v[j] > maxs[j])                    maxs[j] = v[j];            }        }    }    void SubdividePolygon(int numverts, float[][] verts) {        int i, j, k;        float[] mins = { 0, 0, 0 };        float[] maxs = { 0, 0, 0 };        float m;        float[] v = { 0, 0, 0 };        float[][] front = new float[64][3];        float[][] back = new float[64][3];        int f, b;        float[] dist = new float[64];        float frac;        float s, t;        float[] total = { 0, 0, 0 };        float total_s, total_t;        if (numverts > 60)            Com.Error(Defines.ERR_DROP, "numverts = " + numverts);        BoundPoly(numverts, verts, mins, maxs);        // x,y und z        for (i = 0; i < 3; i++) {            m = (mins[i] + maxs[i]) * 0.5f;            m = SUBDIVIDE_SIZE * (float) Math.floor(m / SUBDIVIDE_SIZE + 0.5f);            if (maxs[i] - m < 8)                continue;            if (m - mins[i] < 8)                continue;            // cut it            for (j = 0; j < numverts; j++) {                dist[j] = verts[j][i] - m;            }            // wrap cases            dist[j] = dist[0];            Math3D.VectorCopy(verts[0], verts[numverts]);            f = b = 0;            for (j = 0; j < numverts; j++) {                v = verts[j];                if (dist[j] >= 0) {                    Math3D.VectorCopy(v, front[f]);                    f++;                }                if (dist[j] <= 0) {                    Math3D.VectorCopy(v, back[b]);                    b++;                }                if (dist[j] == 0 || dist[j + 1] == 0)                    continue;                if ((dist[j] > 0) != (dist[j + 1] > 0)) {                    // clip point                    frac = dist[j] / (dist[j] - dist[j + 1]);                    for (k = 0; k < 3; k++)                        front[f][k] = back[b][k] = v[k] + frac                                * (verts[j + 1][k] - v[k]);                    f++;                    b++;                }            }            SubdividePolygon(f, front);            SubdividePolygon(b, back);            return;        }        // add a point in the center to help keep warp valid        // wird im Konstruktor erschlagen        // poly = Hunk_Alloc (sizeof(glpoly_t) + ((numverts-4)+2) *        // VERTEXSIZE*sizeof(float));        // init polys        glpoly_t poly = Polygon.create(numverts + 2);        poly.next = warpface.polys;        warpface.polys = poly;        Math3D.VectorClear(total);        total_s = 0;        total_t = 0;        for (i = 0; i < numverts; i++) {            poly.x(i + 1, verts[i][0]);            poly.y(i + 1, verts[i][1]);            poly.z(i + 1, verts[i][2]);            s = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[0]);            t = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[1]);            total_s += s;            total_t += t;            Math3D.VectorAdd(total, verts[i], total);            poly.s1(i + 1, s);            poly.t1(i + 1, t);        }                float scale = 1.0f / numverts;         poly.x(0, total[0] * scale);        poly.y(0, total[1] * scale);        poly.z(0, total[2] * scale);        poly.s1(0, total_s * scale);        poly.t1(0, total_t * scale);        poly.x(i + 1, poly.x(1));        poly.y(i + 1, poly.y(1));        poly.z(i + 1, poly.z(1));        poly.s1(i + 1, poly.s1(1));        poly.t1(i + 1, poly.t1(1));        poly.s2(i + 1, poly.s2(1));        poly.t2(i + 1, poly.t2(1));    }    /*     * GL_SubdivideSurface     *      * Breaks a polygon up along axial 64 unit boundaries so that turbulent and     * sky warps can be done reasonably.     */    float[][] tmpVerts = new float[64][3];    void GL_SubdivideSurface(msurface_t fa) {        float[][] verts = tmpVerts;        float[] vec;        warpface = fa;        //        // convert edges back to a normal polygon        //        int numverts = 0;        for (int i = 0; i < fa.numedges; i++) {            int lindex = loadmodel.surfedges[fa.firstedge + i];            if (lindex > 0)                vec = loadmodel.vertexes[loadmodel.edges[lindex].v[0]].position;            else                vec = loadmodel.vertexes[loadmodel.edges[-lindex].v[1]].position;            Math3D.VectorCopy(vec, verts[numverts]);            numverts++;        }        SubdividePolygon(numverts, verts);    }    //	  =========================================================    //// speed up sin calculations - Ed    //	float r_turbsin[] =    //	{    //		#include "warpsin.h"    //	};    static final float TURBSCALE = (float) (256.0f / (2 * Math.PI));    /*     * ============= EmitWaterPolys     *      * Does a water warp on the pre-fragmented glpoly_t chain =============     */    void EmitWaterPolys(msurface_t fa) {        glpoly_t p, bp;        float s = 0;        float t = 0;        float os, ot;        float scroll;        float rdt = r_newrefdef.time;        if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0)            scroll = -64                    * ((r_newrefdef.time * 0.5f) - (int) (r_newrefdef.time * 0.5f));        else            scroll = 0;        for (bp = fa.polys; bp != null; bp = bp.next) {            p = bp;            gl.glBegin(GL.GL_TRIANGLE_FAN);            for (int i = 0; i < p.numverts; i++) {                os = p.s1(i);                ot = p.t1(i);                s = os                        + Warp.SIN[(int) ((ot * 0.125f + r_newrefdef.time) * TURBSCALE) & 255];                s += scroll;                s *= (1.0f / 64);                t = ot                        + Warp.SIN[(int) ((os * 0.125f + rdt) * TURBSCALE) & 255];                t *= (1.0f / 64);                gl.glTexCoord2f(s, t);                gl.glVertex3f(p.x(i), p.y(i), p.z(i));            }            gl.glEnd();        }    }    //	  ===================================================================    float[][] skyclip = { { 1, 1, 0 }, { 1, -1, 0 }, { 0, -1, 1 }, { 0, 1, 1 },            { 1, 0, 1 }, { -1, 0, 1 } };    int c_sky;    // 1 = s, 2 = t, 3 = 2048    int[][] st_to_vec = { { 3, -1, 2 }, { -3, 1, 2 },    { 1, 3, 2 }, { -1, -3, 2 },    { -2, -1, 3 }, // 0 degrees yaw, look straight up            { 2, -1, -3 } // look straight down    };    int[][] vec_to_st = { { -2, 3, 1 }, { 2, 3, -1 },

⌨️ 快捷键说明

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