void CBlendingAnimationsView::OnTimer(UINT_PTR nIDEvent)
{
	CEngine *Engine = ((CBlendingAnimationsApp*)AfxGetApp())->m_Engine;			
	Ogre::Root *Root = Engine->GetRoot();
	Ogre::SceneNode *RobotNode = Root->getSceneManager("Walking")->getSceneNode("Robot");

	Ogre::Entity *RobotEntity = Root->getSceneManager("Walking")->getEntity("Robot");
	Ogre::Skeleton *Skeleton = RobotEntity->getSkeleton();

	if (m_WeightDlg->m_IsAverage)
	{
		Skeleton->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_AVERAGE);
	}
	else
	{
		Skeleton->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_CUMULATIVE);
	}

	double WalkWeight;
	double SlumpWeight;

	switch(nIDEvent)
	{
	case 1:
	
		WalkWeight = m_WeightDlg->m_WalkWeight.GetPos() / 10.0;
		SlumpWeight = m_WeightDlg->m_SlumpWeight.GetPos() / 10.0;

		m_WalkAnimation->setWeight(WalkWeight);
		m_SlumpAnimation->setWeight(SlumpWeight);
		
		m_WalkAnimation->addTime(0.01);
		m_SlumpAnimation->addTime(0.01);

		break;
	
	case 2:

		m_WalkAnimation->addTime(0.01);

	break;

	case 3:
		
		m_SlumpAnimation->addTime(0.01);

		break;
	}

	Root->renderOneFrame();
	CView::OnTimer(nIDEvent);
}
void NavigationCell::debugDrawClassification( Ogre::Vector3 start, Ogre::Vector3 end )
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* node;

    if( mgr->hasManualObject( "debugDrawClassification" ) )
        debug = mgr->getManualObject( "debugDrawClassification" );
    else
    {
        debug = mgr->createManualObject( "debugDrawClassification" );
        node = mgr->getRootSceneNode()->createChildSceneNode();
        node->attachObject( debug );
        node->translate( 0, 1, 0 );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_LIST );
    debug->position( start );
    debug->position( end );
    debug->end();

