Пример #1
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;
	IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");
	resourceGroupManager->loadResourceGroup("General");

	XMFLOAT3 vertices[4];
	vertices[0] = XMFLOAT3(-10.0f, 0.0f, 10.0f);
	vertices[1] = XMFLOAT3(10.0f, 0.0f, 10.0f);
	vertices[2] = XMFLOAT3(-10.0f, 0.0f, -10.0f);
	vertices[3] = XMFLOAT3(10.0f, 0.0f, -10.0f);

	ISimpleMesh* mesh = meshManager->createSimpleMesh("pointlist", vertices, NULL, 4, sizeof(XMFLOAT3), 0, false);
	IMeshNode* meshNode = smgr->addMeshNode(mesh, nullptr, nullptr);
	meshNode->setMaterialName("test/ts_material");

	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f));
	char caption[200];

	ITimer* timer = device->createTimer();
	timer->reset();

	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		float dt = timer->tick();
		updateCamera(camera, dt);


		smgr->drawAll();

		driver->endScene();

		sprintf(caption, "FPS:%f", getFps(dt));
		device->setWindowCaption(caption);
	}

	device->drop();

	return 0;
}
Пример #2
0
int _tmain(int argc, _TCHAR* argv[])
{
    SDeviceContextSettings settings;
    settings.MultiSamplingCount = 1;
    settings.MultiSamplingQuality = 0;
    settings.WindowsProcedure = EditorWindow::WndProc;

    EditorWindow* window = new EditorWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
    EditorWindow::_setInstance(window);

    IDevice* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
    IVideoDriver* driver = device->getVideoDriver();
    EditorScene* scene = new EditorScene(device);
    EditorScene::_setInstance(scene);


    scene->setupInitialScene();
    window->init();

    ITimer* timer = device->getTimer();
    timer->reset();
    char caption[200];
    while (device->run())
    {
        const float clearColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        driver->beginScene(true, true, clearColor);

        f32 dt = timer->tick();
        scene->update(dt);
        scene->drawAll();

        driver->endScene();

        sprintf(caption, "FPS:%f", getFps(dt));
        device->setWindowCaption(caption);
    }

    delete scene;
    device->drop();

    return 0;
}
//----------------------------------------------------------------------------------------
//Constructors
//----------------------------------------------------------------------------------------
GenericDataViewPresenter::GenericDataViewPresenter(const std::wstring& aviewGroupName, const std::wstring& aviewName, int aviewID, GenericAccessMenus& aowner, const IDevice& amodelInstanceKey, IGenericAccess& amodel, const IGenericAccessPage* apage)
:ViewPresenterBase(aowner.GetAssemblyHandle(), aviewGroupName, aviewName, aviewID, amodelInstanceKey.GetDeviceInstanceName(), amodelInstanceKey.GetDeviceModuleID(), amodelInstanceKey.GetModuleDisplayName()), owner(aowner), modelInstanceKey(amodelInstanceKey), model(amodel), page(apage)
{}
Пример #4
0
int main(int argc, char *argv[])
{
	IMagicX *mx = CreateMagicX(RDT_OPENGL, 0, 0, 1280, 768);
	ISceneManager *sceneManager = mx->GetSceneManager();
	IKeyEvent *event = CEventManager::Instance()->GetKeyEvent();
	IScene *scene = sceneManager->GetCurrentScene();
	IDevice *device = mx->GetDevice();

	IRenderObject *pRenderObject = new CReflectObject();

	CSphereEntity *pSphere = nullptr;
	ICamera *camera = nullptr;
	if (scene)
	{		
		pSphere = new CSphereEntity(pRenderObject, 5, 52, 26);
		

		CVector3 vDir(0, 0, -1);
		CVector3 vUp(0, 1, 0);
		//camera = scene->SetupCamera(CVector3(0, 0, 5), vDir, vUp, PI / 6, 1.0f * device->GetWindowWidth() / device->GetWindowHeight(), 1.0f, 5000.0f);
		camera = scene->SetupCamera(30, pSphere, vDir, vUp, PI / 3, 1.0f * device->GetWindowWidth() / device->GetWindowHeight(), 1.0f, 5000.0f);
		//scene->SetupSkyBox("texture/pos_x.tga", "texture/neg_x.tga", "texture/pos_y.tga", "texture/neg_y.tga", "texture/pos_z.tga", "texture/neg_z.tga", 1024);
		scene->SetupSkyBox("texture/FullMoonLeft.tga", "texture/FullMoonRight.tga", "texture/FullMoonUp.tga", "texture/FullMoonDown.tga", "texture/FullMoonFront.tga", "texture/FullMoonBack.tga", 512);
		//scene->SetupSkyBox("texture/CloudyLightRaysLeft2048.tga", "texture/CloudyLightRaysRight2048.tga", "texture/CloudyLightRaysUp2048.tga", "texture/CloudyLightRaysDown2048.tga", "texture/CloudyLightRaysFront2048.tga", "texture/CloudyLightRaysBack2048.tga", 512);
		//scene->SetupSkyBox("texture/DarkStormyLeft2048.tga", "texture/DarkStormyRight2048.tga", "texture/DarkStormyUp2048.tga", "texture/DarkStormyDown2048.tga", "texture/DarkStormyFront2048.tga", "texture/DarkStormyBack2048.tga", 512);
		//scene->SetupSkyBox("texture/SunSetLeft2048.tga", "texture/SunSetRight2048.tga", "texture/SunSetUp2048.tga", "texture/SunSetDown2048.tga", "texture/SunSetFront2048.tga", "texture/SunSetBack2048.tga", 512);
		//scene->SetupSkyBox("texture/ThickCloudsWaterLeft2048.tga", "texture/ThickCloudsWaterRight2048.tga", "texture/ThickCloudsWaterUp2048.tga", "texture/ThickCloudsWaterDown2048.tga", "texture/ThickCloudsWaterFront2048.tga", "texture/ThickCloudsWaterBack2048.tga", 512);
		//scene->SetupSkyBox("texture/TropicalSunnyDayLeft2048.tga", "texture/TropicalSunnyDayRight2048.tga", "texture/TropicalSunnyDayUp2048.tga", "texture/TropicalSunnyDayDown2048.tga", "texture/TropicalSunnyDayFront2048.tga", "texture/TropicalSunnyDayBack2048.tga", 512);

		pSphere->Create();
		pSphere->SetPosition(CVector3(0, 0, 0));
		scene->GetRootNode()->AddChild(pSphere);
	}

	uint next_game_tick = GetTickCount();
	int sleep_time = 0;

	bool bQuit = false;
	while (device->Run())
	{
		uint cur_time = GetTickCount();
		sleep_time = next_game_tick - cur_time;
		if (sleep_time <= 0)
		{
			if (event)
			{
				static int lastX;
				static int lastY;

				int currentX = event->GetMousePositonX();
				int currentY = event->GetMousePositionY();

				float rotY = (currentX - lastX) * 2.0f * PI / device->GetWindowWidth();
				float rotX = (currentY - lastY) * 2.0f * PI / device->GetWindowHeight();

				CVector3 camDir = camera->GetDirection();
				CVector3 curRot = pSphere->GetRotation();
				if (event->IsPress(EKP_MOUSE_LBUTTON))
				{				
					if (!ISZERO(rotX) || !ISZERO(rotY))
					{
						CVector3 rot(rotX + curRot.x, curRot.y + rotY, 0);
						pSphere->SetRotation(rot);
					}
				}
				if (event->IsPress(EKP_MOUSE_RBUTTON))
				{		
					if (!ISZERO(rotX) || !ISZERO(rotY))
					{
						camDir.rotateXZBy(-rotY);
						CMatrix4 rotMat4;												
						rotMat4.SetRotationRadians(rotX, (-camDir).crossProduct(CVector3(0, 1.0f, 0)));
						rotMat4.TransformVect(camDir);
						
						camDir.normalize();
						camera->SetDirection(camDir);
					}

				}				
				
				if (event->IsPress(EKP_KEYBOARD_A))
				{
					CVector3 leftDir = camDir;
					leftDir.rotateXZBy(PI / 2);
					pSphere->SetPosition(pSphere->GetPosition() + leftDir * 1.0f);
				}

				if (event->IsPress(EKP_KEYBOARD_D))
				{
					CVector3 rightDir = camDir;
					rightDir.rotateXZBy(PI / 2);
					pSphere->SetPosition(pSphere->GetPosition() - rightDir * 1.0f);
				}

				if (event->IsPress(EKP_KEYBOARD_W))
				{
					pSphere->SetPosition(pSphere->GetPosition() + camDir * 1.0f);
				}

				if (event->IsPress(EKP_KEYBOARD_S))
				{
					pSphere->SetPosition(pSphere->GetPosition() - camDir * 1.0f);
				}

				if (event->IsPress(EKP_KEYBOARD_ESC))
				{
					exit(1);
				}

				lastX = event->GetMousePositonX();
				lastY = event->GetMousePositionY();
			}

			next_game_tick = GetTickCount() + SKIP_TICKS;

			sceneManager->Update(SKIP_TICKS - sleep_time);
			sceneManager->Draw();
			device->SwapBuffers();
		}
		else
		{
			device->Sleep(sleep_time);
		}


	}

	delete pSphere;
	delete pRenderObject;
	DestroyMagicX();
	return 0;
}
Пример #5
0
ExtendedFrame* ExtendedFrame::BuildFrameFromBuff(const UCHAR* buff, const UCHAR len, BOOL recved, BOOL check_address)
{
	ExtendedFrame* frame = NULL;
	int addr_checked_pos = 0;
	int apdu_len, frame_expected_len;
	BOOL check_group_address;

	if ( len <= 22 || NULL == buff )
		goto _out;

	if ( 0 != ( *buff & 0x80 ) ) // 扩展帧的bit7位是0
	{
		goto _out;
	}

	// 处理扩展字段的逻辑.暂时木有。
	if ( buff[1] )
	{
		// ...
	}

	check_group_address = FALSE; // 是否把地址当作组地址看待. 
	if ( recved )
	{
		addr_checked_pos = 4;
		if ( buff[1] & 0x80 )
		{
			check_group_address = TRUE;
		}
	}
	else
	{
		addr_checked_pos = 2;
	}

	if ( check_address )
	{
		BOOL matched = FALSE;
		if ( !check_group_address )
		{
			const UCHAR* host_addr_bin = NULL;

			for ( IDevice* dev = ms_dev_manager->NextDevice(true);
				NULL != dev;
				dev = ms_dev_manager->NextDevice(false))
			{
				host_addr_bin = dev->GetHostAddr(NULL);
				if ( host_addr_bin && 0 == memcmp(host_addr_bin, buff + addr_checked_pos, 2) )
				{
					matched = TRUE;
					break;
				}
			}

			if ( !matched && 0 == memcmp(g_myconfig.GetBroadcastAddr(), buff + addr_checked_pos, 2) )
			{
				matched = TRUE;
			}
		}

		if ( check_group_address )
		{
			matched = ms_dev_manager->ExistThisGroupAddr(buff+addr_checked_pos);
		}

		if ( !matched )
		{
			goto _out;
		}
	}

	apdu_len = buff[6];
    frame_expected_len = 6 + 1 + apdu_len + 1;
	if ( frame_expected_len != len || buff[len-1] != xor_check_sum(buff, len-1) )
	{
		goto _out;
	}

	frame = new ExtendedFrame;
	frame->m_frame_len = len;
	frame->m_frame_mem = new UCHAR[len];
	memcpy(frame->m_frame_mem, buff, len);

_out:
	return frame;
}
Пример #6
0
StandardFrame* StandardFrame::BuildFrameFromBuff(const UCHAR* buff, UCHAR len, BOOL recved, BOOL check_address)
{
	StandardFrame* frame = NULL;
	int addr_checked_pos = 0;
	int apdu_len, frame_expected_len;
	BOOL check_group_address;
	
	if ( len > 22 || len <= 7 || NULL == buff )
		goto _out;

	if ( 0 == (*buff & 0x80) ) // 标准帧的bit7位是1
	{
		goto _out;
	}

	check_group_address = FALSE; // 是否把地址当作组地址看待. 
	if ( recved )
	{
		addr_checked_pos = 3;
		if ( buff[5] & 0x80 )
		{
			check_group_address = TRUE;
		}
	}
	else
	{
		addr_checked_pos = 1;
	}

	if ( check_address )  // 是否检查地址信息. 
	{
		BOOL matched = FALSE;	
		if ( !check_group_address )  // 检查单个地址. 
		{
			const UCHAR* host_addr_bin = NULL;
			for ( IDevice* dev = ms_dev_manager->NextDevice(true);
				NULL != dev;
				dev = ms_dev_manager->NextDevice(false))
			{
				host_addr_bin = dev->GetHostAddr(NULL); // 没有设置地址的设备有可能访问NULL.
				if ( host_addr_bin && 0 == memcmp(host_addr_bin, buff + addr_checked_pos, 2) )
				{
					matched = TRUE;
					break;
				}
			}

			// 和广播地址比较. 
			if ( !matched && 0 == memcmp(g_myconfig.GetBroadcastAddr(), buff + addr_checked_pos, 2) )
			{
				matched = TRUE;
			}
		}

		if ( check_group_address )
		{
			matched = ms_dev_manager->ExistThisGroupAddr(buff + addr_checked_pos);
		}

		if ( !matched )
		{
			goto _out;
		}
	}

	apdu_len = ( buff[5] & 0x0f );
	frame_expected_len = 5 + 1 + apdu_len + 1;  // 长度必须精确一致. 
	if ( frame_expected_len != len || buff[len-1] != xor_check_sum(buff, len-1) )
	{
		goto _out;
	}

	frame = new StandardFrame;
	frame->m_frame_len = len;
	frame->m_frame_mem = new UCHAR[len];
	memcpy(frame->m_frame_mem, buff, len);

_out:
	return frame;
}
//----------------------------------------------------------------------------------------
//Constructors
//----------------------------------------------------------------------------------------
RegistersViewPresenter::RegistersViewPresenter(const std::wstring& aviewGroupName, const std::wstring& aviewName, int aviewID, YM2612Menus& aowner, const IDevice& amodelInstanceKey, IYM2612& amodel)
:ViewPresenterBase(aowner.GetAssemblyHandle(), aviewGroupName, aviewName, aviewID, amodelInstanceKey.GetDeviceInstanceName(), amodelInstanceKey.GetDeviceModuleID(), amodelInstanceKey.GetModuleDisplayName()), owner(aowner), modelInstanceKey(amodelInstanceKey), model(amodel)
{}
Пример #8
0
int main()
{
	//int avg = 2 * 90 + 3 * 88 + 4 * 87 + 3 * 84 + 4 * 92 + 2 * 93 + 2 * 83 + 2 * 80 + 2 * 95;
	//std::cout << "Avg : " << avg << std::endl;

	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");
	resourceGroupManager->loadResourceGroup("General");

	ISimpleMesh* cubeMesh = meshManager->createCubeMesh("cube1");
	IMeshNode* cubeMeshNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, XMFLOAT3(0, 3.0f, 0));
	cubeMeshNode->setMaterialName("test/material01");
	//cubeMeshNode->remove();

	ISimpleMesh* planeMesh = meshManager->createPlaneMesh("plane1", 10.0, 10.0f, 50, 50, 10.0f, 10.0f);
	IMeshNode* planeMeshNode = smgr->addMeshNode(planeMesh, nullptr);
	planeMeshNode->setMaterialName("test/ground_material");

	IAnimatedMesh* animMesh = meshManager->getAnimatedMesh("lxq.mesh");
	IAnimatedMeshNode* animNode = smgr->addAnimatedMeshNode(animMesh);
	animNode->scale(0.02f, 0.02f, 0.02f);
	IModelMesh* heroMesh = meshManager->getModelMesh("hero.mesh");
	IMeshNode* heroNode = smgr->addModelMeshNode(heroMesh);	
	
	heroNode->scale(0.01f, 0.01f, 0.01f);
	heroNode->translate(2.0f, 0.5f, 0);

	// create sampler state
	SSamplerDesc samplerDesc;
	samplerDesc.Filter = ESF_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = EAM_WRAP;
	samplerDesc.AddressV = EAM_WRAP;
	samplerDesc.AddressW = EAM_WRAP;
	ISampler* sampler = driver->getSamplerManager()->create(std::string("sampler1"), samplerDesc);

	IPipeline* pipeline = driver->getPipelineManager()->get("test/pipeline01");
	//pipeline->setSampler(std::string("sampleType"), sampler);

	ILightNode* light = smgr->addLightNode(1);
	light->setType(ELT_POINT);
	light->setAmbient(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));
	light->setPosition(2.0f, 5.0f, -3.0f);
	light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));
	light->setAttenuation(1.0f, 0.0f, 0.0f);
	light->setRange(100.0f);

	materialManager->destroy(std::string("test/material02"));

	//ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f));
	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f));

	f32 rotx = 0;
	f32 roty = 0;
	f32 rotz = 0;

	char caption[200];

	//FILE* fp = fopen("log.txt", "w");

	ITimer* timer = device->createTimer();
	timer->reset();

	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		float dt = timer->tick();
		
		rotx += dt * 2.0f;
		roty += dt * 1.0f;
		rotz += dt * 0.5f;
		if (rotx > XM_2PI) rotx -= XM_2PI;
		if (roty > XM_2PI) roty -= XM_2PI;
		if (rotz > XM_2PI) rotz -= XM_2PI;

		XMMATRIX Mx = XMMatrixRotationX(rotx);
		XMMATRIX My = XMMatrixRotationY(roty);
		XMMATRIX Mz = XMMatrixRotationZ(rotz);
		XMMATRIX rotM = Mx * My * Mz;

		cubeMeshNode->setOrientation(rotM);
	//	heroNode->yaw(dt);
		animNode->addTime(dt * 3000.0f);

		updateCamera(camera, dt);
	//	std::cout << dt << std::endl;

		smgr->drawAll();

		driver->endScene();

		sprintf(caption, "FPS:%f", getFps(dt));
		device->setWindowCaption(caption);
	}

	device->drop();

	return 0;
}
Пример #9
0
int _tmain(int argc, _TCHAR* argv[])
{
	srand(time(0));

	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IDevice* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();

	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 10.0f, 0);
	aabb.Extents = XMFLOAT3(500.0f, 500.0f, 500.0f);
	ISceneManager* smgr = device->createSceneManager(aabb);
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();
	IPipelineManager* pipelineManager = driver->getPipelineManager();
	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");

	PhysicsEngine::getInstance();

	setupPhysics(smgr);

	// create ground
	
	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", groundSize, groundSize, 10, 10, 30.0f, 30.0f);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, nullptr, nullptr, false);
	groundNode->setMaterialName("ground_material");

	createBoxes(smgr);

	// add directional light
	XMFLOAT3 light_dir(5.0f, -5.0f, -2.0f);
	f32 lightDistance = -20;
	ILightNode* light = smgr->addDirectionalLight(1, nullptr, light_dir);
	light->setSpecular(XMFLOAT4(1.0f, 1.0, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));
	//light->setShadowCameraOrthographicSize(10.0f, 7.0f);

	XMFLOAT4 unit_dir = light->getDirection();
	light->setPosition(XMFLOAT3(unit_dir.x * lightDistance, unit_dir.y * lightDistance, unit_dir.z * lightDistance));
	light->setShadowMapSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	light->setShadowCameraOrthographicSize(100.0f, 100.0f);
	light->enableShadow(true);
	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	camera->setPosition(XMFLOAT3(0, 20.0f, -40.0f));
	camera->lookAt(XMFLOAT3(0, 0, 0));
	camera->setNearZ(1.0f);
	camera->setFarZ(1000.0f);
	camera->setShadowRange(200.0f);
	smgr->setAmbient(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));

	updateLightDirection(10.0f, light);

	char caption[200];

	ITimer* timer = device->getTimer();
	timer->reset();

	const f32 color2[] = { 1.0f, 0.0f, 0.0f, 1.0f };

	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		u32 ms = timer->tick();
		float dt = ms * 0.001f;

		updatePhysics(dt);
		updateCamera(camera, dt);
		//updateLightDirection(dt, light);

		smgr->update(ms);

		smgr->drawAll();

		driver->endScene();

		sprintf_s(caption, "FPS:%f", getFps(dt));
		device->setWindowCaption(caption);

		//Sleep(10);
	}

	//sphereMaterial.drop();
	smgr->destroy();
	device->drop();

	delete g_ground;
	delete g_box;
	PhysicsEngine::deleteInstance();

	return 0;
}
 void Init (IDevice& device)
 {
   state    = device.GetImmediateContext ()->RSGetState ();
   viewport = device.GetImmediateContext ()->RSGetViewport (0);
   scissor  = device.GetImmediateContext ()->RSGetScissor (0);
 }
