示例#1
0
//----------------------------------------------------------------------------
void RoughPlaneParticle2::OnDisplay ()
{
    ClearScreen();

    ColorRGB black(0, 0, 0);
    ColorRGB gray(128, 128, 128);
    ColorRGB blue(0, 0, 255);

    // Draw the rod.
    double x1, y1, x2, y2;
    mModule.Get(x1, y1, x2, y2);
    int iX1 = (int)(x1 + 0.5);
    int iY1 = (int)(y1 + 0.5);
    int iX2 = (int)(x2 + 0.5);
    int iY2 = (int)(y2 + 0.5);
    DrawLine(iX1, iY1, iX2, iY2, gray);

    // Draw the masses.
    SetThickPixel(iX1, iY1, 2, black);
    SetThickPixel(iX2, iY2, 2, black);

    // Draw the center of mass.
    int x = (int)(mModule.GetX() + 0.5);
    int y = (int)(mModule.GetY() + 0.5);
    SetThickPixel(x, y, 2, blue);

    WindowApplication2::OnDisplay();
}
//----------------------------------------------------------------------------
void RoughPlaneParticle1::OnDisplay ()
{
    ClearScreen();

    ColorRGB black(0, 0, 0);
    ColorRGB gray(128, 128, 128);
    ColorRGB blue(0, 0, 128);
    ColorRGB lightBlue(0, 0, 255);
    int x0, w0, x1, w1, i;
    Vector2d position;

    const double xScale = 1.25;
    const double wScale = 0.75;
    const int wOffset = 96;

    // Draw viscous friction path of motion.
    const int numVFPositions = (int)mVFPositions.size();
    position = mVFPositions[0];
    x0 = (int)(xScale*position.X() + 0.5);
    w0 = (int)(wScale*position.Y() + 0.5) + wOffset;
    x1 = x0;
    w1 = w0;
    for (i = 1; i < numVFPositions; ++i)
    {
        position = mVFPositions[i];
        x1 = (int)(xScale*position.X() + 0.5);
        w1 = (int)(wScale*position.Y() + 0.5) + wOffset;
        DrawLine(x0, w0, x1, w1, lightBlue);
        x0 = x1;
        w0 = w1;
    }

    // Draw the mass.
    SetThickPixel(x1, w1, 2, blue);

    // Draw static friction path of motion.
    const int numSFPositions = (int)mSFPositions.size();
    position = mSFPositions[0];
    x0 = (int)(xScale*position.X() + 0.5);
    w0 = (int)(wScale*position.Y() + 0.5) + wOffset;
    x1 = x0;
    w1 = w0;
    for (i = 1; i < numSFPositions; ++i)
    {
        position = mSFPositions[i];
        x1 = (int)(xScale*position.X() + 0.5);
        w1 = (int)(wScale*position.Y() + 0.5) + wOffset;
        DrawLine(x0, w0, x1, w1, gray);
        x0 = x1;
        w0 = w1;
    }

    // Draw the mass.
    SetThickPixel(x1, w1, 2, black);

    WindowApplication2::OnDisplay();
}
示例#3
0
//----------------------------------------------------------------------------
void Boolean2D::DrawPolySolid (BspPolygon2& polygon, ColorRGB color)
{
    Vector2d  v0, v1;
    Edge2 edge;
    int i, x0, y0, x1, y1;

    // Draw the edges.
    for (i = 0; i < polygon.GetNumEdges(); ++i)
    {
        polygon.GetEdge(i, edge);
        polygon.GetVertex(edge.I0, v0);
        polygon.GetVertex(edge.I1, v1);
        
        x0 = (int)(v0.X() + 0.5f);
        y0 = GetWidth() - 1 - (int)(v0.Y() + 0.5f);
        x1 = (int)(v1.X() + 0.5f);
        y1 = GetWidth() - 1 - (int)(v1.Y() + 0.5f);

        DrawLine(x0, y0, x1, y1, color);
    }

    // Draw the vertices.
    ColorRGB black(0, 0, 0);
    for (i = 0; i < polygon.GetNumVertices(); ++i)
    {
        polygon.GetVertex(i, v0);
        x0 = (int)(v0.X() + 0.5f);
        y0 = GetWidth() - 1 - (int)(v0.Y() + 0.5f);
        SetThickPixel(x0, y0, 1, black);
    }
}
//----------------------------------------------------------------------------
void ClodPolyline::OnDisplay ()
{
    ClearScreen();

    ColorRGB black(0, 0, 0);
    const int numVertices = mPolyline->GetNumVertices();
    const Vector3f* vertices = mPolyline->GetVertices();
    const int numEdges = mPolyline->GetNumEdges();
    const int* edges = mPolyline->GetEdges();

    Vector3f vertex;
    int i;
    for (i = 0; i < numVertices; ++i)
    {
        vertex = vertices[i];
        int x = (int)(0.25f*mSize*(vertex.X() + 2.0f));
        int y = mSize - 1 - (int)(0.25f*mSize*(vertex.Y() + 2.0f));
        SetThickPixel(x, y, 1, black);
    }

    for (i = 0; i < numEdges; ++i)
    {
        vertex = vertices[edges[2*i]];
        int x0 = (int)(0.25f*mSize*(vertex.X() + 2.0f));
        int y0 = mSize - 1 - (int)(0.25f*mSize*(vertex.Y() + 2.0f));

        vertex = vertices[edges[2*i+1]];
        int x1 = (int)(0.25*mSize*(vertex.X() + 2.0f));
        int y1 = mSize - 1 - (int)(0.25f*mSize*(vertex.Y() + 2.0f));
        DrawLine(x0, y0, x1, y1, black);
    }

    WindowApplication2::OnDisplay();
}
//----------------------------------------------------------------------------
void BSplineCurveExamples::OnDisplay ()
{
    ClearScreen();

    ColorRGB lightGray(224, 224, 224);
    ColorRGB mediumGray(192, 192, 192);
    ColorRGB darkGray(128, 128, 128);
    ColorRGB black(0, 0, 0);

    // draw axes
    int i;
    for (i = mSize/16; i < mSize; ++i)
    {
        SetPixel(mSize/16, mSize - 1 - i, lightGray);
        SetPixel(i, mSize - 1 - mSize/16, lightGray);
    }

    // draw control points
    int imax = mSpline->GetNumCtrlPoints();
    int x, y;
    for (i = 0; i < imax; ++i)
    {
        const Vector2f& ctrl = mSpline->GetControlPoint(i);
        x = (int)(ctrl.X() + 0.5f);
        y = mSize - 1 - (int)(ctrl.Y() + 0.5f);
        SetThickPixel(x, y, 2, darkGray);
    }

    // draw spline
    imax = 2048;
    for (i = 0; i <= imax; ++i)
    {
        // draw point
        float u = i/(float)imax;
        Vector2f pos = mSpline->GetPosition(u);
        x = (int)(pos.X() + 0.5f);
        y = mSize - 1 - (int)(pos.Y() + 0.5f);

        if (mModified
        &&  mLocCtrlMin[mCurveType] <= u && u <= mLocCtrlMax[mCurveType])
        {
            SetPixel(x, y, mediumGray);
        }
        else
        {
            SetPixel(x, y, black);
        }
    }

    WindowApplication2::OnDisplay();
}
//----------------------------------------------------------------------------
void QuadraticFreeForm2D::OnDisplay ()
{
    ClearScreen();

    int dim0 = mTexture->GetDimension(0, 0);
    int dim1 = mTexture->GetDimension(1, 0);
    unsigned char* data = (unsigned char*)mTexture->GetData(0);

    const int numSamples = 2*mSize;
    const float invNumSamples = 1.0f/(float)numSamples;
    Vector2f param;
    for (int s = 0; s < numSamples; ++s)
    {
        int u = s*dim0/numSamples;
        param.X() = invNumSamples*s;
        for (int t = 0; t < numSamples; ++t)
        {
            int v = t*dim1/numSamples;
            param.Y() = invNumSamples*t;
            Vector2f result = Evaluate(param);

            int x = ControlToScreen(result.X());
            int y = ControlToScreen(result.Y());
            int index = 4*(u + dim0*v);
            unsigned char b = data[index++];
            unsigned char g = data[index++];
            unsigned char r = data[index++];
            ++index;

            SetPixel(x, y, ColorRGB(r, g, b));
        }
    }

    // Draw the control points.
    ColorRGB green(0, 255, 0);
    for (int row = 0; row <= 2; ++row)
    {
        for (int col = 0; col <= 2; ++col)
        {
            SetThickPixel(mCtrlX[row][col], mCtrlY[row][col], 2, green);
        }
    }

    WindowApplication2::OnDisplay();
}
示例#7
0
//----------------------------------------------------------------------------
void NURBSCurveExample::OnDisplay ()
{
    ClearScreen();

    ColorRGB curveColor(0,0,0);
    ColorRGB controlColor(128, 128, 128);

    int imax = 2048;
    int i, x, y;
    float t;
    Vector2f position;

    // Draw the spline.
    for (i = 0; i <= imax; ++i)
    {
        t = i/(float)imax;
        position = mSpline->GetPosition(t);
        x = (int)(position.X() + 0.5f);
        y = mSize - 1 - (int)(position.Y() + 0.5f);
        SetPixel(x, y, curveColor);
    }

    // Draw the circle.
    if (mCircle)
    {
        for (i = 0; i <= imax; ++i)
        {
            t = i/(float)imax;
            position = mCircle->GetPosition(t);
            x = (int)(position.X() + 0.5f);
            y = mSize - 1 - (int)(position.Y() + 0.5f);
            SetPixel(x, y, curveColor);
        }
    }

    // Draw the control points.
    if (mDrawControlPoints)
    {
        // Draw the spline control points.
        imax = mSpline->GetNumCtrlPoints();
        for (i = 0; i < imax; ++i)
        {
            const Vector2f& ctrl = mSpline->GetControlPoint(i);
            x = (int)(ctrl.X() + 0.5f);
            y = mSize - 1 -(int)(ctrl.Y() + 0.5f);
            SetThickPixel(x, y, 2, controlColor);
        }

        // Draw the circle control points.
        if (mCircle)
        {
            imax = mCircle->GetNumCtrlPoints();
            for (i = 0; i < imax; ++i)
            {
                const Vector2f& ctrl = mCircle->GetControlPoint(i);
                x = (int)(ctrl.X() + 0.5f);
                y = mSize - 1 - (int)(ctrl.Y() + 0.5f);
                SetThickPixel(x, y, 2, controlColor);
            }
        }
    }

    WindowApplication2::OnDisplay();
}
示例#8
0
//----------------------------------------------------------------------------
void ConvexHull2D::OnDisplay ()
{
    ClearScreen();

    ColorRGB black(0,0,0), gray(128,128,128), blue(0,0,255);

    int dimension = mHull->GetDimension();
    int numSimplices = mHull->GetNumSimplices();
    const int* indices = mHull->GetIndices();

    int i0, i1, x0, y0, x1, y1;
    Vector2f v0, v1;

    if (dimension == 0)
    {
        // draw point
        v0 = mVertices[0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetPixel(x0, y0, gray);
    }
    else if (dimension == 1)
    {
        // draw line segment
        v0 = mVertices[indices[0]];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());

        v1 = mVertices[indices[1]];
        x1 = UnitToScreen(v1.X());
        y1 = UnitToScreen(v1.Y());

        DrawLine(x0, y0, x1, y1, gray);
    }
    else
    {
        // draw convex polygon
        for (i0 = numSimplices - 1, i1 = 0; i1 < numSimplices; i0 = i1++)
        {
            v0 = mVertices[indices[i0]];
            x0 = UnitToScreen(v0.X());
            y0 = UnitToScreen(v0.Y());

            v1 = mVertices[indices[i1]];
            x1 = UnitToScreen(v1.X());
            y1 = UnitToScreen(v1.Y());

            DrawLine(x0, y0, x1, y1, gray);
        }
    }

    // draw input points
    for (i0 = 0; i0 < mNumVertices; ++i0)
    {
        v0 = mVertices[i0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetThickPixel(x0, y0, 1, blue);
    }

    // draw hull vertices
    if (indices)
    {
        for (i0 = 0; i0 < numSimplices; ++i0)
        {
            v0 = mVertices[indices[i0]];
            x0 = UnitToScreen(v0.X());
            y0 = UnitToScreen(v0.Y());
            SetThickPixel(x0, y0, 1, black);
        }
    }
    else
    {
        v0 = mVertices[0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetThickPixel(x0, y0, 1, black);
    }

    WindowApplication2::OnDisplay();
}