Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualSteveHatcher

Posted 29 November 2013 - 06:37 AM

Hi Guys..

 

Stuck yet again. This time I am simply trying to display my triangle slightly rotated.

 

I have added some vertices:

VertexPos gVertices[] = 
{
	XMFLOAT3(0.5f, 0.5f, 0.5f), 
	XMFLOAT3(0.5f, -0.5f, 0.5f),
	XMFLOAT3(-0.5f, -0.5f, 0.5f)
};

which come into play here in InitObjects(void)

	ZeroMemory(&resourceData, sizeof(resourceData));
	resourceData.pSysMem = gVertices;
	d3dResult = d3dDevice_->CreateBuffer(&vertexDesc, &resourceData, &vertexBuffer_);

	D3D11_BUFFER_DESC constDesc;
	ZeroMemory(&constDesc, sizeof(constDesc));
	constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	constDesc.ByteWidth = sizeof(XMMATRIX);
	constDesc.Usage = D3D11_USAGE_DEFAULT;

	d3dResult = d3dDevice_->CreateBuffer(&constDesc, 0, &mvpCB_);

with the final Render() function as

void Render(void)
{
	if (d3dContext_ == 0) //Checks that the Direct3D context is valid. 
		return;


	float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
	d3dContext_->ClearRenderTargetView(backBufferTarget_, clearColor);
	unsigned int stride = sizeof(VertexPos);
	unsigned int offset = 0;

	//Setting up the input assembly
	d3dContext_->IASetInputLayout(inputLayout_); 
	d3dContext_->IASetVertexBuffers(0, 1, &vertexBuffer_, &stride, &offset); 
	d3dContext_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 
	d3dContext_->VSSetShader(solidColorVS_, 0, 0);
	d3dContext_->PSSetShader(solidColorPS_, 0, 0);


	XMMATRIX view = XMMatrixIdentity();
	XMMATRIX projection = XMMatrixOrthographicOffCenterLH(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f); //1a. Creates an orthographic projection matrix using LHS. Return value is a XMMATRIX structure where the resulting projection matrix is placed.
	XMMATRIX vpMatrix_ = XMMatrixMultiply(view, projection);

	XMMATRIX translation = XMMatrixTranslation(10.0f, 10.0f, 10.0f);
	XMMATRIX rotationZ = XMMatrixRotationZ(30.0f);
	XMMATRIX scale = XMMatrixScaling(0.0f, 0.0f, 0.0f);
	XMMATRIX TriangleWorld = translation * rotationZ;

	XMMATRIX mvp = TriangleWorld*vpMatrix_*translation;
	mvp = XMMatrixTranspose(mvp);

	d3dContext_->UpdateSubresource(mvpCB_, 0, 0, &mvp, 0, 0);
	d3dContext_->VSSetConstantBuffers(0, 1, &mvpCB_);

	d3dContext_->Draw(3, 0); 
	swapChain_->Present(0, 0);
}

No matter what I change in the XMMatrixRotationZ or XMMatrixTranslation, my triangle stays the same. Its as if since the buffer is created I am not altering it at all.

 

I have tried many combinations of matrix multiplication ways and large numbers to no avail. It is as if the mvp matrix is having no effect on the final image. Thank you for your time - I have spent many hours trying to figure this out and only come here as a last resort. I find the best way to learn is trying to figure out broken code...


#1SteveHatcher

Posted 29 November 2013 - 06:36 AM

Hi Guys..

 

Stuck yet again. This time I am simply trying to display my triangle slightly rotated.

 

I have added some vertices:

VertexPos gVertices[] = 
{
	XMFLOAT3(0.5f, 0.5f, 0.5f), 
	XMFLOAT3(0.5f, -0.5f, 0.5f),
	XMFLOAT3(-0.5f, -0.5f, 0.5f)
};

which come into play here in InitObjects(void)

	ZeroMemory(&resourceData, sizeof(resourceData));
	resourceData.pSysMem = gVertices;
	d3dResult = d3dDevice_->CreateBuffer(&vertexDesc, &resourceData, &vertexBuffer_);

	D3D11_BUFFER_DESC constDesc;
	ZeroMemory(&constDesc, sizeof(constDesc));
	constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	constDesc.ByteWidth = sizeof(XMMATRIX);
	constDesc.Usage = D3D11_USAGE_DEFAULT;

	d3dResult = d3dDevice_->CreateBuffer(&constDesc, 0, &mvpCB_);

with the final Render() function as

void Render(void)
{
	if (d3dContext_ == 0) //Checks that the Direct3D context is valid. 
		return;


	float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
	d3dContext_->ClearRenderTargetView(backBufferTarget_, clearColor);
	unsigned int stride = sizeof(VertexPos);
	unsigned int offset = 0;

	//Setting up the input assembly
	d3dContext_->IASetInputLayout(inputLayout_); 
	d3dContext_->IASetVertexBuffers(0, 1, &vertexBuffer_, &stride, &offset); 
	d3dContext_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 
	d3dContext_->VSSetShader(solidColorVS_, 0, 0);
	d3dContext_->PSSetShader(solidColorPS_, 0, 0);


	XMMATRIX view = XMMatrixIdentity();
	XMMATRIX projection = XMMatrixOrthographicOffCenterLH(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f); //1a. Creates an orthographic projection matrix using LHS. Return value is a XMMATRIX structure where the resulting projection matrix is placed.
	XMMATRIX vpMatrix_ = XMMatrixMultiply(view, projection);

	XMMATRIX translation = XMMatrixTranslation(10.0f, 10.0f, 10.0f);
	XMMATRIX rotationZ = XMMatrixRotationZ(30.0f);
	XMMATRIX scale = XMMatrixScaling(0.0f, 0.0f, 0.0f);
	XMMATRIX TriangleWorld = translation * rotationZ;

	XMMATRIX mvp = TriangleWorld*vpMatrix_*translation;
	mvp = XMMatrixTranspose(mvp);

	d3dContext_->UpdateSubresource(mvpCB_, 0, 0, &mvp, 0, 0);
	d3dContext_->VSSetConstantBuffers(0, 1, &mvpCB_);

	d3dContext_->Draw(3, 0); 
	swapChain_->Present(0, 0);
}

No matter what I do my triangle stays the same. Its as if since the buffer is created I am not altering it at all. Any help would be greatly appreciated, I hope it is a quick fix like the last two problems.

 

I have tried many combinations of matrix multiplication ways and large numbers to no avail. It is as if the mvp matrix is having no effect on the final image. Thank you for your time - I have spent many hours trying to figure this out and only come here as a last resort. I find the best way to learn is trying to figure out broken code...


PARTNERS