X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGraphic%2FSprite.cpp;h=6bf7bb9f5ba777f8616c058539378113184fe240;hb=0aab437dc560d2afa982e61cc2547756ad7b0761;hp=4276ce5e8cbb18a8fa037162728c8abddf3f7262;hpb=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git diff --git a/Source/Graphic/Sprite.cpp b/Source/Graphic/Sprite.cpp index 4276ce5..6bf7bb9 100644 --- a/Source/Graphic/Sprite.cpp +++ b/Source/Graphic/Sprite.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) +Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Graphic/Sprite.h" -#include "Objects/Person.h" +#include "Graphic/Sprite.hpp" + +#include "Game.hpp" +#include "Objects/Person.hpp" extern XYZ viewer; extern float viewdistance; @@ -31,7 +32,6 @@ extern Light light; extern float multiplier; extern float gravity; extern Terrain terrain; -extern Objects objects; extern int detail; extern XYZ viewerfacing; extern int bloodtoggle; @@ -100,105 +100,112 @@ void Sprite::Draw() for (unsigned i = 0; i < sprites.size(); i++) { if (lasttype != sprites[i]->type) { switch (sprites[i]->type) { - case cloudsprite: - cloudtexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case breathsprite: - case cloudimpactsprite: - cloudimpacttexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case smoketype: - smoketexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case bloodsprite: - bloodtexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case splintersprite : - if (lastspecial != sprites[i]->special) { - if (sprites[i]->special == 0) - splintertexture.bind(); - if (sprites[i]->special == 1) - leaftexture.bind(); - if (sprites[i]->special == 2) - snowflaketexture.bind(); - if (sprites[i]->special == 3) - toothtexture.bind(); + case cloudsprite: + cloudtexture.bind(); if (!blend) { blend = 1; glAlphaFunc(GL_GREATER, 0.0001); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - } - break; - case snowsprite: - snowflaketexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - break; - case weaponshinesprite: - shinetexture.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - break; - case flamesprite: - case weaponflamesprite: - flametexture.bind(); - if (blend || lasttype == bloodflamesprite) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.3); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - break; - case bloodflamesprite: - bloodflametexture.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.3); - glBlendFunc(GL_ONE, GL_ZERO); - } - break; + break; + case breathsprite: + case cloudimpactsprite: + cloudimpacttexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case smoketype: + smoketexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case bloodsprite: + bloodtexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case splintersprite: + if (lastspecial != sprites[i]->special) { + if (sprites[i]->special == 0) { + splintertexture.bind(); + } + if (sprites[i]->special == 1) { + leaftexture.bind(); + } + if (sprites[i]->special == 2) { + snowflaketexture.bind(); + } + if (sprites[i]->special == 3) { + toothtexture.bind(); + } + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + } + break; + case snowsprite: + snowflaketexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + break; + case weaponshinesprite: + shinetexture.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + } + break; + case flamesprite: + case weaponflamesprite: + flametexture.bind(); + if (blend || lasttype == bloodflamesprite) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.3); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + } + break; + case bloodflamesprite: + bloodflametexture.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.3); + glBlendFunc(GL_ONE, GL_ZERO); + } + break; } } - if (sprites[i]->type == snowsprite) + if (sprites[i]->type == snowsprite) { distancemult = (144 - (distsq(&tempviewer, &sprites[i]->position) - (144 * fadestart)) * (1 / (1 - fadestart))) / 144; - else + } else { distancemult = (viewdistsquared - (distsq(&viewer, &sprites[i]->position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared; + } if (sprites[i]->type == flamesprite) { - if (distancemult >= 1) + if (distancemult >= 1) { glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity); - else + } else { glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity * distancemult); + } } else { - if (distancemult >= 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity); - else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * distancemult); + if (distancemult >= 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity); + } else { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult); + } } lasttype = sprites[i]->type; lastspecial = sprites[i]->special; @@ -224,48 +231,54 @@ void Sprite::Draw() glRotatef(sprites[i]->rotation, 0, 0, 1); if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) { - if (sprites[i]->alivetime < .14) + if (sprites[i]->alivetime < .14) { glScalef(sprites[i]->alivetime / .14, sprites[i]->alivetime / .14, sprites[i]->alivetime / .14); + } } if (sprites[i]->type == smoketype || sprites[i]->type == snowsprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == breathsprite) { if (sprites[i]->alivetime < .3) { - if (distancemult >= 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * sprites[i]->alivetime / .3); - if (distancemult < 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * distancemult * sprites[i]->alivetime / .3); + if (distancemult >= 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * sprites[i]->alivetime / .3); + } + if (distancemult < 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult * sprites[i]->alivetime / .3); + } } } if (sprites[i]->type == splintersprite && sprites[i]->special > 0 && sprites[i]->special != 3) { if (sprites[i]->alivetime < .2) { - if (distancemult >= 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->alivetime / .2); - else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult * sprites[i]->alivetime / .2); + if (distancemult >= 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->alivetime / .2); + } else { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult * sprites[i]->alivetime / .2); + } } else { - if (distancemult >= 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); - else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); + if (distancemult >= 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); + } else { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult); + } } } if (sprites[i]->type == splintersprite && (sprites[i]->special == 0 || sprites[i]->special == 3)) { - if (distancemult >= 1) - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); - else - glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1); + if (distancemult >= 1) { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1); + } else { + glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult); + } } glBegin(GL_TRIANGLES); glTexCoord2f(1.0f, 1.0f); - glVertex3f( .5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glTexCoord2f(1.0f, 0.0f); - glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(1.0f, 0.0f); - glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); + glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f); glEnd(); @@ -278,10 +291,12 @@ void Sprite::Draw() sprites[i]->position += sprites[i]->velocity * multiplier; sprites[i]->velocity += windvector * multiplier; } - if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype) + if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype) { sprites[i]->position += windvector * multiplier / 2; - if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) + } + if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) { multiplier *= sprites[i]->speed * .7; + } sprites[i]->alivetime += multiplier; if (sprites[i]->type == cloudsprite || sprites[i]->type == cloudimpactsprite) { @@ -307,12 +322,24 @@ void Sprite::Draw() sprites[i]->rotation += multiplier * 360; sprites[i]->position.y -= multiplier; sprites[i]->position += windvector * multiplier; - if (sprites[i]->position.y < tempviewer.y - 6) sprites[i]->position.y += 12; - if (sprites[i]->position.y > tempviewer.y + 6) sprites[i]->position.y -= 12; - if (sprites[i]->position.z < tempviewer.z - 6) sprites[i]->position.z += 12; - if (sprites[i]->position.z > tempviewer.z + 6) sprites[i]->position.z -= 12; - if (sprites[i]->position.x < tempviewer.x - 6) sprites[i]->position.x += 12; - if (sprites[i]->position.x > tempviewer.x + 6) sprites[i]->position.x -= 12; + if (sprites[i]->position.y < tempviewer.y - 6) { + sprites[i]->position.y += 12; + } + if (sprites[i]->position.y > tempviewer.y + 6) { + sprites[i]->position.y -= 12; + } + if (sprites[i]->position.z < tempviewer.z - 6) { + sprites[i]->position.z += 12; + } + if (sprites[i]->position.z > tempviewer.z + 6) { + sprites[i]->position.z -= 12; + } + if (sprites[i]->position.x < tempviewer.x - 6) { + sprites[i]->position.x += 12; + } + if (sprites[i]->position.x > tempviewer.x + 6) { + sprites[i]->position.x -= 12; + } } if (sprites[i]->type == bloodsprite) { bool spritehit = 0; @@ -327,13 +354,15 @@ void Sprite::Draw() if (!spritehit && Person::players[j]->dead && sprites[i]->alivetime > .1) { where = sprites[i]->oldposition; where -= Person::players[j]->coords; - if (!Person::players[j]->skeleton.free) + if (!Person::players[j]->skeleton.free) { where = DoRotation(where, 0, -Person::players[j]->yaw, 0); + } startpoint = where; where = sprites[i]->position; where -= Person::players[j]->coords; - if (!Person::players[j]->skeleton.free) + if (!Person::players[j]->skeleton.free) { where = DoRotation(where, 0, -Person::players[j]->yaw, 0); + } endpoint = where; movepoint = 0; @@ -349,43 +378,50 @@ void Sprite::Draw() whichpatchx = sprites[i]->position.x / (terrain.size / subdivision * terrain.scale); whichpatchz = sprites[i]->position.z / (terrain.size / subdivision * terrain.scale); - if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) - if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { - if (!spritehit) - for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) { - k = terrain.patchobjects[whichpatchx][whichpatchz][j]; - start = sprites[i]->oldposition; - end = sprites[i]->position; - if (!spritehit) - if (objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]) != -1) { - if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0)) - objects.model[k].MakeDecal(blooddecalfast, DoRotation(colpoint - objects.position[k], 0, -objects.yaw[k], 0), sprites[i]->size * 1.6, .5, Random() % 360); - DeleteSprite(i); - spritehit = 1; + if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) { + if (!spritehit) { + for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) { + k = terrain.patchobjects[whichpatchx][whichpatchz][j]; + start = sprites[i]->oldposition; + end = sprites[i]->position; + if (!spritehit) { + if (Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw) != -1) { + if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0)) { + Object::objects[k]->model.MakeDecal(blooddecalfast, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), sprites[i]->size * 1.6, .5, Random() % 360); } + DeleteSprite(i); + spritehit = 1; + } } + } } - if (!spritehit) + } + if (!spritehit) { if (sprites[i]->position.y < terrain.getHeight(sprites[i]->position.x, sprites[i]->position.z)) { terrain.MakeDecal(blooddecalfast, sprites[i]->position, sprites[i]->size * 1.6, .6, Random() % 360); DeleteSprite(i); } + } } } if (sprites[i]->type == splintersprite) { sprites[i]->rotation += sprites[i]->rotatespeed * multiplier; sprites[i]->opacity -= multiplier / 2; - if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3) + if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3) { sprites[i]->velocity.y += gravity * multiplier; - if (sprites[i]->special == 1) + } + if (sprites[i]->special == 1) { sprites[i]->velocity.y += gravity * multiplier * .5; + } } if (sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite) { sprites[i]->rotation += multiplier * sprites[i]->rotatespeed; sprites[i]->opacity -= multiplier * 5 / 4; - if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite) - if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0))) + if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite) { + if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0))) { MakeSprite(smoketype, sprites[i]->position, sprites[i]->velocity, .9, .9, .6, sprites[i]->size * 1.2, .4); + } + } if (sprites[i]->alivetime > .14 && (sprites[i]->type == flamesprite)) { sprites[i]->velocity = 0; sprites[i]->velocity.y = 1.5; @@ -396,24 +432,29 @@ void Sprite::Draw() sprites[i]->color[0] -= multiplier; sprites[i]->color[1] -= multiplier; sprites[i]->color[2] -= multiplier; - if (sprites[i]->color[0] < .6) + if (sprites[i]->color[0] < .6) { sprites[i]->color[0] = .6; - if (sprites[i]->color[1] < .6) + } + if (sprites[i]->color[1] < .6) { sprites[i]->color[1] = .6; - if (sprites[i]->color[2] < .6) + } + if (sprites[i]->color[2] < .6) { sprites[i]->color[2] = .6; + } sprites[i]->size += multiplier; sprites[i]->velocity = 0; sprites[i]->velocity.y = 1.5; sprites[i]->rotation += multiplier * sprites[i]->rotatespeed / 5; } - if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0) + if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0) { DeleteSprite(i); + } } - if (check) + if (check) { for (int i = sprites.size() - 1; i >= 0; i--) { sprites[i]->oldposition = sprites[i]->position; } + } glAlphaFunc(GL_GREATER, 0.0001); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } @@ -462,19 +503,3 @@ Sprite::Sprite() speed = 0; rotatespeed = 0; } - -void Sprite::clearTextures() -{ - toothtexture.destroy(); - cloudtexture.destroy(); - cloudimpacttexture.destroy(); - bloodtexture.destroy(); - flametexture.destroy(); - bloodflametexture.destroy(); - smoketexture.destroy(); - snowflaketexture.destroy(); - shinetexture.destroy(); - splintertexture.destroy(); - leaftexture.destroy(); -} -