- static float distance;
- static int i,j;
- static XYZ moved,terrainlight;
- bool hidden;
-
- for(i=0;i<numobjects;i++){
- if(type[i]!=firetype){
- moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
- if(type[i]==tunneltype||frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
- distance=findDistancefast(&viewer,&position[i]);
- distance*=1.2;
- hidden=!(findDistancefastflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype));
- if(!hidden){
-
- if(detail==2&&distance>viewdistance*viewdistance/4&&environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
- else glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
- distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
- if(distance>1)distance=1;
- if(distance>0){
-
- /*if(checkcollide(viewer,DoRotation(model[i].vertex[model[i].vertexNum],0,yaw[i],0)*scale[i]+position[i],i)){
- occluded[i]+=1;
- }
- else occluded[i]=0;*/
- if(occluded[i]<6){
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glPushMatrix();
- if(!model[i].color)glEnable(GL_LIGHTING);
- else glDisable(GL_LIGHTING);
- glDepthMask(1);
- glTranslatef(position[i].x,position[i].y,position[i].z);
- if(type[i]==bushtype){
- messedwith[i]-=multiplier;
- if(rotxvel[i]||rotx[i]){
- if(rotx[i]>0)rotxvel[i]-=multiplier*8*fabs(rotx[i]);
- if(rotx[i]<0)rotxvel[i]+=multiplier*8*fabs(rotx[i]);
- if(rotx[i]>0)rotxvel[i]-=multiplier*4;
- if(rotx[i]<0)rotxvel[i]+=multiplier*4;
- if(rotxvel[i]>0)rotxvel[i]-=multiplier*4;
- if(rotxvel[i]<0)rotxvel[i]+=multiplier*4;
- if(fabs(rotx[i])<multiplier*4)rotx[i]=0;
- if(fabs(rotxvel[i])<multiplier*4)rotxvel[i]=0;
-
- rotx[i]+=rotxvel[i]*multiplier*4;
- }
- if(rotyvel[i]||roty[i]){
- if(roty[i]>0)rotyvel[i]-=multiplier*8*fabs(roty[i]);
- if(roty[i]<0)rotyvel[i]+=multiplier*8*fabs(roty[i]);
- if(roty[i]>0)rotyvel[i]-=multiplier*4;
- if(roty[i]<0)rotyvel[i]+=multiplier*4;
- if(rotyvel[i]>0)rotyvel[i]-=multiplier*4;
- if(rotyvel[i]<0)rotyvel[i]+=multiplier*4;
- if(fabs(roty[i])<multiplier*4)roty[i]=0;
- if(fabs(rotyvel[i])<multiplier*4)rotyvel[i]=0;
-
- roty[i]+=rotyvel[i]*multiplier*4;
- }
- if(roty[i]){
- glRotatef(roty[i],1,0,0);
- }
- if(rotx[i]){
- glRotatef(-rotx[i],0,0,1);
- }
- if(rotx[i]>10)rotx[i]=10;
- if(rotx[i]<-10)rotx[i]=-10;
- if(roty[i]>10)roty[i]=10;
- if(roty[i]<-10)roty[i]=-10;
- }
- if(type[i]==treetrunktype||type[i]==treeleavestype){
- if(type[i]==treetrunktype||environment==2){
- messedwith[i]-=multiplier;
- if(rotxvel[i]||rotx[i]){
- if(rotx[i]>0)rotxvel[i]-=multiplier*8*fabs(rotx[i]);
- if(rotx[i]<0)rotxvel[i]+=multiplier*8*fabs(rotx[i]);
- if(rotx[i]>0)rotxvel[i]-=multiplier*4;
- if(rotx[i]<0)rotxvel[i]+=multiplier*4;
- if(rotxvel[i]>0)rotxvel[i]-=multiplier*4;
- if(rotxvel[i]<0)rotxvel[i]+=multiplier*4;
- if(fabs(rotx[i])<multiplier*4)rotx[i]=0;
- if(fabs(rotxvel[i])<multiplier*4)rotxvel[i]=0;
-
- rotx[i]+=rotxvel[i]*multiplier*4;
- }
- if(rotyvel[i]||roty[i]){
- if(roty[i]>0)rotyvel[i]-=multiplier*8*fabs(roty[i]);
- if(roty[i]<0)rotyvel[i]+=multiplier*8*fabs(roty[i]);
- if(roty[i]>0)rotyvel[i]-=multiplier*4;
- if(roty[i]<0)rotyvel[i]+=multiplier*4;
- if(rotyvel[i]>0)rotyvel[i]-=multiplier*4;
- if(rotyvel[i]<0)rotyvel[i]+=multiplier*4;
- if(fabs(roty[i])<multiplier*4)roty[i]=0;
- if(fabs(rotyvel[i])<multiplier*4)rotyvel[i]=0;
-
- roty[i]+=rotyvel[i]*multiplier*4;
- }
- if(roty[i]){
- glRotatef(roty[i]/6,1,0,0);
- }
- if(rotx[i]){
- glRotatef(-rotx[i]/6,0,0,1);
- }
- if(rotx[i]>10)rotx[i]=10;
- if(rotx[i]<-10)rotx[i]=-10;
- if(roty[i]>10)roty[i]=10;
- if(roty[i]<-10)roty[i]=-10;
- }
- else
- {
- messedwith[i]-=multiplier;
- if(rotxvel[i]||rotx[i]){
- if(rotx[i]>0)rotxvel[i]-=multiplier*8*fabs(rotx[i]);
- if(rotx[i]<0)rotxvel[i]+=multiplier*8*fabs(rotx[i]);
- if(rotx[i]>0)rotxvel[i]-=multiplier*4;
- if(rotx[i]<0)rotxvel[i]+=multiplier*4;
- if(rotxvel[i]>0)rotxvel[i]-=multiplier*4;
- if(rotxvel[i]<0)rotxvel[i]+=multiplier*4;
- if(fabs(rotx[i])<multiplier*4)rotx[i]=0;
- if(fabs(rotxvel[i])<multiplier*4)rotxvel[i]=0;
-
- rotx[i]+=rotxvel[i]*multiplier*4;
- }
- if(rotyvel[i]||roty[i]){
- if(roty[i]>0)rotyvel[i]-=multiplier*8*fabs(roty[i]);
- if(roty[i]<0)rotyvel[i]+=multiplier*8*fabs(roty[i]);
- if(roty[i]>0)rotyvel[i]-=multiplier*4;
- if(roty[i]<0)rotyvel[i]+=multiplier*4;
- if(rotyvel[i]>0)rotyvel[i]-=multiplier*4;
- if(rotyvel[i]<0)rotyvel[i]+=multiplier*4;
- if(fabs(roty[i])<multiplier*4)roty[i]=0;
- if(fabs(rotyvel[i])<multiplier*4)rotyvel[i]=0;
-
- roty[i]+=rotyvel[i]*multiplier*4;
- }
- if(roty[i]){
- glRotatef(roty[i]/4,1,0,0);
- }
- if(rotx[i]){
- glRotatef(-rotx[i]/4,0,0,1);
- }
- if(rotx[i]>10)rotx[i]=10;
- if(rotx[i]<-10)rotx[i]=-10;
- if(roty[i]>10)roty[i]=10;
- if(roty[i]<-10)roty[i]=-10;
- }
-
- }
- if(/*detail==2&&*/environment==snowyenvironment){
- if(type[i]==treeleavestype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*1.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==treetrunktype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==bushtype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*4*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- }
- if(/*detail==2&&*/environment==grassyenvironment){
- if(type[i]==treeleavestype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*1.5*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==treetrunktype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*.5*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==bushtype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*4*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- }
- if(/*detail==2&&*/environment==desertenvironment){
- if(type[i]==bushtype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*4*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- }
- glRotatef(yaw[i],0,1,0);
- if(distance>1)distance=1;
- glColor4f((1-shadowed[i])/2+.5,(1-shadowed[i])/2+.5,(1-shadowed[i])/2+.5,distance);
- if(distance>=1){
- glDisable(GL_BLEND);
- glAlphaFunc(GL_GREATER, 0.5);
- }
- if(distance<1){
- glEnable(GL_BLEND);
- glAlphaFunc(GL_GREATER, 0.1);
- }
- if(type[i]!=treetrunktype&&type[i]!=treeleavestype&&type[i]!=bushtype&&type[i]!=rocktype){
- glEnable(GL_CULL_FACE);
- glAlphaFunc(GL_GREATER, 0.0001);
- model[i].drawdifftex(boxtextureptr);
- model[i].drawdecals(terrain.shadowtexture,terrain.bloodtexture,terrain.bloodtexture2,terrain.breaktexture);
- }
- if(type[i]==rocktype){
- glEnable(GL_CULL_FACE);
- glAlphaFunc(GL_GREATER, 0.0001);
- glColor4f((1-shadowed[i])/2+light.ambient[0],(1-shadowed[i])/2+light.ambient[1],(1-shadowed[i])/2+light.ambient[2],distance);
- model[i].drawdifftex(rocktextureptr);
- model[i].drawdecals(terrain.shadowtexture,terrain.bloodtexture,terrain.bloodtexture2,terrain.breaktexture);
- }
- if(type[i]==treeleavestype){
- glDisable(GL_CULL_FACE);
- glDisable(GL_LIGHTING);
- terrainlight=terrain.getLighting(position[i].x,position[i].z);
- if(!hidden){
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
- if(distance<1)glAlphaFunc(GL_GREATER, 0.2);
- }
- if(hidden){
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance/3);
- glAlphaFunc(GL_GREATER, 0);
- }
- model[i].drawdifftex(treetextureptr);
- }
- if(type[i]==bushtype){
- glDisable(GL_CULL_FACE);
- glDisable(GL_LIGHTING);
- terrainlight=terrain.getLighting(position[i].x,position[i].z);
- if(!hidden){
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
- if(distance<1)glAlphaFunc(GL_GREATER, 0.2);
- }
- if(hidden){
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance/3);
- glAlphaFunc(GL_GREATER, 0);
- }
- model[i].drawdifftex(bushtextureptr);
- }
- if(type[i]==treetrunktype){
- glEnable(GL_CULL_FACE);
- terrainlight=terrain.getLighting(position[i].x,position[i].z);
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
- model[i].drawdifftex(treetextureptr);
- }
- glPopMatrix();
- }
- }
- }
- }
- }
- }
-
- glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
- for(i=0;i<numobjects;i++){
- if(type[i]==treeleavestype||type[i]==bushtype){
- moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
- if(frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
- hidden=findDistancefastflat(&viewer,&position[i])<=playerdist+3;
- if(hidden){
- distance=1;
- if(distance>0){
- if(1==1||occluded[i]<6){
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glPushMatrix();
- glEnable(GL_LIGHTING);
- glDepthMask(1);
- glTranslatef(position[i].x,position[i].y,position[i].z);
- if(type[i]==bushtype){
- messedwith[i]-=multiplier;
- if(rotxvel[i]||rotx[i]){
- if(rotx[i]>0)rotxvel[i]-=multiplier*8*fabs(rotx[i]);
- if(rotx[i]<0)rotxvel[i]+=multiplier*8*fabs(rotx[i]);
- if(rotx[i]>0)rotxvel[i]-=multiplier*4;
- if(rotx[i]<0)rotxvel[i]+=multiplier*4;
- if(rotxvel[i]>0)rotxvel[i]-=multiplier*4;
- if(rotxvel[i]<0)rotxvel[i]+=multiplier*4;
- if(fabs(rotx[i])<multiplier*4)rotx[i]=0;
- if(fabs(rotxvel[i])<multiplier*4)rotxvel[i]=0;
-
- rotx[i]+=rotxvel[i]*multiplier*4;
- }
- if(rotyvel[i]||roty[i]){
- if(roty[i]>0)rotyvel[i]-=multiplier*8*fabs(roty[i]);
- if(roty[i]<0)rotyvel[i]+=multiplier*8*fabs(roty[i]);
- if(roty[i]>0)rotyvel[i]-=multiplier*4;
- if(roty[i]<0)rotyvel[i]+=multiplier*4;
- if(rotyvel[i]>0)rotyvel[i]-=multiplier*4;
- if(rotyvel[i]<0)rotyvel[i]+=multiplier*4;
- if(fabs(roty[i])<multiplier*4)roty[i]=0;
- if(fabs(rotyvel[i])<multiplier*4)rotyvel[i]=0;
-
- roty[i]+=rotyvel[i]*multiplier*4;
- }
- if(roty[i]){
- glRotatef(roty[i],1,0,0);
- }
- if(rotx[i]){
- glRotatef(-rotx[i],0,0,1);
- }
- if(rotx[i]>10)rotx[i]=10;
- if(rotx[i]<-10)rotx[i]=-10;
- if(roty[i]>10)roty[i]=10;
- if(roty[i]<-10)roty[i]=-10;
- }
- if(type[i]==treetrunktype||type[i]==treeleavestype){
- messedwith[i]-=multiplier;
- if(rotxvel[i]||rotx[i]){
- if(rotx[i]>0)rotxvel[i]-=multiplier*8*fabs(rotx[i]);
- if(rotx[i]<0)rotxvel[i]+=multiplier*8*fabs(rotx[i]);
- if(rotx[i]>0)rotxvel[i]-=multiplier*4;
- if(rotx[i]<0)rotxvel[i]+=multiplier*4;
- if(rotxvel[i]>0)rotxvel[i]-=multiplier*4;
- if(rotxvel[i]<0)rotxvel[i]+=multiplier*4;
- if(fabs(rotx[i])<multiplier*4)rotx[i]=0;
- if(fabs(rotxvel[i])<multiplier*4)rotxvel[i]=0;
-
- rotx[i]+=rotxvel[i]*multiplier*4;
- }
- if(rotyvel[i]||roty[i]){
- if(roty[i]>0)rotyvel[i]-=multiplier*8*fabs(roty[i]);
- if(roty[i]<0)rotyvel[i]+=multiplier*8*fabs(roty[i]);
- if(roty[i]>0)rotyvel[i]-=multiplier*4;
- if(roty[i]<0)rotyvel[i]+=multiplier*4;
- if(rotyvel[i]>0)rotyvel[i]-=multiplier*4;
- if(rotyvel[i]<0)rotyvel[i]+=multiplier*4;
- if(fabs(roty[i])<multiplier*4)roty[i]=0;
- if(fabs(rotyvel[i])<multiplier*4)rotyvel[i]=0;
-
- roty[i]+=rotyvel[i]*multiplier*4;
- }
- if(roty[i]){
- glRotatef(roty[i]/2,1,0,0);
- }
- if(rotx[i]){
- glRotatef(-rotx[i]/2,0,0,1);
- }
- if(rotx[i]>10)rotx[i]=10;
- if(rotx[i]<-10)rotx[i]=-10;
- if(roty[i]>10)roty[i]=10;
- if(roty[i]<-10)roty[i]=-10;
- }
- if(environment==snowyenvironment){
- if(type[i]==treeleavestype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*1.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==treetrunktype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==bushtype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*4*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- }
- if(environment==grassyenvironment){
- if(type[i]==treeleavestype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*1.5*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==treetrunktype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*.5*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- if(type[i]==bushtype){
- glRotatef((sin(windvar+position[i].x*.3)+.5)*4*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
- }
- }
- glRotatef(yaw[i],0,1,0);
- glColor4f(1,1,1,distance);
- if(type[i]==treeleavestype){
- glDisable(GL_CULL_FACE);
- glDisable(GL_LIGHTING);
- terrainlight=terrain.getLighting(position[i].x,position[i].z);
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,.3);
- glAlphaFunc(GL_GREATER, 0);
- glDisable(GL_ALPHA_TEST);
- model[i].drawdifftex(treetextureptr);
- }
- if(type[i]==bushtype){
- glDisable(GL_CULL_FACE);
- glDisable(GL_LIGHTING);
- terrainlight=terrain.getLighting(position[i].x,position[i].z);
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,.3);
- glAlphaFunc(GL_GREATER, 0);
- glDisable(GL_ALPHA_TEST);
- model[i].drawdifftex(bushtextureptr);
- }
- glPopMatrix();
- }
- }
- }
- }
- }
- }
- if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
- glEnable(GL_ALPHA_TEST);
- SetUpLight(&light,0);
+ static float distance;
+ static int i;
+ static XYZ moved, terrainlight;
+ bool hidden;
+
+ for (i = 0; i < numobjects; i++) {
+ if (type[i] != firetype) {
+ moved = DoRotation(model[i].boundingspherecenter, 0, yaw[i], 0);
+ if (type[i] == tunneltype || frustum.SphereInFrustum(position[i].x + moved.x, position[i].y + moved.y, position[i].z + moved.z, model[i].boundingsphereradius)) {
+ distance = distsq(&viewer, &position[i]);
+ distance *= 1.2;
+ hidden = !(distsqflat(&viewer, &position[i]) > playerdist + 3 || (type[i] != bushtype && type[i] != treeleavestype));
+ if (!hidden) {
+
+ if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment)
+ glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
+ else
+ glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
+ if (distance > 1)
+ distance = 1;
+ if (distance > 0) {
+
+ /*if(checkcollide(viewer,DoRotation(model[i].vertex[model[i].vertexNum],0,yaw[i],0)*scale[i]+position[i],i)){
+ occluded[i]+=1;
+ }
+ else occluded[i]=0;*/
+ if (occluded[i] < 6) {
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ if (!model[i].color)
+ glEnable(GL_LIGHTING);
+ else
+ glDisable(GL_LIGHTING);
+ glDepthMask(1);
+ glTranslatef(position[i].x, position[i].y, position[i].z);
+ if (type[i] == bushtype) {
+ messedwith[i] -= multiplier;
+ if (rotxvel[i] || rotx[i]) {
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
+ if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
+ if (fabs(rotx[i]) < multiplier * 4)
+ rotx[i] = 0;
+ if (fabs(rotxvel[i]) < multiplier * 4)
+ rotxvel[i] = 0;
+
+ rotx[i] += rotxvel[i] * multiplier * 4;
+ }
+ if (rotyvel[i] || roty[i]) {
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
+ if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (roty[i] < 0) rotyvel[i] += multiplier * 4;
+ if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
+ if (fabs(roty[i]) < multiplier * 4)
+ roty[i] = 0;
+ if (fabs(rotyvel[i]) < multiplier * 4)
+ rotyvel[i] = 0;
+
+ roty[i] += rotyvel[i] * multiplier * 4;
+ }
+ if (roty[i]) {
+ glRotatef(roty[i], 1, 0, 0);
+ }
+ if (rotx[i]) {
+ glRotatef(-rotx[i], 0, 0, 1);
+ }
+ if (rotx[i] > 10)
+ rotx[i] = 10;
+ if (rotx[i] < -10)
+ rotx[i] = -10;
+ if (roty[i] > 10)
+ roty[i] = 10;
+ if (roty[i] < -10)
+ roty[i] = -10;
+ }
+ if (type[i] == treetrunktype || type[i] == treeleavestype) {
+ if (type[i] == treetrunktype || environment == 2) {
+ messedwith[i] -= multiplier;
+ if (rotxvel[i] || rotx[i]) {
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
+ if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
+ if (fabs(rotx[i]) < multiplier * 4)
+ rotx[i] = 0;
+ if (fabs(rotxvel[i]) < multiplier * 4)
+ rotxvel[i] = 0;
+
+ rotx[i] += rotxvel[i] * multiplier * 4;
+ }
+ if (rotyvel[i] || roty[i]) {
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
+ if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (roty[i] < 0) rotyvel[i] += multiplier * 4;
+ if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
+ if (fabs(roty[i]) < multiplier * 4)
+ roty[i] = 0;
+ if (fabs(rotyvel[i]) < multiplier * 4)
+ rotyvel[i] = 0;
+
+ roty[i] += rotyvel[i] * multiplier * 4;
+ }
+ if (roty[i]) {
+ glRotatef(roty[i] / 6, 1, 0, 0);
+ }
+ if (rotx[i]) {
+ glRotatef(-rotx[i] / 6, 0, 0, 1);
+ }
+ if (rotx[i] > 10)
+ rotx[i] = 10;
+ if (rotx[i] < -10)
+ rotx[i] = -10;
+ if (roty[i] > 10)
+ roty[i] = 10;
+ if (roty[i] < -10)
+ roty[i] = -10;
+ } else {
+ messedwith[i] -= multiplier;
+ if (rotxvel[i] || rotx[i]) {
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
+ if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
+ if (fabs(rotx[i]) < multiplier * 4)
+ rotx[i] = 0;
+ if (fabs(rotxvel[i]) < multiplier * 4)
+ rotxvel[i] = 0;
+
+ rotx[i] += rotxvel[i] * multiplier * 4;
+ }
+ if (rotyvel[i] || roty[i]) {
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
+ if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (roty[i] < 0) rotyvel[i] += multiplier * 4;
+ if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
+ if (fabs(roty[i]) < multiplier * 4)
+ roty[i] = 0;
+ if (fabs(rotyvel[i]) < multiplier * 4)
+ rotyvel[i] = 0;
+
+ roty[i] += rotyvel[i] * multiplier * 4;
+ }
+ if (roty[i]) {
+ glRotatef(roty[i] / 4, 1, 0, 0);
+ }
+ if (rotx[i]) {
+ glRotatef(-rotx[i] / 4, 0, 0, 1);
+ }
+ if (rotx[i] > 10)
+ rotx[i] = 10;
+ if (rotx[i] < -10)
+ rotx[i] = -10;
+ if (roty[i] > 10)
+ roty[i] = 10;
+ if (roty[i] < -10)
+ roty[i] = -10;
+ }
+
+ }
+ if (/*detail==2&&*/environment == snowyenvironment) {
+ if (type[i] == treeleavestype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == treetrunktype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == bushtype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ }
+ if (/*detail==2&&*/environment == grassyenvironment) {
+ if (type[i] == treeleavestype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == treetrunktype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == bushtype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ }
+ if (/*detail==2&&*/environment == desertenvironment) {
+ if (type[i] == bushtype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ }
+ glRotatef(yaw[i], 0, 1, 0);
+ if (distance > 1)
+ distance = 1;
+ glColor4f((1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, distance);
+ if (distance >= 1) {
+ glDisable(GL_BLEND);
+ glAlphaFunc(GL_GREATER, 0.5);
+ }
+ if (distance < 1) {
+ glEnable(GL_BLEND);
+ glAlphaFunc(GL_GREATER, 0.1);
+ }
+ if (type[i] != treetrunktype && type[i] != treeleavestype && type[i] != bushtype && type[i] != rocktype) {
+ glEnable(GL_CULL_FACE);
+ glAlphaFunc(GL_GREATER, 0.0001);
+ model[i].drawdifftex(boxtextureptr);
+ model[i].drawdecals(terrain.shadowtexture, terrain.bloodtexture, terrain.bloodtexture2, terrain.breaktexture);
+ }
+ if (type[i] == rocktype) {
+ glEnable(GL_CULL_FACE);
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glColor4f((1 - shadowed[i]) / 2 + light.ambient[0], (1 - shadowed[i]) / 2 + light.ambient[1], (1 - shadowed[i]) / 2 + light.ambient[2], distance);
+ model[i].drawdifftex(rocktextureptr);
+ model[i].drawdecals(terrain.shadowtexture, terrain.bloodtexture, terrain.bloodtexture2, terrain.breaktexture);
+ }
+ if (type[i] == treeleavestype) {
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ terrainlight = terrain.getLighting(position[i].x, position[i].z);
+ if (!hidden) {
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
+ if (distance < 1)
+ glAlphaFunc(GL_GREATER, 0.2);
+ }
+ if (hidden) {
+ glDepthMask(0);
+ glEnable(GL_BLEND);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
+ glAlphaFunc(GL_GREATER, 0);
+ }
+ model[i].drawdifftex(treetextureptr);
+ }
+ if (type[i] == bushtype) {
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ terrainlight = terrain.getLighting(position[i].x, position[i].z);
+ if (!hidden) {
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
+ if (distance < 1)
+ glAlphaFunc(GL_GREATER, 0.2);
+ }
+ if (hidden) {
+ glDepthMask(0);
+ glEnable(GL_BLEND);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
+ glAlphaFunc(GL_GREATER, 0);
+ }
+ model[i].drawdifftex(bushtextureptr);
+ }
+ if (type[i] == treetrunktype) {
+ glEnable(GL_CULL_FACE);
+ terrainlight = terrain.getLighting(position[i].x, position[i].z);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
+ model[i].drawdifftex(treetextureptr);
+ }
+ glPopMatrix();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ for (i = 0; i < numobjects; i++) {
+ if (type[i] == treeleavestype || type[i] == bushtype) {
+ moved = DoRotation(model[i].boundingspherecenter, 0, yaw[i], 0);
+ if (frustum.SphereInFrustum(position[i].x + moved.x, position[i].y + moved.y, position[i].z + moved.z, model[i].boundingsphereradius)) {
+ hidden = distsqflat(&viewer, &position[i]) <= playerdist + 3;
+ if (hidden) {
+ distance = 1;
+ if (distance > 0) {
+ if (1 == 1 || occluded[i] < 6) {
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glEnable(GL_LIGHTING);
+ glDepthMask(1);
+ glTranslatef(position[i].x, position[i].y, position[i].z);
+ if (type[i] == bushtype) {
+ messedwith[i] -= multiplier;
+ if (rotxvel[i] || rotx[i]) {
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
+ if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
+ if (fabs(rotx[i]) < multiplier * 4)
+ rotx[i] = 0;
+ if (fabs(rotxvel[i]) < multiplier * 4)
+ rotxvel[i] = 0;
+
+ rotx[i] += rotxvel[i] * multiplier * 4;
+ }
+ if (rotyvel[i] || roty[i]) {
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
+ if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (roty[i] < 0) rotyvel[i] += multiplier * 4;
+ if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
+ if (fabs(roty[i]) < multiplier * 4)
+ roty[i] = 0;
+ if (fabs(rotyvel[i]) < multiplier * 4)
+ rotyvel[i] = 0;
+
+ roty[i] += rotyvel[i] * multiplier * 4;
+ }
+ if (roty[i]) {
+ glRotatef(roty[i], 1, 0, 0);
+ }
+ if (rotx[i]) {
+ glRotatef(-rotx[i], 0, 0, 1);
+ }
+ if (rotx[i] > 10)
+ rotx[i] = 10;
+ if (rotx[i] < -10)
+ rotx[i] = -10;
+ if (roty[i] > 10)
+ roty[i] = 10;
+ if (roty[i] < -10)
+ roty[i] = -10;
+ }
+ if (type[i] == treetrunktype || type[i] == treeleavestype) {
+ messedwith[i] -= multiplier;
+ if (rotxvel[i] || rotx[i]) {
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
+ if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
+ if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
+ if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
+ if (fabs(rotx[i]) < multiplier * 4)
+ rotx[i] = 0;
+ if (fabs(rotxvel[i]) < multiplier * 4)
+ rotxvel[i] = 0;
+
+ rotx[i] += rotxvel[i] * multiplier * 4;
+ }
+ if (rotyvel[i] || roty[i]) {
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
+ if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
+ if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (roty[i] < 0) rotyvel[i] += multiplier * 4;
+ if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
+ if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
+ if (fabs(roty[i]) < multiplier * 4)
+ roty[i] = 0;
+ if (fabs(rotyvel[i]) < multiplier * 4)
+ rotyvel[i] = 0;
+
+ roty[i] += rotyvel[i] * multiplier * 4;
+ }
+ if (roty[i]) {
+ glRotatef(roty[i] / 2, 1, 0, 0);
+ }
+ if (rotx[i]) {
+ glRotatef(-rotx[i] / 2, 0, 0, 1);
+ }
+ if (rotx[i] > 10)
+ rotx[i] = 10;
+ if (rotx[i] < -10)
+ rotx[i] = -10;
+ if (roty[i] > 10)
+ roty[i] = 10;
+ if (roty[i] < -10)
+ roty[i] = -10;
+ }
+ if (environment == snowyenvironment) {
+ if (type[i] == treeleavestype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == treetrunktype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == bushtype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ }
+ if (environment == grassyenvironment) {
+ if (type[i] == treeleavestype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == treetrunktype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ if (type[i] == bushtype) {
+ glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
+ }
+ }
+ glRotatef(yaw[i], 0, 1, 0);
+ glColor4f(1, 1, 1, distance);
+ if (type[i] == treeleavestype) {
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ terrainlight = terrain.getLighting(position[i].x, position[i].z);
+ glDepthMask(0);
+ glEnable(GL_BLEND);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3);
+ glAlphaFunc(GL_GREATER, 0);
+ glDisable(GL_ALPHA_TEST);
+ model[i].drawdifftex(treetextureptr);
+ }
+ if (type[i] == bushtype) {
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ terrainlight = terrain.getLighting(position[i].x, position[i].z);
+ glDepthMask(0);
+ glEnable(GL_BLEND);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3);
+ glAlphaFunc(GL_GREATER, 0);
+ glDisable(GL_ALPHA_TEST);
+ model[i].drawdifftex(bushtextureptr);
+ }
+ glPopMatrix();
+ }
+ }
+ }
+ }
+ }
+ }
+ if (environment == desertenvironment)
+ glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ glEnable(GL_ALPHA_TEST);
+ SetUpLight(&light, 0);