X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FModels.cpp;h=9f92cb531d2f5eeabc43b4396ba7e83eb5905f49;hb=15636b33cb62d23b686f6620067a597cb11934ea;hp=bdc44dcdd2182a76278f95c4641a85ab1006d890;hpb=263a338c0c3648cfa2388d4a21584a09294ffd9e;p=lugaru.git diff --git a/Source/Models.cpp b/Source/Models.cpp index bdc44dc..9f92cb5 100644 --- a/Source/Models.cpp +++ b/Source/Models.cpp @@ -173,7 +173,7 @@ int Model::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate) oldp1=*p1; *p1=*p1-*move; if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0); - if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1; + if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1; for(i=0;i<4;i++){ for (j=0;jradius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;} + if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;} for (j=0;jboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -524,7 +524,7 @@ bool Model::load(const char *filename,bool texture ) funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]); } - Texture.xsz=0; + modelTexture.xsz=0; fclose(tfile); @@ -538,8 +538,8 @@ bool Model::load(const char *filename,bool texture ) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -607,7 +607,7 @@ bool Model::loaddecal(const char *filename,bool texture ) } - Texture.xsz=0; + modelTexture.xsz=0; fclose(tfile); @@ -620,8 +620,8 @@ bool Model::loaddecal(const char *filename,bool texture ) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -769,8 +769,8 @@ void Model::Scale(float xscale,float yscale,float zscale) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -809,8 +809,8 @@ void Model::Translate(float xtrans,float ytrans,float ztrans) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -830,8 +830,8 @@ void Model::Rotate(float xang,float yang,float zang) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -878,7 +878,7 @@ void Model::CalculateNormals(bool facenormalise) void Model::drawimmediate() { - glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr); + textureptr.bind(); glBegin(GL_TRIANGLES); for(int i=0;i=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){ @@ -919,7 +919,7 @@ void Model::draw() if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]); if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]); - glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr); + textureptr.bind(); #if PLATFORM_MACOSX glLockArraysEXT( 0, TriangleNum*3); @@ -937,6 +937,7 @@ void Model::draw() //drawimmediate(); } +//TODO: phase out in favor of Texture void Model::drawdifftex(GLuint texture) { glEnableClientState(GL_NORMAL_ARRAY); @@ -950,6 +951,35 @@ void Model::drawdifftex(GLuint texture) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); +#ifndef WIN32 + glLockArraysEXT( 0, TriangleNum*3); +#endif + glDrawArrays(GL_TRIANGLES, 0, TriangleNum*3); +#ifndef WIN32 + glUnlockArraysEXT(); +#endif + + + if(!color)glDisableClientState(GL_NORMAL_ARRAY); + if(color)glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + //drawdiffteximmediate(texture); +} + +void Model::drawdifftex(Texture texture) +{ + glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]); + if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]); + + texture.bind(); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + + #ifndef WIN32 glLockArraysEXT( 0, TriangleNum*3); #endif @@ -999,7 +1029,7 @@ void Model::drawdiffteximmediate(GLuint texture) glEnd(); } -void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtexture2,GLuint breaktexture) +void Model::drawdecals(Texture shadowtexture,Texture bloodtexture,Texture bloodtexture2,Texture breaktexture) { if(decals){ if(type!=decalstype)return; @@ -1023,7 +1053,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2; if(decaltype[i]==shadowdecal&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, shadowtexture); + shadowtexture.bind(); if(!blend){ blend=1; glAlphaFunc(GL_GREATER, 0.0001); @@ -1031,7 +1061,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if(decaltype[i]==breakdecal&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, breaktexture); + breaktexture.bind(); if(!blend){ blend=1; glAlphaFunc(GL_GREATER, 0.0001); @@ -1039,7 +1069,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, bloodtexture); + bloodtexture.bind(); if(blend){ blend=0; glAlphaFunc(GL_GREATER, 0.15); @@ -1047,7 +1077,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, bloodtexture2); + bloodtexture2.bind(); if(blend){ blend=0; glAlphaFunc(GL_GREATER, 0.15); @@ -1121,7 +1151,7 @@ void Model::MakeDecal(int atype, XYZ *where,float *size, float *opacity, float * static int i,j; if(*opacity>0) - if(findDistancefast(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size)) + if(distsq(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size)) for(i=0;iy||vertex[Triangles[i].vertex[1]].yy||vertex[Triangles[i].vertex[2]].yy)){ decalposition[numdecals]=*where; @@ -1198,7 +1228,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota static int i,j; if(opacity>0) - if(findDistancefast(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size)) + if(distsq(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size)) for(i=0;iabs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){ @@ -1385,8 +1415,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota Model::~Model() { deallocate(); - - glDeleteTextures( 1, &textureptr ); + textureptr.destroy(); } void Model::deallocate() @@ -1474,8 +1503,7 @@ Model::Model() Triangles=0; vArray=0; - textureptr = 0; - memset(&Texture, 0, sizeof(Texture)); + memset(&modelTexture, 0, sizeof(modelTexture)); numpossible = 0; color = 0;