mirror of https://github.com/skeeto/pixelcity.git
Integrated hip new vector use that all the young people are into these days, from Bryan Kadzban. Much cleaner.
This commit is contained in:
parent
00afbde126
commit
94871004c0
70
Building.cpp
70
Building.cpp
|
@ -157,7 +157,7 @@ void CBuilding::ConstructCube (int left, int right, int front, int back, int bot
|
||||||
GLvertex p[10];
|
GLvertex p[10];
|
||||||
float x1, x2, z1, z2, y1, y2;
|
float x1, x2, z1, z2, y1, y2;
|
||||||
int i;
|
int i;
|
||||||
int index_list[10];
|
cube c;
|
||||||
float u, v1, v2;
|
float u, v1, v2;
|
||||||
float mapping;
|
float mapping;
|
||||||
int base_index;
|
int base_index;
|
||||||
|
@ -194,10 +194,9 @@ void CBuilding::ConstructCube (int left, int right, int front, int back, int bot
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
|
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
|
||||||
_mesh->VertexAdd (p[i]);
|
_mesh->VertexAdd (p[i]);
|
||||||
index_list[i] = base_index + i;
|
c.index_list.push_back(base_index + i);
|
||||||
}
|
}
|
||||||
_mesh->CubeAdd (&index_list[0]);
|
_mesh->CubeAdd (c);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +210,7 @@ void CBuilding::ConstructCube (float left, float right, float front, float back,
|
||||||
GLvertex p[10];
|
GLvertex p[10];
|
||||||
float x1, x2, z1, z2, y1, y2;
|
float x1, x2, z1, z2, y1, y2;
|
||||||
int i;
|
int i;
|
||||||
int index_list[10];
|
cube c;
|
||||||
int base_index;
|
int base_index;
|
||||||
|
|
||||||
x1 = left;
|
x1 = left;
|
||||||
|
@ -235,10 +234,9 @@ void CBuilding::ConstructCube (float left, float right, float front, float back,
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
|
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
|
||||||
_mesh_flat->VertexAdd (p[i]);
|
_mesh_flat->VertexAdd (p[i]);
|
||||||
index_list[i] = base_index + i;
|
c.index_list.push_back(base_index + i);
|
||||||
}
|
}
|
||||||
_mesh_flat->CubeAdd (&index_list[0]);
|
_mesh_flat->CubeAdd (c);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,13 +360,13 @@ void CBuilding::ConstructSpike (int left, int right, int front, int back, int bo
|
||||||
{
|
{
|
||||||
|
|
||||||
GLvertex p;
|
GLvertex p;
|
||||||
int index_list[6];
|
fan f;
|
||||||
int i;
|
int i;
|
||||||
GLvector center;
|
GLvector center;
|
||||||
|
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 5; i++)
|
||||||
index_list[i] = _mesh_flat->VertexCount () + i;
|
f.index_list.push_back(_mesh_flat->VertexCount () + i);
|
||||||
index_list[5] = index_list[1];
|
f.index_list.push_back(f.index_list[1]);
|
||||||
p.uv = glVector (0.0f, 0.0f);
|
p.uv = glVector (0.0f, 0.0f);
|
||||||
center.x = ((float)left + (float)right) / 2.0f;
|
center.x = ((float)left + (float)right) / 2.0f;
|
||||||
center.z = ((float)front + (float)back) / 2.0f;
|
center.z = ((float)front + (float)back) / 2.0f;
|
||||||
|
@ -387,7 +385,7 @@ void CBuilding::ConstructSpike (int left, int right, int front, int back, int bo
|
||||||
p.position = glVector ((float)left, (float)bottom, (float)front);
|
p.position = glVector ((float)left, (float)bottom, (float)front);
|
||||||
_mesh_flat->VertexAdd (p);
|
_mesh_flat->VertexAdd (p);
|
||||||
|
|
||||||
_mesh_flat->FanAdd (&index_list[0], 6);
|
_mesh_flat->FanAdd (f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,8 +404,7 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
|
||||||
int x, z;
|
int x, z;
|
||||||
int step_x, step_z;
|
int step_x, step_z;
|
||||||
int i;
|
int i;
|
||||||
int index_list[100];
|
quad_strip qs;
|
||||||
int current_index;
|
|
||||||
int column;
|
int column;
|
||||||
int mid;
|
int mid;
|
||||||
int odd;
|
int odd;
|
||||||
|
@ -415,6 +412,8 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
|
||||||
bool blank;
|
bool blank;
|
||||||
bool last_blank;
|
bool last_blank;
|
||||||
|
|
||||||
|
qs.index_list.reserve(100);
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
step_z = 1; step_x = 0; break;
|
step_z = 1; step_x = 0; break;
|
||||||
|
@ -427,7 +426,6 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
|
||||||
}
|
}
|
||||||
x = start_x;;
|
x = start_x;;
|
||||||
z = start_z;
|
z = start_z;
|
||||||
current_index = 0;
|
|
||||||
mid = (length / 2) - 1;
|
mid = (length / 2) - 1;
|
||||||
odd = 1 - (length % 2);
|
odd = 1 - (length % 2);
|
||||||
if (length % 2)
|
if (length % 2)
|
||||||
|
@ -452,13 +450,11 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
|
||||||
v.position = glVector ((float)x, (float)start_y, (float)z);
|
v.position = glVector ((float)x, (float)start_y, (float)z);
|
||||||
v.uv.y = (float)start_y / SEGMENTS_PER_TEXTURE;
|
v.uv.y = (float)start_y / SEGMENTS_PER_TEXTURE;
|
||||||
_mesh->VertexAdd (v);
|
_mesh->VertexAdd (v);
|
||||||
index_list[current_index] = _mesh->VertexCount () - 1;
|
qs.index_list.push_back(_mesh->VertexCount () - 1);
|
||||||
current_index++;
|
|
||||||
v.position.y = (float)(start_y + height);
|
v.position.y = (float)(start_y + height);
|
||||||
v.uv.y = (float)(start_y + height) / SEGMENTS_PER_TEXTURE;;
|
v.uv.y = (float)(start_y + height) / SEGMENTS_PER_TEXTURE;;
|
||||||
_mesh->VertexAdd (v);
|
_mesh->VertexAdd (v);
|
||||||
index_list[current_index] = _mesh->VertexCount () - 1;
|
qs.index_list.push_back(_mesh->VertexCount () - 1);
|
||||||
current_index++;
|
|
||||||
}
|
}
|
||||||
//if (!blank && i != 0 && i != (length - 1))
|
//if (!blank && i != 0 && i != (length - 1))
|
||||||
if (!blank && i != length)
|
if (!blank && i != length)
|
||||||
|
@ -466,13 +462,11 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
|
||||||
x += step_x;
|
x += step_x;
|
||||||
z += step_z;
|
z += step_z;
|
||||||
}
|
}
|
||||||
_mesh->QuadStripAdd (&index_list[0], current_index);
|
_mesh->QuadStripAdd (qs);
|
||||||
return v.uv.x;
|
return v.uv.x;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int maxt;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
|
||||||
This makes a big chunky building of intersecting cubes.
|
This makes a big chunky building of intersecting cubes.
|
||||||
|
@ -524,9 +518,6 @@ void CBuilding::CreateBlocky ()
|
||||||
max_tiers = 2;
|
max_tiers = 2;
|
||||||
else
|
else
|
||||||
max_tiers = 1;
|
max_tiers = 1;
|
||||||
max_tiers = MIN (maxt, max_tiers);
|
|
||||||
maxt++;
|
|
||||||
maxt %= 8;
|
|
||||||
//We begin at the top of the building, and work our way down.
|
//We begin at the top of the building, and work our way down.
|
||||||
//Viewed from above, the sections of the building are randomly sized
|
//Viewed from above, the sections of the building are randomly sized
|
||||||
//rectangles that ALWAYS include the center of the building somewhere within
|
//rectangles that ALWAYS include the center of the building somewhere within
|
||||||
|
@ -588,11 +579,14 @@ void CBuilding::CreateSimple ()
|
||||||
|
|
||||||
GLvertex p;
|
GLvertex p;
|
||||||
float x1, x2, z1, z2, y1, y2;
|
float x1, x2, z1, z2, y1, y2;
|
||||||
int index_list[] = {0,1,2,3,4,5,6,7,8,9,10};
|
quad_strip qs;
|
||||||
float u, v1, v2;
|
float u, v1, v2;
|
||||||
float cap_height;
|
float cap_height;
|
||||||
float ledge;
|
float ledge;
|
||||||
|
|
||||||
|
for(int i=0; i<=10; i++)
|
||||||
|
qs.index_list.push_back(i);
|
||||||
|
|
||||||
//How tall the flat-color roof is
|
//How tall the flat-color roof is
|
||||||
cap_height = (float)(1 + RandomVal (4));
|
cap_height = (float)(1 + RandomVal (4));
|
||||||
//how much the ledge sticks out
|
//how much the ledge sticks out
|
||||||
|
@ -638,12 +632,13 @@ void CBuilding::CreateSimple ()
|
||||||
p.position = glVector (x1, y2, z1); p.uv = glVector (u, v2);
|
p.position = glVector (x1, y2, z1); p.uv = glVector (u, v2);
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
|
|
||||||
_mesh->QuadStripAdd (index_list, 10);
|
_mesh->QuadStripAdd (qs);
|
||||||
ConstructCube (x1 - ledge, x2 + ledge, z2 - ledge, z1 + ledge, (float)_height, (float)_height + cap_height);
|
ConstructCube (x1 - ledge, x2 + ledge, z2 - ledge, z1 + ledge, (float)_height, (float)_height + cap_height);
|
||||||
_mesh->Compile ();
|
_mesh->Compile ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
|
||||||
This makes a deformed cylinder building.
|
This makes a deformed cylinder building.
|
||||||
|
@ -664,11 +659,13 @@ void CBuilding::CreateModern ()
|
||||||
int half_depth, half_width;
|
int half_depth, half_width;
|
||||||
float dist;
|
float dist;
|
||||||
float length;
|
float length;
|
||||||
int* index_list;
|
quad_strip qs;
|
||||||
|
fan f;
|
||||||
int points;
|
int points;
|
||||||
int skip_interval;
|
int skip_interval;
|
||||||
int skip_counter;
|
int skip_counter;
|
||||||
int skip_delta;
|
int skip_delta;
|
||||||
|
int i;
|
||||||
bool logo_done;
|
bool logo_done;
|
||||||
bool do_trim;
|
bool do_trim;
|
||||||
CDeco* d;
|
CDeco* d;
|
||||||
|
@ -735,21 +732,20 @@ void CBuilding::CreateModern ()
|
||||||
d = new CDeco;
|
d = new CDeco;
|
||||||
d->CreateLightTrim (vector_buffer, (points / 2) - 2, (float)cap_height / 2, _seed, RANDOM_COLOR);
|
d->CreateLightTrim (vector_buffer, (points / 2) - 2, (float)cap_height / 2, _seed, RANDOM_COLOR);
|
||||||
}
|
}
|
||||||
index_list = new int[points];
|
qs.index_list.reserve(points);
|
||||||
//Add the outer walls
|
//Add the outer walls
|
||||||
for (int i = 0; i < points; i++)
|
for (i = 0; i < points; i++)
|
||||||
index_list[i] = i;
|
qs.index_list.push_back(i);
|
||||||
_mesh->QuadStripAdd (index_list, points);
|
_mesh->QuadStripAdd (qs);
|
||||||
_mesh_flat->QuadStripAdd (index_list, points);
|
_mesh_flat->QuadStripAdd (qs);
|
||||||
//add the fan to cap the top of the buildings
|
//add the fan to cap the top of the buildings
|
||||||
|
f.index_list.push_back(points);
|
||||||
for (i = 0; i < points / 2; i++)
|
for (i = 0; i < points / 2; i++)
|
||||||
index_list[i + 1] = points - (1 + i * 2);
|
f.index_list.push_back(points - (1 + i * 2));
|
||||||
p.position.x = _center.x;
|
p.position.x = _center.x;
|
||||||
p.position.z = _center.z;
|
p.position.z = _center.z;
|
||||||
_mesh_flat->VertexAdd (p);
|
_mesh_flat->VertexAdd (p);
|
||||||
index_list[0] = points;
|
_mesh_flat->FanAdd (f);
|
||||||
_mesh_flat->FanAdd (index_list, 1 + points / 2);
|
|
||||||
delete index_list;
|
|
||||||
radius /= 2.0f;
|
radius /= 2.0f;
|
||||||
//ConstructRoof ((int)(_center.x - radius), (int)(_center.x + radius), (int)(_center.z - radius), (int)(_center.z + radius), _height + cap_height);
|
//ConstructRoof ((int)(_center.x - radius), (int)(_center.x + radius), (int)(_center.z - radius), (int)(_center.z + radius), _height + cap_height);
|
||||||
_mesh->Compile ();
|
_mesh->Compile ();
|
||||||
|
|
75
Deco.cpp
75
Deco.cpp
|
@ -121,7 +121,10 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
|
||||||
CLight* l;
|
CLight* l;
|
||||||
float offset;
|
float offset;
|
||||||
GLvertex v;
|
GLvertex v;
|
||||||
int index_list[] = {0,1,2,3,4,5};
|
fan f;
|
||||||
|
|
||||||
|
for(int i=0; i<6; i++)
|
||||||
|
f.index_list.push_back(i);
|
||||||
|
|
||||||
offset = height / 15.0f;
|
offset = height / 15.0f;
|
||||||
_center = pos;
|
_center = pos;
|
||||||
|
@ -139,7 +142,7 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
|
||||||
_mesh->VertexAdd (v);
|
_mesh->VertexAdd (v);
|
||||||
v.position = glVector (_center.x - offset, _center.y, _center.z - offset); v.uv = glVector (1,0);
|
v.position = glVector (_center.x - offset, _center.y, _center.z - offset); v.uv = glVector (1,0);
|
||||||
_mesh->VertexAdd (v);
|
_mesh->VertexAdd (v);
|
||||||
_mesh->FanAdd (&index_list[0], 6);
|
_mesh->FanAdd (f);
|
||||||
l = new CLight (glVector (_center.x, _center.y + height + 1.0f, _center.z), glRgba (255,192,160), 1);
|
l = new CLight (glVector (_center.x, _center.y + height + 1.0f, _center.z), glRgba (255,192,160), 1);
|
||||||
l->Blink ();
|
l->Blink ();
|
||||||
_texture = TextureId (TEXTURE_LATTICE);
|
_texture = TextureId (TEXTURE_LATTICE);
|
||||||
|
@ -153,15 +156,20 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
|
||||||
void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed, GLrgba color)
|
void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed, GLrgba color)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLvertex p;
|
GLvertex p;
|
||||||
int index_list[] = {0,1,3,2};
|
quad_strip qs;
|
||||||
float u1, u2, v1, v2;
|
float u1, u2, v1, v2;
|
||||||
float top;
|
float top;
|
||||||
float height, length;
|
float height, length;
|
||||||
GLvector2 center2d;
|
GLvector2 center2d;
|
||||||
GLvector to;
|
GLvector to;
|
||||||
GLvector out;
|
GLvector out;
|
||||||
int logo_index;
|
int logo_index;
|
||||||
|
|
||||||
|
qs.index_list.push_back(0);
|
||||||
|
qs.index_list.push_back(1);
|
||||||
|
qs.index_list.push_back(3);
|
||||||
|
qs.index_list.push_back(2);
|
||||||
|
|
||||||
_use_alpha = true;
|
_use_alpha = true;
|
||||||
_color = color;
|
_color = color;
|
||||||
|
@ -186,7 +194,7 @@ void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed,
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
p.position = glVector (start.x, top, start.y) + out; p.uv = glVector (u1, v2);
|
p.position = glVector (start.x, top, start.y) + out; p.uv = glVector (u1, v2);
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
_mesh->QuadStripAdd (&index_list[0], 4);
|
_mesh->QuadStripAdd (qs);
|
||||||
_texture = TextureId (TEXTURE_LOGOS);
|
_texture = TextureId (TEXTURE_LOGOS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -198,10 +206,14 @@ void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed,
|
||||||
void CDeco::CreateLightStrip (float x, float z, float width, float depth, float height, GLrgba color)
|
void CDeco::CreateLightStrip (float x, float z, float width, float depth, float height, GLrgba color)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLvertex p;
|
GLvertex p;
|
||||||
int index_list1[] = {0,1,3,2};
|
quad_strip qs1;
|
||||||
float u, v;
|
float u, v;
|
||||||
|
|
||||||
|
qs1.index_list.push_back(0);
|
||||||
|
qs1.index_list.push_back(1);
|
||||||
|
qs1.index_list.push_back(3);
|
||||||
|
qs1.index_list.push_back(2);
|
||||||
_color = color;
|
_color = color;
|
||||||
_use_alpha = true;
|
_use_alpha = true;
|
||||||
_center = glVector (x + width / 2, height, z + depth / 2);
|
_center = glVector (x + width / 2, height, z + depth / 2);
|
||||||
|
@ -221,8 +233,7 @@ void CDeco::CreateLightStrip (float x, float z, float width, float depth, float
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
p.position = glVector (x + width, height, z); p.uv = glVector (u, 0.0f);
|
p.position = glVector (x + width, height, z); p.uv = glVector (u, 0.0f);
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
|
_mesh->QuadStripAdd (qs1);
|
||||||
_mesh->QuadStripAdd (&index_list1[0], 4);
|
|
||||||
_mesh->Compile ();
|
_mesh->Compile ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -234,19 +245,19 @@ void CDeco::CreateLightStrip (float x, float z, float width, float depth, float
|
||||||
void CDeco::CreateLightTrim (GLvector* chain, int count, float height, int seed, GLrgba color)
|
void CDeco::CreateLightTrim (GLvector* chain, int count, float height, int seed, GLrgba color)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLvertex p;
|
GLvertex p;
|
||||||
GLvector to;
|
GLvector to;
|
||||||
GLvector out;
|
GLvector out;
|
||||||
int i;
|
int i;
|
||||||
int index;
|
int index;
|
||||||
int prev, next;
|
int prev, next;
|
||||||
float u, v1, v2;
|
float u, v1, v2;
|
||||||
float row;
|
float row;
|
||||||
int* index_list;
|
quad_strip qs;
|
||||||
|
|
||||||
_color = color;
|
_color = color;
|
||||||
_center = glVector (0.0f, 0.0f, 0.0f);
|
_center = glVector (0.0f, 0.0f, 0.0f);
|
||||||
index_list = new int[count * 2 + 2];
|
qs.index_list.reserve(count * 2 + 2);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
_center += chain[i];
|
_center += chain[i];
|
||||||
_center /= (float)count;
|
_center /= (float)count;
|
||||||
|
@ -267,18 +278,14 @@ void CDeco::CreateLightTrim (GLvector* chain, int count, float height, int seed,
|
||||||
out = glVectorCrossProduct (glVector (0.0f, 1.0f, 0.0f), to) * LOGO_OFFSET;
|
out = glVectorCrossProduct (glVector (0.0f, 1.0f, 0.0f), to) * LOGO_OFFSET;
|
||||||
p.position = chain[i % count] + out; p.uv = glVector (u, v2);
|
p.position = chain[i % count] + out; p.uv = glVector (u, v2);
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
index_list[index] = index;
|
qs.index_list.push_back(index++);
|
||||||
index++;
|
|
||||||
//Top point
|
//Top point
|
||||||
p.position.y += height;p.uv = glVector (u, v1);
|
p.position.y += height;p.uv = glVector (u, v1);
|
||||||
_mesh->VertexAdd (p);
|
_mesh->VertexAdd (p);
|
||||||
index_list[index] = index;
|
qs.index_list.push_back(index++);
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
_mesh->QuadStripAdd (index_list, index);
|
_mesh->QuadStripAdd (qs);
|
||||||
delete index_list;
|
|
||||||
_texture = TextureId (TEXTURE_TRIM);
|
_texture = TextureId (TEXTURE_TRIM);
|
||||||
_mesh->Compile ();
|
_mesh->Compile ();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
128
Mesh.cpp
128
Mesh.cpp
|
@ -16,12 +16,12 @@
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <gl\gl.h>
|
#include <GL/gl.h>
|
||||||
#include <gl\glu.h>
|
#include <GL/glu.h>
|
||||||
#include <gl\glaux.h>
|
|
||||||
#include "glTypes.h"
|
|
||||||
|
|
||||||
#include "mesh.h"
|
#include <vector>
|
||||||
|
#include "glTypes.h"
|
||||||
|
#include "Mesh.h"
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -30,20 +30,9 @@
|
||||||
CMesh::CMesh ()
|
CMesh::CMesh ()
|
||||||
{
|
{
|
||||||
|
|
||||||
_vertex_count = 0;
|
|
||||||
_triangle_count = 0;
|
|
||||||
_quad_strip_count = 0;
|
|
||||||
_fan_count = 0;
|
|
||||||
_cube_count = 0;
|
|
||||||
_polycount = 0;
|
|
||||||
_list = glGenLists(1);
|
_list = glGenLists(1);
|
||||||
_compiled = false;
|
_compiled = false;
|
||||||
_vertex = NULL;
|
_polycount = 0;
|
||||||
_normal = NULL;
|
|
||||||
_triangle = NULL;
|
|
||||||
_cube = NULL;
|
|
||||||
_quad_strip = NULL;
|
|
||||||
_fan = NULL;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,24 +43,6 @@ CMesh::CMesh ()
|
||||||
CMesh::~CMesh ()
|
CMesh::~CMesh ()
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if (_vertex)
|
|
||||||
free (_vertex);
|
|
||||||
if (_normal)
|
|
||||||
free (_normal);
|
|
||||||
if (_triangle)
|
|
||||||
free (_triangle);
|
|
||||||
if (_cube)
|
|
||||||
free (_cube);
|
|
||||||
for (i = 0; i < _quad_strip_count; i++)
|
|
||||||
delete _quad_strip[i].index_list;
|
|
||||||
if (_quad_strip)
|
|
||||||
delete _quad_strip;
|
|
||||||
for (i = 0; i < _fan_count; i++)
|
|
||||||
delete _fan[i].index_list;
|
|
||||||
if (_fan)
|
|
||||||
delete _fan;
|
|
||||||
if (_list)
|
if (_list)
|
||||||
glDeleteLists (_list, 1);
|
glDeleteLists (_list, 1);
|
||||||
|
|
||||||
|
@ -81,12 +52,10 @@ CMesh::~CMesh ()
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void CMesh::VertexAdd (GLvertex v)
|
void CMesh::VertexAdd (const GLvertex& v)
|
||||||
{
|
{
|
||||||
|
|
||||||
_vertex = (GLvertex*)realloc (_vertex, sizeof (GLvertex) * (_vertex_count + 1));
|
_vertex.push_back(v);
|
||||||
_vertex[_vertex_count] = v;
|
|
||||||
_vertex_count++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,12 +63,10 @@ void CMesh::VertexAdd (GLvertex v)
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void CMesh::CubeAdd (int* index)
|
void CMesh::CubeAdd (const cube& c)
|
||||||
{
|
{
|
||||||
|
|
||||||
_cube = (cube*)realloc (_cube, sizeof (cube) * (_cube_count + 1));
|
_cube.push_back(c);
|
||||||
memcpy (&_cube[_cube_count].index_list[0], index, sizeof (int) * 10);
|
|
||||||
_cube_count++;
|
|
||||||
_polycount += 5;
|
_polycount += 5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -108,15 +75,11 @@ void CMesh::CubeAdd (int* index)
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void CMesh::QuadStripAdd (int* index, int count)
|
void CMesh::QuadStripAdd (const quad_strip& qs)
|
||||||
{
|
{
|
||||||
|
|
||||||
_quad_strip = (quad_strip*)realloc (_quad_strip, sizeof (quad_strip) * (_quad_strip_count + 1));
|
_quad_strip.push_back(qs);
|
||||||
_quad_strip[_quad_strip_count].index_list = (int*)malloc (sizeof (int) * count);
|
_polycount += (qs.index_list.size() - 2) / 2;
|
||||||
_quad_strip[_quad_strip_count].count = count;
|
|
||||||
memcpy (&_quad_strip[_quad_strip_count].index_list[0], &index[0], sizeof (int) * count);
|
|
||||||
_quad_strip_count++;
|
|
||||||
_polycount += (count - 2) / 2;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,15 +88,11 @@ void CMesh::QuadStripAdd (int* index, int count)
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void CMesh::FanAdd (int* index, int count)
|
void CMesh::FanAdd (const fan& f)
|
||||||
{
|
{
|
||||||
|
|
||||||
_fan = (fan*)realloc (_fan, sizeof (fan) * (_fan_count + 1));
|
_fan.push_back(f);
|
||||||
_fan[_fan_count].index_list = (int*)malloc (sizeof (int) * count);
|
_polycount += f.index_list.size() - 2;
|
||||||
_fan[_fan_count].count = count;
|
|
||||||
memcpy (&_fan[_fan_count].index_list[0], &index[0], sizeof (int) * count);
|
|
||||||
_fan_count++;
|
|
||||||
_polycount += count - 2;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,55 +104,54 @@ void CMesh::FanAdd (int* index, int count)
|
||||||
void CMesh::Render ()
|
void CMesh::Render ()
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned i, n;
|
std::vector<quad_strip>::iterator qsi;
|
||||||
int* index;
|
std::vector<cube>::iterator ci;
|
||||||
|
std::vector<fan>::iterator fi;
|
||||||
|
std::vector<int>::iterator n;
|
||||||
|
|
||||||
if (_compiled) {
|
if (_compiled) {
|
||||||
glCallList (_list);
|
glCallList (_list);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (i = 0; i < _quad_strip_count; i++) {
|
for (qsi = _quad_strip.begin(); qsi < _quad_strip.end(); ++qsi) {
|
||||||
index = &_quad_strip[i].index_list[0];
|
|
||||||
glBegin (GL_QUAD_STRIP);
|
glBegin (GL_QUAD_STRIP);
|
||||||
for (n = 0; n < _quad_strip[i].count; n++) {
|
for (n = qsi->index_list.begin(); n < qsi->index_list.end(); ++n) {
|
||||||
glTexCoord2fv (&_vertex[index[n]].uv.x);
|
glTexCoord2fv (&_vertex[*n].uv.x);
|
||||||
glVertex3fv (&_vertex[index[n]].position.x);
|
glVertex3fv (&_vertex[*n].position.x);
|
||||||
}
|
}
|
||||||
glEnd ();
|
glEnd ();
|
||||||
}
|
}
|
||||||
for (i = 0; i < _cube_count; i++) {
|
for (ci = _cube.begin(); ci < _cube.end(); ++ci) {
|
||||||
index = &_cube[i].index_list[0];
|
|
||||||
glBegin (GL_QUAD_STRIP);
|
glBegin (GL_QUAD_STRIP);
|
||||||
for (n = 0; n < 10; n++) {
|
for (n = ci->index_list.begin(); n < ci->index_list.end(); ++n) {
|
||||||
glTexCoord2fv (&_vertex[index[n]].uv.x);
|
glTexCoord2fv (&_vertex[*n].uv.x);
|
||||||
glVertex3fv (&_vertex[index[n]].position.x);
|
glVertex3fv (&_vertex[*n].position.x);
|
||||||
}
|
}
|
||||||
glEnd ();
|
glEnd ();
|
||||||
|
|
||||||
glBegin (GL_QUADS);
|
glBegin (GL_QUADS);
|
||||||
glTexCoord2fv (&_vertex[index[7]].uv.x);
|
glTexCoord2fv (&_vertex[ci->index_list[7]].uv.x);
|
||||||
glVertex3fv (&_vertex[index[7]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[7]].position.x);
|
||||||
glVertex3fv (&_vertex[index[5]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[5]].position.x);
|
||||||
glVertex3fv (&_vertex[index[3]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[3]].position.x);
|
||||||
glVertex3fv (&_vertex[index[1]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[1]].position.x);
|
||||||
glEnd ();
|
glEnd ();
|
||||||
|
|
||||||
glBegin (GL_QUADS);
|
glBegin (GL_QUADS);
|
||||||
glTexCoord2fv (&_vertex[index[6]].uv.x);
|
glTexCoord2fv (&_vertex[ci->index_list[6]].uv.x);
|
||||||
glVertex3fv (&_vertex[index[0]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[0]].position.x);
|
||||||
glVertex3fv (&_vertex[index[2]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[2]].position.x);
|
||||||
glVertex3fv (&_vertex[index[4]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[4]].position.x);
|
||||||
glVertex3fv (&_vertex[index[6]].position.x);
|
glVertex3fv (&_vertex[ci->index_list[6]].position.x);
|
||||||
glEnd ();
|
glEnd ();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < _fan_count; i++) {
|
for (fi = _fan.begin(); fi < _fan.end(); ++fi) {
|
||||||
index = &_fan[i].index_list[0];
|
|
||||||
glBegin (GL_TRIANGLE_FAN);
|
glBegin (GL_TRIANGLE_FAN);
|
||||||
for (n = 0; n < _fan[i].count; n++) {
|
for (n = fi->index_list.begin(); n < fi->index_list.end(); ++n) {
|
||||||
glTexCoord2fv (&_vertex[index[n]].uv.x);
|
glTexCoord2fv (&_vertex[*n].uv.x);
|
||||||
glVertex3fv (&_vertex[index[n]].position.x);
|
glVertex3fv (&_vertex[*n].position.x);
|
||||||
}
|
}
|
||||||
glEnd ();
|
glEnd ();
|
||||||
}
|
}
|
||||||
|
@ -213,4 +171,4 @@ void CMesh::Compile ()
|
||||||
glEndList();
|
glEndList();
|
||||||
_compiled = true;
|
_compiled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
49
Mesh.h
49
Mesh.h
|
@ -1,50 +1,43 @@
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct cube
|
struct cube
|
||||||
{
|
{
|
||||||
int index_list[10];
|
std::vector<int> index_list; // probably always .size() == 10...
|
||||||
};
|
};
|
||||||
|
|
||||||
struct quad_strip
|
struct quad_strip
|
||||||
{
|
{
|
||||||
int* index_list;
|
std::vector<int> index_list;
|
||||||
unsigned count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fan
|
struct fan
|
||||||
{
|
{
|
||||||
int* index_list;
|
std::vector<int> index_list;
|
||||||
unsigned count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMesh
|
class CMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMesh ();
|
CMesh ();
|
||||||
~CMesh ();
|
~CMesh ();
|
||||||
unsigned _vertex_count;
|
unsigned _list;
|
||||||
unsigned _triangle_count;
|
int _polycount;
|
||||||
unsigned _cube_count;
|
std::vector<GLvertex> _vertex;
|
||||||
unsigned _quad_strip_count;
|
std::vector<GLvector> _normal;
|
||||||
unsigned _fan_count;
|
std::vector<GLtriangle> _triangle;
|
||||||
unsigned _normal_count;
|
std::vector<cube> _cube;
|
||||||
unsigned _list;
|
std::vector<quad_strip> _quad_strip;
|
||||||
int _polycount;
|
std::vector<fan> _fan;
|
||||||
GLvertex* _vertex;
|
bool _compiled;
|
||||||
GLvector* _normal;
|
|
||||||
GLtriangle* _triangle;
|
|
||||||
cube* _cube;
|
|
||||||
quad_strip* _quad_strip;
|
|
||||||
fan* _fan;
|
|
||||||
bool _compiled;
|
|
||||||
|
|
||||||
void NormalAdd (GLvector n);
|
void NormalAdd (const GLvector& n);
|
||||||
void VertexAdd (GLvertex v);
|
void VertexAdd (const GLvertex& v);
|
||||||
int VertexCount () { return _vertex_count; }
|
int VertexCount () { return _vertex.size(); }
|
||||||
int PolyCount () { return _polycount; }
|
int PolyCount () { return _polycount; }
|
||||||
void CubeAdd (int* index);
|
void CubeAdd (const cube& c);
|
||||||
void QuadStripAdd (int* index, int count);
|
void QuadStripAdd (const quad_strip& qs);
|
||||||
void FanAdd (int* index, int count);
|
void FanAdd (const fan& f);
|
||||||
void Render ();
|
void Render ();
|
||||||
void Compile ();
|
void Compile ();
|
||||||
|
|
||||||
|
|
4
Sky.cpp
4
Sky.cpp
|
@ -64,13 +64,13 @@ void CSky::Render ()
|
||||||
|
|
||||||
GLvector angle, position;
|
GLvector angle, position;
|
||||||
|
|
||||||
if (!RenderFog ())
|
if (!TextureReady ())
|
||||||
return;
|
return;
|
||||||
glDepthMask (false);
|
glDepthMask (false);
|
||||||
glPushAttrib (GL_POLYGON_BIT | GL_FOG_BIT);
|
glPushAttrib (GL_POLYGON_BIT | GL_FOG_BIT);
|
||||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||||
glDisable (GL_FOG);
|
|
||||||
glDisable (GL_CULL_FACE);
|
glDisable (GL_CULL_FACE);
|
||||||
|
glDisable (GL_FOG);
|
||||||
glPushMatrix ();
|
glPushMatrix ();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
angle = CameraAngle ();
|
angle = CameraAngle ();
|
||||||
|
|
74
foo.h
74
foo.h
|
@ -1,74 +0,0 @@
|
||||||
i
|
|
||||||
Green
|
|
||||||
Mega
|
|
||||||
Super
|
|
||||||
Omni
|
|
||||||
e
|
|
||||||
Hyper
|
|
||||||
Global
|
|
||||||
Vital
|
|
||||||
Next
|
|
||||||
Pacific
|
|
||||||
Metro
|
|
||||||
Unity
|
|
||||||
G-
|
|
||||||
Trans
|
|
||||||
Infinity
|
|
||||||
Superior
|
|
||||||
Monolith
|
|
||||||
Best
|
|
||||||
Atlantic
|
|
||||||
First
|
|
||||||
Union
|
|
||||||
National
|
|
||||||
|
|
||||||
|
|
||||||
Biotic
|
|
||||||
Info
|
|
||||||
Data
|
|
||||||
Solar
|
|
||||||
Aerospace
|
|
||||||
Motors
|
|
||||||
Nano
|
|
||||||
Online
|
|
||||||
Circuits
|
|
||||||
Energy
|
|
||||||
Med
|
|
||||||
Robotic
|
|
||||||
Exports
|
|
||||||
Security
|
|
||||||
Systems
|
|
||||||
Financial
|
|
||||||
Industrial
|
|
||||||
Media
|
|
||||||
Materials
|
|
||||||
Foods
|
|
||||||
Networks
|
|
||||||
Shipping
|
|
||||||
Tools
|
|
||||||
Medical
|
|
||||||
Publishing
|
|
||||||
Enterpise
|
|
||||||
Audio
|
|
||||||
Health
|
|
||||||
Bank
|
|
||||||
Imports
|
|
||||||
Apparel
|
|
||||||
Petroleum
|
|
||||||
Studios
|
|
||||||
|
|
||||||
|
|
||||||
Corp
|
|
||||||
Inc.
|
|
||||||
Co
|
|
||||||
World
|
|
||||||
.Com
|
|
||||||
USA
|
|
||||||
Ltd.
|
|
||||||
Net
|
|
||||||
Tech
|
|
||||||
Labs
|
|
||||||
Mfg.
|
|
||||||
UK
|
|
||||||
Unlimited
|
|
||||||
One
|
|
Loading…
Reference in New Issue