Exemplo n.º 1
0
HRESULT mesh_cubewithtargent::find_point(point_with_tangent *vertex, UINT *index, int &num_vertex, int &num_index)
{
	point_with_tangent square_test[] =
	{
		{ XMFLOAT3(-1.0, -1.0, -1.0), XMFLOAT3(0.0, 0.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(-1.0, 1.0, -1.0), XMFLOAT3(0.0, 0.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(1.0, 1.0, -1.0), XMFLOAT3(0.0, 0.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0), XMUINT4(1.0f,0.0f,0.0f,0.0f),XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(1.0, -1.0, -1.0), XMFLOAT3(0.0, 0.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 1.0) },
		{ XMFLOAT3(-1.0, -1.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, -1.0), XMUINT4(1.0f,0.0f,0.0f,0.0f),XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(-1.0, 1.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, -1.0), XMUINT4(1.0f,0.0f,0.0f,0.0f),XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(-1.0, 1.0, -1.0), XMFLOAT3(-1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, -1.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(-1.0, -1.0, -1.0), XMFLOAT3(-1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, -1.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 1.0) },
		{ XMFLOAT3(1.0, -1.0, 1.0), XMFLOAT3(0.0, 0.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(1.0, 1.0, 1.0), XMFLOAT3(0.0, 0.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(-1.0, 1.0, 1.0), XMFLOAT3(0.0, 0.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(-1.0, -1.0, 1.0), XMFLOAT3(0.0, 0.0, 1.0), XMFLOAT3(-1.0, 0.0, 0.0), XMUINT4(1.0f,0.0f,0.0f,0.0f),XMFLOAT2(1.0, 1.0) },
		{ XMFLOAT3(1.0, -1.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, 1.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(1.0, 1.0, -1.0), XMFLOAT3(1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, 1.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(1.0, 1.0, 1.0), XMFLOAT3(1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, 1.0), XMUINT4(1.0f,0.0f,0.0f,0.0f),XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(1.0, -1.0, 1.0), XMFLOAT3(1.0, 0.0, 0.0), XMFLOAT3(0.0, 0.0, 1.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 1.0) },
		{ XMFLOAT3(-1.0, 1.0, -1.0), XMFLOAT3(0.0, 1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(-1.0, 1.0, 1.0), XMFLOAT3(0.0, 1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(1.0, 1.0, 1.0), XMFLOAT3(0.0, 1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(1.0, 1.0, -1.0), XMFLOAT3(0.0, 1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 1.0) },
		{ XMFLOAT3(-1.0, -1.0, 1.0), XMFLOAT3(0.0, -1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 1.0) },
		{ XMFLOAT3(-1.0, -1.0, -1.0), XMFLOAT3(0.0, -1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0, 0.0) },
		{ XMFLOAT3(1.0, -1.0, -1.0), XMFLOAT3(0.0, -1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 0.0) },
		{ XMFLOAT3(1.0, -1.0, 1.0), XMFLOAT3(0.0, -1.0, 0.0), XMFLOAT3(1.0, 0.0, 0.0),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0, 1.0) }
	};
	//创建索引数组。
	num_vertex = sizeof(square_test) / sizeof(point_with_tangent);
	for (int i = 0; i < num_vertex; ++i)
	{
		vertex[i] = square_test[i];
	}
	UINT indices[] = { 0,1,2, 0,2,3, 4,5,6, 4,6,7, 8,9,10, 8,10,11, 12,13,14, 12,14,15, 16,17,18, 16,18,19, 20,21,22, 20,22,23 };
	num_index = sizeof(indices) / sizeof(UINT);
	for (int i = 0; i < num_index; ++i)
	{
		index[i] = indices[i];
	}
	return S_OK;
}
Exemplo n.º 2
0
bool SpriteGame::loadContent()
{
	CComPtr<ID3DBlob> compiledShader(compileShader("SpriteShader.fx", "VS_Main", "vs_4_0"));
	if(compiledShader == nullptr)
		return false;

	HRESULT result = device->CreateVertexShader(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), nullptr, &vertexShader);
	if(FAILED(result))
		return false;
	
	D3D11_INPUT_ELEMENT_DESC vertexProperties[] =	{
														{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
														{ "TEXEL", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
													};
	result = device->CreateInputLayout(vertexProperties, 2, compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), &inputLayout);

	if(FAILED(result))
		return false;

	compiledShader = compileShader("SpriteShader.fx", "PS_Main", "ps_4_0");
	if(compiledShader == nullptr)
		return false;

	result = device->CreatePixelShader(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), nullptr, &pixelShader);
	if(FAILED(result))
		return false;

	result = D3DX11CreateShaderResourceViewFromFile(device, "Resources/Sprite.dds", nullptr, nullptr, &texture, nullptr);
	if(FAILED(result))
		return false;

	D3D11_SAMPLER_DESC samplerDescriptor;
	ZeroMemory(&samplerDescriptor, sizeof(samplerDescriptor));
	samplerDescriptor.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDescriptor.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDescriptor.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDescriptor.ComparisonFunc = D3D11_COMPARISON_NEVER;
	samplerDescriptor.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDescriptor.MaxLOD = D3D11_FLOAT32_MAX;
	result = device->CreateSamplerState(&samplerDescriptor, &textureSampler);
	if(FAILED(result))
		return false;

	CComPtr<ID3D11Resource> textureResource;
	texture->GetResource(&textureResource);
	D3D11_TEXTURE2D_DESC textureDescriptor;
	((ID3D11Texture2D*)(textureResource.p))->GetDesc(&textureDescriptor);

	float halfWidth = textureDescriptor.Width/2.0f;
	float halfHeight = textureDescriptor.Height/2.0f;

	Vertex vertices[] = {
							{ XMFLOAT3(-halfWidth,  halfHeight, 1.0f), XMFLOAT2(0.0f, 0.0f) },
							{ XMFLOAT3( halfWidth,  halfHeight, 1.0f), XMFLOAT2(1.0f, 0.0f) },
							{ XMFLOAT3(-halfWidth, -halfHeight, 1.0f), XMFLOAT2(0.0f, 1.0f) },
							{ XMFLOAT3( halfWidth, -halfHeight, 1.0f), XMFLOAT2(1.0f, 1.0f) }
						};
	D3D11_BUFFER_DESC bufferDescriptor = {0};
	bufferDescriptor.Usage = D3D11_USAGE_DEFAULT;
	bufferDescriptor.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bufferDescriptor.ByteWidth = sizeof(vertices);

	D3D11_SUBRESOURCE_DATA vertexData = {0};
	vertexData.pSysMem = vertices;

	result = device->CreateBuffer(&bufferDescriptor, &vertexData, &vertexBuffer);
	if(FAILED(result))
		return false;

	D3D11_BUFFER_DESC matrixBufferDescriptor = {0};
	matrixBufferDescriptor.Usage = D3D11_USAGE_DEFAULT;
	matrixBufferDescriptor.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	matrixBufferDescriptor.ByteWidth = sizeof(XMMATRIX);

	result = device->CreateBuffer(&matrixBufferDescriptor, nullptr, &mvpMatrixBuffer);
	if(FAILED(result))
		return false;
	
	sprites[0].setPosition(100, 300);
	sprites[1].setPosition(400, 100);
	
	vpMatrix = XMMatrixIdentity() * XMMatrixOrthographicOffCenterLH(0.0f, 600.0f, 0.0f, 600.0f, 0.1f, 100.0f);

	D3D11_BLEND_DESC blendDescriptor = {0};
	blendDescriptor.RenderTarget[0].BlendEnable = true;
	blendDescriptor.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	blendDescriptor.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	blendDescriptor.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	blendDescriptor.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	blendDescriptor.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
	blendDescriptor.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	blendDescriptor.RenderTarget[0].RenderTargetWriteMask = 0x0F;

	float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	device->CreateBlendState(&blendDescriptor, &blendState);
	deviceContext->OMSetBlendState(blendState, blendFactor, 0xFFFFFFFF);

	return true;
}
void CubeTexturedModel::InitializeModel(float lengthX, float lengthY, float lengthZ, WCHAR** pTextureFileNames)
{

	/*
	pTextures is expected to be an array[6] which holds the textures files names for the faces of the cube as follows:
	pTextures[0] frontFace
	pTextures[1] backFace
	pTextures[2] rightFace
	pTextures[3] leftFace
	pTextures[4] topFace
	pTextures[5] bottomFace
	*/


	int vertexCountPerFace = 4; 
	int indexCountPerFace = 6;  

	//m_textureVertices = new TextureVertexType[vertexCount];
	m_textureVerticesFront = new TextureVertexType[vertexCountPerFace];
	m_textureVerticesBack = new TextureVertexType[vertexCountPerFace];
	m_textureVerticesRight = new TextureVertexType[vertexCountPerFace];
	m_textureVerticesLeft = new TextureVertexType[vertexCountPerFace];
	m_textureVerticesTop = new TextureVertexType[vertexCountPerFace];
	m_textureVerticesBottom = new TextureVertexType[vertexCountPerFace];

	m_quadTextures = 0; 

	//Create the ModelClass object that will be used to deliver these vertices to the graphics pipeline

	m_VertexModelArray = new ModelClass*[NUMBER_OF_CUBE_FACES]; 


	m_textureFileNames = new WCHAR*[NUMBER_OF_CUBE_FACES]; //file names of 6 face .dds texture files
    for(int i=0; i<NUMBER_OF_CUBE_FACES; i++){
		m_textureFileNames[i] = pTextureFileNames[i]; //record the file names of the six cube face texture files
	}

	m_indicesFront = new unsigned long[indexCountPerFace];
	m_indicesBack = new unsigned long[indexCountPerFace];
	m_indicesRight = new unsigned long[indexCountPerFace];
	m_indicesLeft = new unsigned long[indexCountPerFace];
	m_indicesTop = new unsigned long[indexCountPerFace];
	m_indicesBottom = new unsigned long[indexCountPerFace];
	
	/*
	The index locations are all hard-coded to better illustrate the 
	structure. Alternatively we could use for-loops to contruct the models
	*/

	//Front Face
	m_textureVerticesFront[0].position = XMFLOAT3(-lengthX/2, -lengthY/2, -lengthZ/2); // Front Bottom left.
	m_textureVerticesFront[0].texture = XMFLOAT2(0.0f, 1.0f);
	
	m_textureVerticesFront[1].position = XMFLOAT3(-lengthX/2, lengthY/2, -lengthZ/2);  // Front Top left.
	m_textureVerticesFront[1].texture = XMFLOAT2(0.0f, 0.0f);

	m_textureVerticesFront[2].position = XMFLOAT3(lengthX/2, -lengthY/2, -lengthZ/2);  // Front Bottom right.
	m_textureVerticesFront[2].texture = XMFLOAT2(1.0f, 1.0f);
	
	m_textureVerticesFront[3].position = XMFLOAT3(lengthX/2, lengthY/2, -lengthZ/2);   // Front Top right.
	m_textureVerticesFront[3].texture = XMFLOAT2(1.0f, 0.0f);

	//Front Face
	m_indicesFront[0] = 0;  // Front Bottom left.
	m_indicesFront[1] = 1;  // Front Top left.
	m_indicesFront[2] = 2;  // Front Bottom right.
	m_indicesFront[3] = 1;  // Front Top left.
	m_indicesFront[4] = 3;  // Front Top right.  
	m_indicesFront[5] = 2;  // Front Bottom right.

	m_VertexModelArray[0] = new ModelClass(
			     m_textureVerticesFront, 
				 vertexCountPerFace,  //vertex count
				 m_indicesFront, 
				 indexCountPerFace, //index count
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	//Back Face

	m_textureVerticesBack[0].position = XMFLOAT3(-lengthX/2, -lengthY/2, lengthZ/2); // Back Bottom Left.
	m_textureVerticesBack[0].texture = XMFLOAT2(1.0f, 1.0f);
	
	m_textureVerticesBack[1].position = XMFLOAT3(-lengthX/2, lengthY/2, lengthZ/2);  // Back Top Left.
	m_textureVerticesBack[1].texture = XMFLOAT2(1.0f, 0.0f);

	m_textureVerticesBack[2].position = XMFLOAT3(lengthX/2, -lengthY/2, lengthZ/2);  // Back Bottom Right.
	m_textureVerticesBack[2].texture = XMFLOAT2(0.0f, 1.0f);
	
	m_textureVerticesBack[3].position = XMFLOAT3(lengthX/2, lengthY/2, lengthZ/2);   // Back Top Right.
	m_textureVerticesBack[3].texture = XMFLOAT2(0.0f, 0.0f);

	//Back Face
	m_indicesBack[0] = 3;  // Top Back Right
	m_indicesBack[1] = 1;  // Top Back Left
	m_indicesBack[2] = 0;  // Bottom Back Left
	m_indicesBack[3] = 3;  // Top Back Right
	m_indicesBack[4] = 0;  // Bottom Back Left
	m_indicesBack[5] = 2;  // Bottom Back Right

	m_VertexModelArray[1] = new ModelClass(
			     m_textureVerticesBack, 
				 vertexCountPerFace,  
				 m_indicesBack, 
				 indexCountPerFace, 
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


	//Right Side

	m_textureVerticesRight[0].position = XMFLOAT3(lengthX/2, lengthY/2, -lengthZ/2);   // Front Top right.
	m_textureVerticesRight[0].texture = XMFLOAT2(1.0f, 0.0f);

	m_textureVerticesRight[1].position = XMFLOAT3(lengthX/2, -lengthY/2, -lengthZ/2);  // Front Bottom right.
	m_textureVerticesRight[1].texture = XMFLOAT2(1.0f, 1.0f);

	m_textureVerticesRight[2].position = XMFLOAT3(lengthX/2, lengthY/2, lengthZ/2);   // Back Top right.
	m_textureVerticesRight[2].texture = XMFLOAT2(0.0f, 0.0f);

	m_textureVerticesRight[3].position = XMFLOAT3(lengthX/2, -lengthY/2, lengthZ/2);  // Back Bottom right.
	m_textureVerticesRight[3].texture = XMFLOAT2(0.0f, 1.0f);

	//Right Side
	m_indicesRight[0] = 1;  // Front Bottom right.
	m_indicesRight[1] = 0;  // Front Top right.
	m_indicesRight[2] = 3;  // Back Bottom right.
	m_indicesRight[3] = 0;  // Front Top right.
	m_indicesRight[4] = 2;  // Back Top right.
	m_indicesRight[5] = 3;  // Back Bottom right.

    m_VertexModelArray[2] = new ModelClass(
			     m_textureVerticesRight, 
				 vertexCountPerFace,  
				 m_indicesRight, 
				 indexCountPerFace, 
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);



	//Left Side

	m_textureVerticesLeft[0].position = XMFLOAT3(-lengthX/2, lengthY/2, -lengthZ/2);   // Front Top Left.
	m_textureVerticesLeft[0].texture = XMFLOAT2(1.0f, 0.0f);

	m_textureVerticesLeft[1].position = XMFLOAT3(-lengthX/2, -lengthY/2, -lengthZ/2);  // Front Bottom Left.
	m_textureVerticesLeft[1].texture = XMFLOAT2(1.0f, 1.0f);

	m_textureVerticesLeft[2].position = XMFLOAT3(-lengthX/2, lengthY/2, lengthZ/2);   // Back Top Left.
	m_textureVerticesLeft[2].texture = XMFLOAT2(0.0f, 0.0f);

	m_textureVerticesLeft[3].position = XMFLOAT3(-lengthX/2, -lengthY/2, lengthZ/2);  // Back Bottom Left.
	m_textureVerticesLeft[3].texture = XMFLOAT2(0.0f, 1.0f);

	//Left Side 
	m_indicesLeft[0] = 0;  // Top Front Left.
	m_indicesLeft[1] = 1;  // Bottom Front Left.
	m_indicesLeft[2] = 3;  // Bottom Back Left.
	m_indicesLeft[3] = 0;  // Top Front Left.
	m_indicesLeft[4] = 3;  // Bottom Back Left.
	m_indicesLeft[5] = 2;  // Top Back Left.

	 m_VertexModelArray[3] = new ModelClass(
			     m_textureVerticesLeft, 
				 vertexCountPerFace,  
				 m_indicesLeft, 
				 indexCountPerFace, 
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


	//Top Face

	m_textureVerticesTop[0].position = XMFLOAT3(-lengthX/2, lengthY/2, -lengthZ/2);   // Front Top Left.
	m_textureVerticesTop[0].texture = XMFLOAT2(0.0f, 1.0f);

	m_textureVerticesTop[1].position = XMFLOAT3(lengthX/2, lengthY/2, -lengthZ/2);  // Front Top Right.
	m_textureVerticesTop[1].texture = XMFLOAT2(1.0f, 1.0f);

	m_textureVerticesTop[2].position = XMFLOAT3(-lengthX/2, lengthY/2, lengthZ/2);   // Back Top Left.
	m_textureVerticesTop[2].texture = XMFLOAT2(0.0f, 0.0f);

	m_textureVerticesTop[3].position = XMFLOAT3(lengthX/2, lengthY/2, lengthZ/2);  // Back Top Right.
	m_textureVerticesTop[3].texture = XMFLOAT2(1.0f, 0.0f);

	//Top Face
	m_indicesTop[0] = 1;  // Top Front Right
	m_indicesTop[1] = 0;  // Top Front Left
	m_indicesTop[2] = 2;  // Top Back Left
	m_indicesTop[3] = 1;  // Top Front Right
	m_indicesTop[4] = 2;  // Top Back Left
	m_indicesTop[5] = 3;  // Top Back Right.

	m_VertexModelArray[4] = new ModelClass(
			     m_textureVerticesTop, 
				 vertexCountPerFace,  
				 m_indicesTop, 
				 indexCountPerFace, 
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	//Bottom Face

	m_textureVerticesBottom[0].position = XMFLOAT3(-lengthX/2, -lengthY/2, -lengthZ/2);   // Front Bottom Left.
	m_textureVerticesBottom[0].texture = XMFLOAT2(0.0f, 0.0f);

	m_textureVerticesBottom[1].position = XMFLOAT3(lengthX/2, -lengthY/2, -lengthZ/2);  // Front Bottom Right.
	m_textureVerticesBottom[1].texture = XMFLOAT2(1.0f, 0.0f);

	m_textureVerticesBottom[2].position = XMFLOAT3(-lengthX/2, -lengthY/2, lengthZ/2);   // Back Bottom Left.
	m_textureVerticesBottom[2].texture = XMFLOAT2(0.0f, 1.0f);

	m_textureVerticesBottom[3].position = XMFLOAT3(lengthX/2, -lengthY/2, lengthZ/2);  // Back Bottom Right.
	m_textureVerticesBottom[3].texture = XMFLOAT2(1.0f, 1.0f);

	//Bottom Face
	m_indicesBottom[0] = 0;  // Bottom Front Left
	m_indicesBottom[1] = 3;  // Bottom Back Right
	m_indicesBottom[2] = 2;  // Bottom Back Left
	m_indicesBottom[3] = 0;  // Bottom Front Left
	m_indicesBottom[4] = 1;  // Bottom Front Right
	m_indicesBottom[5] = 3;  // Bottom Back Right

	m_VertexModelArray[5] = new ModelClass(
			     m_textureVerticesBottom, 
				 vertexCountPerFace,  
				 m_indicesBottom, 
				 indexCountPerFace, 
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


	// Load the index array with data.
	// Two triangles per face. The directions are consistent
	// With back-face culling in a left-hand co-ordinate system.



}
Exemplo n.º 4
0
void Game::UpdateScene(ID3D11DeviceContext* md3dImmediateContext, ID3D11Device* md3dDevice, float dt, JetpackArcher* instance)
{
	controlsTimer += dt;

	ID3D11RasterizerState* rs;
	D3D11_RASTERIZER_DESC rsd;
	rsd.CullMode = D3D11_CULL_NONE;
	rsd.AntialiasedLineEnable = false;
	rsd.DepthBias = 0.0f;
	rsd.DepthBiasClamp = 0.0f;
	rsd.DepthClipEnable = true;
	rsd.FillMode = D3D11_FILL_SOLID;
	rsd.FrontCounterClockwise = true;
	rsd.MultisampleEnable = true;
	rsd.ScissorEnable = false;
	rsd.SlopeScaledDepthBias = 0.0f;
	md3dDevice->CreateRasterizerState(&rsd, &rs);
	md3dImmediateContext->RSSetState(rs);

	if (recoverTime > 0.0f)
	{
		recoverTime = recoverTime - dt;
	}
	else
	{
		recoverTime = 0.0f;
	}

	playerBB.pos.x = mPlayer->GetPos().m128_f32[0];
	playerBB.pos.y = mPlayer->GetPos().m128_f32[1];

	UpdateKeyboardInput(md3dDevice, dt);

	m2DCam->Update();

	//update player
	mPlayer->Update(dt);
	mPlayer->AddForce(XMVectorSet(0.0f, -9.8f, 0.0f, 0.0f));   //adds gravity
	//update jetpack flame
	if (isFacingRight)
	{
		mFlame->SetPos(XMVectorSet(mPlayer->GetPos().m128_f32[0] - 5, mPlayer->GetPos().m128_f32[1] - 16, 0.0f, 0.0f));
	}
	else if (!isFacingRight)
	{
		mFlame->SetPos(XMVectorSet(mPlayer->GetPos().m128_f32[0] + 5, mPlayer->GetPos().m128_f32[1] - 16, 0.0f, 0.0f));
	}
	mFlame->Update(dt);
	//update enemy damage done to player
	for (int i = 0; i < enemies.size(); ++i)
	{
		if (PlayerEnemyCollision(mPlayer, enemies[i]) && recoverTime == 0.0f)
		{
			enemies[i]->ApplyDamage(mPlayer);
			recoverTime = 3.0f;   //player has 3 seconds before damage can be done to him again
		}
	}
	//set player health bar
	redXPosP = 60.0f;
	currHealthP = mPlayer->GetHealth();
	maxHealthP = 3.0f;
	ratioP = 1.0f - (currHealthP / maxHealthP);
	redXPosP += ((1.0f - ratioP) / 2.0f) * 96.0f; //96 is barSize
	redXScaleP = ratioP;
	mGreenHBarP->SetPos(XMVectorSet(60.0f, 736.0f, 0.0f, 0.0f));
	mRedHBarP->SetPos(XMVectorSet(redXPosP, 736.0f, 0.0f, 0.0f));
	mRedHBarP->SetScale(XMVectorSet(redXScaleP, 1.0f, 0.0f, 0.0f));
	//player dead / game over
	if (mPlayer->GetHealth() == 0)
	{
		instance->SetState(JetpackArcher::States::GAME_OVER);
	}
	//collision between player and end of level object / game won
	if (RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::top || 
		RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::left || 
		RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::right)
	{
		instance->SetState(JetpackArcher::States::GAME_WON);
	}

	//update enemies
	for (int i = 0; i < enemies.size(); ++i)
	{
		enemies[i]->Update(dt);
		enemies[i]->Chase(enemies, mPlayer, dt);
		//set health bars to above enemies' heads and red bar to adjust accordingly
		redXPos = enemies[i]->GetPos().m128_f32[0];
		currHealth = enemies[i]->GetHealth();
		maxHealth = 5.0f;
		ratio = 1.0f - (currHealth / maxHealth);
		redXPos += ((1.0f - ratio) / 2.0f) * 32.0f; //32 is barSize
		redXScale = ratio;
		greenBarVec[i]->SetPos(XMVectorSet(enemies[i]->GetPos().m128_f32[0], enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetPos(XMVectorSet(redXPos, enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetScale(XMVectorSet(redXScale, 1.0f, 0.0f, 0.0f));
		//collision checks between enemies and playerBB		
		SpriteRectCollision(enemies[i], playerBB);
		//collision checks between enemies and environmentBBs
		for (int j = 0; j < boxes.size(); ++j)
		{
			SpriteRectCollision(enemies[i], boxes[j]);
		}
		//delete enemy upon death
		if (enemies[i]->GetHealth() == 0)
		{
			delete enemies[i];
			enemies.erase(enemies.begin() + i);
			i--;
			break;
		}
	}
	//when all enemies eliminated:
	if (enemies.size() == 0)
	{
		EOLobjActive = true;
		EOLobjBB.pos = XMFLOAT2(EOLobj->GetPos().m128_f32[0], EOLobj->GetPos().m128_f32[1]);
		EOLobjBB.height = 32.0f;
		EOLobjBB.width = 32.0f;
	}

	//collision between playerBB and environmentBBs
	for (int i = 0; i < boxes.size(); ++i)
	{
		RectRectCollision(playerBB, boxes[i], mPlayer);

		//update mGrounded bool for player jump
		if (RectRectCollision(playerBB, boxes[i], mPlayer) == CollisionSide::bot)
		{
			mPlayer->HitGround();
		}
	}

	//update projectiles
	for (int i = 0; i < mProjectiles.size(); ++i)
	{
		mProjectiles[i]->Update(dt);
		for (int j = 0; j < enemies.size(); ++j)
		{
			if (mProjectiles[i]->GetDistanceTravelled() > mProjectiles[i]->MAX_DISTANCE ||
				mProjectiles[i]->GetDistanceTravelled() < mProjectiles[i]->MIN_DISTANCE)
			{
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
			//collision checks between enemies and projectiles	
			if (EnemyProjCollision(enemies[j], mProjectiles[i]))
			{
				mProjectiles[i]->ApplyDamage(enemies[j]);
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
		}
	}

	mGreenFuel->Update(dt);
	mRedFuel->Update(dt);
	EOLobj->Update(dt);
}
Exemplo n.º 5
0
bool CBitmapClass::UpdateBuffers(ID3D11DeviceContext* deviceContext, int positionX, int positionY)
{
	float left, right, top, bottom;
	VertexType* vertices;
	D3D11_MAPPED_SUBRESOURCE mappedResources;
	VertexType* verticesPtr;
	HRESULT result;

	//Si estamos en la misma posicion, entonces no hacemos nada
	if (m_previousPosX == positionX && m_previousPosY == positionY)
	{
		return true;
	}

	//Si se actualizo, entonces movemos todo
	m_previousPosX = positionX;
	m_previousPosY = positionY;

	//Calculamos la coordenada de la parte superior izquierda
	left = (float)((m_screenWidth / 2) * -1) + (float) positionX;

	//Calculamos la coordenada de la parte superior derecha
	right = left + (float)m_bitmapWidth;

	//Calculamos la coordenada de la parte inferior izquierda
	top = (float)((m_screenHeight / 2)) - (float) positionY;

	//Calculamos la coordenada de la parte inferior derecha
	bottom = top - (float)m_bitmapHeight;
	
	//Creamos el array de vertices
	vertices = new VertexType[m_vertexCount];
	if (!vertices)
	{
		return false;
	}
	//Llenamos el array con el primer triangulo y el segundo
	vertices[0].position	= XMFLOAT3(left, top, 0.0f);
	vertices[0].texture		= XMFLOAT2(0.0f, 0.0f);

	vertices[1].position	= XMFLOAT3(right, bottom, 0.0f);
	vertices[1].texture		= XMFLOAT2(1.0f, 1.0f);

	vertices[2].position	= XMFLOAT3(left, bottom, 0.0f);
	vertices[2].texture		= XMFLOAT2(0.0f, 1.0f);

	vertices[3].position	= XMFLOAT3(left, top, 0.0f);
	vertices[3].texture		= XMFLOAT2(0.0f, 0.0f);

	vertices[4].position	= XMFLOAT3(right, top, 0.0f);
	vertices[4].texture		= XMFLOAT2(1.0f, 0.0f);

	vertices[5].position	= XMFLOAT3(right, bottom, 0.0f);
	vertices[5].texture		= XMFLOAT2(1.0f, 1.0f);

	//ahora vamos a lockear y delockear para escribir en el 
	result = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResources);
	if (FAILED(result))
	{
		return false;
	}

	//Sacamos un puntero a los datos
	verticesPtr = (VertexType*)mappedResources.pData;

	//y copiamos lo que ahora tenemos
	memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType) * m_vertexCount));

	//Desbloqueamos el flujo de datos
	deviceContext->Unmap(m_vertexBuffer, 0);

	//Liberamos la memoria de los arrays
	delete [] vertices;
	vertices = 0;

	return true;
}
void RayTracerMaterial::createVertexBuffer(ID3D11Device * device, const Mesh& mesh, ID3D11Buffer** vertexBuffers)const
{
	const std::vector<XMFLOAT3>& sourceVertices = mesh.vertices();
	std::vector<XMFLOAT3>* textureCoordinates = mesh.textureCoords().at(0);
	assert(textureCoordinates->size() == sourceVertices.size());

	std::vector<VertexPositionTexture> vertices;
	vertices.reserve(sourceVertices.size());
	for (UINT i = 0; i < sourceVertices.size(); i++)
	{
		XMFLOAT3 position = sourceVertices.at(i);
		XMFLOAT3 uv = textureCoordinates->at(i);
		vertices.push_back(VertexPositionTexture(XMFLOAT4(position.x, position.y, position.z, 1.0f), XMFLOAT2(uv.x, uv.y)));
	}

	createVertexBuffer(device, &vertices[0], vertices.size(), vertexBuffers);
}
Exemplo n.º 7
0
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t color)
{
#ifdef HAS_DX
  static const DWORD FVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;

  Vertex vertex[5];
  for (int i = 0; i < 4; i++)
  {
    vertex[i].pos = XMFLOAT3( x[i], y[i], 0);
    CD3DHelper::XMStoreColor(&vertex[i].color, color);
    vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f);
    vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f);
  }

  if (pTexture)
  {
    vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth();
    vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight();
  }
  else
  {
    vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f;
    vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f;
  }
  vertex[4] = vertex[0]; // Not used when pTexture != NULL

  CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader();
  pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND);

  // Set state to render the image
  if (pTexture)
  {
    pTexture->LoadToGPU();
    CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture);
    ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource();
    pGUIShader->SetShaderViews(1, &shaderRes);
    pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]);
  }
  else
  {
    if (!UpdateVertexBuffer(vertex))
      return;

    ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();

    unsigned stride = sizeof(Vertex);
    unsigned offset = 0;
    pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset);
    pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP);

    pGUIShader->Draw(5, 0);
    pGUIShader->RestoreBuffers();
  }

#elif defined(HAS_GL)
  if (pTexture)
  {
    int unit = 0;
    pTexture->LoadToGPU();
    pTexture->BindToUnit(unit++);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);          // Turn Blending On

    // diffuse coloring
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
    glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

    if(g_Windowing.UseLimitedColor())
    {
      // compress range
      pTexture->BindToUnit(unit++); // dummy bind
      const GLfloat rgba1[4] = {(235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, 1.0f};
      glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
      glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba1);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_MODULATE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);

      // transition
      pTexture->BindToUnit(unit++); // dummy bind
      const GLfloat rgba2[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f};
      glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
      glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba2);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
      glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
      glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);
    }
  }
  else
    glDisable(GL_TEXTURE_2D);
  glPolygonMode(GL_FRONT_AND_BACK, pTexture ? GL_FILL : GL_LINE);

  glBegin(GL_QUADS);
  float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
  if (pTexture)
  {
    u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
    v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
  }

  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u1, v1);
  glVertex3f(x[0], y[0], 0);

  // Bottom-left vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u2, v1);
  glVertex3f(x[1], y[1], 0);

  // Bottom-right vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u2, v2);
  glVertex3f(x[2], y[2], 0);

  // Top-right vertex (corner)
  glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color));
  glTexCoord2f(u1, v2);
  glVertex3f(x[3], y[3], 0);

  glEnd();
#elif defined(HAS_GLES)
  if (pTexture)
  {
    pTexture->LoadToGPU();
    pTexture->BindToUnit(0);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);          // Turn Blending On

    g_Windowing.EnableGUIShader(SM_TEXTURE);
  }
  else
  {
    glDisable(GL_TEXTURE_2D);

    g_Windowing.EnableGUIShader(SM_DEFAULT);
  }

  float u1 = 0, u2 = 1, v1 = 0, v2 = 1;
  if (pTexture)
  {
    u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth();
    v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight();
  }

  GLubyte col[4];
  GLfloat ver[4][3];
  GLfloat tex[4][2];
  GLubyte idx[4] = {0, 1, 3, 2};        //determines order of triangle strip

  GLint posLoc  = g_Windowing.GUIShaderGetPos();
  GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
  GLint uniColLoc= g_Windowing.GUIShaderGetUniCol();

  glVertexAttribPointer(posLoc,  3, GL_FLOAT, 0, 0, ver);
  glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);

  glEnableVertexAttribArray(posLoc);
  glEnableVertexAttribArray(tex0Loc);

  // Setup Colour values
  col[0] = (GLubyte)GET_R(color);
  col[1] = (GLubyte)GET_G(color);
  col[2] = (GLubyte)GET_B(color);
  col[3] = (GLubyte)GET_A(color);

  for (int i=0; i<4; i++)
  {
    // Setup vertex position values
    ver[i][0] = x[i];
    ver[i][1] = y[i];
    ver[i][2] = 0.0f;
  }
  // Setup texture coordinates
  tex[0][0] = tex[3][0] = u1;
  tex[0][1] = tex[1][1] = v1;
  tex[1][0] = tex[2][0] = u2;
  tex[2][1] = tex[3][1] = v2;

  glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f));
  glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);

  glDisableVertexAttribArray(posLoc);
  glDisableVertexAttribArray(tex0Loc);

  g_Windowing.DisableGUIShader();
