Skip to content

Commit

Permalink
Integrated hip new vector use that all the young people are into thes…
Browse files Browse the repository at this point in the history
…e days, from Bryan Kadzban. Much cleaner.
  • Loading branch information
Shamus Young committed May 8, 2009
1 parent 00afbde commit 9487100
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 260 deletions.
70 changes: 33 additions & 37 deletions Building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void CBuilding::ConstructCube (int left, int right, int front, int back, int bot
GLvertex p[10];
float x1, x2, z1, z2, y1, y2;
int i;
int index_list[10];
cube c;
float u, v1, v2;
float mapping;
int base_index;
Expand Down Expand Up @@ -194,10 +194,9 @@ void CBuilding::ConstructCube (int left, int right, int front, int back, int bot
for (i = 0; i < 10; i++) {
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
_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);

}

Expand All @@ -211,7 +210,7 @@ void CBuilding::ConstructCube (float left, float right, float front, float back,
GLvertex p[10];
float x1, x2, z1, z2, y1, y2;
int i;
int index_list[10];
cube c;
int base_index;

x1 = left;
Expand All @@ -235,10 +234,9 @@ void CBuilding::ConstructCube (float left, float right, float front, float back,
for (i = 0; i < 10; i++) {
p[i].uv.x = (p[i].position.x + p[i].position.z) / (float)SEGMENTS_PER_TEXTURE;
_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);

}

Expand Down Expand Up @@ -362,13 +360,13 @@ void CBuilding::ConstructSpike (int left, int right, int front, int back, int bo
{

GLvertex p;
int index_list[6];
fan f;
int i;
GLvector center;

for (i = 0; i < 5; i++)
index_list[i] = _mesh_flat->VertexCount () + i;
index_list[5] = index_list[1];
f.index_list.push_back(_mesh_flat->VertexCount () + i);
f.index_list.push_back(f.index_list[1]);
p.uv = glVector (0.0f, 0.0f);
center.x = ((float)left + (float)right) / 2.0f;
center.z = ((float)front + (float)back) / 2.0f;
Expand All @@ -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);
_mesh_flat->VertexAdd (p);

_mesh_flat->FanAdd (&index_list[0], 6);
_mesh_flat->FanAdd (f);

}

Expand All @@ -406,15 +404,16 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
int x, z;
int step_x, step_z;
int i;
int index_list[100];
int current_index;
quad_strip qs;
int column;
int mid;
int odd;
GLvertex v;
bool blank;
bool last_blank;

qs.index_list.reserve(100);

switch (direction) {
case NORTH:
step_z = 1; step_x = 0; break;
Expand All @@ -427,7 +426,6 @@ float CBuilding::ConstructWall (int start_x, int start_y, int start_z, int direc
}
x = start_x;;
z = start_z;
current_index = 0;
mid = (length / 2) - 1;
odd = 1 - (length % 2);
if (length % 2)
Expand All @@ -452,27 +450,23 @@ 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.uv.y = (float)start_y / SEGMENTS_PER_TEXTURE;
_mesh->VertexAdd (v);
index_list[current_index] = _mesh->VertexCount () - 1;
current_index++;
qs.index_list.push_back(_mesh->VertexCount () - 1);
v.position.y = (float)(start_y + height);
v.uv.y = (float)(start_y + height) / SEGMENTS_PER_TEXTURE;;
_mesh->VertexAdd (v);
index_list[current_index] = _mesh->VertexCount () - 1;
current_index++;
qs.index_list.push_back(_mesh->VertexCount () - 1);
}
//if (!blank && i != 0 && i != (length - 1))
if (!blank && i != length)
v.uv.x += 1.0f / SEGMENTS_PER_TEXTURE;
x += step_x;
z += step_z;
}
_mesh->QuadStripAdd (&index_list[0], current_index);
_mesh->QuadStripAdd (qs);
return v.uv.x;

}

static int maxt;