Пример #11
0
int _tmain(int argc, _TCHAR* argv[])
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IDevice* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();

	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = device->createSceneManager(aabb);
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");

	ILightNode* light = smgr->addDirectionalLight(1, nullptr, XMFLOAT3(3.0f, -2.0f, 1.5f));
	light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.4f, 0.4f, 0.4f, 1.0f));
	light->enableShadow(true);

	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 30.0f, -4.0f), 
		XMFLOAT3(0, 30.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	camera->setShadowRange(200.0f);

	buildGrassLand(smgr);

	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", GROUND_SIZE, GROUND_SIZE, 50, 50, 10.0f, 10.0f);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, nullptr, nullptr, false);
	groundNode->setMaterialName("ground_material");

	ITextureCube* skyTexture = textureManager->loadCubeTexture("skybox1.dds");
	smgr->setSkyDome(skyTexture);

	ITimer* timer = device->getTimer();
	timer->reset();
	char caption[200];
	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		f32 dt = timer->tick();
		updateCamera(camera, dt);
		g_grassLand->update(dt);

		smgr->update(dt);
		smgr->drawAll();

		driver->endScene();

		u32 num = smgr->getRenderedMeshNum();

		sprintf(caption, "FPS:%f num:%d", getFps(dt), num);
		device->setWindowCaption(caption);
	}

	smgr->destroy();
	device->drop();

	return 0;
}
Пример #12
0
int main(int argc, char *argv[]) {
	
	cout << "iRecovery++  Copyright (C) 2010  GreySyntax\r\n";
	cout << "This program comes with ABSOLUTELY NO WARRANTY; for details `./iRecovery -w'.\r\n";
	cout << "This is free software, and you are welcome to redistribute it\r\n";
	cout << "under certain conditions; type `./iRecovery -o' for details.\r\n" << endl;
	
	if (! (argc > 1)) {
		
		flags();
		return -1;
	}
	
	int c;
	
	while ((c = getopt(argc, argv, "acerosuwvh:")) != -1) {
		
		switch (c) {
			
			case 'a':
				if (! Device.IsConnected() && ! Device.Connect()) {
					
					return -1;
				}
				
				if (! Device.AutoBoot()) {
					
					return 1;
				}
				
				break;
				
			case 'c':
				if (! Device.IsConnected() && ! Device.Connect()) {
				
					return -1;
				}
				
				if (Device.SendCommand(optarg)) {
					
					continue;
				}

				break;
				
			case 'e':
				
				cout << "Not implemented. :(" << endl;
				break;
				
			case 'r':
				if (! Device.IsConnected() && ! Device.Connect()) {
				
					return -1;
				}
				
				Device.Reset();
				break;
				
			case 'o':
				conditions();
				break;
				
			case 's':
				if (! Device.IsConnected() && ! Device.Connect()) {
				
					return -1;
				}
				
				Device.Shell();
				break;
				
			case 'u':
				if (! Device.IsConnected() && ! Device.Connect()) {
			
					return -1;
				}
			
				if (! Device.Upload(optarg)) {
				
					continue;
				}
				break;
			
			case 'w':
				warranty();
				break;
			
			case 'v':
				cout << "iRecovery++ " << VERSION << "," << endl;
				cout << "Thanks to: lilstevie, pod2g, tom3q, planetbeing, geohot, posixninja and westbaer." << endl << endl;
				break;
				
			case '?':
			case 'h':
				flags();
				break;
		}
	}
	
	return 1;
}
Пример #13
0
void shutdown() {
	
	Device.Disconnect();
	exit(1);
}
Пример #14
0
int main()
{
	IDevice* device = gf::createDevice(EDT_DIRECT3D11, 800, 600);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");
	
	ITimer* timer = device->getTimer();
	timer->reset();

	ITextureManager* textureManager = ITextureManager::getInstance();
	IShaderManager* shaderMgr = driver->getShaderManager();
	IShader* shader = shaderMgr->load(EST_COMPUTE_SHADER, "matmul.hlsl", "cs_main");

	const u32 dimension = 512;
	const u32 sq_dimension = dimension * dimension;
	std::vector<f32> A(sq_dimension);
	std::vector<f32> B(sq_dimension);
	std::vector<f32> C(sq_dimension);
	std::vector<f32> D(sq_dimension);

	// init data
	for (u32 i = 0; i < sq_dimension; i++)
	{
		A[i] = math::RandomFloat(0, 10.0f);
		B[i] = math::RandomFloat(0, 10.0f);
	}

	f32 start_time, end_time;

	start_time = timer->getTime();
	// store the right answers to D
	for (u32 i = 0; i < dimension; i++)
	{
		for (u32 j = 0; j < dimension; j++)
		{
			f32 sum = 0;
			for (u32 k = 0; k < dimension; k++)
			{
				sum += A[i * dimension + k] * B[k * dimension + j];
			}
			D[i * dimension + j] = sum;
		}
	}
	end_time = timer->getTime();
	printf("The computation time by CPU: %fs\n", end_time - start_time);


	start_time = timer->getTime();
	ITexture* inputTexture1 = textureManager->createTexture2D("input1", dimension, dimension,
		ETBT_SHADER_RESOURCE, &A[0], 1, EGF_R32_FLOAT, 0);

	ITexture* inputTexture2 = textureManager->createTexture2D("input2", dimension, dimension,
		ETBT_SHADER_RESOURCE, &B[0], 1, EGF_R32_FLOAT, 0);

	ITexture* outputTexture = textureManager->createTexture2D("output", dimension, dimension,
		ETBT_UNORDERED_ACCESS, nullptr, 1, EGF_R32_FLOAT, 0);

	ITexture* copyTexture = textureManager->createTexture2D("copy", dimension, dimension,
		ETBT_CPU_ACCESS_READ, nullptr, 1, EGF_R32_FLOAT, 0);

	shader->setTexture("gInputA", inputTexture1);
	shader->setTexture("gInputB", inputTexture2);
	shader->setTexture("gOutput", outputTexture);

	u32 blockNum = dimension / 8;
	if (blockNum * 8 != dimension)
		blockNum++;

	driver->runComputeShader(shader, blockNum, blockNum, 1);

	//driver->resetRWTextures();
	//driver->resetTextures();

	outputTexture->copyDataToAnotherTexture(copyTexture);
	STextureData outputData;
	copyTexture->lock(ETLT_READ, &outputData);
	u8* data = (u8*)outputData.Data;
	for (u32 i = 0; i < dimension; i++)
	{
		// copy each row.
		memcpy(&C[i * dimension], data + outputData.RowPitch * i, dimension * sizeof(f32));
	}

	copyTexture->unlock();
	end_time = timer->getTime();
	printf("The computation time by GPU: %fs\n", end_time - start_time);

	for (u32 i = 0; i < sq_dimension; i++)
	{
		assert(math::FloatEqual(C[i], D[i]));
	}

	// destory textures.
	if (!textureManager->destroy(inputTexture1))
		printf("Destory texture failed!");

	if (!textureManager->destroy(inputTexture2))
		printf("Destory texture failed!");

	if (!textureManager->destroy(outputTexture))
		printf("Destory texture failed!");

	if (!textureManager->destroy(copyTexture))
		printf("Destory texture failed!");

	//sphereMaterial.drop();
	smgr->destroy();
	device->drop();

	system("pause");

	return 0;
}
Пример #15
0
int main()
{

	int d = 1;
	GF_PRINT_CONSOLE_INFO("Hello:%d\n", d);

	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();
	IShaderManager* shaderManager = driver->getShaderManager();
	IInputLayoutManager* inputlayoutManager = driver->getInputLayoutManager();
	IPipelineManager* pipelineMgr = driver->getPipelineManager();

	IShader* vs = shaderManager->load(EST_VERTEX_SHADER, "color.hlsl", "ColorVertexShader");
	IShader* ps = shaderManager->load(EST_PIXEL_SHADER, "PixelShader.hlsl", "ColorPixelShader");

	std::vector<SInputLayoutElement> elements;
	elements.resize(2);
	elements[0].SemanticName = "POSITION";
	elements[0].SemanticIndex = 0;
	elements[0].Format = EGF_R32G32B32_FLOAT;
	elements[0].Offset = 0;
	elements[1].SemanticName = "COLOR";
	elements[1].SemanticIndex = 0;
	elements[1].Format = EGF_R32G32B32A32_FLOAT;
	elements[1].Offset = 12;

	IInputLayout* layout = inputlayoutManager->create(elements, vs);


	IShader* shaders[2] = { vs, ps };
	IPipeline* pipeline = pipelineMgr->create("color", shaders, 2, layout, EPT_TRIANGLELIST);

	ISceneManager* smgr = device->getSceneManager();
	
	Vertex vertices[3];
	vertices[0] = Vertex(XMFLOAT3(-1.0f, -0.6f, 0.0f), XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f));
	vertices[1] = Vertex(XMFLOAT3(0.0f,   0.6f, 0.0f), XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f));
	vertices[2] = Vertex(XMFLOAT3(1.0f,  -0.6f, 0.0f), XMFLOAT4(1.0f, 0.0f, 1.0f, 1.0f));
	//IMesh* mesh = smgr->createSimpleMesh(&vertices, 3, sizeof(Vertex), nullptr, 0, 0);
	IMesh* mesh = smgr->createCubeMesh();
	IMeshNode* meshNode = smgr->addMeshNode(mesh, pipeline);

	//CD3D11ShaderManager* s = new CD3D11ShaderManager(nullptr);

	XMVECTOR eye = XMVectorSet(0.0f, 0.0f, -5.0f, 1.0f);
	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	XMVECTOR at = XMVectorZero();

	XMMATRIX view = XMMatrixLookAtLH(eye, at, up);

	XMMATRIX proj = XMMatrixPerspectiveFovLH(0.25f * 3.14f,
		static_cast<float>(SCREEN_WIDTH) / static_cast<float>(SCREEN_HEIGHT),
		1.0f, 1000.0f);


	meshNode->translate(0, 0, 5.0f);
	XMMATRIX world = meshNode->getAbsoluteTransformation();
	//XMMATRIX world = XMMatrixIdentity();

	
	pipeline->setMatrix("viewMatrix", reinterpret_cast<f32*>(&view));
	pipeline->setMatrix("projectionMatrix", reinterpret_cast<f32*>(&proj));

	SShaderAutoVariable var;
	var.Type = ESAVT_WORLD_MATRIX;
	var.ShaderType = EST_VERTEX_SHADER;
	var.VariableName = "worldMatrix";

	pipeline->addShaderAutoVariable(var);

	std::cout << "Hello World" << std::endl;

	ITimer* timer = device->createTimer();
	timer->reset();
	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		f32 dt = timer->tick();
		//std::cout << dt << std::endl;

		meshNode->setPosition(0, 0, -2.0f);
		meshNode->yaw(1.0f * dt);

		smgr->drawAll();

		//XMMATRIX world = meshNode->getAbsoluteTransformation();
		//pipeline->setMatrix("worldMatrix", reinterpret_cast<f32*>(&world));

		driver->endScene();
	}

	return 0;
}