/*
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.
//Functions
-Object::Object() :
- position(),
- type(0),
- yaw(0),
- pitch(0),
- rotx(0),
- rotxvel(0),
- roty(0),
- rotyvel(0),
- possible(false),
- model(),
- displaymodel(),
- friction(0),
- scale(0),
- messedwith(0),
- checked(0),
- shadowed(0),
- occluded(0),
- onfire(false),
- flamedelay(0)
+Object::Object()
+ : position()
+ , type(boxtype)
+ , yaw(0)
+ , pitch(0)
+ , rotx(0)
+ , rotxvel(0)
+ , roty(0)
+ , rotyvel(0)
+ , possible(false)
+ , model()
+ , displaymodel()
+ , friction(0)
+ , scale(0)
+ , messedwith(0)
+ , checked(0)
+ , shadowed(0)
+ , occluded(0)
+ , onfire(false)
+ , flamedelay(0)
{
}
-Object::Object(int _type, XYZ _position, float _yaw, float _pitch, float _scale) : Object()
+Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale)
+ : Object()
{
scale = _scale;
type = _type;
yaw = _yaw;
pitch = _pitch;
- switch(type) {
+ switch (type) {
case boxtype:
- model.loaddecal("Models/Box.solid", 0);
+ model.loaddecal("Models/Box.solid");
friction = 1.5;
break;
case cooltype:
- model.loaddecal("Models/Cool.solid", 0);
+ model.loaddecal("Models/Cool.solid");
friction = 1.5;
break;
case walltype:
- model.loaddecal("Models/Wall.solid", 0);
+ model.loaddecal("Models/Wall.solid");
friction = 1.5;
break;
case tunneltype:
- model.loaddecal("Models/Tunnel.solid", 0);
+ model.loaddecal("Models/Tunnel.solid");
friction = 1.5;
break;
case chimneytype:
- model.loaddecal("Models/Chimney.solid", 0);
+ model.loaddecal("Models/Chimney.solid");
friction = 1.5;
break;
case spiketype:
- model.load("Models/Spike.solid", 0);
+ model.load("Models/Spike.solid");
friction = .4;
break;
case weirdtype:
- model.loaddecal("Models/Weird.solid", 0);
+ model.loaddecal("Models/Weird.solid");
friction = 1.5;
break;
case rocktype:
- model.loaddecal("Models/Rock.solid", 0);
+ model.loaddecal("Models/Rock.solid");
if (scale > .5) {
friction = 1.5;
} else {
}
break;
case treetrunktype:
- model.load("Models/TreeTrunk.solid", 0);
+ model.load("Models/TreeTrunk.solid");
friction = .4;
break;
case treeleavestype:
scale += fabs((float)(Random() % 100) / 900) * scale;
- model.load("Models/Leaves.solid", 0);
+ model.load("Models/Leaves.solid");
friction = 0;
break;
case bushtype:
position.y = terrain.getHeight(position.x, position.z) - .3;
- model.load("Models/Bush.solid", 0);
+ model.load("Models/Bush.solid");
break;
case platformtype:
- model.loaddecal("Models/Platform.solid", 0);
+ model.loaddecal("Models/Platform.solid");
model.Rotate(90, 0, 0);
friction = 1.5;
break;
patchx = terrainpoint.x / (terrain.size / subdivision * terrain.scale);
patchz = terrainpoint.z / (terrain.size / subdivision * terrain.scale);
if (patchx >= 0 && patchz >= 0 && patchx < subdivision && patchz < subdivision) {
- if (terrain.patchobjectnum[patchx][patchz]) {
- for (int k = 0; k < terrain.patchobjectnum[patchx][patchz]; k++) {
- int l = terrain.patchobjects[patchx][patchz][k];
- if (objects[l]->type != treetrunktype) {
- testpoint = terrainpoint;
- testpoint2 = terrainpoint + lightloc * 50 * (1 - shadowed);
- if (objects[l]->model.LineCheck(&testpoint, &testpoint2, &col, &objects[l]->position, &objects[l]->yaw) != -1) {
- shadowed = 1 - (findDistance(&terrainpoint, &col) / 50);
- }
+ for (unsigned int k = 0; k < terrain.patchobjects[patchx][patchz].size(); k++) {
+ unsigned int l = terrain.patchobjects[patchx][patchz][k];
+ if (objects[l]->type != treetrunktype) {
+ testpoint = terrainpoint;
+ testpoint2 = terrainpoint + lightloc * 50 * (1 - shadowed);
+ if (objects[l]->model.LineCheck(&testpoint, &testpoint2, &col, &objects[l]->position, &objects[l]->yaw) != -1) {
+ shadowed = 1 - (findDistance(&terrainpoint, &col) / 50);
}
}
}
if (shadowed > 0) {
col = model.normals[j] - DoRotation(lightloc * shadowed, 0, -yaw, 0);
Normalise(&col);
- for (int k = 0; k < model.TriangleNum; k++) {
+ for (unsigned int k = 0; k < model.Triangles.size(); k++) {
if (model.Triangles[k].vertex[0] == j) {
int l = k * 24;
model.vArray[l + 2] = col.x;
shadowed = 0;
}
+void Object::handleRot(int divide)
+{
+ messedwith -= multiplier;
+ if (rotxvel || rotx) {
+ if (rotx > 0) {
+ rotxvel -= multiplier * 8 * fabs(rotx);
+ }
+ if (rotx < 0) {
+ rotxvel += multiplier * 8 * fabs(rotx);
+ }
+ if (rotx > 0) {
+ rotxvel -= multiplier * 4;
+ }
+ if (rotx < 0) {
+ rotxvel += multiplier * 4;
+ }
+ if (rotxvel > 0) {
+ rotxvel -= multiplier * 4;
+ }
+ if (rotxvel < 0) {
+ rotxvel += multiplier * 4;
+ }
+ if (fabs(rotx) < multiplier * 4) {
+ rotx = 0;
+ }
+ if (fabs(rotxvel) < multiplier * 4) {
+ rotxvel = 0;
+ }
+
+ rotx += rotxvel * multiplier * 4;
+ }
+ if (rotyvel || roty) {
+ if (roty > 0) {
+ rotyvel -= multiplier * 8 * fabs(roty);
+ }
+ if (roty < 0) {
+ rotyvel += multiplier * 8 * fabs(roty);
+ }
+ if (roty > 0) {
+ rotyvel -= multiplier * 4;
+ }
+ if (roty < 0) {
+ rotyvel += multiplier * 4;
+ }
+ if (rotyvel > 0) {
+ rotyvel -= multiplier * 4;
+ }
+ if (rotyvel < 0) {
+ rotyvel += multiplier * 4;
+ }
+ if (fabs(roty) < multiplier * 4) {
+ roty = 0;
+ }
+ if (fabs(rotyvel) < multiplier * 4) {
+ rotyvel = 0;
+ }
+
+ roty += rotyvel * multiplier * 4;
+ }
+ if (roty) {
+ glRotatef(roty / divide, 1, 0, 0);
+ }
+ if (rotx) {
+ glRotatef(-rotx / divide, 0, 0, 1);
+ }
+ if (rotx > 10) {
+ rotx = 10;
+ }
+ if (rotx < -10) {
+ rotx = -10;
+ }
+ if (roty > 10) {
+ roty = 10;
+ }
+ if (roty < -10) {
+ roty = -10;
+ }
+}
+
void Object::draw()
{
static float distance;
hidden = !(distsqflat(&viewer, &position) > playerdist + 3 || (type != bushtype && type != treeleavestype));
if (!hidden) {
- if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment)
- glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
- else
- glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) {
+ glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness);
+ } else {
+ glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
+ }
distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
- if (distance > 1)
+ if (distance > 1) {
distance = 1;
+ }
if (distance > 0) {
if (occluded < 6) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- if (!model.color)
+ if (!model.color) {
glEnable(GL_LIGHTING);
- else
+ } else {
glDisable(GL_LIGHTING);
+ }
glDepthMask(1);
glTranslatef(position.x, position.y, position.z);
if (type == bushtype) {
- messedwith -= multiplier;
- if (rotxvel || rotx) {
- if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
- if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
- if (rotx > 0) rotxvel -= multiplier * 4;
- if (rotx < 0) rotxvel += multiplier * 4;
- if (rotxvel > 0) rotxvel -= multiplier * 4;
- if (rotxvel < 0) rotxvel += multiplier * 4;
- if (fabs(rotx) < multiplier * 4)
- rotx = 0;
- if (fabs(rotxvel) < multiplier * 4)
- rotxvel = 0;
-
- rotx += rotxvel * multiplier * 4;
- }
- if (rotyvel || roty) {
- if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
- if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
- if (roty > 0) rotyvel -= multiplier * 4;
- if (roty < 0) rotyvel += multiplier * 4;
- if (rotyvel > 0) rotyvel -= multiplier * 4;
- if (rotyvel < 0) rotyvel += multiplier * 4;
- if (fabs(roty) < multiplier * 4)
- roty = 0;
- if (fabs(rotyvel) < multiplier * 4)
- rotyvel = 0;
-
- roty += rotyvel * multiplier * 4;
- }
- if (roty) {
- glRotatef(roty, 1, 0, 0);
- }
- if (rotx) {
- glRotatef(-rotx, 0, 0, 1);
- }
- if (rotx > 10)
- rotx = 10;
- if (rotx < -10)
- rotx = -10;
- if (roty > 10)
- roty = 10;
- if (roty < -10)
- roty = -10;
+ handleRot(1);
}
if (type == treetrunktype || type == treeleavestype) {
if (type == treetrunktype || environment == desertenvironment) {
- messedwith -= multiplier;
- if (rotxvel || rotx) {
- if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
- if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
- if (rotx > 0) rotxvel -= multiplier * 4;
- if (rotx < 0) rotxvel += multiplier * 4;
- if (rotxvel > 0) rotxvel -= multiplier * 4;
- if (rotxvel < 0) rotxvel += multiplier * 4;
- if (fabs(rotx) < multiplier * 4)
- rotx = 0;
- if (fabs(rotxvel) < multiplier * 4)
- rotxvel = 0;
-
- rotx += rotxvel * multiplier * 4;
- }
- if (rotyvel || roty) {
- if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
- if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
- if (roty > 0) rotyvel -= multiplier * 4;
- if (roty < 0) rotyvel += multiplier * 4;
- if (rotyvel > 0) rotyvel -= multiplier * 4;
- if (rotyvel < 0) rotyvel += multiplier * 4;
- if (fabs(roty) < multiplier * 4)
- roty = 0;
- if (fabs(rotyvel) < multiplier * 4)
- rotyvel = 0;
-
- roty += rotyvel * multiplier * 4;
- }
- if (roty) {
- glRotatef(roty / 6, 1, 0, 0);
- }
- if (rotx) {
- glRotatef(-rotx / 6, 0, 0, 1);
- }
- if (rotx > 10)
- rotx = 10;
- if (rotx < -10)
- rotx = -10;
- if (roty > 10)
- roty = 10;
- if (roty < -10)
- roty = -10;
+ handleRot(6);
} else {
- messedwith -= multiplier;
- if (rotxvel || rotx) {
- if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
- if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
- if (rotx > 0) rotxvel -= multiplier * 4;
- if (rotx < 0) rotxvel += multiplier * 4;
- if (rotxvel > 0) rotxvel -= multiplier * 4;
- if (rotxvel < 0) rotxvel += multiplier * 4;
- if (fabs(rotx) < multiplier * 4)
- rotx = 0;
- if (fabs(rotxvel) < multiplier * 4)
- rotxvel = 0;
-
- rotx += rotxvel * multiplier * 4;
- }
- if (rotyvel || roty) {
- if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
- if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
- if (roty > 0) rotyvel -= multiplier * 4;
- if (roty < 0) rotyvel += multiplier * 4;
- if (rotyvel > 0) rotyvel -= multiplier * 4;
- if (rotyvel < 0) rotyvel += multiplier * 4;
- if (fabs(roty) < multiplier * 4)
- roty = 0;
- if (fabs(rotyvel) < multiplier * 4)
- rotyvel = 0;
-
- roty += rotyvel * multiplier * 4;
- }
- if (roty) {
- glRotatef(roty / 4, 1, 0, 0);
- }
- if (rotx) {
- glRotatef(-rotx / 4, 0, 0, 1);
- }
- if (rotx > 10)
- rotx = 10;
- if (rotx < -10)
- rotx = -10;
- if (roty > 10)
- roty = 10;
- if (roty < -10)
- roty = -10;
+ handleRot(4);
}
-
}
- if (/*detail==2&&*/environment == snowyenvironment) {
+ if (environment == snowyenvironment) {
if (type == treeleavestype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 1.5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == treetrunktype) {
- glRotatef((sin(windvar + position.x * .3) + .5)*.5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
+ glRotatef((sin(windvar + position.x * .3) + .5) * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == bushtype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 4 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
}
- if (/*detail==2&&*/environment == grassyenvironment) {
+ if (environment == grassyenvironment) {
if (type == treeleavestype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == treetrunktype) {
- glRotatef((sin(windvar + position.x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
+ glRotatef((sin(windvar + position.x * .3) + .5) * .5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == bushtype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
}
- if (/*detail==2&&*/environment == desertenvironment) {
+ if (environment == desertenvironment) {
if (type == bushtype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
}
glRotatef(yaw, 0, 1, 0);
- if (distance > 1)
- distance = 1;
glColor4f((1 - shadowed) / 2 + .5, (1 - shadowed) / 2 + .5, (1 - shadowed) / 2 + .5, distance);
if (distance >= 1) {
glDisable(GL_BLEND);
glAlphaFunc(GL_GREATER, 0.5);
- }
- if (distance < 1) {
+ } else {
glEnable(GL_BLEND);
glAlphaFunc(GL_GREATER, 0.1);
}
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
terrainlight = terrain.getLighting(position.x, position.z);
- if (!hidden) {
- glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
- if (distance < 1)
- glAlphaFunc(GL_GREATER, 0.2);
- }
- if (hidden) {
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
- glAlphaFunc(GL_GREATER, 0);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
+ if (distance < 1) {
+ glAlphaFunc(GL_GREATER, 0.2);
}
model.drawdifftex(treetextureptr);
}
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
terrainlight = terrain.getLighting(position.x, position.z);
- if (!hidden) {
- glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
- if (distance < 1)
- glAlphaFunc(GL_GREATER, 0.2);
- }
- if (hidden) {
- glDepthMask(0);
- glEnable(GL_BLEND);
- glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
- glAlphaFunc(GL_GREATER, 0);
+ glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
+ if (distance < 1) {
+ glAlphaFunc(GL_GREATER, 0.2);
}
model.drawdifftex(bushtextureptr);
}
glDepthMask(1);
glTranslatef(position.x, position.y, position.z);
if (type == bushtype) {
- messedwith -= multiplier;
- if (rotxvel || rotx) {
- if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
- if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
- if (rotx > 0) rotxvel -= multiplier * 4;
- if (rotx < 0) rotxvel += multiplier * 4;
- if (rotxvel > 0) rotxvel -= multiplier * 4;
- if (rotxvel < 0) rotxvel += multiplier * 4;
- if (fabs(rotx) < multiplier * 4)
- rotx = 0;
- if (fabs(rotxvel) < multiplier * 4)
- rotxvel = 0;
-
- rotx += rotxvel * multiplier * 4;
- }
- if (rotyvel || roty) {
- if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
- if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
- if (roty > 0) rotyvel -= multiplier * 4;
- if (roty < 0) rotyvel += multiplier * 4;
- if (rotyvel > 0) rotyvel -= multiplier * 4;
- if (rotyvel < 0) rotyvel += multiplier * 4;
- if (fabs(roty) < multiplier * 4)
- roty = 0;
- if (fabs(rotyvel) < multiplier * 4)
- rotyvel = 0;
-
- roty += rotyvel * multiplier * 4;
- }
- if (roty) {
- glRotatef(roty, 1, 0, 0);
- }
- if (rotx) {
- glRotatef(-rotx, 0, 0, 1);
- }
- if (rotx > 10)
- rotx = 10;
- if (rotx < -10)
- rotx = -10;
- if (roty > 10)
- roty = 10;
- if (roty < -10)
- roty = -10;
+ handleRot(1);
}
if (type == treetrunktype || type == treeleavestype) {
- messedwith -= multiplier;
- if (rotxvel || rotx) {
- if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
- if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
- if (rotx > 0) rotxvel -= multiplier * 4;
- if (rotx < 0) rotxvel += multiplier * 4;
- if (rotxvel > 0) rotxvel -= multiplier * 4;
- if (rotxvel < 0) rotxvel += multiplier * 4;
- if (fabs(rotx) < multiplier * 4)
- rotx = 0;
- if (fabs(rotxvel) < multiplier * 4)
- rotxvel = 0;
-
- rotx += rotxvel * multiplier * 4;
- }
- if (rotyvel || roty) {
- if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
- if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
- if (roty > 0) rotyvel -= multiplier * 4;
- if (roty < 0) rotyvel += multiplier * 4;
- if (rotyvel > 0) rotyvel -= multiplier * 4;
- if (rotyvel < 0) rotyvel += multiplier * 4;
- if (fabs(roty) < multiplier * 4)
- roty = 0;
- if (fabs(rotyvel) < multiplier * 4)
- rotyvel = 0;
-
- roty += rotyvel * multiplier * 4;
- }
- if (roty) {
- glRotatef(roty / 2, 1, 0, 0);
- }
- if (rotx) {
- glRotatef(-rotx / 2, 0, 0, 1);
- }
- if (rotx > 10)
- rotx = 10;
- if (rotx < -10)
- rotx = -10;
- if (roty > 10)
- roty = 10;
- if (roty < -10)
- roty = -10;
+ handleRot(2);
}
if (environment == snowyenvironment) {
if (type == treeleavestype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 1.5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == treetrunktype) {
- glRotatef((sin(windvar + position.x * .3) + .5)*.5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
+ glRotatef((sin(windvar + position.x * .3) + .5) * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == bushtype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 4 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
glRotatef((sin(windvar + position.x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == treetrunktype) {
- glRotatef((sin(windvar + position.x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
+ glRotatef((sin(windvar + position.x * .3) + .5) * .5 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
}
if (type == bushtype) {
glRotatef((sin(windvar + position.x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position.x * .3) + 1) / 2, 1, 0, 0);
{
float maxdistance = 0;
float tempdist;
- for (int i = 0; i < objects.size(); i++) {
+ for (unsigned int i = 0; i < objects.size(); i++) {
tempdist = distsq(¢er, &objects[i]->position);
if (tempdist > maxdistance) {
maxdistance = tempdist;
int numobjects;
int type;
XYZ position;
- float yaw, pitch, scale, lastscale;
+ float yaw, pitch, scale;
+ float lastscale = 1.0f;
funpackf(tfile, "Bi", &numobjects);
if (!skip) {
objects.clear();
if (type == treeleavestype) {
scale = lastscale;
}
- objects.emplace_back(new Object(type, position, yaw, pitch, scale));
+ objects.emplace_back(new Object(object_type(type), position, yaw, pitch, scale));
lastscale = scale;
}
}
}
}
-void Object::SphereCheckPossible(XYZ *p1, float radius)
+void Object::SphereCheckPossible(XYZ* p1, float radius)
{
int whichpatchx = p1->x / (terrain.size / subdivision * terrain.scale);
int whichpatchz = p1->z / (terrain.size / subdivision * terrain.scale);
if (whichpatchx >= 0 && whichpatchz >= 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
- if (terrain.patchobjectnum[whichpatchx][whichpatchz] > 0 && terrain.patchobjectnum[whichpatchx][whichpatchz] < 500) {
- for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) {
- int i = terrain.patchobjects[whichpatchx][whichpatchz][j];
+ if (terrain.patchobjects[whichpatchx][whichpatchz].size() < 500) {
+ for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) {
+ unsigned int i = terrain.patchobjects[whichpatchx][whichpatchz][j];
objects[i]->possible = false;
if (objects[i]->model.SphereCheckPossible(p1, radius, &objects[i]->position, &objects[i]->yaw) != -1) {
objects[i]->possible = true;
objects[i]->draw();
}
- glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
for (unsigned i = 0; i < objects.size(); i++) {
objects[i]->drawSecondPass();
}
if (environment == desertenvironment) {
- glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+ glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
}
glEnable(GL_ALPHA_TEST);
SetUpLight(&light, 0);
void Object::DeleteObject(int which)
{
objects.erase(objects.begin() + which);
+ terrain.DeleteObject(which);
}
void Object::MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale)
{
if ((atype != treeleavestype && atype != bushtype) || foliage == 1) {
unsigned nextid = objects.size();
- objects.emplace_back(new Object(atype, where, ayaw, apitch, ascale));
+ objects.emplace_back(new Object(object_type(atype), where, ayaw, apitch, ascale));
objects.back()->addToTerrain(nextid);
}
}
{
XYZ lightloc;
lightloc = light.location;
- if (!skyboxtexture)
+ if (!skyboxtexture) {
lightloc = 0;
+ }
lightloc.y += 10;
Normalise(&lightloc);
maxy = max(startpoint.y, endpoint.y) + 1;
maxz = max(startpoint.z, endpoint.z) + 1;
- for (int i = 0; i < objects.size(); i++) {
+ for (unsigned int i = 0; i < objects.size(); i++) {
if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) {
- return i;
+ return (int)i;
}
}
return what;
}
} else {
- if ( objects[what]->position.x > minx - objects[what]->model.boundingsphereradius &&
- objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius &&
- objects[what]->position.y > miny - objects[what]->model.boundingsphereradius &&
- objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius &&
- objects[what]->position.z > minz - objects[what]->model.boundingsphereradius &&
- objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) {
- if ( objects[what]->type != treeleavestype &&
- objects[what]->type != bushtype &&
- objects[what]->type != firetype) {
+ if (objects[what]->position.x > minx - objects[what]->model.boundingsphereradius &&
+ objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius &&
+ objects[what]->position.y > miny - objects[what]->model.boundingsphereradius &&
+ objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius &&
+ objects[what]->position.z > minz - objects[what]->model.boundingsphereradius &&
+ objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) {
+ if (objects[what]->type != treeleavestype &&
+ objects[what]->type != bushtype &&
+ objects[what]->type != firetype) {
colviewer = startpoint;
coltarget = endpoint;
if (objects[what]->model.LineCheck(&colviewer, &coltarget, &colpoint, &objects[what]->position, &objects[what]->yaw) != -1) {
//~ Object::~Objects()
//~ {
- //~ boxtextureptr.destroy();
- //~ treetextureptr.destroy();
- //~ bushtextureptr.destroy();
- //~ rocktextureptr.destroy();
+//~ boxtextureptr.destroy();
+//~ treetextureptr.destroy();
+//~ bushtextureptr.destroy();
+//~ rocktextureptr.destroy();
//~ }