コード例 #1
0
ファイル: main.cpp プロジェクト: woyaofacai/GameFinal
void setupPhysics(ISceneManager* smgr)
{
	IMeshManager* meshManager = IMeshManager::getInstance();
	PhysicsEngine* engine = PhysicsEngine::getInstance();

	hkpRigidBodyCinfo groundInfo;
	hkVector4 groundSize(groundSize * 0.5f, 0.5, groundSize * 0.5f);
	hkpBoxShape* groundShape = new hkpBoxShape(groundSize, 0);
	groundInfo.m_shape = groundShape;
	groundInfo.m_motionType = hkpMotion::MOTION_FIXED;
	groundInfo.m_position.set(0.0f, -0.5, 0.0f);
	groundInfo.m_restitution = 0.9f;
	groundInfo.m_friction = 0.5f;

	hkpRigidBody* floorRigidBody = new hkpRigidBody(groundInfo);
	groundShape->removeReference();
	engine->addRigidBody(floorRigidBody);
	floorRigidBody->removeReference();

	// create BOX
	f32 boxHalfSize = 2.0f;
	ISimpleMesh* boxMesh = meshManager->createCubeMesh("box", boxHalfSize*2.0f,
		boxHalfSize * 2.0f, boxHalfSize*2.0f);
	IMeshNode* boxNode = smgr->addMeshNode(boxMesh, nullptr, nullptr, false);
	boxNode->setMaterialName("box_material");
	boxNode->addShadow(1);

	g_box = new PhysicsCube(boxNode, XMFLOAT3(boxHalfSize, boxHalfSize, boxHalfSize), XMFLOAT3(0, 40.0f, 0),
		false, 0.5f, 0.5f);
}
コード例 #2
0
ファイル: CEditorScene.cpp プロジェクト: woyaofacai/GameFinal
void CEditorScene::setupInitialScene()
{
	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = mDevice->createSceneManager(aabb);
	mSceneManager = smgr;

	ISimpleMesh* planeMesh = mMeshManager->createPlaneMesh("ground_plane", 40, 40, 40, 40);
	IMeshNode* planeNode = smgr->addMeshNode(planeMesh, nullptr, nullptr, true);
	
	planeNode->setMaterialName("ground_wire_material");
	
	mCamera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 10.0f, -15.0f),
		XMFLOAT3(0, 5, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	//mCamera->setShadowRange(300.0f);

	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.8f, 0.8f, 0.8f, 1.0f));
	light->enableShadow(true);
	smgr->setAmbient(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));

	mCubeMesh = mMeshManager->createCubeMesh("cube_bounding");
	mSphereMesh = mMeshManager->createSphereMesh("sphere_bounding");
	mCylinderMesh = mMeshManager->createCylinderMesh("cylinder_bounding");

	mTimer = mDevice->getTimer();
	smgr->update(0);

	// init all mesh names
	std::vector<std::string> names;
	mResourceGroupManager->listResourceNames(ERFT_MESH, names);
	std::set<std::string> nameSet;
	for (u32 i = 0; i < names.size(); i++)
	{
		nameSet.insert(names[i]);
	}

	for (auto it = nameSet.begin(); it != nameSet.end(); it++)
	{
		std::string s = *it;
		mMeshNames.push_back(s);
	}

	for (u32 i = 0; i < mMeshNames.size(); i++)
	{
		mMeshNodeInfos.insert(std::make_pair(mMeshNames[i], SMeshNodeInfo()));
	}

	CXmlFileManager::Read("main.physics.xml");
	for (auto it = mMeshNodeInfos.begin(); it != mMeshNodeInfos.end(); it++)
	{
		it->second.SetVisible(false);
	}
}
コード例 #3
0
ファイル: EditorScene.cpp プロジェクト: Wu1994/GameFinal
bool EditorScene::PrepareAddingObject(const std::string& meshName)
{
	IModelMesh* mesh = mMeshManager->getModelMesh(meshName, true);
	IMeshNode* node = mSceneManager->addModelMeshNode(mesh, nullptr, false);
	node->addShadow(1);
	node->setTag(MESH_NODE_TAG);
	mAddedNode = node;
	return true;
}
コード例 #4
0
ファイル: CEditorScene.cpp プロジェクト: woyaofacai/GameFinal
void CEditorScene::UpdateWireFrameNode(SBoundingShape* shape)
{
	E_BOUNDING_CATEGORY category = shape->getCategory();
	IMeshNode* node = shape->WireFrameNode;
	XMFLOAT4X4 mat = shape->getTransform();
	XMMATRIX M = XMLoadFloat4x4(&mat);

	node->setTransform(M);
	node->update();
}
コード例 #5
0
ファイル: main.cpp プロジェクト: woyaofacai/GameFinal
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;
}
コード例 #6
0
ファイル: RaceScene.cpp プロジェクト: Wu1994/GameFinal
void RaceScene::Enter()
{
	mFollowCamera = mSceneManager->addFpsCameraNode(2, nullptr, XMFLOAT3(0, 100.0f, -100.0f), XMFLOAT3(0, 1.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	mFollowCamera->setNearZ(1.0f);
	mFollowCamera->setFarZ(1000.0f);
	mFollowCamera->setShadowRange(300.0f);

	mSideCamera = mSceneManager->addFpsCameraNode(3, nullptr);
	mSideCamera->setNearZ(1.0f);
	mSideCamera->setFarZ(1000.0f);
	mSideCamera->setShadowRange(300.0f);

	mPlayerVehicle = new Vehicle(mSceneManager, mTerrainNode, "carA");

	mSceneManager->setActiveCamera(2);
	
	XMFLOAT3 camPos = mFreeCamera->getPosition();
	mPlayerVehicle->setPosition(camPos);

	mFreeCamera->update(0);
	XMFLOAT3 look = mFreeCamera->getLookVector();
	XMVECTOR look_v = XMVector3Normalize(XMVectorSet(look.x, 0, look.z, 0));
	XMVECTOR neg_x_v = XMVectorSet(-1.0f, 0, 0, 0);
	XMVECTOR axis = XMVector3Normalize(XMVector3Cross(neg_x_v, look_v));
	
	XMVECTOR angle = XMVector3AngleBetweenNormals(neg_x_v, look_v);
	XMVECTOR quat_v = XMQuaternionRotationAxis(axis, XMVectorGetX(angle));
	XMFLOAT4 quat;
	XMStoreFloat4(&quat, quat_v);
	mPlayerVehicle->setRotation(quat);

	mVideoDriver->setDeferredAntiAliasing(true);

	IMeshNode* skyNode = mSceneManager->getSkyNode();
	if (skyNode)
		skyNode->setMaterialName("skydome_material");

	u32 textureWidth = mVideoDriver->getBackBufferWidth() / 2;
	u32 textureHeight = mVideoDriver->getBackBufferHeight() / 2;

	ITextureManager* textureManager = ITextureManager::getInstance();
	mTireTrailTexture = textureManager->createTexture2D("tire_trail", 
		textureWidth,
		textureHeight, 
		ETBT_SHADER_RESOURCE | ETBT_RENDER_TARGET,
		nullptr, 1, EGF_R16_FLOAT);

	mTireTrailDepthSurface = textureManager->createDepthStencilSurface("tire_trail_depth",
		textureWidth,
		textureHeight,
		16, 0, false, 1, 0, false, false);
}
コード例 #7
0
ファイル: CEditorScene.cpp プロジェクト: woyaofacai/GameFinal
SBoundingShape* CEditorScene::SelectBoundingShape(u32 index)
{
	SBoundingShape* shape = GetBoundingShapeByIndex(index);
	if (mCurrentBoundingShape)
	{
		IMeshNode* node = mCurrentBoundingShape->WireFrameNode;
		node->setMaterialName("bounding_wire_material");
	}

	mCurrentBoundingShape = shape;
	mCurrentBoundingShape->WireFrameNode->setMaterialName("selected_bounding_wire_material");
	return mCurrentBoundingShape;
}
コード例 #8
0
ファイル: CBlurCompositor.cpp プロジェクト: Wu1994/GameFinal
	void CBlurCompositor::gaussBlur(ISceneManager* smgr, bool lastCompositor)
	{
		IVideoDriver* driver = smgr->getVideoDriver();
		ITextureManager* tmgr = ITextureManager::getInstance();

		IRenderTarget* input = driver->getRenderTarget();
		IRenderTarget* output = tmgr->getTempRenderTarget(input->getWidth(), input->getHeight(), input->getFormat());

		IMeshNode* quad = smgr->getQuadNode();
		quad->setMaterial(&mMaterial);

		IPipelineManager* pipelineManager = IPipelineManager::getInstance();
		IPipeline* vblurPipeline = pipelineManager->get("gf/gauss_vertical_blur");
		IPipeline* hblurPipeline = pipelineManager->get("gf/gauss_horizontal_blur");

		// render pass - 1
		for (u32 i = 0; i < mPassCount - 1; i++)
		{
			// vertical blur
			mMaterial.setPipeline(vblurPipeline);
			renderQuad(driver, smgr, quad, input, output);

			// horizontal blur
			mMaterial.setPipeline(hblurPipeline);
			renderQuad(driver, smgr, quad, output, input);
		}

		// render last pass
		mMaterial.setPipeline(vblurPipeline);
		renderQuad(driver, smgr, quad, input, output);

		mMaterial.setPipeline(hblurPipeline);
		if (lastCompositor)
		{
			renderQuad(driver, smgr, quad, output, nullptr);
			tmgr->releaseTempRenderTarget(output);
		}
		else
		{
			renderQuad(driver, smgr, quad, output, input);
		}

		tmgr->releaseTempRenderTarget(input);
	}
コード例 #9
0
ファイル: CBlurCompositor.cpp プロジェクト: Wu1994/GameFinal
	void CBlurCompositor::squareBlur(ISceneManager* smgr, bool lastCompositor)
	{
		IVideoDriver* driver = smgr->getVideoDriver();
		ITextureManager* tmgr = ITextureManager::getInstance();

		IRenderTarget* input = driver->getRenderTarget();
		IRenderTarget* output = nullptr;

		IMeshNode* quad = smgr->getQuadNode();
		quad->setMaterial(&mMaterial);

		if (mPassCount == 1)
		{
			if (!lastCompositor)
				output = tmgr->getTempRenderTarget(input->getWidth(), input->getHeight(), input->getFormat());

			renderQuad(driver, smgr, quad, input, output);
			tmgr->releaseTempRenderTarget(input);
		}
		else
		{
			output = tmgr->getTempRenderTarget(input->getWidth(), input->getHeight(), input->getFormat());

			// render pass - 1 
			for (u32 i = 0; i < mPassCount - 1; i++)
			{
				renderQuad(driver, smgr, quad, input, output);
				std::swap(input, output);
			}

			// render the last pass
			if (!lastCompositor)
			{
				renderQuad(driver, smgr, quad, input, output);
			}
			else
			{
				renderQuad(driver, smgr, quad, input, nullptr);
				tmgr->releaseTempRenderTarget(output);
			}

			tmgr->releaseTempRenderTarget(input);
		}
	}
コード例 #10
0
ファイル: EditorScene.cpp プロジェクト: Wu1994/GameFinal
void EditorScene::UpdateNodeInfo(SNodeInfo* info)
{
	XMMATRIX S = XMMatrixScaling(info->Scaling.x, info->Scaling.y, info->Scaling.z);
	XMMATRIX R = XMMatrixRotationRollPitchYaw(info->Rotation.x, info->Rotation.y, info->Rotation.z);
	XMMATRIX T = XMMatrixTranslation(info->Position.x, info->Position.y, info->Position.z);
	XMMATRIX M = S * R * T;
	info->Node->setTransform(M);
	info->Node->update();

	if (info->Node->getNodeType() & ESNT_MESH)
	{
		IMeshNode* meshNode = dynamic_cast<IMeshNode*>(info->Node);
		if (info->ShadowCasting)
			meshNode->addShadow(1);
		else
			meshNode->removeShadow(1);
	}

	updateSelectedNodeCube();
}
コード例 #11
0
ファイル: CEditorScene.cpp プロジェクト: woyaofacai/GameFinal
SBoxBounding* CEditorScene::AddBoxBounding()
{
	if (!mCurrentMeshNodeInfo)
		return nullptr;

	IMesh* mesh = mCurrentMeshNodeInfo->Node->getMesh();
	math::SAxisAlignedBox aabb = mesh->getAabb();
	SBoxBounding* box = new SBoxBounding;
	box->Center = aabb.Center;
	box->Size = XMFLOAT3(aabb.Extents.x * 2.0f, aabb.Extents.y * 2.0f, aabb.Extents.z * 2.0f);

	IMeshNode* node = mSceneManager->addMeshNode(mCubeMesh,
		nullptr, nullptr, false, aabb.Center, XMFLOAT3(0, 0, 0),
		box->Size);
	
	node->setMaterialName("bounding_wire_material");
	box->WireFrameNode = node;
	mCurrentMeshNodeInfo->BoundingShapes.push_back(box);
	
	return box;
}
コード例 #12
0
ファイル: LoadingScene.cpp プロジェクト: Wu1994/GameFinal
void LoadingScene::setupScene()
{
	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = mDevice->createSceneManager(aabb);
	mSceneManager = smgr;
	
	IMeshManager* meshManager = IMeshManager::getInstance();
	ISimpleMesh* cubeMesh = meshManager->createCubeMesh("debug_loading", 3.0f, 3.0f, 3.0f);
	IMeshNode* meshNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false);
	meshNode->setMaterialName("picking_cube_material");

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

	mVideoDriver->setDeferredShading(false);

	ITextureManager* textureManager = ITextureManager::getInstance();
	mLoadingImage = textureManager->get("loading_image.jpg");
}
コード例 #13
0
ファイル: CEditorScene.cpp プロジェクト: woyaofacai/GameFinal
SCylinderBounding* CEditorScene::AddCylinderBounding()
{
	if (!mCurrentMeshNodeInfo)
		return nullptr;

	IMesh* mesh = mCurrentMeshNodeInfo->Node->getMesh();
	math::SAxisAlignedBox aabb = mesh->getAabb();

	SCylinderBounding* cylinder = new SCylinderBounding;
	cylinder->Center = aabb.Center;
	cylinder->Height = aabb.Extents.y * 2.0f;
	cylinder->Radius = max(aabb.Extents.x, aabb.Extents.z);

	IMeshNode* node = mSceneManager->addMeshNode(mCylinderMesh,
		nullptr, nullptr, false, aabb.Center, XMFLOAT3(0, 0, 0),
		XMFLOAT3(cylinder->Radius, cylinder->Height, cylinder->Radius));

	node->setMaterialName("bounding_wire_material");
	cylinder->WireFrameNode = node;
	mCurrentMeshNodeInfo->BoundingShapes.push_back(cylinder);

	return cylinder;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: whztt07/GameFinal
ISceneManager* setupScene(IDevice* device) {

	// create scene manager
	ISceneManager* smgr = device->createSceneManager();

	// get mesh manager
	IMeshManager* meshManager = IMeshManager::getInstance();

	// set up ground.
	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", 100.0f, 100.0f, 10, 10, 50, 50);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, "ground_material", nullptr, true);

	// create a sphere
	ISimpleMesh* sphereMesh = meshManager->createSphereMesh("sphere", 1.0f, 100, 100);
	IMeshNode* sphereNode = smgr->addMeshNode(sphereMesh, "sphere_material", nullptr, true, XMFLOAT3(-1.2f, 1.0f, 0));

	// create a box
	ISimpleMesh* boxMesh = meshManager->createCubeMesh("box", 1.2f, 3.0f, 1.2f);
	IMeshNode* boxNode = smgr->addMeshNode(boxMesh, "box_material", nullptr, true, XMFLOAT3(1.0f, 1.5f, 1.0f));

	// create a teapot
	IModelMesh* teapotMesh = meshManager->getModelMesh("teapot.mesh");
	IMeshNode* teapot = smgr->addModelMeshNode(teapotMesh, nullptr, true, XMFLOAT3(1.2f, 0, -1.0f));
	teapot->setMaterialName("teapot_material");

	// add 100 point light
	for (u32 i = 0; i < 100; i++) {
		XMFLOAT3 pos(math::RandomFloat(-20.0, 20.0f), math::RandomFloat(3.0, 10.0f), math::RandomFloat(-20.0, 20.0f));
		XMFLOAT4 diffuse(math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), 1.0f);
		XMFLOAT4 specular(math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), 32.0f);

		ILightNode* light = smgr->addPointLight(i, nullptr, false, pos, 20.0f);
		light->setSpecular(specular);
		light->setDiffuse(diffuse);
		light->setAttenuation(1.0f, 0.05f, 0);
	}

	sphereNode->addShadow(1);
	boxNode->addShadow(1);
	teapot->addShadow(1);

	// create a fps camera node
	IFpsCameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -6.0f),
		XMFLOAT3(0, 1.0f, 0.0f), XMFLOAT3(0, 1.0f, 0));
	camera->setNearZ(1.0f);
	camera->setFarZ(1000.0f);

	// set ambient in the environment.
	smgr->setAmbient(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));

	return smgr;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: k024zz/GameFinal
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;
}
コード例 #16
0
ファイル: EditorScene.cpp プロジェクト: Wu1994/GameFinal
void EditorScene::setupInitialScene()
{
	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = mDevice->createSceneManager(aabb);
	mSceneManager = smgr;

	ITextureCube* skyTexture = mTextureManager->loadCubeTexture("skybox1.dds");
	smgr->setSkyDome(skyTexture);
	IMeshNode* skyNode = mSceneManager->getSkyNode();
	if (skyNode)
		skyNode->setMaterialName("skydome_material");

	mTimer = mDevice->getTimer();

	ISimpleMesh* cubeMesh = mMeshManager->createCubeMesh("cube1");

	mSelectedCubeNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false);
	mSelectedCubeNode->setMaterialName("selected_cube_material");
	mSelectedCubeNode->setVisible(false);
	mSelectedCubeNode->setTag(WIRE_NODE_TAG);

	mPickingCubeNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false);
	mPickingCubeNode->setMaterialName("picking_cube_material");
	mPickingCubeNode->setVisible(false);
	mPickingCubeNode->setTag(WIRE_NODE_TAG);

	ISimpleMesh* sphereMesh = mMeshManager->createSphereMesh("pointlight_mesh", 1.0f, 10, 10);
	
	mPointLightCollectionNode = smgr->addInstanceCollectionNode(sphereMesh, 
		nullptr, 4000, sizeof(XMFLOAT4));
	mPointLightCollectionNode->setMaterialName("multi_wire_material");
	mPointLightCollectionNode->setTag(WIRE_NODE_TAG);
	mPointLightCollectionNode->setVisible(false);

	mSceneManager->update(0);
	

	IVideoDriver* driver = IVideoDriver::getInstance();
	mVideoDriver->setDeferredShading(true);
	driver->setDeferredShadingAlgorithm(EDSA_CS_TILE_BASED_DEFERRED_SHADING);

	IShaderManager* shaderManager = IShaderManager::getInstance();
	mTileBasedDSShader = shaderManager->load(EST_COMPUTE_SHADER, "defer_shader_cs.hlsl", "cs_main");
	smgr->setTileBasedDeferredShadingCS(mTileBasedDSShader);

	if (!CFileParser::ReadScene("main.scene"))
	{
		setupTerrain();

		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.8f, 0.8f, 0.8f, 1.0f));
		light->enableShadow(true);
		mDirectionalLightNode = light;

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

		mCamera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 30.0f, -4.0f),
			XMFLOAT3(0, 30.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
		mCamera->setShadowRange(300.0f);

		mVideoDriver->setDeferredShading(true);
		mDeferredShading = true;
	}

	UpdateGlobalLighting();
	
	smgr->update();
}
コード例 #17
0
ファイル: main.cpp プロジェクト: Wu1994/GameFinal
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;
}
コード例 #18
0
ファイル: main.cpp プロジェクト: woyaofacai/GameFinal
int _tmain(int argc, _TCHAR* argv[])
{
	srand(time(0));
	SAppSettings settings;
	settings.Graphics.MultiSamplingCount = 8;
	settings.Graphics.MultiSamplingQuality = 32;
	settings.Window.Width = 400;
	settings.Window.Height = 300;

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

	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 10.0f, 0);
	aabb.Extents = XMFLOAT3(500.0f, 500.0f, 500.0f);
	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);
	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);

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

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

	device->setUpdateCallback(game_update);
	device->run();

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

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

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

		smgr->update(dt);

		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;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: woyaofacai/GameFinal
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;
}
コード例 #20
0
ファイル: main.cpp プロジェクト: woyaofacai/GameFinal
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;
}
コード例 #21
0
ファイル: main.cpp プロジェクト: k024zz/GameFinal
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;
}