GLvector3 glVectorNormalize(GLvector3 v) { float length; length = glVectorLength(v); if (length < 0.000001f) return v; return glVectorScale(v, 1.0f / length); }
GLvector2 glVectorNormalize (GLvector2 v) { float length; length = glVectorLength (v); if (length < 0.000001f) return v; return v * (1.0f / length); }
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; quad_strip qs; _color = color; _center = glVector (0.0f, 0.0f, 0.0f); qs.index_list.reserve(count * 2 + 2); for (i = 0; i < count; i++) _center += chain[i]; _center /= (float)count; row = (float)(seed % TRIM_ROWS); v1 = row * TRIM_SIZE; v2 = (row + 1.0f) * TRIM_SIZE; index = 0; u = 0.0f; for (i = 0; i < count + 1; i++) { if (i) u += glVectorLength (chain[i % count] - p.position) * 0.1f; //Add the bottom point prev = i - 1; if (prev < 0) prev = count + prev; next = (i + 1) % count; to = glVectorNormalize (chain[next] - chain[prev]); 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); qs.index_list.push_back(index++); //Top point p.position.y += height; p.uv = glVector (u, v1); _mesh->VertexAdd (p); qs.index_list.push_back(index++); } _mesh->QuadStripAdd (qs); _texture = TextureId (TEXTURE_TRIM); _mesh->Compile (); }
void CDeco::CreateLogo (GLvector2 start, GLvector2 end, float bottom, int seed, GLrgba color) { 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; logo_index = seed % LOGO_ROWS; to = glVector (start.x, 0.0f, start.y) - glVector (end.x, 0.0f, end.y); to = glVectorNormalize (to); out = glVectorCrossProduct (glVector (0.0f, 1.0f, 0.0f), to) * LOGO_OFFSET; center2d = (start + end) / 2; _center = glVector (center2d.x, bottom, center2d.y); length = glVectorLength (start - end); height = (length / 8.0f) * 1.5f; top = bottom + height; u1 = 0.0f; u2 = 0.5f;//We actually only use the left half of the texture v1 = (float)logo_index / LOGO_ROWS; v2 = v1 + (1.0f / LOGO_ROWS); p.position = glVector (start.x, bottom, start.y) + out; p.uv = glVector (u1,v1); _mesh->VertexAdd (p); p.position = glVector (end.x, bottom, end.y) + out; p.uv = glVector (u2, v1); _mesh->VertexAdd (p); p.position = glVector (end.x, top, end.y) + out; p.uv = glVector (u2, v2); _mesh->VertexAdd (p); p.position = glVector (start.x, top, start.y) + out; p.uv = glVector (u1, v2); _mesh->VertexAdd (p); _mesh->QuadStripAdd (qs); _texture = TextureId (TEXTURE_LOGOS); }
void TerraformPrepare () { int x, y; Region r; GLcoord from_center; GLcoord offset; //Set some defaults offset.x = RandomVal () % 1024; offset.y = RandomVal () % 1024; for (x = 0; x < WORLD_GRID; x++) { for (y = 0; y < WORLD_GRID; y++) { memset (&r, 0, sizeof (Region)); sprintf (r.title, "NOTHING"); r.geo_bias = r.geo_detail = 0; r.mountain_height = 0; r.grid_pos.x = x; r.grid_pos.y = y; r.tree_threshold = 0.15f; from_center.x = abs (x - WORLD_GRID_CENTER); from_center.y = abs (y - WORLD_GRID_CENTER); //Geo scale is a number from -1 to 1. -1 is lowest ocean. 0 is sea level. //+1 is highest elevation on the island. This is used to guide other derived numbers. r.geo_scale = glVectorLength (glVector ((float)from_center.x, (float)from_center.y)); r.geo_scale /= (WORLD_GRID_CENTER - OCEAN_BUFFER); //Create a steep drop around the edge of the world if (r.geo_scale > 1.0f) r.geo_scale = 1.0f + (r.geo_scale - 1.0f) * 4.0f; r.geo_scale = 1.0f - r.geo_scale; r.geo_scale += (Entropy ((x + offset.x), (y + offset.y)) - 0.5f); r.geo_scale += (Entropy ((x + offset.x) * FREQUENCY, (y + offset.y) * FREQUENCY) - 0.2f); r.geo_scale = clamp (r.geo_scale, -1.0f, 1.0f); if (r.geo_scale > 0.0f) r.geo_water = 1.0f + r.geo_scale * 16.0f; r.color_atmosphere = glRgba (0.0f, 0.0f, 0.0f); r.geo_bias = 0.0f; r.geo_detail = 0.0f; r.color_map = glRgba (0.0f); r.climate = CLIMATE_INVALID; WorldRegionSet (x, y, r); } } }