Пример #1
0
//----------------------------------------------------------------------------
bool ClodPolyline::OnKeyDown (unsigned char key, int x, int y)
{
    if (WindowApplication2::OnKeyDown(key, x, y))
    {
        return true;
    }

    int levelOfDetail;

    switch (key)
    {
    case '+':  // increase level of detail
    case '=':
        levelOfDetail = mPolyline->GetLevelOfDetail();
        if (levelOfDetail < mPolyline->GetMaxLevelOfDetail())
        {
            mPolyline->SetLevelOfDetail(levelOfDetail + 1);
            OnDisplay();
        }
        return true;
    case '-':  // decrease level of detail
    case '_':
        levelOfDetail = mPolyline->GetLevelOfDetail();
        if (levelOfDetail > mPolyline->GetMinLevelOfDetail())
        {
            mPolyline->SetLevelOfDetail(levelOfDetail - 1);
            OnDisplay();
        }
        return true;
    }

    return false;
}
Пример #2
0
//----------------------------------------------------------------------------
bool NURBSCurveExample::OnKeyDown (unsigned char key, int x, int y)
{
    if (WindowApplication2::OnKeyDown(key, x, y))
    {
        return true;
    }

    switch (key)
    {
    case 'g':
        if (mSimTime <= 1.0f)
        {
            DoSimulation1();
        }
        else if (mSimTime <= 2.0f)
        {
            DoSimulation2();
        }
        else
        {
            InitialConfiguration();
        }
        return true;
    case '0':
        InitialConfiguration();
        OnDisplay();
        return true;
    case 'c':
        mDrawControlPoints = !mDrawControlPoints;
        OnDisplay();
        return true;
    }

    return false;
}
Пример #3
0
bool TriangulationCDTWindow::OnCharPress(unsigned char key, int x, int y)
{
    switch (key)
    {
    case '0':
        UnindexedSimplePolygon();
        OnDisplay();
        return true;
    case '1':
        IndexedSimplePolygon();
        OnDisplay();
        return true;
    case '2':
        OneNestedPolygon();
        OnDisplay();
        return true;
    case '3':
        TwoNestedPolygons();
        OnDisplay();
        return true;
    case '4':
        TreeOfNestedPolygons();
        OnDisplay();
        return true;
    }

    return Window::OnCharPress(key, x, y);
}
Пример #4
0
//----------------------------------------------------------------------------
void NURBSCurveExample::OnKeyDown (unsigned char ucKey, int, int)
{
    if ( ucKey == 'q' || ucKey == 'Q' || ucKey == KEY_ESCAPE )
    {
        RequestTermination();
        return;
    }

    switch ( ucKey )
    {
    case 'g':
        if ( m_fSimTime <= 1.0f )
            DoSimulation1();
        else if ( m_fSimTime <= 2.0f )
            DoSimulation2();
        else
            InitialConfiguration();
        break;
    case '0':
        InitialConfiguration();
        OnDisplay();
        break;
    case 'c':
        m_bDrawControlPoints = !m_bDrawControlPoints;
        OnDisplay();
        break;
    }
}
Пример #5
0
//----------------------------------------------------------------------------
bool PolygonDistance::OnKeyDown (unsigned char key, int x, int y)
{
	if (WindowApplication2::OnKeyDown(key, x, y))
	{
		return true;
	}

	switch (key)
	{
	case 'g':
		NextConfiguration();
		OnDisplay();
		return true;
	case '0':
		InitialConfiguration();
		OnDisplay();
		return true;
	case 'p':  // toggle for drawing the perpendiculars
		mDrawPerpendiculars = !mDrawPerpendiculars;
		OnDisplay();
		return true;
	}

	return false;
}
Пример #6
0
//----------------------------------------------------------------------------
bool Triangulation::OnKeyDown (unsigned char key, int x, int y)
{
    if (WindowApplication2::OnKeyDown(key, x, y))
    {
        return true;
    }

    switch (key)
    {
    case '0':
        DoExample0();
        OnDisplay();
        return true;
    case '1':
        DoExample1();
        OnDisplay();
        return true;
    case '2':
        DoExample2();
        OnDisplay();
        return true;
    case '3':
        DoExample3();
        OnDisplay();
        return true;
    case '4':
        DoExample4();
        OnDisplay();
        return true;
    }

    return false;
}
Пример #7
0
//----------------------------------------------------------------------------
bool DrawImplicitSurface::OnKeyDown (unsigned char key, int x, int y)
{
	if (WindowApplication2::OnKeyDown(key, x, y))
	{
		return true;
	}

	switch (key)
	{
	case '+':  // increase ray sample size
	case '=':
		mNumSamples += 100;
		mTracer.DrawSurface(mNumSamples, mTracer.DVector, mBlur);
		OnDisplay();
		return true;
	case '-':  // decrease ray sample size
	case '_':
		if (mNumSamples > 100)
		{
			mNumSamples -= 100;
			mTracer.DrawSurface(mNumSamples, mTracer.DVector, mBlur);
			OnDisplay();
		}
		return true;
	case 'b':  // toggle blur of output image
	case 'B':
		mBlur = !mBlur;
		mTracer.DrawSurface(mNumSamples, mTracer.DVector, mBlur);
		OnDisplay();
		return true;
	}

	return false;
}
Пример #8
0
//----------------------------------------------------------------------------
void DrawImplicitSurface::OnKeyDown (unsigned char ucKey, int, int)
{
    if ( ucKey == 'q' || ucKey == 'Q' || ucKey == KEY_ESCAPE )
    {
        RequestTermination();
        return;
    }

    switch ( ucKey )
    {
    case '+':  // increase ray sample size
    case '=':
        m_iMaxSample += 100;
        m_kRT.DrawSurface(m_iMaxSample,m_kRT.Direction(),m_bBlur);
        OnDisplay();
        break;
    case '-':  // decrease ray sample size
    case '_':
        if ( m_iMaxSample > 100 )
        {
            m_iMaxSample -= 100;
            m_kRT.DrawSurface(m_iMaxSample,m_kRT.Direction(),m_bBlur);
            OnDisplay();
        }
        break;
    case 'b':  // toggle blur of output image
    case 'B':
        m_bBlur = !m_bBlur;
        m_kRT.DrawSurface(m_iMaxSample,m_kRT.Direction(),m_bBlur);
        OnDisplay();
        break;
    }
}
//----------------------------------------------------------------------------
bool QuadraticFreeForm2D::OnMouseClick (int button, int state, int x, int y,
    unsigned int)
{
    if (button != MOUSE_LEFT_BUTTON)
    {
        return false;
    }

    // Handle the flip in y that is used for drawing.
    y = mSize - 1 - y;

    if (state == MOUSE_DOWN)
    {
        mMouseDown = true;
        SelectVertex(x, y);
        return true;
    }

    if (state == MOUSE_UP)
    {
        mMouseDown = false;
        if (mRow >= 0 && mCol >= 0
        &&  0 <= x && x < GetWidth() && 0 <= y && y < GetHeight())
        {
            mCtrlX[mRow][mCol] = x;
            mCtrlY[mRow][mCol] = y;
            mCtrl[mRow][mCol].X() = ScreenToControl(x);
            mCtrl[mRow][mCol].Y() = ScreenToControl(y);
            OnDisplay();
        }
        return true;
    }

    return false;
}
Пример #10
0
//----------------------------------------------------------------------------
void RoughPlaneThinRod2::OnIdle ()
{
#ifndef SINGLE_STEP
	mModule.Update();
	OnDisplay();
#endif
}
Пример #11
0
//----------------------------------------------------------------------------
void NURBSCurveExample::DoSimulation2 ()
{
    mSimTime += mSimDelta;

    if (!mCircle)
    {
        NextConfiguration();
    }
    else
    {
        // The curve evolves to a line segment.
        float t = mSimTime - 1.0f;
        float oneMinusT = 1.0f - t;
        Vector2f ctrl = oneMinusT*mSpline->GetControlPoint(2) +
            t*mSpline->GetControlPoint(1);
        mSpline->SetControlPoint(2, ctrl);

        // The circle floats up a little bit.
        int imax = mCircle->GetNumCtrlPoints();
        for (int i = 0; i < imax; ++i)
        {
            ctrl = mCircle->GetControlPoint(i) + Vector2f::UNIT_Y;
            mCircle->SetControlPoint(i, ctrl);
        }
    }

    OnDisplay();
}
Пример #12
0
//----------------------------------------------------------------------------
void NURBSCurveExample::DoSimulation1 ()
{
    mSimTime += mSimDelta;

    float t = mSimTime;
    float oneMinusT = 1.0f - t;
    int imax = mSpline->GetNumCtrlPoints();
    for (int i = 0; i < imax; ++i)
    {
        if (i == 2 || i == 10)
        {
            float s = Mathf::Pow(t, 1.5f);
            float oneMinusS = 1.0f - s;
            mSpline->SetControlPoint(i,
                oneMinusS*mCtrlPoints[i] + s*mTargets[i]);
        }
        else
        {
            mSpline->SetControlPoint(i,
                oneMinusT*mCtrlPoints[i] + t*mTargets[i]);
        }
    }

    OnDisplay();
}
Пример #13
0
//----------------------------------------------------------------------------
bool ClodPolyline::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    // Generate points on unit circle, then adjust the distances to center.
    int numVertices = 16;
    Vector3f* vertices = new1<Vector3f>(numVertices);
    int i;
    for (i = 0; i < numVertices; ++i)
    {
        float angle = Mathf::TWO_PI*i/numVertices;
        vertices[i].X() = Mathf::Cos(angle);
        vertices[i].Y() = Mathf::Sin(angle);
        vertices[i].Z() = 0.0f;

        float adjust = 1.0f + 0.25f*Mathf::SymmetricRandom();
        vertices[i] *= adjust;
    }

    mPolyline = new0 Polyline3(numVertices, vertices, true);

    OnDisplay();
    return true;
}
Пример #14
0
//----------------------------------------------------------------------------
void NURBSCurveExample::DoSimulation2 ()
{
    m_fSimTime += m_fSimDelta;

    if ( !m_pkCircle )
    {
        NextConfiguration();
    }
    else
    {
        // curve evolves to a line segment
        float fT = m_fSimTime - 1.0f, fOmT = 1.0f - fT;
        Vector2f kCtrl = fOmT*m_pkSpline->GetControlPoint(2) +
            fT*m_pkSpline->GetControlPoint(1);
        m_pkSpline->SetControlPoint(2,kCtrl);

        // circle floats up a little bit
        int iMax = m_pkCircle->GetNumCtrlPoints();
        for (int i = 0; i < iMax; i++)
        {
            kCtrl = m_pkCircle->GetControlPoint(i)+Vector2f::UNIT_Y;
            m_pkCircle->SetControlPoint(i,kCtrl);
        }
    }

    OnDisplay();
}
Пример #15
0
//----------------------------------------------------------------------------
bool DrawImplicitSurface::OnInitialize ()
{
	if (!WindowApplication2::OnInitialize())
	{
		return false;
	}

	// Initialize camera and view frustum.
	mTracer.Location = Vector3f(2.0f, 0.0f, 0.0f);
	mTracer.DVector = Vector3f(-1.0f, 0.0f, 0.0f);
	mTracer.UVector = Vector3f(0.0f, 1.0f, 0.0f);
	mTracer.RVector = mTracer.DVector.Cross(mTracer.UVector);
	mTracer.Near = 0.1f;
	mTracer.Far = 10.0f;
	mTracer.HalfWidth = 2.0f*mTracer.Near;  // 90 degree horizontal FOV
	mTracer.HalfHeight = 2.0f*mTracer.Near;  // 90 degree vertical FOV

	// The light direction will be the camera direction so that we can see
	// the surface from all camera locations.

	// Draw the level surface.
	mTracer.DrawSurface(mNumSamples, mTracer.DVector, mBlur);
	OnDisplay();
	return true;
}
Пример #16
0
//----------------------------------------------------------------------------
bool BallRubberBand::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    // Set up the physics module.
    mModule.SpringConstant = 16.0;
    mModule.Mass = 1.0;

    double time = 0.0;
    double deltaTime = 0.01;
    Vector2d position(96.0, 96.0);
    Vector2d velocity(64.0, 0.0);
    mModule.Initialize(time, deltaTime, position, velocity);

    const int imax = 128;
    mPosition.resize(imax);
    for (int i = 0; i < imax; ++i)
    {
        mPosition[i] = mModule.GetPosition();
        mModule.Update();
    }

    OnDisplay();
    return true;
}
Пример #17
0
//----------------------------------------------------------------------------
bool RoughPlaneParticle2::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    // Set up the physics module.
    mModule.Gravity = 10.0;
    mModule.Mass1 = 10.0;
    mModule.Mass2 = 20.0;
    mModule.Friction1 = 1.0;
    mModule.Friction2 = 1.0;

    // Initialize the differential equations.
    double time = 0.0;
    double deltaTime = 1.0/60.0;
    double x1 = 16.0;
    double y1 = 116.0;
    double x2 = 100.0;
    double y2 = 200.0;
    double xDot = 10.0;
    double yDot = -10.0;
    double thetaDot = 0.5;
    mModule.Initialize(time, deltaTime, x1, y1, x2, y2, xDot, yDot, thetaDot);

    // Use right-handed coordinates.
    DoFlip(true);

    // Drawing might extend outside the application window.
    ClampToWindow() = true;

    OnDisplay();
    return true;
}
Пример #18
0
void BSplineSurfaceFitterWindow::OnIdle()
{
    if (mCameraRig.Move())
    {
        OnDisplay();
    }
}
Пример #19
0
//----------------------------------------------------------------------------
bool Delaunay2DWindow::OnMouseClick(MouseButton button, MouseState state,
    int x, int y, unsigned int)
{
    if (button != MOUSE_LEFT)
    {
        return false;
    }

    if (state == MOUSE_DOWN)
    {
        Vector2<float> pos((float)x, (float)y);
        mInfo.initialTriangle = mInfo.finalTriangle;
        int i = mDelaunay.GetContainingTriangle(pos, mInfo);
        if (i >= 0)
        {
            mCurrentTriX = x;
            mCurrentTriY = y;
            mInfo.finalTriangle = i;
        }
        else
        {
            mCurrentTriX = -1;
            mCurrentTriY = -1;
        }
        OnDisplay();
    }

    return true;
}
//----------------------------------------------------------------------------
bool RoughPlaneParticle1::OnKeyDown (unsigned char key, int x, int y)
{
    if (WindowApplication2::OnKeyDown(key, x, y))
    {
        return true;
    }

#ifdef SINGLE_STEP
    switch (key)
    {
    case 'g':
    case 'G':
        if (mContinueSolving)
        {
            mModule.Update();
            if (mModule.GetX() > 0.0 && mModule.GetW() <= 0.0)
            {
                mContinueSolving = false;
                return true;
            }
            mVFPositions.push_back(GetVFPosition(mModule.GetTime()));
            mSFPositions.push_back(Vector2d(mModule.GetX(), mModule.GetW()));
            OnDisplay();
        }
        return true;
    }
#endif

    return false;
}
Пример #21
0
//----------------------------------------------------------------------------
bool VolumeRenderer::OnMouseClick (int button, int state, int x, int y,
    unsigned int)
{
    if (button != MOUSE_LEFT_BUTTON)
    {
        return false;
    }

    if (state == MOUSE_DOWN)
    {
        mButtonDown = true;
        mX0 = (x - mHBound)/mHBound;
        mY0 = (y - mHBound)/mHBound;
    }
    else
    {
        mButtonDown = false;
        mX1 = (x - mHBound)/mHBound;
        mY1 = (y - mHBound)/mHBound;

        if (mRT->MoveTrackBall(mX0, mY0, mX1, mY1))
        {
            mRT->Trace(1);
            OnDisplay();
        }
    }

    return true;
}
Пример #22
0
//----------------------------------------------------------------------------
bool PolygonDistance::OnInitialize ()
{
	if (!WindowApplication2::OnInitialize())
	{
		return false;
	}

	// Warm up the random number generator.
	srand((unsigned int)time(0));
	int i, j = rand() % 100;
	for (i = 0; i < j; ++i)
	{
		rand();
	}

	for (i = 0; i < NUM_POLYGONS; ++i)
	{
		mPolygons[i].NumVertices = 5 - i;
		mPolygons[i].Vertices = new1<Vector2f>(mPolygons[i].NumVertices);
		mPolygons[i].Polars = new1<Vector2f>(mPolygons[i].NumVertices);
		mPolygons[i].Faces = new1<Tuple<2,int> >(mPolygons[i].NumVertices);
	}

	InitialConfiguration();
	OnDisplay();
	return true;
}
Пример #23
0
//----------------------------------------------------------------------------
bool NURBSCurveExample::OnInitialize ()
{
    if ( !Application2::OnInitialize() )
        return false;

    InitialConfiguration();
    OnDisplay();
    return true;
}
Пример #24
0
bool BSplineSurfaceFitterWindow::OnMouseMotion(MouseButton button, int x,
    int y, unsigned int modifiers)
{
    if (Window3::OnMouseMotion(button, x, y, modifiers))
    {
        OnDisplay();
    }
    return true;
}
Пример #25
0
bool BSplineSurfaceFitterWindow::OnMouseClick(MouseButton button,
    MouseState state, int x, int y, unsigned int modifiers)
{
    if (Window3::OnMouseClick(button, state, x, y, modifiers))
    {
        OnDisplay();
    }
    return true;
}
Пример #26
0
//----------------------------------------------------------------------------
bool WmtfViewer::OnMotion (int, int x, int y, unsigned int)
{
    if (mMouseDown)
    {
        ReadPixelValue(x, y);
        OnDisplay();
        return true;
    }
    return false;
}
bool ConstrainedDelaunay2DWindow::OnCharPress(unsigned char key, int x, int y)
{
    std::vector<int> outEdge;
    switch (key)
    {
    case '0':
        mDelaunay.Insert({ 0, 5 }, outEdge);
        OnDisplay();
        return true;
    case '1':
        mDelaunay.Insert({ 5, 9 }, outEdge);
        OnDisplay();
        return true;
    case '2':
        mDelaunay.Insert({ 9, 0 }, outEdge);
        OnDisplay();
        return true;
    }
    return Window::OnCharPress(key, x, y);
}
Пример #28
0
//----------------------------------------------------------------------------
bool VolumeRenderer::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    mRT->Trace(1);
    OnDisplay();
    return true;
}
Пример #29
0
//----------------------------------------------------------------------------
bool ConvexHull2D::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    GenerateHull2D();
    OnDisplay();
    return true;
}
Пример #30
0
//----------------------------------------------------------------------------
void RoughPlaneParticle2::OnIdle ()
{
#ifndef SINGLE_STEP
    if (mIteration < mMaxIteration)
    {
        mModule.Update();
        OnDisplay();
        ++mIteration;
    }
#endif
}