#else
// SDL render
  g_Windowing.BlitToScreen(m_pImage, NULL, NULL);
#endif
}
Exemplo n.º 8
0
void BitmapFontClass::DrawString(ID3D11DeviceContext* deviceContext, char* message, float startX, float startY, XMFLOAT4 pixelColor)
{
	const int sizeOfSprite = sizeof(VertexPos) * 6;
	const int maxLetters = 24;
	int length = strlen(message);

	if (length > maxLetters)
	{
		length = maxLetters;
	}

	float charWidth = 32.0f;
	float charHeight = 32.0f;

	const int verticesPerLetter = 6;

	D3D11_MAPPED_SUBRESOURCE mapResource;
	HRESULT d3dResult = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource);
	if (FAILED(d3dResult))
	{
		MessageBox(0, L"Failed to map resource!", L"BitmapFont Error", MB_OK);
		return;
	}

	VertexPos* spritePtr = (VertexPos*)mapResource.pData;
	const int indexA = static_cast<char>('A');
	const int indexZ = static_cast<char>('Z');

	for (int i = 0; i < length; i++)
	{
		float thisStartX = startX + (charWidth * static_cast<float>(i));
		float thisEndX = thisStartX + charWidth;
		float thisEndY = startY + charHeight;

		spritePtr[0].pos = XMFLOAT3(thisEndX, thisEndY, 1.0f);
		spritePtr[1].pos = XMFLOAT3(thisEndX, startY, 1.0f);
		spritePtr[2].pos = XMFLOAT3(thisStartX, startY, 1.0f);
		spritePtr[3].pos = XMFLOAT3(thisStartX, startY, 1.0f);
		spritePtr[4].pos = XMFLOAT3(thisStartX, thisEndY, 1.0f);
		spritePtr[5].pos = XMFLOAT3(thisEndX, thisEndY, 1.0f);

		int texLookup = 0;
		int letter = static_cast<char>(message[i]);

		if (letter < indexA || letter > indexZ)
		{
			// Grab one index past Z, which is a blank space in the texture.
			texLookup = (indexZ - indexA) + 1;
		}
		else
		{
			// A = 0, B = 1, Z = 25, etc.
			texLookup = (letter - indexA);
		}
		
		int zeroBasedIndex = letter;// -32;
		int tilesAmountX = 16;
		int tilesAmountY = 16;
		int indexX = zeroBasedIndex % tilesAmountX;
		int indexY = zeroBasedIndex / tilesAmountX;

		float startX = (float)indexX / tilesAmountX;
		float endX = (float)(indexX + 1.0f) / tilesAmountX;
		float startY = (float)indexY / tilesAmountY;
		float endY = (float)(indexY + 1.0f) / tilesAmountY;

		spritePtr[0].tex0 = XMFLOAT2(endX, startY);		// TOP RIGHT
		spritePtr[1].tex0 = XMFLOAT2(endX, endY);		// BOTTOM RIGHT
		spritePtr[2].tex0 = XMFLOAT2(startX, endY);	// BOTTOM LEFT
		spritePtr[3].tex0 = XMFLOAT2(startX, endY);	// BOTTOM LEFT
		spritePtr[4].tex0 = XMFLOAT2(startX, startY);	// TOP LEFT
		spritePtr[5].tex0 = XMFLOAT2(endX, startY);		// TOP RIGHT

		spritePtr += 6;
	}

	deviceContext->Unmap(m_vertexBuffer, 0);

	deviceContext->PSSetShaderResources(0, 1, &m_textureView);
	unsigned int bufferNumber;
	PixelBufferType* dataPtr2;

	d3dResult = deviceContext->Map(m_pixelBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource);
	if (FAILED(d3dResult))
	{
		MessageBox(0, L"Failed to map resource!", L"BitmapFont Error", MB_OK);
		return;
	}

	dataPtr2 = (PixelBufferType*)mapResource.pData;
	dataPtr2->pixelColor = pixelColor;

	deviceContext->Unmap(m_pixelBuffer, 0);

	bufferNumber = 0;

	deviceContext->PSSetConstantBuffers(bufferNumber, 1, &m_pixelBuffer);


	deviceContext->Draw(6 * length, 0);
}
Exemplo n.º 9
0
	void TextureModelDemo::CreateVertexBuffer(ID3D11Device* device, const Mesh& mesh, ID3D11Buffer** vertexBuffer) const
	{
		const std::vector<XMFLOAT3>& sourceVertices = mesh.Vertices();

		std::vector<TextureMappingVertex> vertices;
		vertices.reserve(sourceVertices.size());

		std::vector<XMFLOAT3>* textureCoordinates = mesh.TextureCoordinates().at(0);
		assert(textureCoordinates->size() == sourceVertices.size());

		for (UINT i = 0; i < sourceVertices.size(); i++)
		{
			XMFLOAT3 position = sourceVertices.at(i);
			XMFLOAT3 uv = textureCoordinates->at(i);
			vertices.push_back(TextureMappingVertex(XMFLOAT4(position.x, position.y, position.z, 1.0f), XMFLOAT2(uv.x, uv.y)));
		}

		D3D11_BUFFER_DESC vertexBufferDesc;
		ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
		vertexBufferDesc.ByteWidth = sizeof(TextureMappingVertex) * vertices.size();
		vertexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
		vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;

		D3D11_SUBRESOURCE_DATA vertexSubResourceData;
		ZeroMemory(&vertexSubResourceData, sizeof(vertexSubResourceData));
		vertexSubResourceData.pSysMem = &vertices[0];
		if (FAILED(device->CreateBuffer(&vertexBufferDesc, &vertexSubResourceData, vertexBuffer)))
		{
			throw GameException("ID3D11Device::CreateBuffer() failed.");
		}
	}
