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

📄 surf.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			int smax, tmax;			if ( ( (surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0 ) && ( surf.dlightframe != r_framecount ) )			{				smax = (surf.extents[0]>>4)+1;				tmax = (surf.extents[1]>>4)+1;				R_BuildLightMap( surf, temp, smax);				R_SetCacheState( surf );				GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum );				lmtex = surf.lightmaptexturenum;				gl.glTexSubImage2D( GL11.GL_TEXTURE_2D, 0,								  surf.light_s, surf.light_t, 								  smax, tmax, 								  GL_LIGHTMAP_FORMAT, 								  GL11.GL_UNSIGNED_BYTE, temp );			}			else			{				smax = (surf.extents[0]>>4)+1;				tmax = (surf.extents[1]>>4)+1;				R_BuildLightMap( surf, temp, smax);				GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 );				lmtex = 0;				gl.glTexSubImage2D( GL11.GL_TEXTURE_2D, 0,								  surf.light_s, surf.light_t, 								  smax, tmax, 								  GL_LIGHTMAP_FORMAT, 								  GL11.GL_UNSIGNED_BYTE, temp );			}			c_brush_polys++;			GL_MBind( GL_TEXTURE0, image.texnum );			GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + lmtex );			// ==========			//	  PGM			if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0)			{				float scroll;						scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) );				if(scroll == 0.0f)					scroll = -64.0f;				for ( p = surf.polys; p != null; p = p.chain )				{				    p.beginScrolling(scroll);					gl.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);				    p.endScrolling();				}			}			else			{				for ( p = surf.polys; p != null; p = p.chain )				{					gl.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);				}			}			// PGM			// ==========		}		else		{			c_brush_polys++;			GL_MBind( GL_TEXTURE0, image.texnum );			GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + lmtex);						// ==========			//	  PGM			if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0)			{				float scroll;						scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) );				if(scroll == 0.0)					scroll = -64.0f;				for ( p = surf.polys; p != null; p = p.chain )				{				    p.beginScrolling(scroll);					gl.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);				    p.endScrolling();				}			}			else			{			// PGM			//  ==========				for ( p = surf.polys; p != null; p = p.chain )				{					gl.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);				}							// ==========			// PGM			}			// PGM			// ==========		}	}	/**	 * R_DrawInlineBModel	 */	void R_DrawInlineBModel()	{		// calculate dynamic lighting for bmodel		if ( gl_flashblend.value == 0 )		{			dlight_t	lt;			for (int k=0 ; k<r_newrefdef.num_dlights ; k++)			{				lt = r_newrefdef.dlights[k];				R_MarkLights(lt, 1<<k, currentmodel.nodes[currentmodel.firstnode]);			}		}		// psurf = &currentmodel->surfaces[currentmodel->firstmodelsurface];		int psurfp = currentmodel.firstmodelsurface;		msurface_t[] surfaces = currentmodel.surfaces;		//psurf = surfaces[psurfp];		if ( (currententity.flags & Defines.RF_TRANSLUCENT) != 0 )		{			gl.glEnable (GL11.GL_BLEND);			gl.glColor4f (1,1,1,0.25f);			GL_TexEnv( GL11.GL_MODULATE );		}		//		// draw texture		//		msurface_t psurf;		cplane_t pplane;		float dot;		for (int i=0 ; i<currentmodel.nummodelsurfaces ; i++)		{			psurf = surfaces[psurfp++];			// find which side of the node we are on			pplane = psurf.plane;			dot = Math3D.DotProduct(modelorg, pplane.normal) - pplane.dist;			// draw the polygon			if (((psurf.flags & Defines.SURF_PLANEBACK) != 0 && (dot < -BACKFACE_EPSILON)) ||				((psurf.flags & Defines.SURF_PLANEBACK) == 0 && (dot > BACKFACE_EPSILON)))			{				if ((psurf.texinfo.flags & (Defines.SURF_TRANS33 | Defines.SURF_TRANS66)) != 0 )				{	// add to the translucent chain					psurf.texturechain = r_alpha_surfaces;					r_alpha_surfaces = psurf;				}				else if ( (psurf.flags & Defines.SURF_DRAWTURB) == 0 )				{					GL_RenderLightmappedPoly( psurf );				}				else				{					GL_EnableMultitexture( false );					R_RenderBrushPoly( psurf );					GL_EnableMultitexture( true );				}			}		}				if ( (currententity.flags & Defines.RF_TRANSLUCENT) != 0 ) {			gl.glDisable (GL11.GL_BLEND);			gl.glColor4f (1,1,1,1);			GL_TexEnv( GL11.GL_REPLACE );		}	}	// stack variable	private final float[] mins = {0, 0, 0};	private final float[] maxs = {0, 0, 0};	private final float[] org = {0, 0, 0};	private final float[] forward = {0, 0, 0};	private final float[] right = {0, 0, 0};	private final float[] up = {0, 0, 0};	/**	 * R_DrawBrushModel	 */	void R_DrawBrushModel(entity_t e)	{		if (currentmodel.nummodelsurfaces == 0)			return;		currententity = e;		gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;		boolean rotated;		if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0)		{			rotated = true;			for (int i=0 ; i<3 ; i++)			{				mins[i] = e.origin[i] - currentmodel.radius;				maxs[i] = e.origin[i] + currentmodel.radius;			}		}		else		{			rotated = false;			Math3D.VectorAdd(e.origin, currentmodel.mins, mins);			Math3D.VectorAdd(e.origin, currentmodel.maxs, maxs);		}		if (R_CullBox(mins, maxs)) return;		gl.glColor3f (1,1,1);				// memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));				// TODO wird beim multitexturing nicht gebraucht		//gl_lms.clearLightmapSurfaces();				Math3D.VectorSubtract (r_newrefdef.vieworg, e.origin, modelorg);		if (rotated)		{			Math3D.VectorCopy (modelorg, org);			Math3D.AngleVectors (e.angles, forward, right, up);			modelorg[0] = Math3D.DotProduct (org, forward);			modelorg[1] = -Math3D.DotProduct (org, right);			modelorg[2] = Math3D.DotProduct (org, up);		}		gl.glPushMatrix();				e.angles[0] = -e.angles[0];	// stupid quake bug		e.angles[2] = -e.angles[2];	// stupid quake bug		R_RotateForEntity(e);		e.angles[0] = -e.angles[0];	// stupid quake bug		e.angles[2] = -e.angles[2];	// stupid quake bug		GL_EnableMultitexture( true );		GL_SelectTexture(GL_TEXTURE0);		GL_TexEnv( GL11.GL_REPLACE );		gl.glInterleavedArrays(GL11.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf);		GL_SelectTexture(GL_TEXTURE1);		GL_TexEnv( GL11.GL_MODULATE );		gl.glTexCoordPointer(2, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf);		gl.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);		R_DrawInlineBModel();		gl.glClientActiveTextureARB(GL_TEXTURE1);		gl.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);		GL_EnableMultitexture( false );		gl.glPopMatrix();	}	/*	=============================================================		WORLD MODEL	=============================================================	*/	/**	 * R_RecursiveWorldNode	 */	void R_RecursiveWorldNode (mnode_t node)	{		if (node.contents == Defines.CONTENTS_SOLID)			return;		// solid				if (node.visframe != r_visframecount)			return;					if (R_CullBox(node.mins, node.maxs))			return;			int c;		msurface_t mark;		// if a leaf node, draw stuff		if (node.contents != -1)		{			mleaf_t pleaf = (mleaf_t)node;			// check for door connected areas			if (r_newrefdef.areabits != null)			{				if ( ((r_newrefdef.areabits[pleaf.area >> 3] & 0xFF) & (1 << (pleaf.area & 7)) ) == 0 )					return;		// not visible			}			int markp = 0;			mark = pleaf.getMarkSurface(markp); // first marked surface			c = pleaf.nummarksurfaces;			if (c != 0)			{				do				{					mark.visframe = r_framecount;					mark = pleaf.getMarkSurface(++markp); // next surface				} while (--c != 0);			}			return;		}		// node is just a decision point, so go down the apropriate sides		// find which side of the node we are on		cplane_t plane = node.plane;		float dot;		switch (plane.type)		{		case Defines.PLANE_X:			dot = modelorg[0] - plane.dist;			break;		case Defines.PLANE_Y:			dot = modelorg[1] - plane.dist;			break;		case Defines.PLANE_Z:			dot = modelorg[2] - plane.dist;			break;		default:			dot = Math3D.DotProduct(modelorg, plane.normal) - plane.dist;			break;		}		int side, sidebit;		if (dot >= 0.0f)		{			side = 0;			sidebit = 0;		}		else		{			side = 1;			sidebit = Defines.SURF_PLANEBACK;		}		// recurse down the children, front side first		R_RecursiveWorldNode(node.children[side]);		// draw stuff		msurface_t surf;		image_t image;		//for ( c = node.numsurfaces, surf = r_worldmodel.surfaces[node.firstsurface]; c != 0 ; c--, surf++)		for ( c = 0; c < node.numsurfaces; c++)		{			surf = r_worldmodel.surfaces[node.firstsurface + c];			if (surf.visframe != r_framecount)				continue;			if ( (surf.flags & Defines.SURF_PLANEBACK) != sidebit )				continue;		// wrong side			if ((surf.texinfo.flags & Defines.SURF_SKY) != 0)			{	// just adds to visible sky bounds				R_AddSkySurface(surf);			}			else if ((surf.texinfo.flags & (Defines.SURF_TRANS33 | Defines.SURF_TRANS66)) != 0)			{	// add to the translucent chain				surf.texturechain = r_alpha_surfaces;				r_alpha_surfaces = surf;			}			else			{				if (  ( surf.flags & Defines.SURF_DRAWTURB) == 0 )				{					GL_RenderLightmappedPoly( surf );				}				else				{					// the polygon is visible, so add it to the texture					// sorted chain					// FIXME: this is a hack for animation					image = R_TextureAnimation(surf.texinfo);					surf.texturechain = image.texturechain;					image.texturechain = surf;				}			}		}		// recurse down the back side		R_RecursiveWorldNode(node.children[1 - side]);	}	private final entity_t worldEntity = new entity_t();		/**	 * R_DrawWorld	 */	void R_DrawWorld()	{		if (r_drawworld.value == 0)			return;		if ( (r_newrefdef.rdflags & Defines.RDF_NOWORLDMODEL) != 0 )			return;		currentmodel = r_worldmodel;		Math3D.VectorCopy(r_newrefdef.vieworg, modelorg);		entity_t ent = worldEntity;		// auto cycle the world frame for texture animation		ent.clear();		ent.frame = (int)(r_newrefdef.time*2);		currententity = ent;		gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;		gl.glColor3f (1,1,1);		// memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));		// TODO wird bei multitexture nicht gebraucht		//gl_lms.clearLightmapSurfaces();				R_ClearSkyBox();		GL_EnableMultitexture( true );		GL_SelectTexture( GL_TEXTURE0);		GL_TexEnv( GL11.GL_REPLACE );		gl.glInterleavedArrays(GL11.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf);		GL_SelectTexture( GL_TEXTURE1);		gl.glTexCoordPointer(2, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf);		gl.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);		if ( gl_lightmap.value != 0)			GL_TexEnv( GL11.GL_REPLACE );		else 			GL_TexEnv( GL11.GL_MODULATE );						R_RecursiveWorldNode(r_worldmodel.nodes[0]); // root node						gl.glClientActiveTextureARB(GL_TEXTURE1);

⌨️ 快捷键说明

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