Пример #1
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;
}
Пример #2
0
void Update(board state, int player, int X, int Y)
{
    int i,j;

    if (X<0) return; /* pass move */
    if (state[X][Y] != 0) {
        printboard(state, player, turn, X, Y);
        error("Illegal move");
    }
    state[X][Y] = player;
    for (i=-1; i<=1; i++)
        for (j=-1; j<=1; j++)
            if ((i!=0 || j!=0) && CanFlip(state, player, X, Y, i, j))
                DoFlip(state, player, X, Y, i, j);
}
//----------------------------------------------------------------------------
bool RoughPlaneParticle1::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    // Set up the physics module.
    mModule.Gravity = 10.0;
    mModule.Mass = 10.0;
    mModule.Friction = 1.0;
    mModule.Angle = 0.125*Mathd::PI;

    // Initialize the differential equations.
    double time = 0.0;
    double deltaTime = 1.0/60.0;
    double x = 0.0;
    double w = 0.0;
    double xDer = 10.0;
    double wDer = 40.0;
    mModule.Initialize(time, deltaTime, x, w, xDer, wDer);

    // Initialize the coefficients for the viscous friction solution.
    mR = mModule.Friction/mModule.Mass;
    mA0 = -xDer/mR;
    mA1 = x - mA0;
    mB1 = -mModule.Gravity*Mathd::Sin(mModule.Angle)/mR;
    mB2 = (wDer + mR*w - mB1)/mR;
    mB0 = w - mB2;

    // Save path of motion.
    mVFPositions.push_back(GetVFPosition(time));
    mSFPositions.push_back(Vector2d(x, w));

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

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

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

	// Same starting values as in RoughPlaneParticle2.
	double x1 = 16.0;
	double y1 = 116.0;
	double x2 = 100.0;
	double y2 = 200.0;
	double xDelta = x2 - x1;
	double yDelta = y2 - y1;

	// Set up the physics module.
	mModule.Length = Mathd::Sqrt(xDelta*xDelta + yDelta*yDelta);
	mModule.MuGravity = 5.0;  // mu*g = c/delta0 from RoughPlaneThinRod1

	// Initialize the differential equations.
	double time = 0.0;
	double deltaTime = 1.0/60.0;
	double x = 0.5*(x1 + x2);
	double y = 0.5*(y1 + y2);
	double theta = Mathd::ATan2(yDelta, xDelta);
	double xDer = 10.0;
	double yDer = -10.0;
	double thetaDer = 4.0;
	mModule.Initialize(time, deltaTime, x, y, theta, xDer, yDer, thetaDer);

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

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

	OnDisplay();
	return true;
}
//----------------------------------------------------------------------------
bool QuadraticFreeForm2D::OnInitialize ()
{
    if (!WindowApplication2::OnInitialize())
    {
        return false;
    }

    // The texture whose image will be drawn on the quadrilateral.
    std::string path = Environment::GetPathR("Magician.wmtf");
    mTexture = Texture2D::LoadWMTF(path);

    // The default control points produce the identity function.
    int x = mSize/4, y = mSize/4;
    mCtrlX[0][0] =   x;  mCtrlY[0][0] =   y;
    mCtrlX[0][1] =   x;  mCtrlY[0][1] = 2*y;
    mCtrlX[0][2] =   x;  mCtrlY[0][2] = 3*y;
    mCtrlX[1][0] = 2*x;  mCtrlY[1][0] =   y;
    mCtrlX[1][1] = 2*x;  mCtrlY[1][1] = 2*y;
    mCtrlX[1][2] = 2*x;  mCtrlY[1][2] = 3*y;
    mCtrlX[2][0] = 3*x;  mCtrlY[2][0] =   y;
    mCtrlX[2][1] = 3*x;  mCtrlY[2][1] = 2*y;
    mCtrlX[2][2] = 3*x;  mCtrlY[2][2] = 3*y;
    mCtrl[0][0] = Vector2f(0.0f, 0.0f);
    mCtrl[0][1] = Vector2f(0.0f, 0.5f);
    mCtrl[0][2] = Vector2f(0.0f, 1.0f);
    mCtrl[1][0] = Vector2f(0.5f, 0.0f);
    mCtrl[1][1] = Vector2f(0.5f, 0.5f);
    mCtrl[1][2] = Vector2f(0.5f, 1.0f);
    mCtrl[2][0] = Vector2f(1.0f, 0.0f);
    mCtrl[2][1] = Vector2f(1.0f, 0.5f);
    mCtrl[2][2] = Vector2f(1.0f, 1.0f);

    DoFlip(true);
    OnDisplay();
    return true;
}