Exemplo n.º 10
0
void CGuiFont::BuildVertexArray( SMeshData<SMeshTexture>& _vertices, text _text, float drawX, float drawY )
{
	int countLetters, index, i, letter;

	// Get the number of letters in the sentence.
	countLetters = (int)wcslen( _text.c_str() );

	index = 0;

	// Draw each letter onto a quad.
	for(i = 0; i < countLetters; i++)
	{
		letter = ((int)_text[i]) - 32;

		// If the letter is a space then just move over three pixels.
		if(letter == 0)
		{
			drawX = drawX + 3.0f;
		}
		else
		{
			// First triangle in quad.

			SMeshTexture tempText;

			tempText = SMeshTexture( XMFLOAT3( drawX, drawY, 0.0f ), XMFLOAT2( m_type[letter].left, 0.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( drawX, drawY, 0.0f );  // Top left.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 0.0f );
			index++;

			tempText = SMeshTexture( XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].right, 1.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f );  // Bottom right.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 1.0f );
			index++;

			tempText = SMeshTexture( XMFLOAT3( drawX, (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].left, 1.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( drawX, (drawY - 16), 0.0f );  // Bottom left.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 1.0f );
			index++;

			// Second triangle in quad.
			tempText = SMeshTexture( XMFLOAT3( drawX, drawY, 0.0f ), XMFLOAT2( m_type[letter].left, 0.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( drawX, drawY, 0.0f );  // Top left.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 0.0f );
			index++;

			tempText = SMeshTexture( XMFLOAT3( drawX + m_type[letter].size, drawY, 0.0f ), XMFLOAT2( m_type[letter].right, 0.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( drawX + m_type[letter].size, drawY, 0.0f );  // Top right.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 0.0f );
			index++;

			tempText = SMeshTexture( XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].right, 1.0f ) );
			_vertices.vertices.push_back( tempText );
			_vertices.indices.push_back( index );
			//_vertices.vertices[index].vertex = XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f );  // Bottom right.
			//_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 1.0f );
			index++;

			// Update the x location for drawing by the size of the letter and one pixel.
			drawX = drawX + m_type[letter].size + 1.0f;
		}
	}
}
Exemplo n.º 11
0
void GameOverState::Init()
{
	auto o = System::GetOptions();
	float width = (float)o->GetScreenResolutionWidth();
	float height = (float)o->GetScreenResolutionHeight();
	auto i = System::GetInput();
	auto c = _controller;
	auto a = System::GetInstance()->GetAudio();
	a->PlayBGMusic(L"mamb.wav", 0.5f);
	XMFLOAT4 TextColor = XMFLOAT4(41.0f / 255.0f, 127.0f / 255.0f, 185.0f / 255.0f, 1.0f);
	XMFLOAT4 ScoreTextColor = XMFLOAT4(17.0f / 255.0f, 166.0f / 255.0f, 67.0f / 255.0f, 1.0f);

	//==========================
	//====	High Score Text	====
	//==========================

	float widthPercentOfDefault = (1.0f / 1920.0f) * width;
	float heightPercentOfDefault = (1.0f / 1080.0f) * height;

	Entity scoreOverlay = _builder->CreateOverlay(XMFLOAT3(0.0f, 0.0f, 0.0f), 550.0f*widthPercentOfDefault, 350.0f*heightPercentOfDefault, "Assets/Textures/GameOverOverlay.png");

	float fontSize = 40 * widthPercentOfDefault;

	//High Score
	Entity textHighScore = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Statistics",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(textHighScore, (uint)(fontSize*1.5f));
	_builder->Transform()->SetPosition(textHighScore, XMFLOAT3(550.0f*widthPercentOfDefault / 2 - _builder->Text()->GetLength(textHighScore) / 2, 0.0f, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, textHighScore);

	//Light High Score
	Entity totalLightHighScoreText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Light Collected:",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalLightHighScoreText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalLightHighScoreText, XMFLOAT3(0.0f, fontSize*1.5f + fontSize * 0 + 10.0f * 1 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalLightHighScoreText);

	Entity totalLightCollectedText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		std::to_string(_thePlayer->GetTotalLightCollected()),
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalLightCollectedText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalLightCollectedText, XMFLOAT3(560.0f*widthPercentOfDefault / 2, fontSize*1.5f + fontSize * 0 + 10.0f * 1 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalLightCollectedText);


	//Shots Fired
	Entity totalShotsFiredHighScoreText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Shots Fired:",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalShotsFiredHighScoreText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalShotsFiredHighScoreText, XMFLOAT3(0.0f, fontSize*1.5f + fontSize * 1 + 10.0f * 2 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalShotsFiredHighScoreText);

	Entity totalShotsFiredText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		std::to_string(_thePlayer->GetShotsFired()),
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalShotsFiredText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalShotsFiredText, XMFLOAT3(560.0f*widthPercentOfDefault / 2, fontSize*1.5f + fontSize * 1 + 10.0f * 2 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalShotsFiredText);


	//Shots Connected
	Entity totalShotsConnectedHighScoreText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Shots Hitting:",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalShotsConnectedHighScoreText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalShotsConnectedHighScoreText, XMFLOAT3(0.0f, fontSize*1.5f + fontSize * 2 + 10.0f * 3 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalShotsConnectedHighScoreText);

	Entity totalShotsConnectedText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		std::to_string(_thePlayer->GetShotsConnected()),
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalShotsConnectedText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalShotsConnectedText, XMFLOAT3(560.0f*widthPercentOfDefault / 2, fontSize*1.5f + fontSize * 2 + 10.0f * 3 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalShotsConnectedText);


	//Hit Chance
	Entity totalHitChanceHighScoreText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Hit Percent:",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalHitChanceHighScoreText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalHitChanceHighScoreText, XMFLOAT3(0.0f, fontSize*1.5f + fontSize * 3 + 10.0f * 4 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalHitChanceHighScoreText);
	float value = _thePlayer->GetHitPercent();
	int intValue = static_cast<int>(value);
	Entity totalHitPercentText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		std::to_string(intValue) + "." + std::to_string(static_cast<int>((value-(float)intValue)*100))+ "%",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalHitPercentText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalHitPercentText, XMFLOAT3(560.0f*widthPercentOfDefault / 2, fontSize*1.5f + fontSize * 3 + 10.0f * 4 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalHitPercentText);


	//Enemies Defeated
	Entity totalEnemiesDefeatedScoreText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		"Enemies Defeated:",
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalEnemiesDefeatedScoreText, (uint)(fontSize*0.55f));
	_builder->Transform()->SetPosition(totalEnemiesDefeatedScoreText, XMFLOAT3(0.0f, fontSize*1.5f + fontSize * 4 + 10.0f * 5 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalEnemiesDefeatedScoreText);

	Entity totalEnemiesDefeatedText = _builder->CreateLabel(XMFLOAT3(0.0f, 0.0f, 0.0f),
		std::to_string(_thePlayer->GetEnemiesDefeated()),
		fontSize,
		ScoreTextColor,
		125.0f,
		25.0f,
		"");
	_builder->Text()->ChangeFontSize(totalEnemiesDefeatedText, (uint)(fontSize*0.75f));
	_builder->Transform()->SetPosition(totalEnemiesDefeatedText, XMFLOAT3(560.0f*widthPercentOfDefault / 2, fontSize*1.5f + fontSize * 4 + 10.0f * 5 * heightPercentOfDefault, 0.0f));
	_builder->Transform()->BindChild(scoreOverlay, totalEnemiesDefeatedText);



	//Set the overlay, and all it's childrens', positions.
	_builder->Transform()->SetPosition(scoreOverlay, XMFLOAT3(width - 550.0f*widthPercentOfDefault, height - 350.0f*heightPercentOfDefault, 0.0f));


	//==========================
	//====		Buttons		====
	//==========================


	// Start game button
	Entity b1 = _builder->CreateButton(
		XMFLOAT3(50.0f, height - 230.0f, 0.0f),
		"New Game",
		fontSize,
		TextColor,
		"",
		[i, a]()
	{
		a->PlaySoundEffect(L"menuclick.wav", 1);
		ChangeStateTo(StateChange(new GameState()));
	});

	//Options button
	Entity b5 = _builder->CreateButton(
		XMFLOAT3(50.0f, height - 180.0f, 0.0f),
		"Main Menu",
		fontSize,
		TextColor,
		"",
		[i, a]()
	{
		a->PlaySoundEffect(L"menuclick.wav", 1);
		ChangeStateTo(StateChange(new MenuState));
	});


	// Exit button
	Entity b2 = _builder->CreateButton(
		XMFLOAT3(50.0f, height - 130.0f, 0.0f),
		"Exit",
		fontSize,
		TextColor,
		"",
		[a]() {
		a->PlaySoundEffect(L"menuclick.wav", 1);
		ExitApplication;
	});

	//==========================
	//====	Background		====
	//==========================

	// Game Over text
	_builder->CreateLabel(
		XMFLOAT3(width / 2.0f - 100.0f, 25.0f, 0.0f),
		"Game Over",
		fontSize,
		TextColor,
		250.0f,
		45.0f,
		"");

	_altar = _builder->CreateObject(
		XMVectorSet(1.5f, 0.0f, 1.0f, 1.0f),
		XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f),
		XMVectorSet(0.5f, 0.5f, 0.5f, 0.0f),
		"Assets/Models/Altar.arf",
		"Assets/Textures/Altar_Albedo.png",
		"Assets/Textures/Altar_NM.png",
		"Assets/Textures/default_displacement.png",
		"Assets/Textures/Altar_Roughness.png");
	_builder->Material()->SetMaterialProperty(_altar, "ParallaxBias", -0.05f, "Shaders/GBuffer.hlsl");
	_builder->Material()->SetMaterialProperty(_altar, "ParallaxScaling", 0.12f, "Shaders/GBuffer.hlsl");


	_builder->Bounding()->CreateBoundingSphere(_altar, 2.0f);

	_altarCenterLight = _builder->EntityC().Create();
	_builder->Light()->BindPointLight(_altarCenterLight, XMFLOAT3(0.0f, 0.0f, 0.0f), 3.0f, XMFLOAT3(0.0f, 0.25f, 0.35f), 10.0f);
	_builder->Light()->ChangeLightBlobRange(_altarCenterLight, 1.0f);
	_builder->Transform()->CreateTransform(_altarCenterLight);
	_builder->Transform()->SetPosition(_altarCenterLight, XMFLOAT3(0.0f, 1.4f, 0.0f));
	_builder->Transform()->BindChild(_altar, _altarCenterLight);

	for (int i = 0; i < _numAltarBolts; ++i)
	{
		_altarBolts[i] = _builder->EntityC().Create();
		_builder->Light()->BindPointLight(_altarBolts[i], XMFLOAT3(0.0f, 0.0f, 0.0f), 1.0f, XMFLOAT3(0.35f, 1.0f, 0.25f), 5.0f);
		_builder->Light()->ChangeLightBlobRange(_altarBolts[i], 0.3f);
		_builder->Lightning()->CreateLightningBolt(_altarBolts[i], _altarCenterLight);
		_builder->Lightning()->SetScale(_altarBolts[i], XMFLOAT2(0.4f, 0.4f));
		_builder->Transform()->CreateTransform(_altarBolts[i]);
		_builder->Transform()->BindChild(_altarCenterLight, _altarBolts[i]);

		float angle = XM_2PI / _numAltarBolts;
		_builder->Transform()->SetPosition(_altarBolts[i], XMFLOAT3(1.5f * sinf(i * angle), 0.0f, 1.5f * cosf(i * angle)));

		_altarBoltAngle[i] = i * angle;
	}

	_builder->Transform()->SetPosition(_altar, XMFLOAT3(0.0f, 0.0f, 0.0f));


	_controller->BindEventHandler(_altar, EventManager::Type::Object);
	_controller->BindEvent(_altar, EventManager::EventType::Update,
		[this]()
	{
		_builder->Transform()->RotateYaw(_altarCenterLight, _gameTimer.DeltaTime() * 25.0f);
		static float animDeltaTime = 0;
		animDeltaTime += _gameTimer.DeltaTime();
		bool resetAnimTime = false;
		for (int i = 0; i < _numAltarBolts; ++i)
		{
			_altarBoltAngle[i] += _gameTimer.DeltaTime() * XM_PIDIV2 + _gameTimer.DeltaTime()*XM_PI * (i / 6);
			if (_altarBoltAngle[i] >= XM_2PI)
				_altarBoltAngle[i] -= XM_2PI;

			XMVECTOR pos = _builder->Transform()->GetPosition(_altarBolts[i]);
			_builder->Transform()->SetPosition(_altarBolts[i], XMVectorSetY(pos, 0.8f * sinf(_altarBoltAngle[i])));

			if (animDeltaTime >= 0.02f)
			{
				resetAnimTime = true;
				_builder->Lightning()->Animate(_altarBolts[i]);
			}
		}

		if (resetAnimTime)
			animDeltaTime -= 0.02f;

	});

	Entity camera = _builder->CreateCamera(XMVectorSet(0.0f, 1.0f, -3.0f, 0.0f));
	_builder->Transform()->SetRotation(camera, XMFLOAT3(0.0f, 0.0f, 0.0f));



	//==========================
	//====		Update		====
	//==========================

	_controller->BindEvent(b2, EventManager::EventType::Update, [i, this]()
	{
		if (i->IsKeyPushed(VK_ESCAPE))
		{
			ExitApplication;
		}
		if (i->IsKeyPushed('1'))
		{
			ChangeStateTo(StateChange(new GameState()));
		}
		if (i->IsKeyPushed('2'))
		{
			ChangeStateTo(StateChange(new MenuState()));
		}
	}
	);

}
Exemplo n.º 12
0
bool MultiTextureDemo::LoadContent()
{
	ID3DBlob * buffer = 0;

	bool compileResult = CompileD3DShader( "MultiTexture.fx" , 0 , "fx_5_0" , &buffer );
	
	if( compileResult == false )
	{
		DXTRACE_MSG( "±àÒëeffect shader ʧ°Ü£¡" );
		return false;
	}

	HRESULT d3dResult ;

	d3dResult = D3DX11CreateEffectFromMemory( buffer ->GetBufferPointer() , buffer ->GetBufferSize() , 0 , d3dDevice_ , &effect_ );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "´´½¨effect shader ʧ°Ü£¡" );
		
		if( buffer )
		{
			buffer ->Release();
		}
		return false;
	}

	D3D11_INPUT_ELEMENT_DESC solidColorLayout[ ] =
	{
		{ "POSITION" , 0 , DXGI_FORMAT_R32G32B32_FLOAT , 0 , 0 , D3D11_INPUT_PER_VERTEX_DATA , 0 } ,
		{ "TEXTURE" , 0 , DXGI_FORMAT_R32G32_FLOAT , 0 , 12 , D3D11_INPUT_PER_VERTEX_DATA , 0 }
	};

	unsigned int totalLayoutElements = ARRAYSIZE( solidColorLayout );

	ID3DX11EffectTechnique * MultiTexTechnique;

	MultiTexTechnique = effect_ ->GetTechniqueByName( "MultiTexture" );
	ID3DX11EffectPass * effectPass = MultiTexTechnique ->GetPassByIndex( 0 );

	D3DX11_PASS_SHADER_DESC passDesc;
	D3DX11_EFFECT_SHADER_DESC shaderDesc;
	effectPass->GetVertexShaderDesc( &passDesc );
	passDesc.pShaderVariable ->GetShaderDesc( passDesc.ShaderIndex , &shaderDesc );

	d3dResult = d3dDevice_ ->CreateInputLayout( solidColorLayout , totalLayoutElements , shaderDesc.pBytecode , shaderDesc.BytecodeLength , &inputLayout_ );
	buffer ->Release();

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "´´½¨ÊäÈë²ãʧ°Ü£¡" );
		return false;
	}

	
	VertexPos vertices[ ] = 
	{
		{ XMFLOAT3( -1.0f , 1.0f , -1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , -1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , 1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( -1.0f , 1.0f , 1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } ,

		{ XMFLOAT3( -1.0f , -1.0f , -1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , -1.0f , -1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , -1.0f , 1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( -1.0f , -1.0f , 1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } ,
		
		{ XMFLOAT3( -1.0f , -1.0f , 1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( -1.0f , -1.0f , -1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( -1.0f , 1.0f , -1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( -1.0f , 1.0f , 1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } ,

		{ XMFLOAT3( 1.0f , -1.0f , 1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , -1.0f , -1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , -1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , 1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } ,

		{ XMFLOAT3( -1.0f , -1.0f , -1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , -1.0f , -1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , -1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( -1.0f , 1.0f , -1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } ,

		{ XMFLOAT3( -1.0f , -1.0f , 1.0f ) , XMFLOAT2( 0.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , -1.0f , 1.0f ) , XMFLOAT2( 1.0f , 0.0f ) } ,
		{ XMFLOAT3( 1.0f , 1.0f , 1.0f ) , XMFLOAT2( 1.0f , 1.0f ) } ,
		{ XMFLOAT3( -1.0f , 1.0f , 1.0f ) , XMFLOAT2( 0.0f , 1.0f ) } 
	};

	D3D11_BUFFER_DESC vertexDesc;
	ZeroMemory( &vertexDesc , sizeof( vertexDesc ));
	vertexDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexDesc.ByteWidth = sizeof( VertexPos ) * 24;

	D3D11_SUBRESOURCE_DATA resourceData;
	ZeroMemory( &resourceData , sizeof( resourceData ));
	resourceData.pSysMem = vertices;

	d3dResult = d3dDevice_ ->CreateBuffer( &vertexDesc , &resourceData , &vertexBuffer_ );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "´´½¨¶¥µã»º³åÇøʧ°Ü£¡" );
		return false;
	}

	WORD indices[ ] =
	{
		3 , 1 , 0 , 2 , 1 , 3 ,
		6 , 4 , 5 , 7 , 4 , 6 ,
		11 , 9 , 8 , 10 , 9 , 11 ,
		14 , 12 , 13 , 15 , 12 , 14 ,
		19 , 17 , 16 , 18 , 17 , 19 ,
		22 , 20 , 21 ,23 , 20 , 22 
	};

	D3D11_BUFFER_DESC indexDesc;
	ZeroMemory( &indexDesc , sizeof( indexDesc ));
	indexDesc.Usage = D3D11_USAGE_DEFAULT ; 
	indexDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexDesc.ByteWidth = sizeof( WORD ) * 36 ;
	indexDesc.CPUAccessFlags = 0;
	resourceData.pSysMem = indices;

	d3dResult =d3dDevice_ ->CreateBuffer( &indexDesc , &resourceData , &indexBuffer_ );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "´´½¨Ë÷Òý»º³åÇøʧ°Ü£¡" );
		return false;
	}

	d3dResult = D3DX11CreateShaderResourceViewFromFile( d3dDevice_ , "decal.dds" , 0 , 0 , &colorMap_ , 0 );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "¼ÓÔØÎÆÀíͼÏñʧ°Ü£¡" );
		return false;
	}

	d3dResult = D3DX11CreateShaderResourceViewFromFile( d3dDevice_ , "decal2.dds" , 0 , 0 , &secondMap_ , 0 );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "¼ÓÔصڶþÎÆÀíͼÏñʧ°Ü£¡" );
		return false;
	}

	D3D11_SAMPLER_DESC colorMapDesc;
	ZeroMemory( &colorMapDesc , sizeof( colorMapDesc ));
	colorMapDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	colorMapDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX;

	d3dResult = d3dDevice_ ->CreateSamplerState( &colorMapDesc ,&colorMapSampler_ );

	if( FAILED( d3dResult ))
	{
		DXTRACE_MSG( "´´½¨²ÉÑùÆ÷ʧ°Ü£¡" );
		return false;
	}

	viewMatrix_ = XMMatrixIdentity();
	projMatrix_ = XMMatrixPerspectiveFovLH( XM_PIDIV4 , 800.0f / 600.0f , 0.01f , 100.0f );

	return true;

}
Exemplo n.º 13
0
bool BitmapClass::UpdateBuffers(ID3D11DeviceContext* deviceContext, int positionX, int positionY, int bitmapWidth, int bitmapHeight, float angle){
	float left, right, top, bottom;
	VertexType* vertices;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	VertexType* verticesPtr;
	HRESULT hr;

	if ((positionX == m_previousPosX) && (positionY == m_previousPosY) && (angle == m_previousAngle) && (bitmapWidth == m_bitmapWidth) && (bitmapHeight == m_bitmapHeight)){
		return true;
	}

	m_previousPosX = positionX;
	m_previousPosY = positionY;
	m_previousAngle = angle;
	m_bitmapWidth = bitmapWidth;
	m_bitmapHeight = bitmapHeight;

	left = (float)((m_screenWidth / 2)*-1) + (float)positionX - (float)m_bitmapWidth / 2.0f;
	right = left + (float)m_bitmapWidth;
	top = (float)(m_screenHeight / 2) - (float)positionY + (float)m_bitmapHeight / 2.0f;
	bottom = top - (float)m_bitmapHeight;

	float midPtX = (left + right) / 2.0f;
	float midPtY = (bottom + top) / 2.0f;
	float radius = (float)sqrt(pow(top - bottom, 2) + pow(right - left, 2))/2.0f;
	float refAngle = atan2(top - bottom, right - left);

	XMFLOAT3 topRight = XMFLOAT3(midPtX + radius*cos(refAngle + angle), midPtY + radius*sin(refAngle + angle), 0.0f);
	XMFLOAT3 topLeft = XMFLOAT3(midPtX + radius*cos(XM_PI - refAngle + angle), midPtY + radius*sin(XM_PI - refAngle + angle), 0.0f);
	XMFLOAT3 bottomLeft = XMFLOAT3(midPtX + radius*cos(XM_PI + refAngle + angle), midPtY + radius*sin(XM_PI + refAngle + angle), 0.0f);
	XMFLOAT3 bottomRight = XMFLOAT3(midPtX + radius*cos(XM_2PI - refAngle + angle), midPtY + radius*sin(XM_2PI - refAngle + angle), 0.0f);

	vertices = new VertexType[m_vertexCount];
	if (!vertices){
		return false;
	}

	//vertices[0].position = XMFLOAT3(left, top, 0.0f);
	//vertices[0].texture = XMFLOAT2(0.0f, 0.0f);
	//vertices[1].position = XMFLOAT3(right, bottom, 0.0f);
	//vertices[1].texture = XMFLOAT2(1.0f, 1.0f);
	//vertices[2].position = XMFLOAT3(left, bottom, 0.0f);
	//vertices[2].texture = XMFLOAT2(0.0f, 1.0f);
	//vertices[3].position = XMFLOAT3(left, top, 0.0f);
	//vertices[3].texture = XMFLOAT2(0.0f, 0.0f);
	//vertices[4].position = XMFLOAT3(right, top, 0.0f);
	//vertices[4].texture = XMFLOAT2(1.0f, 0.0f);
	//vertices[5].position = XMFLOAT3(right, bottom, 0.0f);
	//vertices[5].texture = XMFLOAT2(1.0f, 1.0f);

	vertices[0].position = topLeft;
	vertices[0].texture = XMFLOAT2(0.0f, 0.0f);
	vertices[1].position = bottomRight;
	vertices[1].texture = XMFLOAT2(1.0f, 1.0f);
	vertices[2].position = bottomLeft;
	vertices[2].texture = XMFLOAT2(0.0f, 1.0f);
	vertices[3].position = topLeft;
	vertices[3].texture = XMFLOAT2(0.0f, 0.0f);
	vertices[4].position = topRight;
	vertices[4].texture = XMFLOAT2(1.0f, 0.0f);
	vertices[5].position = bottomRight;
	vertices[5].texture = XMFLOAT2(1.0f, 1.0f);

	hr = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(hr)){
		return false;
	}

	verticesPtr = (VertexType*)mappedResource.pData;
	memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType)*m_vertexCount));

	deviceContext->Unmap(m_vertexBuffer, 0);
	delete[] vertices;
	vertices = 0;

	return true;
}
Exemplo n.º 14
0
HRESULT mesh_square_tessellation::find_point(point_with_tangent *vertex, UINT *index, int &num_vertex, int &num_index)
{
	point_with_tangent square_test[] =
	{
		{ XMFLOAT3(-1.0f,1.0f,1.0f), XMFLOAT3(0.0f,1.0f,0.0f), XMFLOAT3(1.0f,0.0f,0.0f),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0f,0.0f) },
		{ XMFLOAT3(1.0f,1.0f,1.0f),  XMFLOAT3(0.0f,1.0f,0.0f), XMFLOAT3(1.0f,0.0f,0.0f),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0f,0.0f) },
		{ XMFLOAT3(-1.0f,1.0f,-1.0f),XMFLOAT3(0.0f,1.0f,0.0f), XMFLOAT3(1.0f,0.0f,0.0f),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(1.0f,1.0f) },
		{ XMFLOAT3(1.0f,1.0f,-1.0f), XMFLOAT3(0.0f,1.0f,0.0f), XMFLOAT3(1.0f,0.0f,0.0f),XMUINT4(1.0f,0.0f,0.0f,0.0f), XMFLOAT2(0.0f,1.0f) },
	};
	for (int i = 0; i < 4; ++i)
	{
		vertex[i] = square_test[i];
	}
	num_vertex = 4;
	num_index = 0;
	return S_OK;
}
Exemplo n.º 15
0
		inline XMFLOAT2 left_thumb() {
			return XMFLOAT2(
				dpc<short>(raw_state.Gamepad.sThumbLX, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE),
				dpc<short>(raw_state.Gamepad.sThumbLY, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE));
		}
