void CMap::DrawShot( const std::pair<std::pair<float, float>, std::pair<float, float>>& shot ) const { glColor3f( 1, 0, 0 ); glLineWidth( 3 ); glBegin( GL_LINES ); { auto point1 = transateToWcoord( shot.first.first + 0.5, shot.first.second + 0.5, cellSize, indent, GetSize() ); auto point2 = transateToWcoord( shot.first.first + 0.5 + shot.second.first * 100, shot.first.second + 0.5 + shot.second.second * 100, cellSize, indent, GetSize() ); glVertex2d( point1.x, point1.y ); glVertex2d( point2.x, point2.y ); } glEnd(); }
void CMap::HighlightActiveCells() const { glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, CDrawing::activeCell ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 1, 1, 1, 0.5 ); for( auto cell : highlightedCells ) { auto center = transateToWcoord( cell.x + 0.5, cell.y + 0.5, cellSize, indent, GetSize() ); auto top = center.y - 0.5 * cellSize; auto left = center.x - 0.5 * cellSize; auto right = center.x + 0.5 * cellSize; auto bottom = center.y + 0.5 * cellSize; glBegin( GL_POLYGON ); { glTexCoord2f( 0, 1 ); glVertex2f( left, top ); glTexCoord2f( 1, 1 ); glVertex2f( right, top ); glTexCoord2f( 1, 0 ); glVertex2f( right, bottom ); glTexCoord2f( 0, 0 ); glVertex2f( left, bottom ); } glEnd(); } glDisable( GL_BLEND ); glDisable( GL_TEXTURE_2D ); }
void CMap::DrawFinishLine( std::pair<CCoordinates, CCoordinates> finishLine ) const { glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, CDrawing::finish ); glColor3f( 1, 1, 1 ); glBegin( GL_POLYGON ); { auto point1 = transateToWcoord( finishLine.first.x + 0.5, finishLine.first.y + 0.5, cellSize, indent, GetSize() ); auto point2 = transateToWcoord( finishLine.second.x + 0.5, finishLine.second.y + 0.5, cellSize, indent, GetSize() ); double distance = std::hypot( finishLine.first.x - finishLine.second.x, finishLine.first.y - finishLine.second.y ); double distanceWindow = std::hypot( point1.x - point2.x, point1.y - point2.y ); std::pair<double, double> direction( (point2.x - point1.x) / distanceWindow, (point2.y - point1.y) / distanceWindow ); direction = std::make_pair( direction.second, -direction.first ); glTexCoord2f( 0.0f, 0.0f ); glVertex2f( point1.x - 5 * direction.first, point1.y - 5 * direction.second ); glTexCoord2f( distance, 0.0f ); glVertex2f( point2.x - 5 * direction.first, point2.y - 5 * direction.second ); glTexCoord2f( distance, 1.0f ); glVertex2f( point2.x + 5 * direction.first, point2.y + 5 * direction.second ); glTexCoord2f( 0.0f, 1.0f ); glVertex2f( point1.x + 5 * direction.first, point1.y + 5 * direction.second ); } glEnd(); glDisable( GL_BLEND ); glDisable( GL_TEXTURE_2D ); }
void CCar::Draw( float cellSize, CWindowCoordinates indent, CSize mapSize ) { if( crashed ) { return; } glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture ); glTexEnvf( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE ); CWindowCoordinates coord = transateToWcoord( coords.x, coords.y, cellSize, indent, mapSize ); float left = coord.x; float right = coord.x + cellSize; float bottom = coord.y - cellSize / 4; float top = coord.y - 3 * cellSize / 4; glDepthMask( GL_FALSE ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBegin( GL_POLYGON ); { glColor4f( 1, 1, 1, alpha ); float Ax = left, Ay = bottom, Bx = right, By = bottom, Cx = right, Cy = top, Dx = left, Dy = top; float centerX = Dx - (Dx - Bx) / 2, centerY = Dy - (Dy - By) / 2; rotateCar( Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, centerX, centerY, coords.angle ); glTexCoord2f( 0.0f, 0.0f ); glVertex3f( Ax, Ay, 0.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( Bx, By, 0.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( Cx, Cy, 0.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( Dx, Dy, 0.0f ); } glEnd(); glBindTexture( GL_TEXTURE_2D, CDrawing:: textureExplosion ); if( curFrameExplosion > 0 ) { left = coord.x; right = coord.x + cellSize; bottom = coord.y; top = coord.y - cellSize; glTexEnvf( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glBegin( GL_POLYGON ); { glColor4f( 1, 1, 1, 1 ); glTexCoord2f( (curFrameExplosion - 1.0f) / CDrawing::numFramesExplosion, 1.0f ); glVertex2f( left, bottom ); glTexCoord2f( (curFrameExplosion - 1.0f) / CDrawing::numFramesExplosion, 0.0f ); glVertex2f( right, bottom ); glTexCoord2f( curFrameExplosion * 1.0f / CDrawing::numFramesExplosion, 0.0f ); glVertex2f( right, top ); glTexCoord2f( curFrameExplosion * 1.0f / CDrawing::numFramesExplosion, 1.0f ); glVertex2f( left, top ); } glEnd(); } glDisable( GL_BLEND ); glDepthMask( GL_TRUE ); }