示例#1
0
文件: Tile.cpp 项目: mackorone/mms
void Tile::initFullPolygon(int mazeWidth, int mazeHeight) {

    Meters halfWallWidth = Meters(P()->wallWidth()) / 2.0;
    Meters tileLength = Meters(P()->wallLength() + P()->wallWidth());
    Cartesian lowerLeftPoint(tileLength * getX() - halfWallWidth * (getX() == 0 ? 1 : 0),
                             tileLength * getY() - halfWallWidth * (getY() == 0 ? 1 : 0));
    Cartesian upperRightPoint(tileLength * (getX() + 1) + halfWallWidth * (getX() == mazeWidth - 1 ? 1 : 0),
                              tileLength * (getY() + 1) + halfWallWidth * (getY() == mazeHeight - 1 ? 1 : 0));
    Cartesian lowerRightPoint(upperRightPoint.getX(), lowerLeftPoint.getY());
    Cartesian upperLeftPoint(lowerLeftPoint.getX(), upperRightPoint.getY());
    m_fullPolygon = Polygon({lowerLeftPoint, upperLeftPoint, upperRightPoint, lowerRightPoint});
}
示例#2
0
CFreewayDoc::CFreewayDoc()
{
    m_stepDuration = Seconds(0.1);
    m_freeSight = Seconds(2);
    ASSERT(m_freeSight > m_stepDuration);
    m_freewayLength = Kilometers(1);
    m_sectorLength = Meters(100);
    m_carLength = Meters(5);
    m_allowedMaxSpeed = Kmh(120);
    m_reducedMaxSpeed = Kmh(80);
    m_carsPerSecond = 2;
    m_speedFactorsSigma = 0.3;
    m_roadWorksStart = Meters(500);
    m_roadWorksLength = Meters(190);
}
示例#3
0
void CFreewayView::OnInitialUpdate() {
	CView::OnInitialUpdate();

	theApp.GetMainFrame()->m_view = this;

	CFreewayDoc* pDoc = GetDocument();
	m_simulation.init(
		Freeway(
			Meters(pDoc->m_freewayLength), 
			pDoc->m_sectorLength, 
			pDoc->m_allowedMaxSpeed,
			pDoc->m_roadWorksStart,
			pDoc->m_roadWorksLength,
			pDoc->m_reducedMaxSpeed), 
		pDoc->m_stepDuration, 
		pDoc->m_carsPerSecond, 
		pDoc->m_speedFactorsSigma, 
		pDoc->m_carLength, 
		pDoc->m_freeSight);

	OnSimPause();

	theApp.GetMainFrame()->m_wndProperties.SendMessage(WM_COMMAND, MAKELONG(ID_PROPERTIES_FW, 0));
	theApp.GetMainFrame()->m_wndProperties.SendMessage(WM_COMMAND, MAKELONG(ID_PROPERTIES_SIM, 0));
}
示例#4
0
文件: Tile.cpp 项目: mackorone/mms
void Tile::initInteriorPolygon(int mazeWidth, int mazeHeight) {

    Meters halfWallWidth = Meters(P()->wallWidth()) / 2.0;
    Cartesian lowerLeftPoint = m_fullPolygon.getVertices().at(0);
    Cartesian upperLeftPoint = m_fullPolygon.getVertices().at(1);
    Cartesian upperRightPoint = m_fullPolygon.getVertices().at(2);
    Cartesian lowerRightPoint = m_fullPolygon.getVertices().at(3);

    m_interiorPolygon = Polygon({
        lowerLeftPoint + Cartesian(
            halfWallWidth * (getX() == 0 ? 2 : 1), halfWallWidth * (getY() == 0 ? 2 : 1)),
        upperLeftPoint + Cartesian(
            halfWallWidth * (getX() == 0 ? 2 : 1), halfWallWidth * (getY() == mazeHeight - 1 ? -2 : -1)),
        upperRightPoint + Cartesian(
            halfWallWidth * (getX() == mazeWidth - 1 ? -2 : -1), halfWallWidth * (getY() == mazeHeight - 1 ? -2 : -1)),
        lowerRightPoint + Cartesian(
            halfWallWidth * (getX() == mazeWidth - 1 ? -2 : -1), halfWallWidth * (getY() == 0 ? 2 : 1))});
}
示例#5
0
std::map<
    std::pair<std::pair<int, int>, std::pair<int, int>>,
    std::pair<Cartesian, Cartesian>> TileGraphicTextCache::buildPositionCache(
        double borderFraction, TileTextAlignment tileTextAlignment) {

    // The tile graphic text could look like either of the following, depending
    // on the layout, boarder, and max size
    //
    //                    col
    //     *-*---------------------------*-*    *-*---------------------------*-*
    //     *-*--------------------------[B]*    *-*--------------------------[B]*
    //     | |                           | |    | |                           | |
    //     | |   *------------------[D]  | |    | |   *------------------[D]  | |
    //     | |   |    |    |    |    |   | |    | |   |                   |   | |
    //     | |   |    |    |    |    |   | |    | |   |                   |   | |
    //     | |   |    | 00 | 01 |    |   | |    | |   |----|----|----|----|   | |
    // row | |   |    |____|____|    |   | | or | |   |    |    |    |    |   | |
    //     | |   |    |    |    |    |   | |    | |   | 00 | 01 | 02 | 03 |   | |
    //     | |   |    |    |    |    |   | |    | |  [E]---|----|----|----|   | |
    //     | |   |    | 10 | 11 |    |   | |    | |   |                   |   | |
    //     | |   |    |    |    |    |   | |    | |   |                   |   | |
    //     | |  [C]--[E]-------------*   | |    | |  [C]------------------*   | |
    //     | |                           | |    | |                           | |
    //     *[A]--------------------------*-*    *[A]--------------------------*-*
    //     *-*---------------------------*-*    *-*---------------------------*-*

    std::map<
        std::pair<std::pair<int, int>, std::pair<int, int>>,
        std::pair<Cartesian, Cartesian>> positionCache;

    int maxRows = m_tileGraphicTextMaxSize.first;
    int maxCols = m_tileGraphicTextMaxSize.second;

    // First we get the unscaled diagonal
    Cartesian A = Cartesian(m_wallWidth / 2.0, m_wallWidth / 2.0);
    Cartesian B = A + Cartesian(m_wallLength, m_wallLength);
    Cartesian C = A + Cartesian(m_wallLength, m_wallLength) * borderFraction;
    Cartesian D = B - Cartesian(m_wallLength, m_wallLength) * borderFraction;
    Cartesian CD = D - C;

    // We assume that each character is twice as tall as it is wide, and we scale accordingly
    Meters characterWidth = CD.getX() / static_cast<double>(maxCols);
    Meters characterHeight = CD.getY() / static_cast<double>(maxRows);
    if (characterWidth * 2.0 < characterHeight) {
        characterHeight = characterWidth * 2.0;
    }
    else {
        characterWidth = characterHeight / 2.0;
    }

    // Now we get the scaled diagonal (note that we'll only shrink in at most one direction)
    Cartesian scalingOffset = Cartesian(
        (CD.getX() - characterWidth * maxCols) / 2.0,
        (CD.getY() - characterHeight * maxRows) / 2.0
    );
    Cartesian E = C + scalingOffset;

    // For all numbers of rows displayed
    for (int numRows = 0; numRows <= maxRows; numRows += 1) {

        // For all numbers of columns displayed
        for (int numCols = 0; numCols <= maxCols; numCols += 1) {

            // For each visible row and col
            for (int row = 0; row <= maxRows; row += 1) {
                for (int col = 0; col <= maxCols; col += 1) {

                    Cartesian LL = Cartesian(Meters(0), Meters(0));
                    Cartesian UR = Cartesian(Meters(0), Meters(0));

                    if (row < numRows && col < numCols) {

                        double rowOffset = 0.0;
                        if (ContainerUtilities::setContains(CENTER_STAR_ALIGNMENTS, tileTextAlignment)) {
                            rowOffset = static_cast<double>(maxRows - numRows) / 2.0;
                        }
                        else if (ContainerUtilities::setContains(UPPER_STAR_ALIGNMENTS, tileTextAlignment)) {
                            rowOffset = static_cast<double>(maxRows - numRows);
                        }

                        double colOffset = 0.0;
                        if (ContainerUtilities::setContains(STAR_CENTER_ALIGNMENTS, tileTextAlignment)) {
                            colOffset = static_cast<double>(maxCols - numCols) / 2.0;
                        }
                        else if (ContainerUtilities::setContains(STAR_RIGHT_ALIGNMENTS, tileTextAlignment)) {
                            colOffset = static_cast<double>(maxCols - numCols);
                        }

                        LL = Cartesian(
                            Meters(E.getX() + characterWidth * (col + colOffset)),
                            Meters(E.getY() + characterHeight * ((numRows - row - 1) + rowOffset))
                        );
                        UR = Cartesian(
                            Meters(E.getX() + characterWidth * (col + colOffset + 1)),
                            Meters(E.getY() + characterHeight * ((numRows - row - 1) + rowOffset + 1))
                        );
                    }

                    positionCache.insert(
                        std::make_pair(
                            std::make_pair(
                                // The number of rows/cols to be drawn
                                std::make_pair(numRows, numCols),
                                // The row and col of the current character
                                std::make_pair(row, col)
                            ),
                            // The lower left and upper right texture coordinate
                            std::make_pair(LL, UR)
                        )
                    );
                }
            }
        }
    }

    return positionCache;
}
示例#6
0
Meters MetersPerSecond::operator*(const Duration& duration) const {
    return Meters(getMetersPerSecond() * duration.getSeconds());
}
示例#7
0
 units::Meters Millimeters::toMeters() const
 {
     return Meters(m_value / 1000.0);
 }