Exemplo n.º 16
0
bool DebugWindowClass::UpdateBuffers(ID3D11DeviceContext* deviceContext, int positionX, int positionY)
{
	float left, right, top, bottom;
	VertexType* vertices;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	VertexType* verticesPtr;
	HRESULT result;


	// If the position we are rendering this bitmap to has not changed then don't update the vertex buffer since it
	// currently has the correct parameters.
	if((positionX == m_previousPosX) && (positionY == m_previousPosY))
	{
		return true;
	}
	
	// If it has changed then update the position it is being rendered to.
	m_previousPosX = positionX;
	m_previousPosY = positionY;

	// Calculate the screen coordinates of the left side of the bitmap.
	left = (float)((m_screenWidth / 2) * -1) + (float)positionX;

	// Calculate the screen coordinates of the right side of the bitmap.
	right = left + (float)m_bitmapWidth;

	// Calculate the screen coordinates of the top of the bitmap.
	top = (float)(m_screenHeight / 2) - (float)positionY;

	// Calculate the screen coordinates of the bottom of the bitmap.
	bottom = top - (float)m_bitmapHeight;

	// Create the vertex array.
	vertices = new VertexType[m_vertexCount];
	if(!vertices)
	{
		return false;
	}

	// Load the vertex array with data.
	// First triangle.
	vertices[0].position = XMFLOAT3(left, top, 10.0f);  // Top left.
	vertices[0].texture = XMFLOAT2(0.0f, 0.0f);

	vertices[1].position = XMFLOAT3(right, bottom, 10.0f);  // Bottom right.
	vertices[1].texture = XMFLOAT2(1.0f, 1.0f);

	vertices[2].position = XMFLOAT3(left, bottom,10.0f);  // Bottom left.
	vertices[2].texture = XMFLOAT2(0.0f, 1.0f);

	// Second triangle.
	vertices[3].position = XMFLOAT3(left, top, 10.0f);  // Top left.
	vertices[3].texture = XMFLOAT2(0.0f, 0.0f);

	vertices[4].position = XMFLOAT3(right, top, 10.0f);  // Top right.
	vertices[4].texture = XMFLOAT2(1.0f, 0.0f);

	vertices[5].position = XMFLOAT3(right, bottom, 10.0f);  // Bottom right.
	vertices[5].texture = XMFLOAT2(1.0f, 1.0f);

	// Lock the vertex buffer so it can be written to.
	result = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if(FAILED(result))
	{
		return false;
	}

	// Get a pointer to the data in the vertex buffer.
	verticesPtr = (VertexType*)mappedResource.pData;

	// Copy the data into the vertex buffer.
	memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType) * m_vertexCount));

	// Unlock the vertex buffer.
	deviceContext->Unmap(m_vertexBuffer, 0);

	// Release the vertex array as it is no longer needed.
	delete [] vertices;
	vertices = 0;

	return true;
}
Exemplo n.º 17
0
		inline XMFLOAT2 right_thumb() {
			return XMFLOAT2(
				dpc<short>(raw_state.Gamepad.sThumbRX, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE),
				dpc<short>(raw_state.Gamepad.sThumbRY, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE));
		}