//    debugDrawCell( debug, "debug/yellow", "debug/blue" );
}
void CSceletalAnimationView::OnTimer(UINT_PTR nIDEvent)
{
	CEngine *Engine = ((CSceletalAnimationApp*)AfxGetApp())->m_Engine;		
	Ogre::Root *Root = Engine->GetRoot();
	Ogre::SceneManager *SceneManager = Root->getSceneManager("Animation");
	Ogre::Entity *Entity = SceneManager->getEntity("Animation");
	Ogre::Skeleton *Skeleton = Entity->getSkeleton();

	m_AnimationState->addTime(0.1);
	Root->renderOneFrame();

	CView::OnTimer(nIDEvent);
}
void NavigationCell::debugDrawCellAndNeigbours()
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* debugNode;

    if( mgr->hasSceneNode( "debugDrawNode" ) )
    {
        debugNode = mgr->getSceneNode( "debugDrawNode" );
    }
    else
    {
        debugNode = mgr->getRootSceneNode()->createChildSceneNode( "debugDrawNode" );
        debugNode->translate( 0, 1, 0 );    // Move up slightly to see lines better.
    }

    if( mgr->hasManualObject( "debugDraw" ) )
        debug = mgr->getManualObject( "debugDraw" );
    else
    {
        debug = mgr->createManualObject( "debugDraw" );
        debugNode->attachObject( debug );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    for( int i = 0; i < 3; i++ )
    {
        if( mLinks[i] )
        {
            debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_STRIP );
            debug->position( mLinks[i]->mVertices[0] );
            debug->position( mLinks[i]->mVertices[1] );
            debug->position( mLinks[i]->mVertices[2] );
            debug->position( mLinks[i]->mVertices[0] );
            debug->end();
        }
    }

    debug->begin( "debug/yellow", Ogre::RenderOperation::OT_LINE_STRIP );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->position( mVertices[1].x, mVertices[1].y+1, mVertices[1].z );
    debug->position( mVertices[2].x, mVertices[2].y+1, mVertices[2].z );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->end();

}
void NavigationMesh::resetPathfinding()
{
    mOpenList.clear();
    for( CellVector::iterator i = mCells.begin(); i != mCells.end(); i++ )
    {
        i->path = -1;   // Not strictly required.
        i->parent = 0;  // Or this either.

        i->isOpen = false;
        i->isClosed = false;
    }

    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    mgr->destroyManualObject( "debugDrawClassification" );
    mgr->destroyManualObject( "debugDraw" );
}
void NavigationMesh::setShow( bool show )
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* debugNode;

    mShow = show;

    if( mgr->hasSceneNode( "debugDrawNode2" ) )
    {
        debugNode = mgr->getSceneNode( "debugDrawNode2" );
    }
    else
    {
        debugNode = mgr->getRootSceneNode()->createChildSceneNode( "debugDrawNode2" );
        debugNode->translate( 0, 1, 0 );    // Move up slightly to see lines better.
    }

    if( mgr->hasManualObject( "debugDraw2" ) )
        debug = mgr->getManualObject( "debugDraw2" );
    else
    {
        debug = mgr->createManualObject( "debugDraw2" );
        debugNode->attachObject( debug );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    if( !mShow )
    {
        mgr->destroyManualObject( debug );
        return;
    }

    for( CellVector::iterator i = mCells.begin(); i != mCells.end(); i++ )
    {
        i->debugDrawCell( debug, "debug/yellow", "debug/blue" );
    }

    return;
}
void CTerrainWalkingView::OnTimer(UINT_PTR nIDEvent)
{
	Ogre::Quaternion Quaternion;
	CEngine *Engine = ((CTerrainWalkingApp*)AfxGetApp())->m_Engine;		
	Ogre::Root *Root = Engine->GetRoot();
	Ogre::SceneNode *RobotNode = Root->getSceneManager("Walking")->getSceneNode("Robot");
	Ogre::Entity *RobotEntity = Root->getSceneManager("Walking")->getEntity("Robot");
	Ogre::AxisAlignedBox RobotBox = RobotEntity->getBoundingBox();

	Ogre::Entity *TopographyEntity = Root->getSceneManager("Walking")->getEntity("Topography");

	Ogre::AxisAlignedBox TopographyBox = TopographyEntity->getBoundingBox();
		
	Ogre::Vector3 Start = TopographyBox.getMinimum();
	Ogre::Vector3 Finish = TopographyBox.getMaximum();

	double x = Start[0] + (Finish[0] - Start[0]) * m_RelativeDistance;
	double y = Start[1] + (Finish[1] - Start[1]) * m_RelativeDistance;
	double z = Start[2] + (Finish[2] - Start[2]) * m_RelativeDistance;
	
	Ogre::Vector3 Elevation(x, y, z);
	Ogre::Vector3 CameraMove;

	switch (nIDEvent)
	{
		case 1:

			m_Animation->addTime(0.01);
			m_RelativeDistance += 0.01;

			if (m_CollisionTools->collidesWithEntity(Elevation, Ogre::Vector3(x,y - 1,z), Ogre::Vector3(x,y + 1,z), 100.0f, 0.0f, 4294967295))
			{
				x = Elevation[0];
				y = Elevation[1] + RobotBox.getSize()[1];
				z = Elevation[2];
			}

			RobotNode->setPosition(x, y, z);
			m_Camera->lookAt(x, y, z);
			
			if (m_RelativeDistance > 1.0)
			  KillTimer(1);

		break;

		case 2:

			CameraMove[0] = -100;
			CameraMove[1] = 0;
			CameraMove[2] = 0;
			m_Camera->moveRelative(CameraMove);

		break;

		case 3:

			CameraMove[0] = 0;
			CameraMove[1] = 100;
			CameraMove[2] = 0;
			m_Camera->moveRelative(CameraMove);

			break;

		case 4:

			CameraMove[0] = 100;
			CameraMove[1] = 0;
			CameraMove[2] = 0;
			m_Camera->moveRelative(CameraMove);

			break;

		case 5:

			CameraMove[0] = 0;
			CameraMove[1] = -100;
			CameraMove[2] = 0;
			m_Camera->moveRelative(CameraMove);

			break;
	}

	Root->renderOneFrame();
	CView::OnTimer(nIDEvent);
}