コード例 #1
0
ファイル: GameModel.cpp プロジェクト: huynhrichy/Avalanche
void GameModel::orientRotateZ(float radianAngle){
        // orientationMatrix *= Matrix.CreateRotationY(ry);
		XMStoreFloat4x4(&orientRotateMatrix, XMLoadFloat4x4(&orientRotateMatrix) * XMMatrixRotationZ(radianAngle));

}
コード例 #2
0
ファイル: Tutorial05.cpp プロジェクト: jpechevarria/lab
//--------------------------------------------------------------------------------------
// Render a frame
//--------------------------------------------------------------------------------------
void Render()
{
	// Update our time
	static float t = 0.0f;
	if (!paused)
	{
		if (g_driverType == D3D_DRIVER_TYPE_REFERENCE)
		{
			t += (float)XM_PI * 0.0125f;
		}
		else
		{
			static DWORD dwTimeStart = 0;
			DWORD dwTimeCur = GetTickCount();
			if (dwTimeStart == 0)
				dwTimeStart = dwTimeCur;
			if (restarted)
			{
				restarted = false;
				t = dwLastT;
				dwTimeStart = dwTimeCur - t * 1000.0f;
			}
			else
			{
				t = (dwTimeCur - dwTimeStart) / 1000.0f;
			}
		}
		dwLastT = t;
	}

	// 1st Cube: Rotate around the origin
	// JPE : Se verifica si debe rotar
	if (rotate)
	{
		//JPE: Para mesh del mono
		if (modelo == ModeloMono)
		{
			g_World1 = XMMatrixRotationX(-1.570796f) * XMMatrixRotationY(t);
		}
		else // Para cubo
		{
			g_World1 = XMMatrixRotationY(t);
		}
	}
	else
	{
		//JPE: Para mesh del mono
		if (modelo == ModeloMono)
		{
			g_World1 = XMMatrixRotationX(-1.570796f);
			g_World1 *= XMMatrixRotationY(2 * -1.570796f);
		}
		else // Para cubo
		{
			g_World1 = XMMatrixIdentity();
		}
	}
	XMVECTOR Det;
	g_Normal1 = XMMatrixTranspose(XMMatrixInverse(&Det, g_World1));

	// 2nd Cube:  Rotate around origin
	XMMATRIX mSpin = XMMatrixRotationZ(-t);
	XMMATRIX mOrbit = XMMatrixRotationY(-t * 2.0f);
	XMMATRIX mTranslate = XMMatrixTranslation(-4.0f, 0.0f, 0.0f);
	XMMATRIX mScale = XMMatrixScaling(0.3f, 0.3f, 0.3f);

	g_World2 = mScale * mSpin * mTranslate * mOrbit;

	//
	// Clear the back buffer
	//
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red, green, blue, alpha
	g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, ClearColor);

	//
	// Clear the depth buffer to 1.0 (max depth)
	//
	g_pImmediateContext->ClearDepthStencilView(g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);


	// JPE:	
	// CARGA LOS CONSTANT BUFFERS
	if (!constBuffer)
	{
		g_pImmediateContext->PSSetConstantBuffers(1, 1, &g_pConstantBufferPS);
		g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pConstantBuffer);
		g_pImmediateContext->VSSetConstantBuffers(1, 1, &g_pConstantBufferPS);
		// Set shader texture resource in the pixel shader.
		g_pImmediateContext->PSSetShaderResources(0, 1, &m_texture);
		g_pImmediateContext->PSSetShaderResources(1, 1, &m_normalmap);
		g_pImmediateContext->PSSetShaderResources(2, 1, &m_specularmap);
		// Set the sampler state in the pixel shader.
		g_pImmediateContext->PSSetSamplers(0, 1, &m_sampleState);

		constBuffer = true;
	}

	//
	// Update variables for the first cube
	//
	ConstantBuffer cb1;
	cb1.mWorld = XMMatrixTranspose(g_World1);
	cb1.mView = XMMatrixTranspose(g_View);
	cb1.mProjection = XMMatrixTranspose(g_Projection);
	cb1.mNormal = XMMatrixTranspose(g_Normal1);
	//
	// Update variables for the second cube
	//
	ConstantBuffer cb2;
	cb2.mWorld = XMMatrixTranspose(g_World2);
	cb2.mView = XMMatrixTranspose(g_View);
	cb2.mProjection = XMMatrixTranspose(g_Projection);

	// JPE: variables for PS
	ConstantBufferPS psCb1;
	psCb1.time = t;
	psCb1.vecEye = XMFLOAT3(x, y, z);
	psCb1.bump = bump;
	psCb1.useTexture = useTexture;

	// FIRST PASS
	g_pImmediateContext->RSSetState(m_rasterState);
	g_pImmediateContext->VSSetShader(g_pVertexShader, NULL, 0);
	g_pImmediateContext->PSSetShader(g_pPixelShader, NULL, 0);

	// Render the first cube
	g_pImmediateContext->UpdateSubresource(g_pConstantBuffer, 0, NULL, &cb1, 0, 0);
	g_pImmediateContext->UpdateSubresource(g_pConstantBufferPS, 0, NULL, &psCb1, 0, 0);
	g_pImmediateContext->DrawIndexed( cantIndices, 0, 0 );
	// Render the second cube
	g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb2, 0, 0 );
	g_pImmediateContext->DrawIndexed(cantIndices, 0, 0);
	
    // SECOND PASS
	if (wireframe)
	{
		g_pImmediateContext->RSSetState(m_rasterStateWF);
		g_pImmediateContext->VSSetShader(g_pVertexShaderWF, NULL, 0);
		g_pImmediateContext->PSSetShader(g_pPixelShaderWF, NULL, 0);

		// Render the first cube
		g_pImmediateContext->UpdateSubresource(g_pConstantBuffer, 0, NULL, &cb1, 0, 0);
		g_pImmediateContext->UpdateSubresource(g_pConstantBufferPS, 0, NULL, &psCb1, 0, 0);
		g_pImmediateContext->DrawIndexed(cantIndices, 0, 0);
		// Render the second cube
		g_pImmediateContext->UpdateSubresource(g_pConstantBuffer, 0, NULL, &cb2, 0, 0);
		g_pImmediateContext->DrawIndexed(cantIndices, 0, 0);
	}

    //
    // Present our back buffer to our front buffer
    //
	// JPE: primer parametro = 1 para Vertical Sync, 0 para Inmediato
	UINT SyncInterval = vsync ? 1: 0;
    g_pSwapChain->Present(SyncInterval, 0 );

	frameCount++;
	
	if (frameCount % frameDelay == 0)
	{
		DWORD tAct = timeGetTime();

		DWORD elapsed = tAct - tAnt;
		long frames = frameCount - frameCountLast;
		float fps = frames / (elapsed / 1000.0f);


		frameDelay = fps / 5;

		if (frameDelay < 10) frameDelay = 10;

		wchar_t text[256];

		swprintf(text, 256, L"FPS = %.1f", fps);

		SetWindowTextW(g_hWnd, text);

		frameCountLast = frameCount;
		tAnt = tAct;
	}
}
コード例 #3
0
void Transform::Update(float t)
{
	// Calculate world matrix
	XMMATRIX scale = XMMatrixScaling(_scale.x, _scale.y, _scale.z);
	XMMATRIX rotation = XMMatrixRotationX(_rotation.x) * XMMatrixRotationY(_rotation.y) * XMMatrixRotationZ(_rotation.z);
	XMMATRIX translation = XMMatrixTranslation(_position.x, _position.y, _position.z);

	XMStoreFloat4x4(&_world, scale * rotation * translation);

	if (_parent != nullptr)
	{
		XMStoreFloat4x4(&_world, this->GetWorldMatrix() * _parent->GetWorldMatrix());
	}

	_lPosition = GetPosition();
}
コード例 #4
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;
}
//==============================================================================
void Mtx44::BuildRotateZ (float rot, Mtx44 * output) {
    ASSERT(output);
    XMMATRIX result = XMMatrixRotationZ(rot);
    memcpy(output->m, result.m, sizeof(output->m));
}
コード例 #6
0
ファイル: Game.cpp プロジェクト: StevTechy/ObjLoader
void Game::CreateSphere(int latLines, int longLines)
{
	NumSphereVertices = ((latLines - 2) * longLines) + 2;
	NumSphereFaces = ((latLines - 3)*(longLines)* 2) + (longLines * 2);

	float sphereYaw = 0.0f;
	float spherePitch = 0.0f;

	std::vector<Vertex> vertices(NumSphereVertices);

	XMVECTOR currVertPos = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

	vertices[0].pos.x = 0.0f;
	vertices[0].pos.y = 0.0f;
	vertices[0].pos.z = 1.0f;

	for (DWORD i = 0; i < latLines - 2; ++i)
	{
		spherePitch = (i + 1) * (3.14 / (latLines - 1));

		skyRotationX = XMMatrixRotationX(spherePitch);
		for (DWORD j = 0; j < longLines; ++j)
		{
			sphereYaw = j * (6.28 / (longLines));
			skyRotationY = XMMatrixRotationZ(sphereYaw);
			currVertPos = XMVector3TransformNormal(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), (skyRotationX * skyRotationY));
			currVertPos = XMVector3Normalize(currVertPos);
			vertices[i*longLines + j + 1].pos.x = XMVectorGetX(currVertPos);
			vertices[i*longLines + j + 1].pos.y = XMVectorGetY(currVertPos);
			vertices[i*longLines + j + 1].pos.z = XMVectorGetZ(currVertPos);
		}
	}

	vertices[NumSphereVertices - 1].pos.x = 0.0f;
	vertices[NumSphereVertices - 1].pos.y = 0.0f;
	vertices[NumSphereVertices - 1].pos.z = -1.0f;


	D3D11_BUFFER_DESC vertexBufferDesc;
	ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));

	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof(Vertex)* NumSphereVertices;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA vertexBufferData;

	ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
	vertexBufferData.pSysMem = &vertices[0];
	hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &sphereVertBuffer);


	std::vector<DWORD> indices(NumSphereFaces * 3);

	int k = 0;
	for (DWORD l = 0; l < longLines - 1; ++l)
	{
		indices[k] = 0;
		indices[k + 1] = l + 1;
		indices[k + 2] = l + 2;
		k += 3;
	}

	indices[k] = 0;
	indices[k + 1] = longLines;
	indices[k + 2] = 1;
	k += 3;

	for (DWORD i = 0; i < latLines - 3; ++i)
	{
		for (DWORD j = 0; j < longLines - 1; ++j)
		{
			indices[k] = i*longLines + j + 1;
			indices[k + 1] = i*longLines + j + 2;
			indices[k + 2] = (i + 1)*longLines + j + 1;

			indices[k + 3] = (i + 1)*longLines + j + 1;
			indices[k + 4] = i*longLines + j + 2;
			indices[k + 5] = (i + 1)*longLines + j + 2;

			k += 6; // next quad
		}

		indices[k] = (i*longLines) + longLines;
		indices[k + 1] = (i*longLines) + 1;
		indices[k + 2] = ((i + 1)*longLines) + longLines;

		indices[k + 3] = ((i + 1)*longLines) + longLines;
		indices[k + 4] = (i*longLines) + 1;
		indices[k + 5] = ((i + 1)*longLines) + 1;

		k += 6;
	}

	for (DWORD l = 0; l < longLines - 1; ++l)
	{
		indices[k] = NumSphereVertices - 1;
		indices[k + 1] = (NumSphereVertices - 1) - (l + 1);
		indices[k + 2] = (NumSphereVertices - 1) - (l + 2);
		k += 3;
	}

	indices[k] = NumSphereVertices - 1;
	indices[k + 1] = (NumSphereVertices - 1) - longLines;
	indices[k + 2] = NumSphereVertices - 2;

	D3D11_BUFFER_DESC indexBufferDesc;
	ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = sizeof(DWORD)* NumSphereFaces * 3;
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA iinitData;

	iinitData.pSysMem = &indices[0];
	device->CreateBuffer(&indexBufferDesc, &iinitData, &sphereIndexBuffer);
}
コード例 #7
0
ファイル: Aircraft.cpp プロジェクト: GRMaverick/DirectX_FGGC
void Aircraft::SetRotation(float x, float y, float z) {
    _rotation.x = x;
    _rotation.y = y;
    _rotation.z = z;

    XMStoreFloat4x4(&_rotate, XMMatrixRotationX(_rotation.x) * XMMatrixRotationY(_rotation.y) * XMMatrixRotationZ(_rotation.z));
}
コード例 #8
0
ファイル: main.cpp プロジェクト: rodonjohn/tutorial-oculus
void Render()
{
    // Update our time
    static float t = 0.0f;
    t += ( float )XM_PI * 0.0125f;

	//ビュー行列をOculus Riftの回転に合わせて回転する
	float yaw,pitch,roll;
	GetSensor(&yaw,&pitch ,&roll);
	XMVECTOR Eye = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );	//カメラの位置
	XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 5.0f, 0.0f );	//カメラの注視先
	XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );	//カメラの真上のベクトル
	g_View = XMMatrixLookAtLH( Eye, At, Up ) *  XMMatrixRotationY(yaw) * XMMatrixRotationX(pitch) * XMMatrixRotationZ(-roll) ;

	//プロジェクション行列を作成
	g_Projection = XMMatrixPerspectiveFovLH( XM_PIDIV2, WIDTH / (FLOAT)(HEIGHT*2), 0.01f, 100.0f );

	//プロジェクション行列をずらす値の計算
	float viewCenter = g_hmdInfo.HScreenSize * 0.25f;
	float eyeProjectionShift = viewCenter - g_hmdInfo.LensSeparationDistance*0.5f;
	float projectionCenterOffset = 4.0f * eyeProjectionShift / g_hmdInfo.HScreenSize;

	//ビュー行列をずらす値の計算
	float halfIPD = g_hmdInfo.InterpupillaryDistance * 0.5f;

	//画面のクリアをするときの色
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // R,G,B,A の順番

	//レンダーターゲットの設定
	g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetViewOculus , g_pDepthStencilView );

	//画面のクリア・深度バッファクリア
	g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetViewOculus, ClearColor );
	g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

	//トポロジ(描画の法則?)を設定
    g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

	for(int i=0;i<2;i++)
	{
		//ビューポートの設定
		D3D11_VIEWPORT vp;
		vp.Width = WIDTH/2;
		vp.Height = HEIGHT;
		vp.MinDepth = 0.0f;
		vp.MaxDepth = 1.0f;
		vp.TopLeftX = i*WIDTH/2;
		vp.TopLeftY = 0;
		g_pImmediateContext->RSSetViewports( 1, &vp );

		// コンスタントバッファの更新
		// シェーダーに渡す際に転置行列にされてしまうためあらかじめ転置行列にしておく
		ConstantBuffer cb;
		cb.mView = XMMatrixTranspose( g_View * XMMatrixTranslation(i==0?halfIPD:-halfIPD,0.0f,0.0f) );
		cb.mProjection = XMMatrixTranspose( g_Projection * XMMatrixTranslation(i==0?projectionCenterOffset:-projectionCenterOffset,0.0f,0.0f) );

		//頂点シェーダーとピクセルシェーダーのセット
		g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
		g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
		g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );
		g_pImmediateContext->PSSetShaderResources( 0, 1, &g_pTextureRV );
		g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerLinear );

		//頂点バッファとインデックスバッファのセット
		UINT stride = sizeof(SimpleVertex), offset = 0;
		g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );
		g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );

		//キューブの描画
		//ワールド行列を変えることでボックスを適当に配置
		//1つめ (0,0,5)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,0,10);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//2つめ (0,4,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,8,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//3つめ (0,-4,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,-8,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//4つめ (-4,0,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(-8,0,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//5つめ (4,0,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(8,0,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );
	}


	//---------------------------------------------
	//--Oculus Rift用に画面を歪ませて描画する処理--
	//---------------------------------------------

	//レンダーターゲットの設定
	g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );

	//レンダーターゲットのクリア
	float ClearColor_[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; // R,G,B,A の順番
	g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor_ );

	//トポロジ(描画の法則?)を設定
	g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );

	// 頂点シェーダー用コンスタントバッファの更新
	ConstantBuffer cb;
	cb.mWorld = XMMatrixIdentity();
	cb.mView = XMMatrixIdentity();
	cb.mProjection = XMMatrixIdentity();
	g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );

	// 設定
	UINT stride = sizeof(SimpleVertex), offset = 0;
	g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
	g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
	g_pImmediateContext->PSSetShader( g_pPixelShaderOculus, NULL, 0 );
	g_pImmediateContext->PSSetShaderResources( 0, 1, &g_pShaderResViewOculus );
	g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerLinear );
	g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pConstantBufferOculus );

	//Oculusのデバイスから定数を計算する
	OculusRiftSettings ocrSet;
		
	//ゆがみ定数
	ocrSet.HmdWarpParam.x = g_hmdInfo.DistortionK[0];
	ocrSet.HmdWarpParam.y = g_hmdInfo.DistortionK[1];
	ocrSet.HmdWarpParam.z = g_hmdInfo.DistortionK[2];
	ocrSet.HmdWarpParam.w = g_hmdInfo.DistortionK[3];

	//色補正の定数(追加部分)
	ocrSet.ChromAbParam.x = g_hmdInfo.ChromaAbCorrection[0];
	ocrSet.ChromAbParam.y = g_hmdInfo.ChromaAbCorrection[1];
	ocrSet.ChromAbParam.z = g_hmdInfo.ChromaAbCorrection[2];
	ocrSet.ChromAbParam.w = g_hmdInfo.ChromaAbCorrection[3];

	//スケールの計算
	float as = (float)WIDTH/(float)HEIGHT;	//アスペクト比
	float r = 1.0f;							//最大半径(倍率?)
	//float r = 1.0f + (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize);	//rに関してはこっちのほうが正しいんだろうけどでかすぎる気もする。
	float rsq   = r*r;
	float scale = r * (g_hmdInfo.DistortionK[0] + g_hmdInfo.DistortionK[1] * rsq + g_hmdInfo.DistortionK[2] * rsq * rsq + g_hmdInfo.DistortionK[3] * rsq * rsq * rsq);
	float scaleFactor = 1/scale;

	ocrSet.Scale.x = (0.5/2) * scaleFactor;
	ocrSet.Scale.y = (0.5/2) * scaleFactor * as;
	ocrSet.ScaleIn.x = (2/0.5); 
	ocrSet.ScaleIn.y = (2/0.5) / as;

	//================左目の描画===============
	//ビューポートの設定
	D3D11_VIEWPORT vp;
	vp.Width = WIDTH/2;
	vp.Height = HEIGHT;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	g_pImmediateContext->RSSetViewports( 1, &vp );
	//左目用の頂点バッファの指定
	g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBufferOculusL, &stride, &offset );
	//スクリーンの中央位置
	ocrSet.ScreenCenter.x = 0.25f;
	ocrSet.ScreenCenter.y = 0.5f;
	//レンズの中央位置
	ocrSet.LensCenter.x = ocrSet.ScreenCenter.x + (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize)/4;	//修正
	ocrSet.LensCenter.y = 0.5f;
	g_pImmediateContext->UpdateSubresource( g_pConstantBufferOculus, 0, NULL, &ocrSet, 0, 0 );
	g_pImmediateContext->Draw( 4, 0);

	//================右目の描画================
	vp.TopLeftX = WIDTH/2;
	vp.TopLeftY = 0;
	g_pImmediateContext->RSSetViewports( 1, &vp );
	//右目用の頂点バッファの指定
	g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBufferOculusR, &stride, &offset );
	//スクリーンの中央位置
	ocrSet.ScreenCenter.x = 0.75;
	ocrSet.ScreenCenter.y = 0.5f;
	//レンズの中央位置
	ocrSet.LensCenter.x = ocrSet.ScreenCenter.x - (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize)/4;	//修正
	ocrSet.LensCenter.y = 0.5f;
	g_pImmediateContext->UpdateSubresource( g_pConstantBufferOculus, 0, NULL, &ocrSet, 0, 0 );
	g_pImmediateContext->Draw( 4, 0);


    // 画面の表示(垂直同期をとる)
    g_pSwapChain->Present( 1, 0 );
}
コード例 #9
0
ファイル: GameObject.cpp プロジェクト: TomAtterton/TAEngine
void GameObject::SetRotation(float x, float y, float z)
{
	XMStoreFloat4x4(&_rotate, XMMatrixRotationX(x) * XMMatrixRotationY(y) * XMMatrixRotationZ(z));
}