Exemplo n.º 18
0
XMFLOAT2 Mesh::toXMFloat2(aiVector3D a_Vector)
{
	return XMFLOAT2(a_Vector.x, a_Vector.y);
}
Exemplo n.º 19
0
bool TerrainClass::InitializeBuffers(ID3D11Device* device)
{
	int index, i, j, index1, index2, index3, index4;
	float tu, tv;


	// Calculate the number of vertices in the terrain mesh.
	m_vertexCount = (m_terrainWidth - 1) * (m_terrainHeight - 1) * 6;

	// Create the vertex array.
	m_vertices = new VertexType[m_vertexCount];
	if(!m_vertices)
	{
		return false;
	}

	// Initialize the index to the vertex buffer.
	index = 0;

	// Load the vertex and index array with the terrain data.
	for(j=0; j<(m_terrainHeight-1); j++)
	{
		for(i=0; i<(m_terrainWidth-1); i++)
		{
			index1 = (m_terrainHeight * j) + i;          // Bottom left.
			index2 = (m_terrainHeight * j) + (i+1);      // Bottom right.
			index3 = (m_terrainHeight * (j+1)) + i;      // Upper left.
			index4 = (m_terrainHeight * (j+1)) + (i+1);  // Upper right.

			// Upper left.
			tv = m_heightMap[index3].tv;

			// Modify the texture coordinates to cover the top edge.
			if(tv == 1.0f) { tv = 0.0f; }

			m_vertices[index].position = XMFLOAT3(m_heightMap[index3].x, m_heightMap[index3].y, m_heightMap[index3].z);
			m_vertices[index].texture = XMFLOAT2(m_heightMap[index3].tu, tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index3].nx, m_heightMap[index3].ny, m_heightMap[index3].nz);
			index++;

			// Upper right.
			tu = m_heightMap[index4].tu;
			tv = m_heightMap[index4].tv;

			// Modify the texture coordinates to cover the top and right edge.
			if(tu == 0.0f) { tu = 1.0f; }
			if(tv == 1.0f) { tv = 0.0f; }

			m_vertices[index].position = XMFLOAT3(m_heightMap[index4].x, m_heightMap[index4].y, m_heightMap[index4].z);
			m_vertices[index].texture = XMFLOAT2(tu, tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index4].nx, m_heightMap[index4].ny, m_heightMap[index4].nz);
			index++;

			// Bottom left.
			m_vertices[index].position = XMFLOAT3(m_heightMap[index1].x, m_heightMap[index1].y, m_heightMap[index1].z);
			m_vertices[index].texture = XMFLOAT2(m_heightMap[index1].tu, m_heightMap[index1].tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index1].nx, m_heightMap[index1].ny, m_heightMap[index1].nz);
			index++;

			// Bottom left.
			m_vertices[index].position = XMFLOAT3(m_heightMap[index1].x, m_heightMap[index1].y, m_heightMap[index1].z);
			m_vertices[index].texture = XMFLOAT2(m_heightMap[index1].tu, m_heightMap[index1].tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index1].nx, m_heightMap[index1].ny, m_heightMap[index1].nz);
			index++;

			// Upper right.
			tu = m_heightMap[index4].tu;
			tv = m_heightMap[index4].tv;

			// Modify the texture coordinates to cover the top and right edge.
			if(tu == 0.0f) { tu = 1.0f; }
			if(tv == 1.0f) { tv = 0.0f; }

			m_vertices[index].position = XMFLOAT3(m_heightMap[index4].x, m_heightMap[index4].y, m_heightMap[index4].z);
			m_vertices[index].texture = XMFLOAT2(tu, tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index4].nx, m_heightMap[index4].ny, m_heightMap[index4].nz);
			index++;

			// Bottom right.
			tu = m_heightMap[index2].tu;

			// Modify the texture coordinates to cover the right edge.
			if(tu == 0.0f) { tu = 1.0f; }

			m_vertices[index].position = XMFLOAT3(m_heightMap[index2].x, m_heightMap[index2].y, m_heightMap[index2].z);
			m_vertices[index].texture = XMFLOAT2(tu, m_heightMap[index2].tv);
			m_vertices[index].normal = XMFLOAT3(m_heightMap[index2].nx, m_heightMap[index2].ny, m_heightMap[index2].nz);
			index++;
		}
	}

	return true;
}
Exemplo n.º 20
0
void Game::Draw(){

	float fill[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
	context->ClearRenderTargetView(backbuffer, fill);

	context->OMSetRenderTargets(1, &backbuffer, 0 );
	float oX = 14.0f;
	float oY = -12.0f;


	sb->Begin(SpriteSortMode_Deferred, states->NonPremultiplied());

	sb->Draw(c1, XMFLOAT2(0.0f, 0.0f));

	float rxLoc = 655 + (B_RX * 0.001);
	float ryLoc = 300 + (B_RY * 0.001);	
	float lxLoc = 492 + (B_LX * 0.001);
	float lyLoc = 300 + (B_LY * 0.001);

		sb->Draw(b_circle, XMFLOAT2(rxLoc + oX, ryLoc + oY));
		sb->Draw(b_circle, XMFLOAT2(lxLoc + oX, lyLoc + oY));

		if (B_L1) {
			sb->Draw(b_lsmall, XMFLOAT2(395.0f + oX, 68.0f + oY));

		}
		if (B_L2) {
			sb->Draw(b_l_larger, XMFLOAT2(395.0f + oX, 10.0f + oY));
		}
		if (B_L3) {

		}

		if (B_R1) {
			sb->Draw(b_lsmall, XMFLOAT2(731.0f + oX, 68.0f + oY));
		}
		if (B_R2) {
			sb->Draw(b_l_larger, XMFLOAT2(731.0f + oX, 10.0f + oY));
		}
		if (B_R3){

		}
		if (B_1) {
			sb->Draw(b_circle, XMFLOAT2(740.0f + oX, 176.0f + oY));
			//AddString(L"Y");
			//countY++;
		}
		if (B_2) {
			sb->Draw(b_circle, XMFLOAT2(702.0f + oX, 216.0f + oY));
			//AddString(L"X");
			//countX++;
		}
		if (B_3) {
			sb->Draw(b_circle, XMFLOAT2(740.0f + oX, 255.0f + oY));
			//AddString(L"A");
			//countA++;
		}
		if (B_4) {
			sb->Draw(b_circle, XMFLOAT2(783.0f + oX, 216.0f + oY));
			//AddString(L"B");
			//countB++;
		}
		if (B_9) {
			sb->Draw(b_square, XMFLOAT2(537.0f + oX, 237.0f + oY));
		}
		if (B_10) {
			sb->Draw(b_square, XMFLOAT2(634.0f + oX, 237.0f + oY));
		}
		if (B_11) {
			sb->Draw(b_square, XMFLOAT2(0.0f + oX, 0.0f + oY));
		}
		if (B_12) {
			sb->Draw(b_square, XMFLOAT2(0.0f + oX, 0.0f + oY));
		}
		if (B_UP) {
			sb->Draw(b_dpad, XMFLOAT2(419.0f + oX, 190.0f + oY));
		}
		if (B_DOWN) {
			sb->Draw(b_dpad, XMFLOAT2(419.0f + oX, 255.0f + oY));
		}
		if (B_LEFT) { 
			sb->Draw(b_dpad, XMFLOAT2(390.0f + oX, 222.0f + oY));
		}
		if (B_RIGHT) {
			sb->Draw(b_dpad, XMFLOAT2(452.0f + oX, 222.0f + oY));
		}

	//float B_LX, B_LY, B_RX, B_LY; sb->Draw(b_smallecircle, XMFLOAT2(0.0f, 0.0f));

		wstring tempS;
	sf->DrawString(sb, L"GAME ANAYLTICS TOOL", XMFLOAT2(50, 100));
	tempS = L"Current Section:" + to_wstring(section);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 120));
	tempS = L"Num of times A pressed:" + to_wstring(countA);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 140));
	tempS = L"Num of times B pressed:" + to_wstring(countB);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 160));
	tempS = L"Num of times X pressed:" + to_wstring(countX);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 180));
	tempS = L"Num of times Y pressed:" + to_wstring(countY);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 200));
	tempS = L"Num of times L1 pressed:" + to_wstring(countL);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 220));
	tempS = L"Num of times R1 pressed:" + to_wstring(countR);
	sf->DrawString(sb, tempS.c_str(), XMFLOAT2(50, 240));


	int tW = 30;
	int tH = 460;

	int tCurrent = currentItem;

	



	for (int i = 0; i < numberOfItems; i++) {
		
		int y = tCurrent;
		if(y <= 9 && filled == 0)sf->DrawString(sb, stringList[i].c_str(), XMFLOAT2(tW, tH));
		if (y <= 9 && filled == 1) {

			int tt = (tCurrent - 10) + i;
			if (tt < 0)tt += 240;

			sf->DrawString(sb, stringList[tt].c_str(), XMFLOAT2(tW, tH));
		}
		else if ( y >=10 && y <= 240 )sf->DrawString(sb, stringList[(tCurrent - 10) + i].c_str(), XMFLOAT2(tW, tH));
		
		
		
		

		tH += 20;

	}

	//sf->DrawString(sb, stringList[numberOfItems].c_str(), XMFLOAT2(tW+300, tH));



	sb->End();


	swapchain->Present(1, 0);
}
Exemplo n.º 21
0
void Game::InitBoundingBoxes()
{
	//player bounding box
	playerBB.pos.x = mPlayer->GetPos().m128_f32[0];
	playerBB.pos.y = mPlayer->GetPos().m128_f32[1];
	playerBB.height = 12.0f;
	playerBB.width = 12.0f;

	//environment bounding boxes
	bb1.pos = XMFLOAT2(0.0f, 736.0f);
	bb1.height = 32.0f;
	bb1.width = 1024.0f;
	boxes.push_back(bb1);

	bb2.pos = XMFLOAT2(0.0f, 32.0f);
	bb2.height = 704.0f;
	bb2.width = 40.0f;
	boxes.push_back(bb2);

	bb3.pos = XMFLOAT2(0.0f, 0.0f);
	bb3.height = 48.0f;
	bb3.width = 1024.0f;
	boxes.push_back(bb3);

	bb4.pos = XMFLOAT2(995.0f, 32.0f);
	bb4.height = 704.0f;
	bb4.width = 32.0f;
	boxes.push_back(bb4);

	bb5.pos = XMFLOAT2(32.0f, 672.0f);
	bb5.height = 64.0f;
	bb5.width = 40.0f;
	boxes.push_back(bb5);

	bb6.pos = XMFLOAT2(64.0f, 704.0f);
	bb6.height = 32.0f;
	bb6.width = 72.0f;
	boxes.push_back(bb6);

	bb7.pos = XMFLOAT2(899.0f, 704.0f);
	bb7.height = 32.0f;
	bb7.width = 64.0f;
	boxes.push_back(bb7);

	bb8.pos = XMFLOAT2(963.0f, 672.0f);
	bb8.height = 64.0f;
	bb8.width = 32.0f;
	boxes.push_back(bb8);

	bb9.pos = XMFLOAT2(227.0f, 608.0f);
	bb9.height = 48.0f;
	bb9.width = 70.0f;
	boxes.push_back(bb9);

	bb10.pos = XMFLOAT2(419.0f, 576.0f);
	bb10.height = 48.0f;
	bb10.width = 198.0f;
	boxes.push_back(bb10);

	bb11.pos = XMFLOAT2(451.0f, 544.0f);
	bb11.height = 48.0f;
	bb11.width = 134.0f;
	boxes.push_back(bb11);

	bb12.pos = XMFLOAT2(739.0f, 608.0f);
	bb12.height = 48.0f;
	bb12.width = 70.0f;
	boxes.push_back(bb12);

	bb13.pos = XMFLOAT2(32.0f, 479.0f);
	bb13.height = 81.0f;
	bb13.width = 105.0f;
	boxes.push_back(bb13);

	bb14.pos = XMFLOAT2(128.0f, 512.0f);
	bb14.height = 48.0f;
	bb14.width = 73.0f;
	boxes.push_back(bb14);

	bb15.pos = XMFLOAT2(835.0f, 512.0f);
	bb15.height = 48.0f;
	bb15.width = 73.0f;
	boxes.push_back(bb15);

	bb16.pos = XMFLOAT2(899.0f, 479.0f);
	bb16.height = 81.0f;
	bb16.width = 105.0f;
	boxes.push_back(bb16);

	bb17.pos = XMFLOAT2(259.0f, 351.0f);
	bb17.height = 113.0f;
	bb17.width = 102.0f;
	boxes.push_back(bb17);

	bb18.pos = XMFLOAT2(675.0f, 351.0f);
	bb18.height = 113.0f;
	bb18.width = 102.0f;
	boxes.push_back(bb18);

	bb19.pos = XMFLOAT2(32.0f, 224.0f);
	bb19.height = 112.0f;
	bb19.width = 72.0f;
	boxes.push_back(bb19);

	bb20.pos = XMFLOAT2(487.0f, 256.0f);
	bb20.height = 78.0f;
	bb20.width = 64.0f;
	boxes.push_back(bb20);

	bb21.pos = XMFLOAT2(932.0f, 224.0f);
	bb21.height = 112.0f;
	bb21.width = 72.0f;
	boxes.push_back(bb21);

	bb22.pos = XMFLOAT2(32.0f, 160.0f);
	bb22.height = 79.0f;
	bb22.width = 104.0f;
	boxes.push_back(bb22);

	bb23.pos = XMFLOAT2(453.0f, 192.0f);
	bb23.height = 78.0f;
	bb23.width = 130.0f;
	boxes.push_back(bb23);

	bb24.pos = XMFLOAT2(900.0f, 160.0f);
	bb24.height = 80.0f;
	bb24.width = 104.0f;
	boxes.push_back(bb24);

	bb25.pos = XMFLOAT2(32.0f, 32.0f);
	bb25.height = 144.0f;
	bb25.width = 264.0f;
	boxes.push_back(bb25);

	bb26.pos = XMFLOAT2(288.0f, 128.0f);
	bb26.height = 48.0f;
	bb26.width = 41.0f;
	boxes.push_back(bb26);

	bb27.pos = XMFLOAT2(484.0f, 159.0f);
	bb27.height = 48.0f;
	bb27.width = 70.0f;
	boxes.push_back(bb27);

	bb28.pos = XMFLOAT2(707.0f, 128.0f);
	bb28.height = 48.0f;
	bb28.width = 41.0f;
	boxes.push_back(bb28);

	bb29.pos = XMFLOAT2(740.0f, 32.0f);
	bb29.height = 144.0f;
	bb29.width = 264.0f;
	boxes.push_back(bb29);

	bb30.pos = XMFLOAT2(227.0f, 350.0f);
	bb30.height = 45.0f;
	bb30.width = 40.0f;
	boxes.push_back(bb30);

	bb31.pos = XMFLOAT2(771.0f, 350.0f);
	bb31.height = 45.0f;
	bb31.width = 40.0f;
	boxes.push_back(bb31);
}
Exemplo n.º 22
0
LightingDemo2::LightingDemo2()
{
    //
    // User input
    //
    mLastMousePos.x = 0;
    mLastMousePos.y = 0;

    //
    // Camera
    //
    mCam.SetPosition(0.0f, 2.0f, -15.0f);


    //
    // RenderOptions
    //
    mRenderOptions = TexturesAndFog;

    //
    // Skull
    //
    mSkullVB = 0; 
    mSkullIB = 0; 
    mSkullIndexCount = 0;

    XMMATRIX skullScale = XMMatrixScaling(1.f, 1.f, 1.f);
    XMMATRIX skullTranslation = XMMatrixTranslation(0.f, 10.f, 0.f);
    XMStoreFloat4x4(&mSkullWorld, XMMatrixMultiply(skullScale, skullTranslation));

    mSkullMaterial.Ambient  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
    mSkullMaterial.Diffuse  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
    mSkullMaterial.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);

    //
    // Cigar Pack
    //
    mCigVB = 0;
    mCigIB = 0;
    mCigVertexOffset = 0;
    mCigIndexOffset = 0;
    mCigIndexCount = 0;
    mCigMapSRV = 0;

    XMMATRIX cigScale = XMMatrixScaling(1.f, 1.f, 1.f);
    XMMATRIX cigTranslation = XMMatrixTranslation(-10.f, 15.f, 10.f);
    XMStoreFloat4x4(&mCigWorld, XMMatrixMultiply(cigScale, cigTranslation));
    mCigMaterial.Ambient  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
    mCigMaterial.Diffuse  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
    mCigMaterial.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 128.0f);


    //
    // Box
    //
    mBoxVB = 0;
    mBoxIB = 0;
    mBoxVertexOffset = 0;
    mBoxIndexOffset = 0;
    mBoxIndexCount = 0;
    mBoxMapSRV = 0;

    XMMATRIX boxScale = XMMatrixScaling(15.f, 15.f, 15.f);
    XMMATRIX boxTranslation = XMMatrixTranslation(8.f, 5.f, -15.f);
    XMStoreFloat4x4(&mBoxWorld, XMMatrixMultiply(boxScale, boxTranslation));

    mBoxMaterial.Ambient  = XMFLOAT4(0.651f, 0.5f, 0.392f, 1.0f);
    mBoxMaterial.Diffuse  = XMFLOAT4(0.651f, 0.5f, 0.392f, 1.0f);
    mBoxMaterial.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f);

    //
    // Land/Terrain
    //
    mLandVB = 0;
    mLandIB = 0;
    mLandIndexCount = 0;
    mGrassMapSRV = 0;

    ;

    XMStoreFloat4x4(&mLandWorld, XMMatrixIdentity());

    XMMATRIX grassTexScale = XMMatrixScaling(5.0f, 5.0f, 0.0f);
    XMStoreFloat4x4(&mGrassTexTransform, grassTexScale);

    mLandMaterial.Ambient  = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
    mLandMaterial.Diffuse  = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
    mLandMaterial.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f);

    //
    // Waves
    //
    mWavesVB = 0;
    mWavesIB = 0;
    mWavesMapSRV = 0; 
    mWaterTexOffset = XMFLOAT2(0.f, 0.f);

    XMStoreFloat4x4(&mWavesWorld, XMMatrixIdentity());

    mWavesMaterial.Ambient  = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
    mWavesMaterial.Diffuse  = XMFLOAT4(1.0f, 1.0f, 1.0f, 0.5f);
    mWavesMaterial.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 32.0f);

    //
    // Environmental Lights
    //
    mLightCount = 1;
    mEyePosWorld = XMFLOAT3(0.f, 0.f, 0.f); 

    mDirLights[0].Ambient  = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f);
    mDirLights[0].Diffuse  = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
    mDirLights[0].Specular = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
    mDirLights[0].Direction = XMFLOAT3(0.57735f, -0.57735f, 0.57735f);

    mDirLights[1].Ambient  = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
    mDirLights[1].Diffuse  = XMFLOAT4(0.20f, 0.20f, 0.20f, 1.0f);
    mDirLights[1].Specular = XMFLOAT4(0.25f, 0.25f, 0.25f, 1.0f);
    mDirLights[1].Direction = XMFLOAT3(-0.57735f, -0.57735f, 0.57735f);

    mDirLights[2].Ambient  = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
    mDirLights[2].Diffuse  = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f);
    mDirLights[2].Specular = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
    mDirLights[2].Direction = XMFLOAT3(0.0f, -0.707f, -0.707f);
}
Exemplo n.º 23
0
void Camera::SetViewSize(float width, float height)
{
  mViewSize = XMFLOAT2(width, height);
  SetAspectRatio(width / height);
}
Exemplo n.º 24
0
//--------------------------------------------------------------------------------------
// Initiates the manoeuvre. This mostly consists of sending initial orders to all
// participating entities and everything that is involved in that process, such as 
// determining targets etc.
// Returns a behaviour status code representing the current state of the initiation of the manoeuvre.
//--------------------------------------------------------------------------------------
BehaviourStatus RunTheFlagHome::Initiate(void)
{
	for(std::vector<Entity*>::iterator it = m_participants.begin(); it != m_participants.end(); ++it)
	{
		// Run the flag to the home base ignoring all enemies
		// Note: In future versions the manoeuvre should send the carrier on a path, where he is less likely to
		//       encounter enemies.
		Order* pNewOrder = new MoveOrder((*it)->GetId(), MoveToPositionOrder, HighPriority, XMFLOAT2(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition));
			
		if(!pNewOrder)
		{
			return StatusFailure;
		}

		FollowOrderMessageData data(pNewOrder);
		SendMessage(*it, FollowOrderMessageType, &data);

		m_activeOrders.insert(std::pair<unsigned long, Order*>((*it)->GetId(), pNewOrder));
	}
	
	return StatusSuccess;
}
Exemplo n.º 25
0
CDebugRender::CDebugRender(ID3D11Device *Device)
{
    //AXIS
    m_Effect=CApplicationDX::GetApplicationDX()->GetEffectManager()->GetEffect(KG_POSITION_COLOR_VERTEX::GetVertexType());
    KG_POSITION_COLOR_VERTEX l_AxisVtxs[6]=
    {
        {XMFLOAT3( 0.0f, 0.0f, 0.0f ), XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f)},
        {XMFLOAT3( 1.0f, 0.0f, 0.0f ), XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f)},

        {XMFLOAT3( 0.0f, 0.0f, 0.0f ), XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f)},
        {XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f)},

        {XMFLOAT3( 0.0f, 0.0f, 0.0f ), XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f)},
        {XMFLOAT3( 0.0f, 0.0f, 1.0f ), XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f)}
    };

    m_AxisRenderableVertexs=new CLinesListRenderableVertexs<KG_POSITION_COLOR_VERTEX>(Device, l_AxisVtxs, 6, 3);

    //CUBE
    const float l_SizeCube=1.0f;
    KG_POSITION_COLOR_VERTEX l_CubeVtxs[]=
    {
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        //tapa
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        //lineas laterales
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(-l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,-l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,-l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
        {XMFLOAT3(l_SizeCube/2.0f,l_SizeCube/2.0f,l_SizeCube/2.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)}
    };

    m_CubeRenderableVertexs=new CLinesListRenderableVertexs<KG_POSITION_COLOR_VERTEX>(Device, l_CubeVtxs, 24, 12);

    //GRID
    float l_Size=10.0f;
    const int l_Grid=10;
    KG_POSITION_COLOR_VERTEX l_GridVtxs[(l_Grid+1)*2*2];
    for(int b=0; b<=l_Grid; ++b)
    {
        l_GridVtxs[b*2].Position=XMFLOAT3(-l_Size/2.0f+((float)(b*l_Size))/(float)l_Grid,0.0f,-l_Size/2.0f);
        l_GridVtxs[b*2].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
        l_GridVtxs[(b*2)+1].Position=XMFLOAT3(-l_Size/2.0f+((float)(b*l_Size))/(float)l_Grid,0.0f,l_Size/2.0f);
        l_GridVtxs[(b*2)+1].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
    }
    //LINEAS EN X
    for(int b=0; b<=l_Grid; ++b)
    {
        l_GridVtxs[(l_Grid+1)*2+(b*2)].Position=XMFLOAT3(-l_Size/2.0f,0.0f,-l_Size/2.0f+((float)(b*l_Size))/(float)l_Grid);
        l_GridVtxs[(l_Grid+1)*2+(b*2)].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
        l_GridVtxs[(l_Grid+1)*2+(b*2)+1].Position=XMFLOAT3(l_Size/2.0f,0.0f,-l_Size/2.0f+((float)(b*l_Size))/(float)l_Grid);
        l_GridVtxs[(l_Grid+1)*2+(b*2)+1].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
    }

    m_GridRenderableVertexs=new CLinesListRenderableVertexs<KG_POSITION_COLOR_VERTEX>(Device, l_GridVtxs, (l_Grid+1)*2*2, (l_Grid+1)*2);

    //SPHERE
    const int l_Aristas=10;
    KG_POSITION_COLOR_VERTEX l_SphereVtxs[4*l_Aristas*l_Aristas];
    for(int t=0; t<l_Aristas; ++t)
    {
        float l_RadiusRing=sin(DEG2RAD(180.0f*((float)t))/((float)l_Aristas));
        for(int b=0; b<l_Aristas; ++b)
        {
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+0].Position=XMFLOAT3(l_RadiusRing*cos(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))),cos(DEG2RAD(180.0f*((float)t))/((float)l_Aristas)),l_RadiusRing*sin(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))));
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+0].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+1].Position=XMFLOAT3(l_RadiusRing*cos(DEG2RAD((float)(360.0f*(float)(b+1))/((float)l_Aristas))),cos(DEG2RAD(180.0f*((float)t))/((float)l_Aristas)),l_RadiusRing*sin(DEG2RAD((float)(360.0f*(float)(b+1))/((float)l_Aristas))));
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+1].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);

            float l_RadiusNextRing=sin(DEG2RAD(180.0f*((float)(t+1)))/((float)l_Aristas));

            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+2].Position=XMFLOAT3(l_RadiusRing*cos(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))),cos(DEG2RAD(180.0f*((float)t))/((float)l_Aristas)),l_RadiusRing*sin(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))));
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+2].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+3].Position=XMFLOAT3(l_RadiusNextRing*cos(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))),cos(DEG2RAD(180.0f*((float)(t+1)))/((float)l_Aristas)),l_RadiusNextRing*sin(DEG2RAD((float)(360.0f*(float)b)/((float)l_Aristas))));
            l_SphereVtxs[(t*l_Aristas*4)+(b*4)+3].Color=XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
        }
    }
    m_SphereRenderableVertexs=new CLinesListRenderableVertexs<KG_POSITION_COLOR_VERTEX>(Device, l_SphereVtxs, 4*l_Aristas*l_Aristas, 2*l_Aristas*l_Aristas);

    //DRAWQUAD
    m_DrawQuadEffect=CApplicationDX::GetApplicationDX()->GetEffectManager()->GetEffect(KG_POSITION4_COLOR_TEXTURE_VERTEX::GetVertexType());

    KG_POSITION4_COLOR_TEXTURE_VERTEX l_ScreenVertexsQuad[4]=
    {
        {XMFLOAT4(-1.0f, 1.0f, 0.5f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT2(0.0f, 0.0f)},
        {XMFLOAT4(1.0f, 1.0f, 0.5f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT2(1.0f, 0.0f)},
        {XMFLOAT4(-1.0f, -1.0f, 0.5f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT2(0.0f, 1.0f)},
        {XMFLOAT4(1.0f, -1.0f, 0.5f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT2(1.0f, 1.0f)}
    };
    m_DrawQuadRV=new CTrianglesStripRenderableVertexs<KG_POSITION4_COLOR_TEXTURE_VERTEX>(Device, l_ScreenVertexsQuad, 4, 2);

    D3D11_BLEND_DESC l_AlphablendDesc;
    ZeroMemory(&l_AlphablendDesc, sizeof(D3D11_BLEND_DESC));
    l_AlphablendDesc.RenderTarget[0].BlendEnable=true;
    l_AlphablendDesc.RenderTarget[0].SrcBlend=D3D11_BLEND_SRC_ALPHA;
    l_AlphablendDesc.RenderTarget[0].DestBlend=D3D11_BLEND_INV_SRC_ALPHA;
    l_AlphablendDesc.RenderTarget[0].BlendOp=D3D11_BLEND_OP_ADD;
    l_AlphablendDesc.RenderTarget[0].SrcBlendAlpha=D3D11_BLEND_ONE;
    l_AlphablendDesc.RenderTarget[0].DestBlendAlpha=D3D11_BLEND_ONE;
    l_AlphablendDesc.RenderTarget[0].BlendOpAlpha=D3D11_BLEND_OP_ADD;
    l_AlphablendDesc.RenderTarget[0].RenderTargetWriteMask=D3D11_COLOR_WRITE_ENABLE_ALL;

    if(FAILED(Device->CreateBlendState(&l_AlphablendDesc, &m_DrawQuadBlendState)))
        return;

    //RENDER STATES
    D3D11_RASTERIZER_DESC l_WireframeDesc;
    ZeroMemory(&l_WireframeDesc, sizeof(D3D11_RASTERIZER_DESC));
    l_WireframeDesc.FillMode=D3D11_FILL_WIREFRAME;
    l_WireframeDesc.CullMode=D3D11_CULL_BACK;

    HRESULT l_HR=Device->CreateRasterizerState(&l_WireframeDesc, &m_WireframeRenderState);

    D3D11_RASTERIZER_DESC l_SolidDesc;
    ZeroMemory(&l_SolidDesc, sizeof(D3D11_RASTERIZER_DESC));
    l_SolidDesc.FillMode=D3D11_FILL_SOLID;
    l_SolidDesc.CullMode=D3D11_CULL_BACK;

    l_HR=Device->CreateRasterizerState(&l_SolidDesc, &m_SolidRenderState);
}
Exemplo n.º 26
0
//--------------------------------------------------------------------------------------
// Processes an inbox message that the manoeuvre received.
// Param1: A pointer to the message to process.
//--------------------------------------------------------------------------------------
void RunTheFlagHome::ProcessMessage(Message* pMessage)
{
	switch(pMessage->GetType())
	{
	case ScoreUpdateMessageType:
	{
	ScoreUpdateMessage* pMsg = reinterpret_cast<ScoreUpdateMessage*>(pMessage);
	if(pMsg->GetData().m_team == GetTeamAI()->GetTeam())
	{
		// The flag was captured -> the manoeuvre succeeded
		SetSucceeded(true);
	}
	break;
	}
	case EntityKilledMessageType:
	{
	EntityKilledMessage* pMsg = reinterpret_cast<EntityKilledMessage*>(pMessage);
	if(IsParticipant(pMsg->GetData().m_id) && pMsg->GetData().m_team == GetTeamAI()->GetTeam())
	{
		// Participants that get killed, drop out of the manoeuvre
		m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_id);
	}
	break;
	}
	case UpdateOrderStateMessageType:
	{
	// Cancel old order, Send Follow-Up Orders, finish manoeuvre etc
	UpdateOrderStateMessage* pMsg = reinterpret_cast<UpdateOrderStateMessage*>(pMessage);
	if(IsParticipant(pMsg->GetData().m_entityId))
	{
		if(pMsg->GetData().m_orderState == SucceededOrderState)
		{
			// Officially cancel the old order that was fulfilled and delete it.
			CancelOrder(pMsg->GetData().m_entityId);
			m_activeOrders.erase(m_activeOrders.find(pMsg->GetData().m_entityId));
		
			// The entity arrived at the home base, take on a defense position until the flag is captured
			// (might have to wait for the own flag to be returned)

			Order* pNewOrder = new DefendOrder(pMsg->GetData().m_entityId, DefendPositionOrder, MediumPriority, XMFLOAT2(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition), XMFLOAT2(0.0f, 0.0f));
			
			if(!pNewOrder)
			{
				SetFailed(true);
			}else
			{
				// Find the entity
				std::vector<Entity*>::iterator foundIt = std::find_if(m_participants.begin(), m_participants.end(), Entity::FindEntityById(pMsg->GetData().m_entityId));

				FollowOrderMessageData data(pNewOrder);
				SendMessage(*foundIt, FollowOrderMessageType, &data);

				m_activeOrders.insert(std::pair<unsigned long, Order*>(pMsg->GetData().m_entityId, pNewOrder));
			}
		}else if(pMsg->GetData().m_orderState == FailedOrderState)
		{
			// Entities executing a defend manoeuvre won't send success messages concerning the order state
			// as the defend order is a passive behaviour that is unlimited in time and thus cannot succeed.
			// It is thus sufficient to check for failure.

			// The order failed -> release the entity from the manoeuvre
			m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId);
		}
	}
	break;
	}
	default:
		TeamManoeuvre::ProcessMessage(pMessage);
	}
}
Exemplo n.º 27
0
#include "MathHelper.h"

const XMFLOAT2 MathHelper::vector2Epsilon = XMFLOAT2(0.00001f, 0.00001f);
const XMFLOAT3 MathHelper::vector3Epsilon = XMFLOAT3(0.00001f, 0.00001f, 0.00001f);


bool MathHelper::CompareVector3WithEpsilon(const XMFLOAT3& lhs, const XMFLOAT3& rhs)
{
	return XMVector3NearEqual(XMLoadFloat3(&lhs), XMLoadFloat3(&rhs), XMLoadFloat3(&vector3Epsilon)) == TRUE;
}

bool MathHelper::CompareVector2WithEpsilon(const XMFLOAT2& lhs, const XMFLOAT2& rhs)
{
	return XMVector3NearEqual(XMLoadFloat2(&lhs), XMLoadFloat2(&rhs), XMLoadFloat2(&vector2Epsilon)) == TRUE;
}
Exemplo n.º 28
0
HRESULT MLAAPostProcess::Render(ID3D11DeviceContext* pd3dImmediateContext, ID3D11ShaderResourceView* src,
                                ID3D11RenderTargetView* dstRTV, Camera* camera, GBuffer* gBuffer, ParticleBuffer* pBuffer,LightBuffer* lightBuffer)
{
    BEGIN_EVENT_D3D(L"MLAA");

    HRESULT hr;
    D3D11_MAPPED_SUBRESOURCE mappedResource;

    // Prepare all the settings and map them
    V_RETURN(pd3dImmediateContext->Map(_mlaaPropertiesBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));
    CB_MLAA_PROPERTIES* properties = (CB_MLAA_PROPERTIES*)mappedResource.pData;

    properties->InverseSceneSize = XMFLOAT2(1.0f / _textureWidth, 1.0f / _textureHeight);
    properties->DepthThreshold = _depthThreshold;
    properties->NormalThreshold = _normalThreshold;
    properties->LuminanceThreshold = _luminanceThreshold;
    properties->CameraNearClip = camera->GetNearClip();
    properties->CameraFarClip = camera->GetFarClip();
    properties->MaxSearchSteps = _maxSearchSteps;

    pd3dImmediateContext->Unmap(_mlaaPropertiesBuffer, 0);

    // Set all the device states
    ID3D11SamplerState* samplers[2] =
    {
        GetSamplerStates()->GetPointClamp(),
        GetSamplerStates()->GetLinearClamp(),
    };

    pd3dImmediateContext->PSSetSamplers(0, 2, samplers);

    float blendFactor[4] = {0, 0, 0, 0};
    pd3dImmediateContext->OMSetBlendState(GetBlendStates()->GetBlendDisabled(), blendFactor, 0xFFFFFFFF);

    Quad* fsQuad = GetFullScreenQuad();

    // Render the edge detection
    BEGIN_EVENT_D3D(L"Edge Detection");

    pd3dImmediateContext->OMSetRenderTargets(1, &_edgeDetectRTV, _dsv);

    // Clear the RT since the edge detection makes use of discard
    const float clearColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    pd3dImmediateContext->ClearRenderTargetView(_edgeDetectRTV, clearColor);
    pd3dImmediateContext->ClearDepthStencilView(_dsv, D3D11_CLEAR_STENCIL, 0.0f, 0x00);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilReplace(), 0xFFFFFFFF);

    ID3D11ShaderResourceView* ppSRVEdgeDetect[3] =
    {
        _depthDetect ? gBuffer->GetDepthSRV() : NULL,
        _normalDetect ?  gBuffer->GetNormalSRV() : NULL,
        _luminanceDetect ? gBuffer->GetDiffuseSRV() : NULL,
    };
    pd3dImmediateContext->PSSetShaderResources(0, 3, ppSRVEdgeDetect);

    pd3dImmediateContext->PSSetConstantBuffers(0, 1, &_mlaaPropertiesBuffer);

    ID3D11PixelShader* _curEdgePS = _edgeDetectPSs[_depthDetect ? 1 : 0][_normalDetect ? 1 : 0][_luminanceDetect ? 1 : 0]->PixelShader;
    V_RETURN(fsQuad->Render(pd3dImmediateContext, _curEdgePS));
    END_EVENT_D3D(L"");

    // Render blend weights
    BEGIN_EVENT_D3D(L"Calculate Blend Weights");

    // Determine which pixel shader and weight texture to use, max search steps must be <= than
    // (max_distance - 1) / 2
    UINT weightTexIdx = 0;
    for (UINT i = 0; i < NUM_WEIGHT_TEXTURES; i++)
    {
        if (_maxSearchSteps >= (WEIGHT_TEXTURE_SIZES[i] - 1) / 2)
        {
            weightTexIdx = i;
        }
    }

    pd3dImmediateContext->OMSetRenderTargets(1, &_blendWeightRTV, _dsv);
    pd3dImmediateContext->ClearRenderTargetView(_blendWeightRTV, clearColor);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilEqual(), 0xFFFFFFFF);

    ID3D11ShaderResourceView* ppSRVBlendWeight[3] =
    {
        _edgeDetectSRV,
        _weightSRVs[weightTexIdx]->ShaderResourceView,
        NULL
    };
    pd3dImmediateContext->PSSetShaderResources(0, 3, ppSRVBlendWeight);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _blendWeightPSs[weightTexIdx]->PixelShader));

    END_EVENT_D3D(L"");

    // Copy src into dst
    BEGIN_EVENT_D3D(L"Background Copy");

    pd3dImmediateContext->OMSetRenderTargets(1, &dstRTV, _dsv);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetDepthDisabled(), 0);

    ID3D11ShaderResourceView* ppSRVCopyAndNeighborhood[2] =
    {
        src,
        _blendWeightSRV,
    };

    pd3dImmediateContext->PSSetShaderResources(0, 2, ppSRVCopyAndNeighborhood);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _copyBackgroundPS->PixelShader));

    END_EVENT_D3D(L"");

    // Neighborhood blend
    BEGIN_EVENT_D3D(L"Neighborhood Blend");

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilEqual(), 0xFFFFFFFF);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _neighborhoodBlendPS->PixelShader));

    END_EVENT_D3D(L"");

    // Clean up
    ID3D11ShaderResourceView* ppSRVNULL[2] = { NULL, NULL };
    pd3dImmediateContext->PSSetShaderResources(0, 2, ppSRVNULL);

    END_EVENT_D3D(L"");
    return S_OK;
}
	void SpecularLightingDemo::CreateVertexBuffer(ID3D11Device* device, const Mesh& mesh, ID3D11Buffer** vertexBuffer) const {
		const std::vector < XMFLOAT3 >& sourceVertices = mesh.Vertices();
		const std::vector < XMFLOAT3 >& sourceNormals = mesh.Normals();
		const auto& sourceUVs = mesh.TextureCoordinates().at(0);

		std::vector <VertexPositionTextureNormal> vertices;
		vertices.reserve(sourceVertices.size());
		for (UINT i = 0; i < sourceVertices.size(); i++) {
			const XMFLOAT3& position = sourceVertices.at(i);
			const XMFLOAT3& uv = sourceUVs->at(i);
			const XMFLOAT3& normal = sourceNormals.at(i);
			vertices.push_back(VertexPositionTextureNormal(XMFLOAT4(position.x, position.y, position.z, 1.0f), XMFLOAT2(uv.x, uv.y), normal));
		}
		//Vertex Buffer
		D3D11_BUFFER_DESC vertexBufferDesc = { 0 };
		vertexBufferDesc.ByteWidth = sizeof(VertexPositionTextureNormal) * static_cast<UINT>(vertices.size());
		vertexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
		vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;

		D3D11_SUBRESOURCE_DATA vertexSubResourceData = { 0 };
		vertexSubResourceData.pSysMem = &vertices[0];

		ThrowIfFailed(device->CreateBuffer(&vertexBufferDesc, &vertexSubResourceData, vertexBuffer), "ID3D11Device::CreateBuffer() failed.");
	}
