void TerrainRenderer::UpdateTrianglePos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update) { unsigned int pos = 2 * width * y + x*2; gl_vertices[pos].pos[0].x = GetTerrainXAround(x,y,4); gl_vertices[pos].pos[0].y = GetTerrainYAround(x,y,4); gl_vertices[pos].pos[1].x = GetTerrainX(x, y); gl_vertices[pos].pos[1].y = GetTerrainY(x, y); gl_vertices[pos].pos[2].x = GetTerrainXAround(x,y,5); gl_vertices[pos].pos[2].y = GetTerrainYAround(x,y,5); ++pos; gl_vertices[pos].pos[0].x = GetTerrainX(x, y); gl_vertices[pos].pos[0].y = GetTerrainY(x, y); gl_vertices[pos].pos[1].x = GetTerrainXAround(x,y,4); gl_vertices[pos].pos[1].y = GetTerrainYAround(x,y,4); gl_vertices[pos].pos[2].x = GetTerrainXAround(x,y,3); gl_vertices[pos].pos[2].y = GetTerrainYAround(x,y,3); if(update && SETTINGS.video.vbo) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,(pos-1) * 3 * 2 * sizeof(float), 2 * 3 * 2 * sizeof(float), &gl_vertices[pos-1]); } }
/// erzeugt Rand-Vertex void TerrainRenderer::UpdateBorderVertex(const MapPoint pt, const GameWorldViewer* gwv) { /// @todo GetTerrainX und Co durch GetTerrainXA ausdrücken GetVertex(pt).border[0].pos.x = ( GetTerrainXAround(pt.x, pt.y, 5) + GetTerrainX(pt) + GetTerrainXAround(pt.x, pt.y, 4) ) / 3.0f; GetVertex(pt).border[0].pos.y = ( GetTerrainYAround(pt.x, pt.y, 5) + GetTerrainY(pt) + GetTerrainYAround(pt.x, pt.y, 4) ) / 3.0f; GetVertex(pt).border[0].color = ( GetColor(gwv->GetNeighbour(pt, 5)) + GetColor(pt) + GetColor(gwv->GetNeighbour(pt, 4)) ) / 3.0f; GetVertex(pt).border[1].pos.x = ( GetTerrainXAround(pt.x, pt.y, 3) + GetTerrainX(pt) + GetTerrainXAround(pt.x, pt.y, 4) ) / 3.0f; GetVertex(pt).border[1].pos.y = ( GetTerrainYAround(pt.x, pt.y, 3) + GetTerrainY(pt) + GetTerrainYAround(pt.x, pt.y, 4) ) / 3.0f; GetVertex(pt).border[1].color = ( GetColor(gwv->GetNeighbour(pt, 3)) + GetColor(pt) + GetColor(gwv->GetNeighbour(pt, 4)) ) / 3.0f; }
/// erzeugt Rand-Vertex void TerrainRenderer::UpdateBorderVertex(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv) { /// @todo GetTerrainX und Co durch GetTerrainXA ausdrücken GetVertex(x,y).border[0].pos.x = ( GetTerrainXAround(x,y,5) + GetTerrainX(x, y) + GetTerrainXAround(x,y,4) ) / 3.0f; GetVertex(x,y).border[0].pos.y = ( GetTerrainYAround(x,y,5) + GetTerrainY(x, y) + GetTerrainYAround(x,y,4) ) / 3.0f; GetVertex(x,y).border[0].color = ( GetColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5)) + GetColor(x, y) + GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4)) ) / 3.0f; GetVertex(x,y).border[1].pos.x = ( GetTerrainXAround(x,y,3) + GetTerrainX(x, y) + GetTerrainXAround(x,y,4) ) / 3.0f; GetVertex(x,y).border[1].pos.y = ( GetTerrainYAround(x,y,3) + GetTerrainY(x, y) + GetTerrainYAround(x,y,4) ) / 3.0f; GetVertex(x,y).border[1].color = ( GetColor(gwv->GetXA(x,y,3), gwv->GetYA(x,y,3)) + GetColor(x, y) + GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4)) ) / 3.0f; }
float TerrainRenderer::GetTerrainXAround(int x, int y, const unsigned dir) { GetPointAround(x, y, dir); int xo; MapPoint t = ConvertCoords(x, y, &xo); return GetTerrainX(t) + xo; }
float TerrainRenderer::GetTerrainXAround(int x, int y, const unsigned dir) { unsigned short tx,ty; GetPointAround(x,y,dir); int xo,yo; ConvertCoords(x,y,tx,ty,&xo,&yo); return GetTerrainX(tx,ty)+xo; }
void TerrainRenderer::PrepareWaysPoint(GameWorldView *gwv, unsigned short tx, unsigned short ty, int xo, int yo) { float xpos = GetTerrainX(tx,ty)-gwv->GetXOffset()+xo; float ypos = GetTerrainY(tx,ty)-gwv->GetYOffset()+yo; // Wegtypen für die drei Richtungen unsigned char type; Visibility visibility = gwv->GetGameWorldViewer()->GetVisibility(tx,ty); for(unsigned char dir = 0;dir<3;++dir) { if ((type = gwv->GetGameWorldViewer()->GetVisibleRoad(tx,ty, dir+3, visibility))) { float xpos2 = GetTerrainX(gwv->GetGameWorldViewer()->GetXA(tx,ty,3+dir),gwv->GetGameWorldViewer()->GetYA(tx,ty,3+dir))-gwv->GetXOffset()+xo; float ypos2 = GetTerrainY(gwv->GetGameWorldViewer()->GetXA(tx,ty,3+dir),gwv->GetGameWorldViewer()->GetYA(tx,ty,3+dir))-gwv->GetYOffset()+yo; // Gehen wir über einen Kartenrand (horizontale Richung?) if(abs(xpos-xpos2) >= gwv->GetGameWorldViewer()->GetWidth() * TR_W / 2) { if(abs(xpos2-int(gwv->GetGameWorldViewer()->GetWidth())*TR_W-xpos) < abs(xpos-xpos2)) xpos2 -= gwv->GetGameWorldViewer()->GetWidth()*TR_W; else xpos2 += gwv->GetGameWorldViewer()->GetWidth()*TR_W; } // Und dasselbe für vertikale Richtung if(abs(ypos-ypos2) >= gwv->GetGameWorldViewer()->GetHeight() * TR_H / 2) { if(abs(ypos2-int(gwv->GetGameWorldViewer()->GetHeight())*TR_H-ypos) < abs(ypos-ypos2)) ypos2 -= gwv->GetGameWorldViewer()->GetHeight()*TR_H; else ypos2 += gwv->GetGameWorldViewer()->GetHeight()*TR_H; } --type; // Wegtypen "konvertieren" switch(type) { case RoadSegment::RT_DONKEY: case RoadSegment::RT_NORMAL: { unsigned t1 = gwv->GetGameWorldViewer()->GetTerrainAround(tx,ty, dir + 2); unsigned t2 = gwv->GetGameWorldViewer()->GetTerrainAround(tx,ty, dir + 3); // Prüfen, ob Bergwerge gezeichnet werden müssen, indem man guckt, ob der Weg einen // Berg "streift" oder auch eine Bergwiese if(( (t1 >= TT_MOUNTAIN1 && t1 <= TT_MOUNTAIN4) || t1 == TT_MOUNTAINMEADOW) || ( (t2 >= TT_MOUNTAIN1 && t2 <= TT_MOUNTAIN4) || t2 == TT_MOUNTAINMEADOW)) type = 3; } break; case RoadSegment::RT_BOAT: { type = 2; } break; } gwv->sorted_roads[type].push_back( PreparedRoad(type, xpos, ypos, xpos2, ypos2, GetColor(tx, ty), GetColor(gwv->GetGameWorldViewer()->GetXA(tx,ty,3+dir),gwv->GetGameWorldViewer()->GetYA(tx,ty,3+dir)), dir ) ); } } }
/// Erzeugt die Dreiecke für die Ränder void TerrainRenderer::UpdateBorderTrianglePos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update) { unsigned int pos = y * width + x; // Für VBO-Aktualisierung: // Erzeugte Ränder zählen unsigned count_borders = 0; // Erstes Offset merken unsigned first_offset = 0; // Rand links - rechts for(unsigned char i = 0; i < 2; ++i) { if(borders[pos].left_right[i]) { unsigned int offset = borders[pos].left_right_offset[i]; if(!first_offset) first_offset = offset; gl_vertices[offset].pos[i ? 0 : 2].x = GetTerrainX(x, y); gl_vertices[offset].pos[i ? 0 : 2].y = GetTerrainY(x, y); gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,4); gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,4); gl_vertices[offset].pos[i ? 2 : 0].x = GetBX(x, y, i); gl_vertices[offset].pos[i ? 2 : 0].y = GetBY(x, y, i); ++count_borders; } } // Rand rechts - links for(unsigned char i = 0; i < 2; ++i) { if(borders[pos].right_left[i]) { unsigned int offset = borders[pos].right_left_offset[i]; if(!first_offset) first_offset = offset; gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x,y,4); gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x,y,4); gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,3); gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,3); if(i == 0) { gl_vertices[offset].pos[2].x = GetBX(x, y, 1); gl_vertices[offset].pos[2].y = GetBY(x, y, 1); } else { gl_vertices[offset].pos[0].x = GetBXAround(x, y, 0, 3); gl_vertices[offset].pos[0].y = GetBYAround(x, y, 0, 3); } ++count_borders; } } // Rand oben - unten for(unsigned char i = 0; i < 2; ++i) { if(borders[pos].top_down[i]) { unsigned int offset = borders[pos].top_down_offset[i]; if(!first_offset) first_offset = offset; gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x,y,5); gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x,y,5); gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,4); gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,4); if(i == 0) { gl_vertices[offset].pos[2].x = GetBX(x,y,i); gl_vertices[offset].pos[2].y = GetBY(x,y,i); } else { //x - i + i * rt, y + i, i gl_vertices[offset].pos[0].x = GetBXAround(x, y, i, 5); gl_vertices[offset].pos[0].y = GetBYAround(x, y, i, 5); } ++count_borders; } } /// Bei Vertexbuffern das die Daten aktualisieren if(update && SETTINGS.video.vbo) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,first_offset * 3 * 2 * sizeof(float), count_borders * 3 * 2 * sizeof(float), &gl_vertices[first_offset]); } }