if (*rotate)
*p2 = DoRotation(*p2, 0, -*rotate, 0);
- if (numpossible > 0 && numpossible < int(Triangles.size())) {
- for (unsigned int j = 0; int(j) < numpossible; j++) {
- if ((possible[j] >= 0) && possible[j] < int(Triangles.size())) {
- intersecting = LineFacetd(p1, p2, &vertex[Triangles[possible[j]].vertex[0]], &vertex[Triangles[possible[j]].vertex[1]], &vertex[Triangles[possible[j]].vertex[2]], &Triangles[possible[j]].facenormal, &point);
- distance = (point.x - p1->x) * (point.x - p1->x) + (point.y - p1->y) * (point.y - p1->y) + (point.z - p1->z) * (point.z - p1->z);
- if ((distance < olddistance || firstintersecting == -1) && intersecting) {
- olddistance = distance;
- firstintersecting = possible[j];
- *p = point;
- }
+ for (unsigned int j = 0; j < possible.size(); j++) {
+ if (possible[j] < Triangles.size()) {
+ intersecting = LineFacetd(p1, p2, &vertex[Triangles[possible[j]].vertex[0]], &vertex[Triangles[possible[j]].vertex[1]], &vertex[Triangles[possible[j]].vertex[2]], &Triangles[possible[j]].facenormal, &point);
+ distance = (point.x - p1->x) * (point.x - p1->x) + (point.y - p1->y) * (point.y - p1->y) + (point.z - p1->z) * (point.z - p1->z);
+ if ((distance < olddistance || firstintersecting == -1) && intersecting) {
+ olddistance = distance;
+ firstintersecting = possible[j];
+ *p = point;
}
}
}
int Model::LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *move, float *rotate)
{
- static int j;
static float distance;
static float olddistance;
static int intersecting;
if (*rotate)
*p2 = DoRotation(*p2, 0, -*rotate, 0);
- if (numpossible)
- for (j = 0; j < numpossible; j++) {
- if (possible[j] >= 0 && possible[j] < int(Triangles.size())) {
- intersecting = LineFacetd(p1, p2, &vertex[Triangles[possible[j]].vertex[0]], &vertex[Triangles[possible[j]].vertex[1]], &vertex[Triangles[possible[j]].vertex[2]], &Triangles[possible[j]].facenormal, &point);
- distance = (point.x - p1->x) * (point.x - p1->x) + (point.y - p1->y) * (point.y - p1->y) + (point.z - p1->z) * (point.z - p1->z);
- if ((distance < olddistance || firstintersecting == -1) && intersecting) {
- olddistance = distance;
- firstintersecting = possible[j];
- }
+ for (unsigned int j = 0; j < possible.size(); j++) {
+ if (possible[j] < Triangles.size()) {
+ intersecting = LineFacetd(p1, p2, &vertex[Triangles[possible[j]].vertex[0]], &vertex[Triangles[possible[j]].vertex[1]], &vertex[Triangles[possible[j]].vertex[2]], &Triangles[possible[j]].facenormal, &point);
+ distance = (point.x - p1->x) * (point.x - p1->x) + (point.y - p1->y) * (point.y - p1->y) + (point.z - p1->z) * (point.z - p1->z);
+ if ((distance < olddistance || firstintersecting == -1) && intersecting) {
+ olddistance = distance;
+ firstintersecting = possible[j];
}
}
+ }
if (firstintersecting > 0) {
distance = abs((Triangles[firstintersecting].facenormal.x * p2->x) + (Triangles[firstintersecting].facenormal.y * p2->y) + (Triangles[firstintersecting].facenormal.z * p2->z) - ((Triangles[firstintersecting].facenormal.x * vertex[Triangles[firstintersecting].vertex[0]].x) + (Triangles[firstintersecting].facenormal.y * vertex[Triangles[firstintersecting].vertex[0]].y) + (Triangles[firstintersecting].facenormal.z * vertex[Triangles[firstintersecting].vertex[0]].z)));
oldp1 = *p1;
*p1 = *p1 - *move;
- numpossible = 0;
+ possible.clear();
if (*rotate)
*p1 = DoRotation(*p1, 0, -*rotate, 0);
if (!intersecting)
intersecting = sphere_line_intersection(&vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[2]], p1, &radius);
if (intersecting) {
- possible[numpossible] = j;
- numpossible++;
+ possible.push_back(j);
}
}
if ((distance < olddistance || firstintersecting == -1) && intersecting) {
if (*rotate)
*p1 = DoRotation(*p1, 0, *rotate, 0);
*p1 += *move;
+
return firstintersecting;
}
{
FILE *tfile;
long i;
- int TriangleNum;
+ short triangleNum;
type = notextype;
color = 0;
// read model settings
fseek(tfile, 0, SEEK_SET);
- funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+ funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
// read the model data
deallocate();
- numpossible = 0;
+ possible.clear();
owner = (int*)malloc(sizeof(int) * vertexNum);
- possible = (int*)malloc(sizeof(int) * TriangleNum);
vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
- Triangles.resize(TriangleNum);
- vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+ Triangles.resize(triangleNum);
+ vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
for (i = 0; i < vertexNum; i++) {
funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
}
- for (i = 0; i < TriangleNum; i++) {
+ for (i = 0; i < triangleNum; i++) {
short vertex[6];
funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
Triangles[i].vertex[0] = vertex[0];
{
FILE *tfile;
long i;
- int TriangleNum;
+ short triangleNum;
LOGFUNC;
// read model settings
fseek(tfile, 0, SEEK_SET);
- funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+ funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
// read the model data
deallocate();
- numpossible = 0;
+ possible.clear();
owner = (int*)malloc(sizeof(int) * vertexNum);
- possible = (int*)malloc(sizeof(int) * TriangleNum);
vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
- Triangles.resize(TriangleNum);
- vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+ Triangles.resize(triangleNum);
+ vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
for (i = 0; i < vertexNum; i++) {
funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
}
- for (i = 0; i < TriangleNum; i++) {
+ for (i = 0; i < triangleNum; i++) {
short vertex[6];
funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
Triangles[i].vertex[0] = vertex[0];
{
FILE *tfile;
long i, j;
- int TriangleNum;
+ short triangleNum;
LOGFUNC;
LOG(std::string("Loading decal...") + Folders::getResourcePath(filename));
type = decalstype;
- decals.clear();
color = 0;
tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
// read model settings
fseek(tfile, 0, SEEK_SET);
- funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+ funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
// read the model data
deallocate();
- numpossible = 0;
+ possible.clear();
owner = (int*)malloc(sizeof(int) * vertexNum);
- possible = (int*)malloc(sizeof(int) * TriangleNum);
vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
- Triangles.resize(TriangleNum);
- vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+ Triangles.resize(triangleNum);
+ vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
for (i = 0; i < vertexNum; i++) {
funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
}
- for (i = 0; i < TriangleNum; i++) {
+ for (i = 0; i < triangleNum; i++) {
short vertex[6];
funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
Triangles[i].vertex[0] = vertex[0];
{
FILE *tfile;
long i;
- int TriangleNum;
+ short triangleNum;
LOGFUNC;
// read model settings
fseek(tfile, 0, SEEK_SET);
- funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
+ funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum);
// read the model data
deallocate();
- numpossible = 0;
+ possible.clear();
owner = (int*)malloc(sizeof(int) * vertexNum);
- possible = (int*)malloc(sizeof(int) * TriangleNum);
vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum);
- Triangles.resize(TriangleNum);
- vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24);
+ Triangles.resize(triangleNum);
+ vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24);
for (i = 0; i < vertexNum; i++) {
funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z);
}
- for (i = 0; i < TriangleNum; i++) {
+ for (i = 0; i < triangleNum; i++) {
short vertex[6];
funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]);
Triangles[i].vertex[0] = vertex[0];
glBegin(GL_TRIANGLES);
for (unsigned int i = 0; i < Triangles.size(); i++) {
glTexCoord2f(Triangles[i].gx[0], Triangles[i].gy[0]);
- if (color)
+ if (color) {
glColor3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
- if (!color && flat)
+ } else if (flat) {
glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+ } else {
+ glNormal3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
+ }
glVertex3f(vertex[Triangles[i].vertex[0]].x, vertex[Triangles[i].vertex[0]].y, vertex[Triangles[i].vertex[0]].z);
glTexCoord2f(Triangles[i].gx[1], Triangles[i].gy[1]);
- if (color)
+ if (color) {
glColor3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
- if (!color && flat)
+ } else if (flat) {
glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+ } else {
+ glNormal3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
+ }
glVertex3f(vertex[Triangles[i].vertex[1]].x, vertex[Triangles[i].vertex[1]].y, vertex[Triangles[i].vertex[1]].z);
glTexCoord2f(Triangles[i].gx[2], Triangles[i].gy[2]);
- if (color)
+ if (color) {
glColor3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
- if (!color && flat)
+ } else if (flat) {
glNormal3f(Triangles[i].facenormal.x, Triangles[i].facenormal.y, Triangles[i].facenormal.y);
+ } else {
+ glNormal3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
+ }
glVertex3f(vertex[Triangles[i].vertex[2]].x, vertex[Triangles[i].vertex[2]].y, vertex[Triangles[i].vertex[2]].z);
}
glEnd();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- if (!color)
- glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
- if (color)
+ if (color) {
glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+ } else {
+ glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+ }
textureptr.bind();
glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
- if (!color)
- glDisableClientState(GL_NORMAL_ARRAY);
- if (color)
+ if (color) {
glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-//TODO: phase out in favor of Texture
-void Model::drawdifftex(GLuint 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]);
-
- glBindTexture(GL_TEXTURE_2D, (unsigned long)texture);
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
-
- glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
-
- if (!color)
+ } else {
glDisableClientState(GL_NORMAL_ARRAY);
- if (color)
- glDisableClientState(GL_COLOR_ARRAY);
+ }
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
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)
+ if (color) {
glInterleavedArrays( GL_T2F_C3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+ } else {
+ glInterleavedArrays( GL_T2F_N3F_V3F, 8 * sizeof(GLfloat), &vArray[0]);
+ }
texture.bind();
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glDrawArrays(GL_TRIANGLES, 0, Triangles.size() * 3);
- if (!color)
- glDisableClientState(GL_NORMAL_ARRAY);
- if (color)
+ if (color) {
glDisableClientState(GL_COLOR_ARRAY);
+ } else {
+ glDisableClientState(GL_NORMAL_ARRAY);
+ }
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture)
{
if (decalstoggle) {
- if (type != decalstype)
+ if (type != decalstype) {
return;
- static int lasttype;
- static bool blend;
+ }
- blend = 1;
+ bool blend = true;
+ int lasttype = -1;
- lasttype = -1;
glEnable(GL_BLEND);
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
if (Triangles[i].facenormal.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)) {
distance = abs(((Triangles[i].facenormal.x * where->x) + (Triangles[i].facenormal.y * where->y) + (Triangles[i].facenormal.z * where->z) - ((Triangles[i].facenormal.x * vertex[Triangles[i].vertex[0]].x) + (Triangles[i].facenormal.y * vertex[Triangles[i].vertex[0]].y) + (Triangles[i].facenormal.z * vertex[Triangles[i].vertex[0]].z))) / Triangles[i].facenormal.y);
- if (*opacity - distance / 10 > 0) {
+ if ((*opacity - distance / 10) > 0) {
Decal decal(*where, atype, *opacity - distance / 10, *rotation, *size, *this, i, 0);
if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0))
for (unsigned int i = 0; i < Triangles.size(); i++) {
distance = abs(((Triangles[i].facenormal.x * where.x) + (Triangles[i].facenormal.y * where.y) + (Triangles[i].facenormal.z * where.z) - ((Triangles[i].facenormal.x * vertex[Triangles[i].vertex[0]].x) + (Triangles[i].facenormal.y * vertex[Triangles[i].vertex[0]].y) + (Triangles[i].facenormal.z * vertex[Triangles[i].vertex[0]].z))));
if (distance < .02 && abs(Triangles[i].facenormal.y) > abs(Triangles[i].facenormal.x) && abs(Triangles[i].facenormal.y) > abs(Triangles[i].facenormal.z)) {
- if (opacity - distance / 10 > 0) {
+ if ((opacity - distance / 10) > 0) {
Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 0);
if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0))
}
}
} else if (distance < .02 && abs(Triangles[i].facenormal.x) > abs(Triangles[i].facenormal.y) && abs(Triangles[i].facenormal.x) > abs(Triangles[i].facenormal.z)) {
- if (opacity - distance / 10 > 0) {
+ if ((opacity - distance / 10) > 0) {
Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 1);
if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0))
}
}
} else if (distance < .02 && abs(Triangles[i].facenormal.z) > abs(Triangles[i].facenormal.y) && abs(Triangles[i].facenormal.z) > abs(Triangles[i].facenormal.x)) {
- if (opacity - distance / 10 > 0) {
+ if ((opacity - distance / 10) > 0) {
Decal decal(where, atype, opacity - distance / 10, rotation, size, *this, i, 2);
if (!(decal.texcoords[0][0] < 0 && decal.texcoords[1][0] < 0 && decal.texcoords[2][0] < 0))
free(owner);
owner = 0;
- if (possible)
- free(possible);
- possible = 0;
-
if (vertex)
free(vertex);
vertex = 0;
if (vArray)
free(vArray);
vArray = 0;
+
+ decals.clear();
}
Model::Model()
: vertexNum(0),
- hastexture(0),
- type(0), oldtype(0),
- possible(0),
+ type(nothing),
owner(0),
vertex(0),
normals(0),
- vArray(0)
+ vArray(0),
+ color(0),
+ boundingspherecenter(),
+ boundingsphereradius(0),
+ flat(false)
{
memset(&modelTexture, 0, sizeof(modelTexture));
- numpossible = 0;
- color = 0;
-
- boundingspherecenter = 0;
- boundingsphereradius = 0;
-
- flat = 0;
-
- type = nothing;
}