/*-----------------------------------------------------------------------------
This makes a big chunky building of intersecting cubes.
Expand Down Expand Up @@ -524,9 +518,6 @@ void CBuilding::CreateBlocky ()
max_tiers = 2;
else
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.
//Viewed from above, the sections of the building are randomly sized
//rectangles that ALWAYS include the center of the building somewhere within
Expand Down Expand Up @@ -588,11 +579,14 @@ void CBuilding::CreateSimple ()

GLvertex p;
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 cap_height;
float ledge;

for(int i=0; i<=10; i++)
qs.index_list.push_back(i);

//How tall the flat-color roof is
cap_height = (float)(1 + RandomVal (4));
//how much the ledge sticks out
Expand Down Expand Up @@ -638,12 +632,13 @@ void CBuilding::CreateSimple ()
p.position = glVector (x1, y2, z1); p.uv = glVector (u, v2);
_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);
_mesh->Compile ();

}


/*-----------------------------------------------------------------------------
This makes a deformed cylinder building.
Expand All @@ -664,11 +659,13 @@ void CBuilding::CreateModern ()
int half_depth, half_width;
float dist;
float length;
int* index_list;
quad_strip qs;
fan f;
int points;
int skip_interval;
int skip_counter;
int skip_delta;
int i;
bool logo_done;
bool do_trim;
CDeco* d;
Expand Down Expand Up @@ -735,21 +732,20 @@ void CBuilding::CreateModern ()
d = new CDeco;
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
for (int i = 0; i < points; i++)
index_list[i] = i;
_mesh->QuadStripAdd (index_list, points);
_mesh_flat->QuadStripAdd (index_list, points);
for (i = 0; i < points; i++)
qs.index_list.push_back(i);
_mesh->QuadStripAdd (qs);
_mesh_flat->QuadStripAdd (qs);
//add the fan to cap the top of the buildings
f.index_list.push_back(points);
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.z = _center.z;
_mesh_flat->VertexAdd (p);
index_list[0] = points;
_mesh_flat->FanAdd (index_list, 1 + points / 2);
delete index_list;
_mesh_flat->FanAdd (f);
radius /= 2.0f;
//ConstructRoof ((int)(_center.x - radius), (int)(_center.x + radius), (int)(_center.z - radius), (int)(_center.z + radius), _height + cap_height);
_mesh->Compile ();
Expand Down
75 changes: 41 additions & 34 deletions Deco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
CLight* l;
float offset;
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;
_center = pos;
Expand All @@ -139,7 +142,7 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
_mesh->VertexAdd (v);
v.position = glVector (_center.x - offset, _center.y, _center.z - offset); v.uv = glVector (1,0);
_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->Blink ();
_texture = TextureId (TEXTURE_LATTICE);
Expand All @@ -153,15 +156,20 @@ void CDeco::CreateRadioTower (GLvector pos, float height)
void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed, GLrgba color)
{

GLvertex p;
int index_list[] = {0,1,3,2};
float u1, u2, v1, v2;
float top;
float height, length;
GLvector2 center2d;
GLvector to;
GLvector out;
int logo_index;
GLvertex p;
quad_strip qs;
float u1, u2, v1, v2;
float top;
float height, length;
GLvector2 center2d;
GLvector to;
GLvector out;
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;
_color = color;
Expand All @@ -186,7 +194,7 @@ void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed,
_mesh->VertexAdd (p);
p.position = glVector (start.x, top, start.y) + out; p.uv = glVector (u1, v2);
_mesh->VertexAdd (p);
_mesh->QuadStripAdd (&index_list[0], 4);
_mesh->QuadStripAdd (qs);
_texture = TextureId (TEXTURE_LOGOS);

}
Expand All @@ -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)
{

GLvertex p;
int index_list1[] = {0,1,3,2};
float u, v;
GLvertex p;
quad_strip qs1;
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;
_use_alpha = true;
_center = glVector (x + width / 2, height, z + depth / 2);
Expand All @@ -221,8 +233,7 @@ void CDeco::CreateLightStrip (float x, float z, float width, float depth, float
_mesh->VertexAdd (p);
p.position = glVector (x + width, height, z); p.uv = glVector (u, 0.0f);
_mesh->VertexAdd (p);

_mesh->QuadStripAdd (&index_list1[0], 4);
_mesh->QuadStripAdd (qs1);
_mesh->Compile ();

}
Expand All @@ -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)
{

GLvertex p;
GLvector to;
GLvector out;
int i;
int index;
int prev, next;
float u, v1, v2;
float row;
int* index_list;
GLvertex p;
GLvector to;
GLvector out;
int i;
int index;
int prev, next;
float u, v1, v2;
float row;
quad_strip qs;

_color = color;
_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++)
_center += chain[i];
_center /= (float)count;
Expand All @@ -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;
p.position = chain[i % count] + out; p.uv = glVector (u, v2);
_mesh->VertexAdd (p);
index_list[index] = index;
index++;
qs.index_list.push_back(index++);
//Top point
p.position.y += height;p.uv = glVector (u, v1);
_mesh->VertexAdd (p);
index_list[index] = index;
index++;
qs.index_list.push_back(index++);
}
_mesh->QuadStripAdd (index_list, index);
delete index_list;
_mesh->QuadStripAdd (qs);
_texture = TextureId (TEXTURE_TRIM);
_mesh->Compile ();


}
Loading

0 comments on commit 9487100

Please sign in to comment.