X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FObjects.cpp;h=efb2c00b6373157cf6c0381f4cf1b0849a3bafc4;hb=f38eb24f446b94d592d97b24b315bb44bed7b12c;hp=15eb79377e58e49ed88ae04949674574df86770f;hpb=cd043e3f9e26c2b3406b40a354c2840941e9db7f;p=lugaru.git diff --git a/Source/Objects.cpp b/Source/Objects.cpp index 15eb793..efb2c00 100644 --- a/Source/Objects.cpp +++ b/Source/Objects.cpp @@ -1,5 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -104,10 +105,6 @@ void Objects::Draw() 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(); @@ -163,7 +160,7 @@ void Objects::Draw() roty[i] = -10; } if (type[i] == treetrunktype || type[i] == treeleavestype) { - if (type[i] == treetrunktype || environment == 2) { + if (type[i] == treetrunktype || environment == desertenvironment) { messedwith[i] -= multiplier; if (rotxvel[i] || rotx[i]) { if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); @@ -362,152 +359,148 @@ void Objects::Draw() 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(); + 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(); } } } @@ -553,17 +546,17 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale) rotx[numobjects] = 0; roty[numobjects] = 0; - if (atype == boxtype) model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0); - if (atype == cooltype) model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0); - if (atype == walltype) model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0); - if (atype == tunneltype) model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0); - if (atype == chimneytype) model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0); - if (atype == spiketype) model[numobjects].load((char *)":Data:Models:Spike.solid", 0); - if (atype == weirdtype) model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0); - if (atype == rocktype) model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0); - if (atype == treetrunktype) model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0); - if (atype == treeleavestype) model[numobjects].load((char *)":Data:Models:Leaves.solid", 0); - if (atype == bushtype) model[numobjects].load((char *)":Data:Models:Bush.solid", 0); + if (atype == boxtype) model[numobjects].loaddecal((char *)"Models/Box.solid", 0); + if (atype == cooltype) model[numobjects].loaddecal((char *)"Models/Cool.solid", 0); + if (atype == walltype) model[numobjects].loaddecal((char *)"Models/Wall.solid", 0); + if (atype == tunneltype) model[numobjects].loaddecal((char *)"Models/Tunnel.solid", 0); + if (atype == chimneytype) model[numobjects].loaddecal((char *)"Models/Chimney.solid", 0); + if (atype == spiketype) model[numobjects].load((char *)"Models/Spike.solid", 0); + if (atype == weirdtype) model[numobjects].loaddecal((char *)"Models/Weird.solid", 0); + if (atype == rocktype) model[numobjects].loaddecal((char *)"Models/Rock.solid", 0); + if (atype == treetrunktype) model[numobjects].load((char *)"Models/TreeTrunk.solid", 0); + if (atype == treeleavestype) model[numobjects].load((char *)"Models/Leaves.solid", 0); + if (atype == bushtype) model[numobjects].load((char *)"Models/Bush.solid", 0); if (atype == boxtype) friction[numobjects] = 1.5; if (atype == cooltype) friction[numobjects] = 1.5; @@ -579,7 +572,7 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale) if (atype == treeleavestype) friction[numobjects] = 0; if (atype == platformtype) { - model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0); + model[numobjects].loaddecal((char *)"Models/Platform.solid", 0); model[numobjects].Rotate(90, 0, 0); } @@ -635,10 +628,6 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a position[numobjects] = where; if (atype == bushtype) position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3; - /*if(atype==firetype){ - if(position[numobjects].y