//----------------------------------------------------------------------------
bool SimplePendulumFriction::OnInitialize ()
{
	if (!WindowApplication3::OnInitialize())
	{
		return false;
	}

	// Set up the camera.
	mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 100.0f);
	float angle = 0.1f*Mathf::PI;
	float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle);
	APoint camPosition(23.0f, 0.0f, 8.0f);
	AVector camDVector(-cs, 0.0f, -sn);
	AVector camUVector(-sn, 0.0f, cs);
	AVector camRVector = camDVector.Cross(camUVector);
	mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector);

	InitializeModule();
	CreateScene();

	// Initial update of objects.
	mScene->Update();

	PhysicsTick();

	// Initial culling of scene.
	mCuller.SetCamera(mCamera);
	mCuller.ComputeVisibleSet(mScene);

	InitializeCameraMotion(0.01f, 0.001f);
	InitializeObjectMotion(mScene);
	return true;
}
示例#2
0
//----------------------------------------------------------------------------
bool BouncingBall::OnInitialize ()
{
    if (!WindowApplication3::OnInitialize())
    {
        return false;
    }

    // Set up the camera.
    mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f);
    float angle = 0.1f*Mathf::PI;
    float cs = Mathf::Cos(angle);
    float sn = Mathf::Sin(angle);
    APoint camPosition(6.75f, 0.0f, 2.3f);
    AVector camDVector(-cs, 0.0f, -sn);
    AVector camUVector(-sn, 0.0f, cs);
    AVector camRVector = camDVector.Cross(camUVector);
    mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector);

    CreateScene();

    // Initial update of objects.
    mScene->Update();
    mBallNode->Update();

    // Initialize ball with correct transformations.
    PhysicsTick();
    mSimTime = 0.0f;

    // All objects are visible.
    mSceneVisibleSet.Insert(mWall);
    mBallNodeVisibleSet.Insert(mBall->GetMesh());

    InitializeCameraMotion(0.1f, 0.01f);
    return true;
}
示例#3
0
//----------------------------------------------------------------------------
bool BouncingSpheres::OnInitialize ()
{
    if (!WindowApplication3::OnInitialize())
    {
        return false;
    }

    // Set up the camera.
    mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f);
    float angle = 0.02f*Mathf::PI;
    float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle);
    APoint camPosition(27.5f, 8.0f, 8.9f);
    AVector camDVector(-cs, 0.0f, -sn);
    AVector camUVector(-sn, 0.0f, cs);
    AVector camRVector = camDVector.Cross(camUVector);
    mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector);

    CreateScene();

    // Initial update of objects.
    mScene->Update();

    // Initialize balls with correct transformations.
    PhysicsTick();

    // Initial culling of scene.
    mCuller.SetCamera(mCamera);
    mCuller.ComputeVisibleSet(mScene);
    return true;
}
//----------------------------------------------------------------------------
void BouncingTetrahedra::OnIdle ()
{
    MeasureTime();
    PhysicsTick();
    GraphicsTick();
    UpdateFrameCount();
}
//----------------------------------------------------------------------------
bool RoughPlaneSolidBox::OnKeyDown (unsigned char key, int x, int y)
{
    switch (key)
    {
    case 'w':  // toggle wireframe
    case 'W':
        mWireState->Enabled = !mWireState->Enabled;
        return true;

    case 'r':  // restart
    case 'R':
        InitializeModule();
        MoveBox();
        return true;

#ifdef SINGLE_STEP
    case 'g':
    case 'G':
        PhysicsTick();
        return true;
#endif
    }

    return WindowApplication3::OnKeyDown(key, x, y);
}
示例#6
0
//----------------------------------------------------------------------------
void BouncingSpheres::OnIdle ()
{
    MeasureTime();
    PhysicsTick();
    GraphicsTick();
    UpdateFrameCount();
}
示例#7
0
//----------------------------------------------------------------------------
void BouncingBall::OnIdle ()
{
    MeasureTime();

#ifndef SINGLE_STEP
    PhysicsTick();
#endif

    GraphicsTick();

    UpdateFrameCount();
}
示例#8
0
//----------------------------------------------------------------------------
void Fluids3D::OnIdle ()
{
    MeasureTime();

#ifdef USE_PARTICLES
    bool particlesNeedUpdate = false;
#endif
    mIndexBufferNeedsUpdate = false;

    if (MoveCamera())
    {
#ifdef USE_PARTICLES
        particlesNeedUpdate = true;
#endif
        mIndexBufferNeedsUpdate = true;
    }

    if (MoveObject())
    {
#ifdef USE_PARTICLES
        particlesNeedUpdate = true;
#endif
        mIndexBufferNeedsUpdate = true;
        mScene->Update();
    }

#ifdef USE_PARTICLES
    if (particlesNeedUpdate)
    {
        mCube->GenerateParticles(mCamera);
    }
#endif

    if (mIndexBufferNeedsUpdate)
    {
        UpdateIndexBuffer();
        mIndexBufferNeedsUpdate = false;
    }

    if (!mSingleStep)
    {
        PhysicsTick();
    }

    GraphicsTick();

    UpdateFrameCount();
}
//----------------------------------------------------------------------------
void RoughPlaneSolidBox::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif
    GraphicsTick();

    UpdateFrameCount();
}
示例#10
0
//----------------------------------------------------------------------------
void SimplePendulumFriction::OnIdle ()
{
	MeasureTime();

	MoveCamera();
	if (MoveObject())
	{
		mScene->Update();
	}

#ifndef SINGLE_STEP
	PhysicsTick();
#endif
	GraphicsTick();

	UpdateFrameCount();
}
//----------------------------------------------------------------------------
bool FoucaultPendulum::OnInitialize ()
{
    if (!WindowApplication3::OnInitialize())
    {
        return false;
    }

    // Initialize the physics module.
    mModule.AngularSpeed = 0.0001;
    mModule.Latitude = 0.25*Mathd::PI;
    mModule.GDivL = 1.0;

    double time = 0.0;
    double deltaTime = 0.001;
    double theta = 0.0;
    double thetaDot = 0.1;
    double phi = 0.75;
    double phiDot = 0.0;
    mModule.Initialize(time, deltaTime, theta, phi, thetaDot, phiDot);

    // Set up the camera.
    mCamera->SetFrustum(60.0f, GetAspectRatio(), 0.1f, 100.0f);
    float angle = 0.1f*Mathf::PI;
    float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle);
    APoint camPosition(23.0f, 0.0f, 8.0f);
    AVector camDVector(-cs, 0.0f, -sn);
    AVector camUVector(-sn, 0.0f, cs);
    AVector camRVector = camDVector.Cross(camUVector);
    mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector);

    CreateScene();

    // Initial update of objects.
    mScene->Update();

    PhysicsTick();

    // Initial culling of scene.
    mCuller.SetCamera(mCamera);
    mCuller.ComputeVisibleSet(mScene);

    InitializeCameraMotion(0.01f, 0.001f);
    InitializeObjectMotion(mScene);
    return true;
}
//----------------------------------------------------------------------------
void IntersectingBoxes::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif

    GraphicsTick();

    UpdateFrameCount();
}
//----------------------------------------------------------------------------
void WaterDropFormation::OnIdle ()
{
	MeasureTime();

#ifndef SINGLE_STEP
	float currSeconds = (float)GetTimeInSeconds();
	float diff = currSeconds - mLastSeconds;
	if (diff >= 0.033333f)
	{
		PhysicsTick();
		mCuller.ComputeVisibleSet(mScene);
		mLastSeconds = currSeconds;
	}
#endif

	GraphicsTick();

	UpdateFrameCount();
}
示例#14
0
//----------------------------------------------------------------------------
void Rope::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

    float currIdle = (float)GetTimeInSeconds();
    float diff = currIdle - mLastIdle;
    if (diff >= 0.001f)
    {
        mLastIdle = currIdle;
        PhysicsTick();
        GraphicsTick();
    }

    UpdateFrameCount();
}
示例#15
0
//----------------------------------------------------------------------------
bool SimplePendulumFriction::OnKeyDown (unsigned char key, int x, int y)
{
	if (WindowApplication3::OnKeyDown(key, x, y))
	{
		return true;
	}

	switch (key)
	{
	case 'w':  // toggle wireframe
	case 'W':
		mWireState->Enabled = !mWireState->Enabled;
		return true;

	case '0': // pendulum oscillates, but slows down slowly
		mMotionType = 0;
		InitializeModule();
		return true;

	case '1': // pendulum slows to a vertical stop, no oscillation
		mMotionType = 1;
		InitializeModule();
		return true;

	case '2': // pendulum oscillates, but slows down quickly
		mMotionType = 2;
		InitializeModule();
		return true;

#ifdef SINGLE_STEP
	case 'g':
	case 'G':
		PhysicsTick();
		return true;
#endif
	}

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

    switch (key)
    {
    case 'w':  // toggle wireframe
        mWireState->Enabled = !mWireState->Enabled;
        return true;

#ifdef SINGLE_STEP
    case 'g':
        mSimTime += mSimDeltaTime;
        PhysicsTick();
        return true;
#endif
    }

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

	switch (key)
	{
	case 'w':  // toggle wireframe
	case 'W':
		mWireState->Enabled = !mWireState->Enabled;
		return true;

#ifdef SINGLE_STEP
	case 'g':
		PhysicsTick();
		return true;
#endif
	}

	return false;
}
示例#18
0
//----------------------------------------------------------------------------
void GelatinCube::OnIdle ()
{
    MeasureTime();

    bool needSort = MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
        needSort = true;
    }
    if (needSort)
    {
        mBox->SortFaces(mCamera->GetDVector());
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif

    GraphicsTick();

    UpdateFrameCount();
}
示例#19
0
//----------------------------------------------------------------------------
bool Fluids3D::OnKeyDown (unsigned char key, int x, int y)
{
    if (WindowApplication3::OnKeyDown(key, x, y))
    {
        return true;
    }

    switch (key)
    {
    case '0':
        mSmoke->Initialize();
        UpdateVertexBuffer();
        return true;
    case ' ':
        if (mSingleStep)
        {
            PhysicsTick();
        }
        return true;
    case 's':
    case 'S':
        mSingleStep = !mSingleStep;
        return true;
    case 'c':
    case 'C':
        mUseColor = !mUseColor;
        UpdateVertexBuffer();
        return true;
    case '+':
    case '=':
    {
        int numActive = mSmoke->GetNumActiveVortices();
        if (numActive < mSmoke->GetNumVortices())
        {
            mSmoke->SetNumActiveVortices(numActive + 1);
        }
        return true;
    }
    case '-':
    case '_':
    {
        int numActive = mSmoke->GetNumActiveVortices();
        if (numActive > 0)
        {
            mSmoke->SetNumActiveVortices(numActive - 1);
        }
        return true;
    }
    case 'g':
    {
        float gravity = mSmoke->GetGravity() - 0.5f;
        if (gravity < 0.0f)
        {
            gravity = 0.0f;
        }
        mSmoke->SetGravity(gravity);
        return true;
    }
    case 'G':
        mSmoke->SetGravity(mSmoke->GetGravity() + 0.5f);
        return true;
    }

    return false;
}