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;j<TriangleNum;j++){
numpossible=0;
if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
- if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
+ if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
for (j=0;j<TriangleNum;j++){
intersecting=0;
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
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);
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
}
- Texture.xsz=0;
+ modelTexture.xsz=0;
fclose(tfile);
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
boundingsphereradius=0;
for(i=0;i<vertexNum;i++){
for(j=0;j<vertexNum;j++){
- if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
- 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;
}
}
void Model::drawimmediate()
{
- glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr);
+ textureptr.bind();
glBegin(GL_TRIANGLES);
for(int i=0;i<TriangleNum;i++){
/*if(Triangles[i].vertex[0]<vertexNum&&Triangles[i].vertex[1]<vertexNum&&Triangles[i].vertex[2]<vertexNum&&Triangles[i].vertex[0]>=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){
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);
//drawimmediate();
}
+//TODO: phase out in favor of Texture
void Model::drawdifftex(GLuint texture)
{
glEnableClientState(GL_NORMAL_ARRAY);
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
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;
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);
}
}
if(decaltype[i]==breakdecal&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, breaktexture);
+ breaktexture.bind();
if(!blend){
blend=1;
glAlphaFunc(GL_GREATER, 0.0001);
}
}
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);
}
}
if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, bloodtexture2);
+ bloodtexture2.bind();
if(blend){
blend=0;
glAlphaFunc(GL_GREATER, 0.15);
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;i<TriangleNum;i++){
if(facenormals[i].y<-.1&&(vertex[Triangles[i].vertex[0]].y<where->y||vertex[Triangles[i].vertex[1]].y<where->y||vertex[Triangles[i].vertex[2]].y<where->y)){
decalposition[numdecals]=*where;
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;i<TriangleNum;i++){
distance=abs(((facenormals[i].x*where.x)+(facenormals[i].y*where.y)+(facenormals[i].z*where.z)-((facenormals[i].x*vertex[Triangles[i].vertex[0]].x)+(facenormals[i].y*vertex[Triangles[i].vertex[0]].y)+(facenormals[i].z*vertex[Triangles[i].vertex[0]].z))));
if(distance<.02&&abs(facenormals[i].y)>abs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){
Model::~Model()
{
deallocate();
-
- if(textureptr) glDeleteTextures( 1, &textureptr );
+ textureptr.destroy();
}
void Model::deallocate()
Triangles=0;
vArray=0;
- textureptr = 0;
- memset(&Texture, 0, sizeof(Texture));
+ memset(&modelTexture, 0, sizeof(modelTexture));
numpossible = 0;
color = 0;