Ejemplo n.º 1
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;
	IApplication* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	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", EVF_POSITION, 
		vertices, NULL, 4, sizeof(XMFLOAT3), 0, math::SAxisAlignedBox(), false);
	IMeshNode* meshNode = smgr->addMeshNode(mesh, nullptr, nullptr);
	meshNode->setMaterialName("test/ts_material");
	meshNode->setNeedCulling(false);

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

	ITimer* timer = device->getTimer();
	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() * 0.001f;
		updateCamera(camera, dt);

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

		driver->endScene();

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

	device->drop();

	return 0;
}
Ejemplo n.º 2
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IApplication* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();
	IPipelineManager* pipelineManager = driver->getPipelineManager();

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



	const f32 groundSize = 1000.0f;

	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", groundSize, groundSize, 100, 100, 100.0f, 100.0f);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, nullptr, nullptr, false);
	groundNode->setMaterialName("ground_material");
	
	// add point lights
	const u32 lightColNum = 10;
	const u32 lightRowNum = 10;
	f32 xLightSpace = groundSize / (lightColNum - 1);
	f32 zLightSpace = groundSize / (lightRowNum - 1);

	for (u32 i = 0; i < lightRowNum; i++)
	{
		for (u32 j = 0; j < lightColNum; j++)
		{
			u32 id = i * lightColNum + j;
			f32 x = -groundSize * 0.5f + xLightSpace * j;
			f32 z = groundSize * 0.5f - zLightSpace * i;
			ILightNode* light = smgr->addPointLight(id, nullptr, true, XMFLOAT3(x, 50.0f, z), 200.0f);
			light->setSpecular(XMFLOAT4(12.0f, 12.0f, 12.0f, 32.0f));
			light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));
			light->setAttenuation(1.0f, 0.1f, 0);
		}
	}

	
	/*
	IModelMesh* carMesh = meshManager->getModelMesh("myfirst.mesh");
	IMeshNode* carNode = smgr->addModelMeshNode(carMesh, NULL, false);
	carNode->translate(0, 0.1f, 0);
	carNode->setNeedCulling(false);
	carNode->scale(0.05f, 0.05f, 0.05f);
	carNode->pitch(XM_PIDIV2);
	*/
	
	IModelMesh* carMesh = meshManager->getModelMesh("car B red.mesh");
	IMeshNode* carNode = smgr->addModelMeshNode(carMesh, NULL, false);
	carNode->translate(0, 1.0f, 0);
	//carNode->setNeedCulling(false);
	//carNode->scale(0.05f, 0.05f, 0.05f);
	//carNode->pitch(XM_PIDIV2);

	IModelMesh* wheelleftFrontMesh = meshManager->getModelMesh("wheel front left.mesh");
	IMeshNode* wheelleftFront = smgr->addModelMeshNode(wheelleftFrontMesh, carNode, false);
	//carNode->setNeedCulling(false);
	
	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f));
	camera->setFarZ(3000.0f);

	smgr->setAmbient(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));

	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;

		updateCamera(camera, dt);
		//updateCarPosition(dt, carNode, camera);

		smgr->update(ms);

		smgr->drawAll();

		driver->endScene();

		f32 fps = getFps(dt);
		sprintf_s(caption, "FPS:%f, delta:%f", fps, 1000.0f/fps);
		device->setWindowCaption(caption);
	}

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

	return 0;
}
Ejemplo n.º 3
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IApplication* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();

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

	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));

	ILightNode* light2 = smgr->addDirectionalLight(2, nullptr, XMFLOAT3(-2.0f, -3.0f, -2.0f));
	light2->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light2->setDiffuse(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));

	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->setViewWidth(300);
	camera->setViewHeight(200);

	char caption[200];
	
	std::string rawFileName("heightmap.raw");
	ITerrainMesh* mesh = meshManager->createTerrainMesh("terrain", rawFileName,
		3.0f, 0.4f, false, true, 1.0f);

	ITerrainNode* terrainNode = smgr->addTerrainNode(mesh);
	//terrainNode->setMaterialName("terrain/tessellation_material");
	terrainNode->setMaterialName("terrain/terrain_material");

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

	
	IRenderTarget* pRenderTarget = textureManager->getRenderTarget("target1");

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

	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;
		updateCamera(camera, dt);

		XMFLOAT3 camPos = camera->getPosition();
		float terrainHeight = terrainNode->getHeight(camPos.x, camPos.z, true);
		camPos.y = terrainHeight + 3.0f;
		//camera->setPosition(camPos);

		smgr->update(ms);
		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;
}
Ejemplo n.º 4
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 1;
	settings.MultiSamplingQuality = 0;
	IApplication* device = createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();
	IPipelineManager* pipelineManager = driver->getPipelineManager();

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

	ISimpleMesh* mesh = createWaterMesh(meshManager, "waterwave", 1000.0f, 1000.0f, 30, 30);
	IMeshNode* meshNode = smgr->addMeshNode(mesh, nullptr, nullptr);
	meshNode->setMaterialName("test/wave_material");
	meshNode->setNeedCulling(false);

	IPipeline* pipeline = pipelineManager->get("test/wave_pipeline");

	ILightNode* light = smgr->addPointLight(1, nullptr, false, XMFLOAT3(10.0f, 50.0f, -10.0f), 1000.0f);
	light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
	light->setDiffuse(XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
	light->setAttenuation(1.0f, 0.0f, 0.0f);

	// gTangentWorldMatrix
	XMVECTOR normal = XMVectorSet(0, 1.0f, 0, 0);
	XMVECTOR tangent = XMVectorSet(1.0f, 0, 0, 0);
	XMVECTOR B = XMVector3Cross(normal, tangent);

	XMMATRIX TBN = XMMATRIX(tangent, B, normal, XMVectorSet(0, 0, 0, 1.0f));
	pipeline->setMatrix("gTangentWorldMatrix", TBN);

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

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

	static float t1 = 0.0f;
	static float t2 = 0.0f;
	
	E_FILL_MODE fillMode = E_FILL_SOLID;

	/*
	SCompositorCreateParam param;
	param.Bloom.BlurPassCount = 3;
	param.Bloom.BrightnessThreshold = 0.85f;
	param.Bloom.BlurTexelDistance = 1.0f;
	param.Bloom.BlurTextureWidth = 400;
	param.Bloom.BlurTextureHeight = 300;
	
	ICompositor* bloom = smgr->createCompositor(ECT_BLOOM, param);
	smgr->addCompositor(bloom);

	*/

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

		float dt = timer->tick() * 0.001f;
		t1 += dt * 0.032f;
		t2 += dt * 0.02f;
		if (t1 > 1.0f)
			t1 -= 1.0f;
		if (t2 > 1.0f)
			t2 -= 1.0f;

		XMMATRIX texTransform1 = XMMatrixTranslation(t1, 0, 0);
		XMMATRIX texTransform2 = XMMatrixTranslation(0, t2, 0);

		pipeline->setMatrix("gTexTransform1", texTransform1);
		pipeline->setMatrix("gTexTransform2", texTransform2);

		updateCamera(camera, dt);

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

		driver->endScene();

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

	device->drop();

	return 0;
}