Пример #1
0
DWORD WINAPI graphics(LPVOID Param)
{
	Params* params = (Params*)Param;
	CEngine* engine = (params->engine);
	
	float index = 0.0f;
	
	engine->SetPerspective(D3DX_PI/4,1.0f,100.0f);
	D3DXMatrixLookAtLH(&(engine->matView),
                   &D3DXVECTOR3 (0.0f, 0.0f, -10.0f),    // eye
                   &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // at
                   &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // up
	engine->d3ddev->SetTransform(D3DTS_VIEW, &(engine->matView));


	while (params->notQuit) {
		engine->Clear();
		engine->Begin();
		
	    

		for(list<CObject*>::iterator it = params->scene->lstChilds.begin(); it != params->scene->lstChilds.end(); ++it)
		{
			(*it)->update();
			//cout << "posX: " << (*it)->vehicle.getPos().x << "posY: " << (*it)->vehicle->getPos().y << "posZ: " << (*it)->vehicle->getPos().z << endl;
		}
		engine->End();
	}
	return 0;
}
void CUsingControllersView::OnMouseMove(UINT nFlags, CPoint point)
{
	if (m_MouseNavigation)
	{
	Ogre::Vector3 CameraMove(0.0, 0.0, 0.0);

	CameraMove[0] = -(m_MousePosition.x - point.x);
	CameraMove[1] = m_MousePosition.y - point.y;

	CEngine * Engine = ((CUsingControllersApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
		return;
	Ogre::Root *Root = Engine->GetRoot();
	if (m_Camera == NULL)
		return;
	Ogre::Vector3 OldPosition = m_Camera->getPosition();
	m_Camera->moveRelative(CameraMove);
		
	m_MousePosition = point;

	Root->renderOneFrame();
	}

	CView::OnMouseMove(nFlags, point);
}
void COrbitViewView::OnMouseMove(UINT nFlags, CPoint point)
{
	Ogre::Vector3 CameraMove(0.0, 0.0, 0.0);

	CEngine * Engine = ((COrbitViewApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
	  return;
	Ogre::Root *Root = Engine->GetRoot();
	if (m_Camera == NULL)
	  return;

	if (m_MouseNavigation)
	{
	if (m_Orbit)
	{
		Ogre::SceneNode* CameraNode = m_SceneManager->getSceneNode("CameraNode");
		CameraMove[1] = m_MousePosition.y - point.y;
		m_Camera->moveRelative(CameraMove);
		CameraNode->yaw(Ogre::Radian(0.01 * (m_MousePosition.x - point.x)));
	}
	else
	{
		CameraMove[0] = -(m_MousePosition.x - point.x);
		CameraMove[1] = m_MousePosition.y - point.y;
		m_Camera->moveRelative(CameraMove);
	}

		m_MousePosition = point;
		Root->renderOneFrame();
	}

	CView::OnMouseMove(nFlags, point);
}
Пример #4
0
void F2()
{
  wstring input_path = L"./Scripts/1.essay";
  ifstream ifs(input_path);

  try
  {
    CEngine engine;

    if (ifs.good())
    {
      auto c = engine.Run(ifs);
      auto context = engine.GetContext();

      auto a = context.GetVariable(L"Business.a").IsAvailable();

      for (int i = 0; i < context.GetSyntaxVector().size(); i++)
      {
        auto syntax = context.GetSyntax(i);
      }
    }
  }
  catch (CException& e)
  {
    auto r = e.ToString();
  }
}
Пример #5
0
int main(int argc, char *argv[])
{
	CEngine *Engine = CEngine::Instance();
	Engine->SetProgramName("Color lines");
	Engine->SetStateHandler<CCustomStateHandler>();
	Engine->Run(argc, argv);
	return EXIT_SUCCESS;
}
void CUsingControllersView::OnTimer(UINT_PTR nIDEvent)
{
	CEngine *Engine = ((CUsingControllersApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();
    Root->renderOneFrame();

	CView::OnTimer(nIDEvent);
}
void COrbitViewView::OnTimer(UINT_PTR nIDEvent)
{
	m_WalkAnimation->addTime(0.001);

	CEngine *Engine = ((COrbitViewApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();
    Root->renderOneFrame();

	CView::OnTimer(nIDEvent);
}
void CLinkedAnimationView::OnTimer(UINT_PTR nIDEvent)
{
	CEngine *Engine = ((CLinkedAnimationApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();

	m_AnimationState1->addTime(0.01);
	m_AnimationState2->addTime(0.01);

	Root->renderOneFrame();
	CView::OnTimer(nIDEvent);
}
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 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);
}
Пример #11
0
//------------------------------------------------------------------------
//  Get engines system
//------------------------------------------------------------------------
void CFuiProbe::GetEngSubsystems()
{ std::vector<CEngine *>engs;           // List of engines
  veh->eng.GetAllEngines(engs);
  std::vector<CEngine*>::iterator si;
  for (si = engs.begin(); si != engs.end(); si++)
  { CEngine   *eng = (*si);
    AddSubsystem(eng);
    CDependent *dp1 = eng->GetPart(1);
    if (dp1) AddSubsystem(dp1);
    CDependent *dp2 = eng->GetPart(2);
    if (dp2) AddSubsystem(dp2);
  }
  engs.clear();
  return;
}
Пример #12
0
int main( int argc, char* args[] )
{
    CEngine* engine = new CEngine( 640, 480, "Evolution-Simulator" );
    CRenderer& renderer = *engine->getRenderer();
    CGame* game = new CGame( engine );

    game->start();
    while ( game->running ) {
        game->update();
    }
    
    delete engine;
    delete game;
    SDL_Quit();

    return 0;
}
Пример #13
0
BOOL CSceneEditorView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	// TODO: Add your message handler code here and/or call default
	Ogre::Vector3 CameraMove(0.0, 0.0, 0.0);

	CameraMove[2] = 1 * zDelta;

	CEngine * Engine = ((CSceneEditorApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
		return false;
	Ogre::Root *Root = Engine->GetRoot();
	if (m_Camera == NULL)
		return false;
	m_Camera->moveRelative(CameraMove);

	return CView::OnMouseWheel(nFlags, zDelta, pt);
}
BOOL CTransparentMaterialView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	Ogre::Vector3 CameraMove(0.0, 0.0, 0.0);

	CameraMove[2] = 0.1 * zDelta;

	CEngine * Engine = ((CTransparentMaterialApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
		return false;
	Ogre::Root *Root = Engine->GetRoot();
	if (m_Camera == NULL)
		return false;
	m_Camera->moveRelative(CameraMove);

	Root->renderOneFrame();
	return CView::OnMouseWheel(nFlags, zDelta, pt);
}
Пример #15
0
void keyup(SDL_Event* event)
{
 SDL_Event e;
 e=*event;
 
  switch(e.key.keysym.sym) 
    {
        case SDLK_F1 : 
          engine.toggleFullScreen();
	  break;

        case SDLK_ESCAPE:
      	  done=true;
	
	 break;
        case SDLK_UP :
         engine.getDefaultCamera()->move(1.0,0,0,1);
	case SDLK_w :
         break;
            
       case SDLK_DOWN : 
          engine.getDefaultCamera()->move(-1.0,0,0,1);
       case SDLK_s :
        
            break;

       case SDLK_RIGHT :
       case SDLK_d :
             view_roty -= 5.0;       
            break;

       case SDLK_LEFT : 
       case SDLK_a :
       view_roty = +5.0;
        break;

        default:  
            break; 
    }
 
}
void CSunControlDlg::OnBnClickedSunAction()
{
	CMainFrame *MainFrame = (CMainFrame *)((CWeatherControlApp*)AfxGetApp())->GetMainWnd();
	CWeatherControlView *View = (CWeatherControlView *)MainFrame->GetActiveView();
  	CEngine *Engine = ((CWeatherControlApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();

	View->m_Sun->setVisible(!View->m_Sun->getVisible());

	if (View->m_Sun->getVisible())
	{
		m_Action.SetWindowTextA("Stop");
		View->SetTimer(ID_SUN_TIMER, 1, 0);
	}
	else
	{
		m_Action.SetWindowTextA("Start");
		View->KillTimer(ID_SUN_TIMER);
	}

	Root->renderOneFrame();
}
Пример #17
0
void CSceneEditorView::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CSceneEditorDoc *Document = GetDocument();
	CEngine *Engine = ((CSceneEditorApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
	  return;

	m_Root = Engine->GetRoot();

	if (m_First && m_Root != NULL)
    {
        m_First = false;
        EngineSetup();
    }

	if (m_Root != NULL)
    {
		m_Root->startRendering();
	}

}
Пример #18
0
BOOL CraytDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	
	motor.initFromTest();

	// Establecer el icono para este cuadro de diálogo. El marco de trabajo realiza esta operación
	//  automáticamente cuando la ventana principal de la aplicación no es un cuadro de diálogo
	SetIcon(m_hIcon, TRUE);			// Establecer icono grande
	SetIcon(m_hIcon, FALSE);		// Establecer icono pequeño


	return TRUE;  // Devuelve TRUE  a menos que establezca el foco en un control
}
void CUsingControllersView::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CView::OnPaint() for painting messages
	CUsingControllersDoc *Document = GetDocument();
	CEngine *Engine = ((CUsingControllersApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
	  return;

	Ogre::Root *Root = Engine->GetRoot();

	if (m_First && Root != NULL)
    {
        m_First = false;
        EngineSetup();
    }

	if (Root != NULL)
    {
       Root->renderOneFrame();
	}
}
void CManualObjectView::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CManualObjectDoc *Document = GetDocument();
	CEngine *Engine = ((CManualObjectApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
	  return;

	Ogre::Root *Root = Engine->GetRoot();

	if (m_First && Root != NULL)
    {
        m_First = false;
        EngineSetup();
    }

	if (Root != NULL)
    {
       Root->renderOneFrame();
	}

}
void COrbitViewView::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	COrbitViewDoc *Document = GetDocument();
	CEngine *Engine = ((COrbitViewApp*)AfxGetApp())->m_Engine;
	if (Engine == NULL)
	  return;

	Ogre::Root *Root = Engine->GetRoot();

	if (m_First && Root != NULL)
    {
        m_First = false;
        EngineSetup();
    }

	if (Root != NULL)
    {
       Root->renderOneFrame();
	}	
	// Do not call CView::OnPaint() for painting messages
}
Пример #22
0
void CSceneEditorView::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	if (m_MouseNavigation)
	{
		Ogre::Vector3 CameraMove(0.0, 0.0, 0.0);

		CameraMove[0] = -(m_MousePosition.x - point.x);
		CameraMove[1] = -(m_MousePosition.y - point.y);

		CEngine * Engine = ((CSceneEditorApp*)AfxGetApp())->m_Engine;
		if (Engine == NULL)
			return;
		Ogre::Root *Root = Engine->GetRoot();
		if (m_Camera == NULL)
			return;
		m_Camera->yaw(Ogre::Degree(CameraMove[0] * 0.10f));
		m_Camera->pitch(Ogre::Degree(CameraMove[1] * 0.10f));

		m_MousePosition = point;
	}

	CView::OnMouseMove(nFlags, point);
}
Пример #23
0
void CraytDlg::OnBnClickedOk()
{
	CDC *pDC = GetDC();

	LARGE_INTEGER F,T0,T1;   // address of current frequency
	QueryPerformanceFrequency(&F);
	QueryPerformanceCounter(&T0);
	motor.render(pDC);
	
	QueryPerformanceCounter(&T1);
	float elapsed_time = (float)(T1.QuadPart - T0.QuadPart) / (float)F.QuadPart;
	char buffer[255];
	sprintf(buffer,"%g s" , elapsed_time);
	AfxMessageBox(buffer);
	ReleaseDC(pDC);
}
Пример #24
0
int main(int argc, char *argv[])
{
 //CEngine engine;
 CLight lit1;
 engine.initializeVideo(800,600,24,false);
 lit1.enableOpenGLLighting();
 engine.getDefaultCamera()->setPosition(0,0,3);
 engine.setPerspective(60,1,1,100);
 engine.setCallbackFuncKeyup(keyup);
 lit1.enableLightSource();
 init(argc, argv);
 
 while(!done)
 {
  engine.startScene(true);
  draw();
  idle();
  engine.pumpEvents();
  engine.endScene();
 }
 engine.shutDown();
 SDL_Quit();
}
Пример #25
0
//---------------------------------------------------------------------------
//	@function:
//		CTreeMapTest::EresUnittest_Memo
//
//	@doc:
//		Test loading map from actual memo
//
//---------------------------------------------------------------------------
GPOS_RESULT
CTreeMapTest::EresUnittest_Memo()
{
	GPOS_SET_TRACE(EtraceDisablePrintMemoryLeak);

	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	// setup a file-based provider
	CMDProviderMemory *pmdp = CTestUtils::m_pmdpf;
	pmdp->AddRef();
	CMDAccessor mda(pmp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp);

	CEngine *peng = NULL;
	CExpression *pexpr = NULL;
	CQueryContext *pqc = NULL;
	CExpression *pexprPlan = NULL;
	{
		// install opt context in TLS
		CAutoOptCtxt aoc
				(
				pmp,
				&mda,
				NULL,  /* pceeval */
				CTestUtils::Pcm(pmp)
				);

		CAutoTraceFlag atf(EopttraceEnumeratePlans, true);

		peng = GPOS_NEW(pmp) CEngine(pmp);

		// generate join expression
		pexpr = CTestUtils::PexprLogicalJoin<CLogicalInnerJoin>(pmp);

		// generate query context
		pqc = CTestUtils::PqcGenerate(pmp, pexpr);

		// Initialize engine
		peng->Init(pqc, NULL /*pdrgpss*/);

		// optimize query
		peng->Optimize();

		// extract plan
		pexprPlan = peng->PexprExtractPlan();
		GPOS_ASSERT(NULL != pexprPlan);

		peng->Trace();
		{
			CAutoTrace at(pmp);
			ULLONG ullCount = peng->Pmemotmap()->UllCount();
#ifdef GPOS_DEBUG
			// test resetting map and re-creating it
			peng->ResetTreeMap();
			ULLONG ullCount2 = peng->Pmemotmap()->UllCount();
			GPOS_ASSERT(ullCount == ullCount2);
#endif // GPOS_DEBUG

			for (ULONG ulRank = 0; ulRank < ullCount; ulRank++)
			{
				CDrvdPropCtxtPlan *pdpctxtplan = GPOS_NEW(pmp) CDrvdPropCtxtPlan(pmp, false /*fUpdateCTEMap*/);
				CExpression *pexprAlt = NULL;
				GPOS_TRY
				{
					pexprAlt = peng->Pmemotmap()->PrUnrank(pmp, pdpctxtplan, ulRank);
					at.Os() << std::endl << "ALTERNATIVE ["<< ulRank <<"]:" << std::endl << *pexprAlt << std::endl;
				}
				GPOS_CATCH_EX(ex)
				{
					if (!GPOS_MATCH_EX(ex, gpopt::ExmaGPOPT, gpopt::ExmiUnsatisfiedRequiredProperties))
					{
						GPOS_RETHROW(ex);
					}
					IErrorContext *perrctxt = CTask::PtskSelf()->Perrctxt();
					at.Os() << perrctxt->WszMsg() << std::endl;
					GPOS_RESET_EX;
				}
				GPOS_CATCH_END;
				CRefCount::SafeRelease(pexprAlt);
				CRefCount::SafeRelease(pdpctxtplan);
			}
		}
	}

	// clean up
	CRefCount::SafeRelease(pexprPlan);
	GPOS_DELETE(pqc);
	CRefCount::SafeRelease(pexpr);
	GPOS_DELETE(peng);

	return GPOS_OK;
}
void CViewManagerView::On3dViews()
{
	int ViewIndex = CMFCRibbonGallery::GetLastSelectedItem(ID_3DVIEWS);
	CEngine *Engine = ((CViewManagerApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();
	m_SceneManager->_updateSceneGraph(m_Camera);
	Ogre::SceneNode *CubeNode = m_SceneManager->getSceneNode("Cube");

	Ogre::AxisAlignedBox Box = m_SceneManager->getRootSceneNode()->_getWorldAABB();
	Ogre::Vector3 Center = Box.getCenter();
	Ogre::Vector3 Position;
	Ogre::Vector3 Destination;

	switch (ViewIndex)
	{
		case 0: //top

			Position = Center;
			Position.y += 4.0 * Box.getSize().y;
			Destination = Center;

		break;
		case 1://bottom
			
			Position = Center;
			Position.y -= 4.0 * Box.getSize().y;
			Destination = Center;

		break;
		case 2:

			Position = Center;
			Position.x += 4.0 * Box.getSize().x;
			Destination = Center;

		break;
		case 3:

			Position = Center;
			Position.x -= 4.0 * Box.getSize().x;
			Destination = Center;

		break;
		case 4:

			Position = Center;
			Position.z -= 4.0 * Box.getSize().z;
			Destination = Center;

		break;
		case 5:

			Position = Center;
			Position.z += 4.0 * Box.getSize().z;
			Destination = Center;

		break;

		case 9:

			CubeNode->roll(Ogre::Radian(-atan(sin(Ogre::Math::PI/4.0))));
			CubeNode->yaw(Ogre::Radian(Ogre::Math::PI/4.0));
			Destination = Center;
			Position = m_Camera->getPosition();

		break;
	}

	m_Camera->setPosition(Position);
	m_Camera->lookAt(Destination);
	Root->renderOneFrame();
}
Пример #27
0
bool CDirectEngine::Init(const CEngine& aEngine, Vector2<unsigned int> aWindowSize, bool enableVSync, bool startInFullScreen)
{
    myEnableVSync = enableVSync;
    HRESULT result = S_OK;

    INFO_PRINT( "%s", "Starting engine" );

    myWindowSize = aWindowSize;
    DXGI_SWAP_CHAIN_DESC swapChainDescription;
    ZeroMemory( &swapChainDescription, sizeof( DXGI_SWAP_CHAIN_DESC ) );
    // fill the swap chain description struct
    swapChainDescription.BufferCount = 1;
    swapChainDescription.BufferDesc.Width = myWindowSize.x;
    swapChainDescription.BufferDesc.Height = myWindowSize.y;
    swapChainDescription.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

    Vector2<int> numDenum;

	IDXGIAdapter* adapter = nullptr;
	if (CollectAdapters(aWindowSize, numDenum, adapter))
    {
        INFO_PRINT( "%s%s", "VSYNC Compatible: Yes, Enabled: ", myEnableVSync ? "Yes" : "No" );
    }

    swapChainDescription.BufferDesc.RefreshRate.Numerator = numDenum.x;
    swapChainDescription.BufferDesc.RefreshRate.Denominator = numDenum.y;

    swapChainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDescription.OutputWindow = aEngine.GetWindow().GetWindowHandle();
    swapChainDescription.SampleDesc.Count = 1;
	swapChainDescription.Windowed = !startInFullScreen;
    swapChainDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
    swapChainDescription.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    swapChainDescription.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
    swapChainDescription.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
#if defined(REPORT_DX_WARNIGNS)
	creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
#endif
    // create a device, device context and swap chain using the information in the scd struct
    INFO_PRINT( "%s", "Creating device" );
	D3D_FEATURE_LEVEL feat_level;
	result = D3D11CreateDeviceAndSwapChain(adapter,
		D3D_DRIVER_TYPE_UNKNOWN,
        NULL,
        creationFlags,
		supported_feature_levels,
		NUM_SUPPORTED_FEATURE_LEVELS,
        D3D11_SDK_VERSION,
        &swapChainDescription,
        &mySwapchain,
        &myDevice,
		&feat_level,
        &myDeviceContext );

#if defined(_DEBUG)
	if (FAILED(result))
	{
		D3D_FEATURE_LEVEL feat_level;
		ERROR_AUTO_PRINT("%s", "Device could not create itself in debug mode, trying without debug layer... If you have Win10, try this:  Settings panel -> System -> Apps & features -> Manage optional Features -> Add a feature -> Select ""Graphics Tools""");
		UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

		INFO_PRINT("%s", "Creating device without debug layer");
		result = D3D11CreateDeviceAndSwapChain(adapter,
			D3D_DRIVER_TYPE_UNKNOWN,
			NULL,
			creationFlags,
			supported_feature_levels,
			NUM_SUPPORTED_FEATURE_LEVELS,
			D3D11_SDK_VERSION,
			&swapChainDescription,
			&mySwapchain,
			&myDevice,
			&feat_level,
			&myDeviceContext);
	}
#endif

	if (!myDeviceContext)
	{
		ERROR_AUTO_PRINT("%s", "Device context error, you might not have a DX11 supported grahics card");
		return false;
	}

	if (FAILED(result) || !mySwapchain || feat_level == D3D_FEATURE_LEVEL_10_0)
    {
        ERROR_AUTO_PRINT( "%s", "Device swap error, you might not have a DX11 supported grahics card" );
        return false;
    }

	SetDebugObjectName(myDeviceContext, "myDeviceContext");

    myD3dDebug = nullptr;
#ifdef _DEBUG
    if( SUCCEEDED( myDevice->QueryInterface( __uuidof( ID3D11Debug ), (void**)&myD3dDebug ) ) )
    {
        ID3D11InfoQueue *d3dInfoQueue = nullptr;
        if( SUCCEEDED( myD3dDebug->QueryInterface( __uuidof( ID3D11InfoQueue ), (void**)&d3dInfoQueue ) ) )
        {
            d3dInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_CORRUPTION, true );
            d3dInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_ERROR, false );

            D3D11_MESSAGE_ID hide[] =
            {
                D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS,
                // Add more message IDs here as needed
            };

            D3D11_INFO_QUEUE_FILTER filter;
            memset( &filter, 0, sizeof( filter ) );
            filter.DenyList.NumIDs = _countof( hide );
            filter.DenyList.pIDList = hide;
            d3dInfoQueue->AddStorageFilterEntries( &filter );
        }
    }
#endif

    // get the address of the back buffer
    ID3D11Texture2D *backBuffer = nullptr;
    result = mySwapchain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID*)&backBuffer );
    INFO_PRINT( "%s", "Creating swapchain" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "Get buffer error" );
        return false;
    }

    INFO_PRINT( "%s", "Swapchain created" );
    // use the back buffer address to create the render target
    result = myDevice->CreateRenderTargetView( backBuffer, NULL, &myBackbuffer );
    SetDebugObjectName( myBackbuffer, "myBackbuffer" );
    INFO_PRINT( "%s", "Creating RenderTargetView" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "Render target view error" );
        return false;
    }
    backBuffer->Release();
    backBuffer = nullptr;

    //myRendertarget = aEngine.GetTextureManager().GetRendertarget(myWindowSize);

    D3D11_TEXTURE2D_DESC depthBufferDesc;
    // Initialize the description of the depth buffer.
    ZeroMemory( &depthBufferDesc, sizeof( depthBufferDesc ) );

    // Set up the description of the depth buffer.
    depthBufferDesc.Width = myWindowSize.x;
    depthBufferDesc.Height = myWindowSize.y;
    depthBufferDesc.MipLevels = 1;
    depthBufferDesc.ArraySize = 1;
	depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    depthBufferDesc.SampleDesc.Count = 1;
    depthBufferDesc.SampleDesc.Quality = 0;
    depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    depthBufferDesc.CPUAccessFlags = 0;
    depthBufferDesc.MiscFlags = 0;

    // Create the texture for the depth buffer using the filled out description.
    result = myDevice->CreateTexture2D( &depthBufferDesc, NULL, &myDepthStencilBuffer );
    INFO_PRINT( "%s", "Creating Texture2D" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "Create tex2d error" );
        return false;
    }

    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;

    // Initialize the description of the stencil state.
    ZeroMemory( &depthStencilDesc, sizeof( depthStencilDesc ) );

    // Set up the description of the stencil state.
    depthStencilDesc.DepthEnable = false;
    depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
    depthStencilDesc.StencilEnable = true;
    depthStencilDesc.StencilReadMask = 0xFF;
    depthStencilDesc.StencilWriteMask = 0xFF;
    depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
    depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

    // Create the depth stencil state.
    result = myDevice->CreateDepthStencilState( &depthStencilDesc, &myDepthStencilState );
    INFO_PRINT( "%s", "Creating DepthStencilState" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "Depth stencil error" );
        return false;
    }

    myDeviceContext->OMSetDepthStencilState( myDepthStencilState, 1 );

    // Initialize the depth stencil view.
    D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
    ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) );

    // Set up the depth stencil view description.
	depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    depthStencilViewDesc.Texture2D.MipSlice = 0;

    // Create the depth stencil view.
    result = myDevice->CreateDepthStencilView( myDepthStencilBuffer, &depthStencilViewDesc, &myDepthStencilView );
    INFO_PRINT( "%s", "Creating DepthStencilView" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "depth stencil view error" );
        return false;
    }

    myDeviceContext->OMSetRenderTargets( 1, &myBackbuffer, myDepthStencilView );

    D3D11_RASTERIZER_DESC rasterDesc;
    // Setup the raster description which will determine how and what polygons will be drawn.
    rasterDesc.AntialiasedLineEnable = false;
	
    rasterDesc.CullMode = D3D11_CULL_NONE;
    rasterDesc.DepthBias = 0;
    rasterDesc.DepthBiasClamp = 0.0f;
    rasterDesc.DepthClipEnable = true;
    rasterDesc.FillMode = D3D11_FILL_SOLID;
    rasterDesc.FrontCounterClockwise = false;
    rasterDesc.MultisampleEnable = false;
    rasterDesc.ScissorEnable = false;
    rasterDesc.SlopeScaledDepthBias = 0.0f;

    // Create the rasterizer state from the description we just filled out.
    result = myDevice->CreateRasterizerState( &rasterDesc, &myRasterState );
    INFO_PRINT( "%s", "Creating RasterizerState" );
    if( FAILED( result ) )
    {
        ERROR_AUTO_PRINT( "%s", "Resterizer error" );
        return false;
    }

    myDeviceContext->RSSetState( myRasterState );

    D3D11_BLEND_DESC blendStateDescription;
    // Clear the blend state description.
    ZeroMemory( &blendStateDescription, sizeof( D3D11_BLEND_DESC ) );
    // Create an alpha enabled blend state description.
    blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
    blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
    blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
    blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
    blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
    blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
    blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f;
    result = myDevice->CreateBlendState( &blendStateDescription, &myAlphaEnableBlendingState );
    if( FAILED( result ) )
    {
        return false;
    }

    float blendFactor[4];

    // Setup the blend factor.
    blendFactor[0] = 0.0f;
    blendFactor[1] = 0.0f;
    blendFactor[2] = 0.0f;
    blendFactor[3] = 0.0f;

    // Turn on the alpha blending.
    myDeviceContext->OMSetBlendState( myAlphaEnableBlendingState, blendFactor, 0xffffffff );

	SetViewPort(0.0f, 0.0f, static_cast<float>(myWindowSize.x), static_cast<float>(myWindowSize.y));


    if( !CreateSampler() )
    {
        return false;
    }

    myTexturedQuadDrawer = new CTexturedQuadDrawer( this );
    myTexturedQuadDrawer->Init();

    myCustomShapeDrawer = new CCustomShapeDrawer( CEngine::GetInstance() );
    myCustomShapeDrawer->Init();

    myLineDrawer = new CLineDrawer( CEngine::GetInstance() );
    myLineDrawer->Init();

    myTexturedQuadBatchDrawer = new CTexturedQuadBatchDrawer( this );
    myTexturedQuadBatchDrawer->Init();

    INFO_PRINT( "%s", "All done, starting..." );
    return true;
}
Пример #28
0
int main( int argc, char* argv[] )
{
	jack_client_t *client;
	const char **ports;
	
	char name[] = "jackvis";
	/* try to become a client of the JACK server */
	
	if ((client = jack_client_new (name)) == 0) {
		fprintf (stderr, "jack server not running?\n");
		return 1;
	}
	
	data_array = (float*)malloc(sizeof(float)*DATA_SIZE);
	height_map = (float**)malloc(sizeof(float*)*BINS);
	for ( int i = 0 ; i < BINS ; i++ ) {
		height_map[i] = (float*)malloc(sizeof(float)*BINS);
		for ( int j = 0 ; j < BINS ; j++ ) {
			height_map[i][j] = 0.0;
		}
	}
	
	fftw_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE*2);
	for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE*2 ; i++ ) {
		fftw_in[i][0] = 0.0; fftw_in[i][1] = 0.0;
	}
	fftw_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
	for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
		fftw_out[i][0] = 0.0; fftw_out[i][1] = 0.0;
	}
	fftw_p = (fftw_plan*)malloc(sizeof(fftw_plan)*WINDOW_SIZE);
	for ( int i = 0 ; i < WINDOW_SIZE ; i++ ) {
		fftw_p[i] = fftw_plan_dft_1d(FRAME_SIZE*WINDOW_SIZE, &(fftw_in[i*FRAME_SIZE]), fftw_out, FFTW_FORWARD, FFTW_ESTIMATE);
	}
	current_window = 0;
	
	
	
	fftw_in_data = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
	for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
		fftw_in_data[i][0] = 0.0; fftw_in[i][1] = 0.0;
	}
	
	window = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
	for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
		window[i][0] = 0.54 - 0.46 * cos((2.0*PI*((double)i))/((double)(FRAME_SIZE*WINDOW_SIZE-1))); 
	}

	fftw_plan_data = fftw_plan_dft_1d(FRAME_SIZE*WINDOW_SIZE, fftw_in_data, fftw_out, FFTW_FORWARD, FFTW_MEASURE);
	
	for ( int i = 0 ; i < DATA_SIZE ; i++ ) { 
		data_array[i] = 0.0;
	}
	pos = 0;
	/* tell the JACK server to call `process()' whenever
	there is work to be done.
	*/
	
	
	
	jack_set_process_callback (client, process, 0);
	
	/* tell the JACK server to call `jack_shutdown()' if
	it ever shuts down, either entirely, or if it
	just decides to stop calling us.
	*/
	
	jack_on_shutdown (client, jack_shutdown, 0);
	
	/* display the current sample rate. 
	*/
	
	//printf ("engine sample rate: %" PRIu32 "\n", jack_get_sample_rate (client));
	
	/* create two ports */
	
	input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
	output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
	
	/* tell the JACK server that we are ready to roll */
	
	if (jack_activate (client)) {
	fprintf (stderr, "cannot activate client");
	return 1;
	}
	
	/* connect the ports. Note: you can't do this before
	the client is activated, because we can't allow
	connections to be made to clients that aren't
	running.
	*/
	
	//if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) {
	if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsOutput)) == NULL) {
	fprintf(stderr, "Cannot find any physical capture ports\n");
	exit(1);
	}
	
	int j = 0;
	while ( ports[j] != NULL ) {
		if (jack_connect (client, ports[j], jack_port_name (input_port))) {
		fprintf (stderr, "cannot connect input ports\n");
		}
		j++;
	}
	
	free (ports);
	
	/*if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
	fprintf(stderr, "Cannot find any physical playback ports\n");
	exit(1);
	}*/
	
	
	/*if (jack_connect (client, jack_port_name (output_port), ports[i])) {
		fprintf (stderr, "cannot connect output ports\n");
	}*/
	
	

	CEngine *myengine = new CEngine(argc, argv);
	myengine->start();
	
	//free (ports);
	
	free(data_array);
	for ( int i = 0 ; i < WINDOW_SIZE; i++ ) {
		fftw_destroy_plan(fftw_p[i]);
	}
	free(fftw_p);
    fftw_free(fftw_in); fftw_free(fftw_out);
    for ( int i = 0 ; i < BINS ; i++ ) {
    	free(height_map[i]);
    }
    free(height_map);
	jack_client_close (client);


	return 0 ;
}
void CResourceManagementView::EngineSetup(void)
{
	CEngine* Engine = ((CResourceManagementApp*)AfxGetApp())->m_Engine;
	Ogre::Root *Root = Engine->GetRoot();

	Ogre::SceneManager *SceneManager = NULL;

	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "ResourceManagement");

    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);

	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Resource Management");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("Resource Management", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
	
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
	m_Camera->setPosition(Ogre::Vector3(200.0, 50.0, 100.0));
	m_Camera->lookAt(0.0, 0.0, 0.0);
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 1.0f, 0.8f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
	Ogre::StringVector Groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();

	Ogre::Entity *MobiusEntity = Engine->m_StlFileManager->createEntity("Mobius", "1_4.stl");
	Ogre::SceneNode *MobiusNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	MobiusNode->attachObject(MobiusEntity);
	Ogre::AxisAlignedBox MobiusBox = MobiusEntity->getBoundingBox();
	Ogre::Vector3 MobiusCenter = MobiusBox.getCenter();
	m_Camera->lookAt(MobiusCenter);

	Ogre::Real Radius = MobiusEntity->getBoundingRadius();
	m_Camera->setPosition(300, 100, 200);
	m_Camera->setPolygonMode(Ogre::PM_WIREFRAME);
}
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);
}