コード例 #1
0
bool BumpModelClass::Initialize(ID3D10Device* device, char* modelFilename, WCHAR* textureFilename1, WCHAR* textureFilename2)
{
    bool result;


    // Load in the model data.
    result = LoadModel(modelFilename);
    if(!result)
    {
        return false;
    }

    // Calculate the normal, tangent, and binormal vectors for the model.
    CalculateModelVectors();

    // Initialize the vertex and index buffer that hold the geometry for the model.
    result = InitializeBuffers(device);
    if(!result)
    {
        return false;
    }

    // Load the textures for this model.
    result = LoadTextures(device, textureFilename1, textureFilename2);
    if(!result)
    {
        return false;
    }

    return true;
}
コード例 #2
0
bool ModelClass::Initialize(ID3D11Device* device, char* modelFilename, 
	WCHAR* filename1, WCHAR* filename2, WCHAR* filename3)
{
	bool result;

	// Load in the model data,
	result = LoadModel(modelFilename);
	if(!result)
	{
		return false;
	}

	// Calculate the normal, tangent, and binormal vectors for the model.
	CalculateModelVectors();

	// Initialize the vertex and index buffers.
	result = InitializeBuffers(device);
	if(!result)
	{
		return false;
	}

	// Load the textures for this model.
	result = LoadTexture(device, filename1, filename2, filename3);
	if(!result)
	{
		return false;
	}

	return true;
}
コード例 #3
0
StaticMesh::StaticMesh(const std::string& filename, D3D& d3d, bool includeTanBin)
    : m_filename(filename),
      m_vertexCount(0),
      m_indexCount(0),
      m_vertexBuffer(0),
      m_indexBuffer(0),
      m_modelData(),
      m_modelDataTanBin(),
      m_includeTanBin(includeTanBin)
{
    LoadObj(filename);
    m_includeTanBin ? CalculateModelVectors() : "";
    m_includeTanBin ? InitBuffersTanBin(d3d) : InitBuffers(d3d);
}
コード例 #4
0
ファイル: cube.cpp プロジェクト: byhj/DirectX11-Tutorials
void Cube::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
{
	HRESULT hr;
	///////////////////////////Index Buffer ////////////////////////////////
	LoadModel("../../media/objects/cube.txt");
	CalculateModelVectors();

	VertexType *VertexData;
	unsigned long *IndexData;
	HRESULT result;
	int VertexCount = 36;
	int IndexCount = 36;

	VertexData = new VertexType[VertexCount];
	IndexData = new unsigned long[IndexCount];


	for (int i = 0; i != VertexCount; ++i)
	{
		VertexData[i].position = XMFLOAT3(pModelVertex[i].x, pModelVertex[i].y, pModelVertex[i].z);
		VertexData[i].texture = XMFLOAT2(pModelVertex[i].tu, pModelVertex[i].tv);
		VertexData[i].normal = XMFLOAT3(pModelVertex[i].nx, pModelVertex[i].ny, pModelVertex[i].nz);
		VertexData[i].tangent = XMFLOAT3(pModelVertex[i].tx, pModelVertex[i].ty, pModelVertex[i].tz);
		VertexData[i].binormal = XMFLOAT3(pModelVertex[i].bx, pModelVertex[i].by, pModelVertex[i].bz);

		IndexData[i] = i;
	}

	// Set up the description of the static vertex buffer.
	D3D11_BUFFER_DESC VertexBufferDesc;
	VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
	VertexBufferDesc.ByteWidth           = sizeof(VertexType)* VertexCount;
	VertexBufferDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
	VertexBufferDesc.CPUAccessFlags      = 0;
	VertexBufferDesc.MiscFlags           = 0;
	VertexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the vertex data.
	D3D11_SUBRESOURCE_DATA VBO;
	VBO.pSysMem          = VertexData;
	VBO.SysMemPitch      = 0;
	VBO.SysMemSlicePitch = 0;

	// Now create the vertex buffer.
	hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
	//DebugHR(hr);

	/////////////////////////////////Index Buffer ///////////////////////////////////////

	// Set up the description of the static index buffer.
	D3D11_BUFFER_DESC IndexBufferDesc;
	IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
	IndexBufferDesc.ByteWidth           = sizeof(unsigned long)* IndexCount;
	IndexBufferDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
	IndexBufferDesc.CPUAccessFlags      = 0;
	IndexBufferDesc.MiscFlags           = 0;
	IndexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the index data.
	D3D11_SUBRESOURCE_DATA IBO;
	IBO.pSysMem          = IndexData;
	IBO.SysMemPitch      = 0;
	IBO.SysMemSlicePitch = 0;

	hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer);
	//DebugHR(hr);
	////////////////////////////////Const Buffer//////////////////////////////////////

	D3D11_BUFFER_DESC mvpDesc;
	ZeroMemory(&mvpDesc, sizeof(D3D11_BUFFER_DESC));
	mvpDesc.Usage          = D3D11_USAGE_DEFAULT;
	mvpDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
	mvpDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
	mvpDesc.CPUAccessFlags = 0;
	mvpDesc.MiscFlags      = 0;
	hr = pD3D11Device->CreateBuffer(&mvpDesc, NULL, &m_pMVPBuffer);
	//DebugHR(hr);


	/////////////////////////////////////////////////////////////////////////////////
	D3D11_BUFFER_DESC lightBufferDesc;
	ZeroMemory(&lightBufferDesc, sizeof(D3D11_BUFFER_DESC));
	lightBufferDesc.Usage          = D3D11_USAGE_DYNAMIC;
	lightBufferDesc.ByteWidth      = sizeof(LightBuffer);
	lightBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
	lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	lightBufferDesc.MiscFlags      = 0;

	hr = pD3D11Device->CreateBuffer(&lightBufferDesc, NULL, &m_pLightBuffer);
	//DebugHR(hr);

	D3D11_MAPPED_SUBRESOURCE mappedResource;
	// Lock the light constant buffer so it can be written to.
	hr = pD3D11DeviceContext->Map(m_pLightBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	//DebugHR(hr);

	// Get a pointer to the data in the constant buffer.
	LightBuffer *dataPtr2 = (LightBuffer*)mappedResource.pData;


	dataPtr2->ambientColor   = XMFLOAT4(0.15f, 0.15f, 0.15f, 0.15f);
	dataPtr2->diffuseColor   = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	dataPtr2->lightDirection = XMFLOAT3(0.0f, 0.0f, 1.0f);
	dataPtr2->specularPower  = 32.0f;
	dataPtr2->specularColor  = XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f);

	pD3D11DeviceContext->Unmap(m_pLightBuffer.Get(), 0);

	int lightSlot = 0;
	pD3D11DeviceContext->PSSetConstantBuffers(lightSlot, 1, m_pLightBuffer.GetAddressOf());


	D3D11_BUFFER_DESC cameraBufferDesc;
	cameraBufferDesc.Usage               = D3D11_USAGE_DYNAMIC;
	cameraBufferDesc.ByteWidth           = sizeof(CameraBuffer);
	cameraBufferDesc.BindFlags           = D3D11_BIND_CONSTANT_BUFFER;
	cameraBufferDesc.CPUAccessFlags      = D3D11_CPU_ACCESS_WRITE;
	cameraBufferDesc.MiscFlags           = 0;
	cameraBufferDesc.StructureByteStride = 0;

	// Create the camera constant buffer pointer so we can access the vertex shader constant buffer from within this class.
	hr = pD3D11Device->CreateBuffer(&cameraBufferDesc, NULL, &m_CameraBuffer);
	//DebugHR(hr);

	// Lock the camera constant buffer so it can be written to.
	hr = pD3D11DeviceContext->Map(m_CameraBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	//DebugHR(hr);

	// Get a pointer to the data in the constant buffer.
	CameraBuffer *dataPtr3 = (CameraBuffer*)mappedResource.pData;
	dataPtr3->camPos = XMFLOAT3(0.0f, 2.0f, -3.0f);
	dataPtr3->padding = 0.0f;
	pD3D11DeviceContext->Unmap(m_CameraBuffer.Get(), 0);

	int bufferSlot = 1;
	pD3D11DeviceContext->VSSetConstantBuffers(bufferSlot, 1, m_CameraBuffer.GetAddressOf());


}
コード例 #5
0
ファイル: TerrainClass.cpp プロジェクト: McBainC/Portfolio
// Initialize                           //
// Added tangent & biNormal calculation //
bool TerrainClass::Initialize( ID3D11Device* device,
							   int terrainDimension,
							   int smoothingPasses,
							   float displacementValue,
							   WCHAR* textureFileName1,
							   WCHAR* textureFileName2,
							   WCHAR* textureFileName3,
							   WCHAR* textureFileName4,
							   WCHAR* textureFileName5,
					           WCHAR* textureFileName6,
					           WCHAR* textureFileName7,
					           WCHAR* textureFileName8 ) {
	bool result;

	/*
	// Load in the height map for the terrain
	result = LoadHeightMap( heightMapFileName );
	if( !result ) {
		return false;
	}

	// Normalize the height of the height map
	NormalizeHeightMap();
	*/

	// Initialize Terrain //

	// Set terrain height & width
	mTerrainHeight = mTerrainWidth = terrainDimension;

	// Create the structure to hold the height map data
	pHeightMap = new HeightMapType[ mTerrainWidth * mTerrainHeight ];
	if( !pHeightMap ) {
		return false;
	}

	// Initialize terrain data structre(1.0f height)
	int index;
	for( int j = 0; j < mTerrainHeight; j++ ) {
		for( int i = 0; i < mTerrainWidth; i++ ) {			
			index = ( mTerrainHeight * j ) + i;

			pHeightMap[ index ].x = ( float )i;
			pHeightMap[ index ].y = 1.0f; 
			pHeightMap[ index ].z = ( float )j;
		}
	}

	// Generate new terrain
	DiamondSquareAlgorithm( 10.0f, displacementValue, 2.0f );

	// Smooth (5 passes)
	SmoothHeights( smoothingPasses );

	// Calculate the normals for the terrain data
	result = CalculateNormals();
	if( !result ) {
		return false;
	}

	// Calculate the texture coordinates
	CalculateTextureCoordinates();

	// Load the texture
	result = LoadTextures( device,
		                   textureFileName1,
						   textureFileName2,
						   textureFileName3,
						   textureFileName4,
						   textureFileName5,
						   textureFileName6,
						   textureFileName7,
						   textureFileName8 );

	if( !result ) {		   
		return false;	   
	}

	// Calculate the normal, tangent, and biNormal vectors for the model
	CalculateModelVectors();

	// Initialize the vertex and index buffer that hold the geometry for the terrain
	result = InitializeBuffers( device );
	if( !result ) {
		return false;
	}

	return true;
}