PostprocessWindow::PostprocessWindow(Renderable3DComponent* comp) : component(comp)
{
	assert(component && "PostprocessWnd invalid component!");

	GUI = &component->GetGUI();

	assert(GUI && "Invalid GUI!");

	float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth();
	float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();

	ppWindow = new wiWindow(GUI, "PostProcess Window");
	ppWindow->SetSize(XMFLOAT2(360, 450));
	GUI->AddWidget(ppWindow);

	float x = 200;
	float y = 0;

	lensFlareCheckBox = new wiCheckBox("LensFlare: ");
	lensFlareCheckBox->SetPos(XMFLOAT2(x, y += 35));
	lensFlareCheckBox->SetCheck(component->getLensFlareEnabled());
	lensFlareCheckBox->OnClick([&](wiEventArgs args) {
		component->setLensFlareEnabled(args.bValue);
	});
	ppWindow->AddWidget(lensFlareCheckBox);

	lightShaftsCheckBox = new wiCheckBox("LightShafts: ");
	lightShaftsCheckBox->SetPos(XMFLOAT2(x, y += 35));
	lightShaftsCheckBox->SetCheck(component->getLightShaftsEnabled());
	lightShaftsCheckBox->OnClick([&](wiEventArgs args) {
		component->setLightShaftsEnabled(args.bValue);
	});
	ppWindow->AddWidget(lightShaftsCheckBox);

	ssaoCheckBox = new wiCheckBox("SSAO: ");
	ssaoCheckBox->SetPos(XMFLOAT2(x, y += 35));
	ssaoCheckBox->SetCheck(component->getSSAOEnabled());
	ssaoCheckBox->OnClick([&](wiEventArgs args) {
		component->setSSAOEnabled(args.bValue);
	});
	ppWindow->AddWidget(ssaoCheckBox);

	ssrCheckBox = new wiCheckBox("SSR: ");
	ssrCheckBox->SetPos(XMFLOAT2(x, y += 35));
	ssrCheckBox->SetCheck(component->getSSREnabled());
	ssrCheckBox->OnClick([&](wiEventArgs args) {
		component->setSSREnabled(args.bValue);
	});
	ppWindow->AddWidget(ssrCheckBox);

	sssCheckBox = new wiCheckBox("SSS: ");
	sssCheckBox->SetPos(XMFLOAT2(x, y += 35));
	sssCheckBox->SetCheck(component->getSSSEnabled());
	sssCheckBox->OnClick([&](wiEventArgs args) {
		component->setSSSEnabled(args.bValue);
	});
	ppWindow->AddWidget(sssCheckBox);

	eyeAdaptionCheckBox = new wiCheckBox("EyeAdaption: ");
	eyeAdaptionCheckBox->SetPos(XMFLOAT2(x, y += 35));
	eyeAdaptionCheckBox->SetCheck(component->getEyeAdaptionEnabled());
	eyeAdaptionCheckBox->OnClick([&](wiEventArgs args) {
		component->setEyeAdaptionEnabled(args.bValue);
	});
	ppWindow->AddWidget(eyeAdaptionCheckBox);

	motionBlurCheckBox = new wiCheckBox("MotionBlur: ");
	motionBlurCheckBox->SetPos(XMFLOAT2(x, y += 35));
	motionBlurCheckBox->SetCheck(component->getMotionBlurEnabled());
	motionBlurCheckBox->OnClick([&](wiEventArgs args) {
		component->setMotionBlurEnabled(args.bValue);
	});
	ppWindow->AddWidget(motionBlurCheckBox);

	depthOfFieldCheckBox = new wiCheckBox("DepthOfField: ");
	depthOfFieldCheckBox->SetPos(XMFLOAT2(x, y += 35));
	depthOfFieldCheckBox->SetCheck(component->getDepthOfFieldEnabled());
	depthOfFieldCheckBox->OnClick([&](wiEventArgs args) {
		component->setDepthOfFieldEnabled(args.bValue);
	});
	ppWindow->AddWidget(depthOfFieldCheckBox);

	bloomCheckBox = new wiCheckBox("Bloom: ");
	bloomCheckBox->SetPos(XMFLOAT2(x, y += 35));
	bloomCheckBox->SetCheck(component->getBloomEnabled());
	bloomCheckBox->OnClick([&](wiEventArgs args) {
		component->setBloomEnabled(args.bValue);
	});
	ppWindow->AddWidget(bloomCheckBox);

	fxaaCheckBox = new wiCheckBox("FXAA: ");
	fxaaCheckBox->SetPos(XMFLOAT2(x, y += 35));
	fxaaCheckBox->SetCheck(component->getFXAAEnabled());
	fxaaCheckBox->OnClick([&](wiEventArgs args) {
		component->setFXAAEnabled(args.bValue);
	});
	ppWindow->AddWidget(fxaaCheckBox);

	colorGradingCheckBox = new wiCheckBox("Color Grading: ");
	colorGradingCheckBox->SetPos(XMFLOAT2(x, y += 35));
	colorGradingCheckBox->SetCheck(component->getColorGradingEnabled());
	colorGradingCheckBox->OnClick([&](wiEventArgs args) {
		component->setColorGradingEnabled(args.bValue);
	});
	ppWindow->AddWidget(colorGradingCheckBox);

	stereogramCheckBox = new wiCheckBox("Stereogram: ");
	stereogramCheckBox->SetPos(XMFLOAT2(x, y += 35));
	stereogramCheckBox->SetCheck(component->getStereogramEnabled());
	stereogramCheckBox->OnClick([&](wiEventArgs args) {
		component->setStereogramEnabled(args.bValue);
	});
	ppWindow->AddWidget(stereogramCheckBox);


	ppWindow->Translate(XMFLOAT3(screenW - 380, 50, 0));
	ppWindow->SetVisible(false);

}