Ejemplo n.º 1
0
bool CollisionMesh::CheckCollisionsCustom(CollisionMesh &otherMesh)
{
  bool collision = false;
  std::vector<XMFLOAT3> convexHull;

  std::vector<VPCNTDesc> vertices = GetVertices();
  std::vector<VPCNTDesc> otherVertices = otherMesh.GetVertices();
  XMMATRIX otherWorld = otherMesh.GetWorldTransform();
  XMMATRIX world = GetWorldTransform();
  XMFLOAT3 origin = XMFLOAT3(0.0f, 0.0f, 0.0f);

  // Create a vector to ease the inversion calculation (we want the opposite direction for the translation vector).
  XMVECTOR inverse = XMVectorSet(-1.0f, -1.0f, -1.0f, 0.0f);
  
  XMVECTOR ourOriginDisplacement = XMVector3Transform(XMVectorSet(origin.x, origin.y, origin.z, 0.0f), world);
  XMMATRIX ourOriginTransform = XMMatrixTranslationFromVector(XMVectorMultiply(ourOriginDisplacement, inverse));

  // This is used for the purposes of moving the normals of the other object back to around (0, 0, 0).
  XMVECTOR theirOriginDisplacement = XMVector3Transform(XMVectorSet(origin.x, origin.y, origin.z, 0.0f), otherWorld);
  XMMATRIX theirOriginTransform = XMMatrixTranslationFromVector(XMVectorMultiply(theirOriginDisplacement, inverse));

  XMMATRIX ourOriginTranslatedWorld = world * ourOriginTransform;
  XMMATRIX theirOriginTranslatedWorld = otherWorld * ourOriginTransform;
  XMMATRIX theirOriginTranslatedWorldNormalAdjustment = theirOriginTransform * otherWorld;

  // Pre-multiply the model's vertices so as to avoid transforming them during comparison.
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    XMStoreFloat3(&vertices[vertIndex].Position, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Position), ourOriginTranslatedWorld));
    XMStoreFloat3(&vertices[vertIndex].Normal, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Normal), ourOriginTranslatedWorld));
  }

  for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
  {
    XMStoreFloat3(&otherVertices[otherVertIndex].Position, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Position), theirOriginTranslatedWorld));
    XMStoreFloat3(&otherVertices[otherVertIndex].Normal, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Normal), theirOriginTranslatedWorldNormalAdjustment));
  }

  int potentialCollisions = 0;
  std::vector<XMFLOAT3> positions;

  // Now that the pre-multiplication is done, time to do our first-case checking: are we inside of it?
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    bool localCollision = true;
    XMVECTOR ourVertex = XMLoadFloat3(&vertices[vertIndex].Position);
    XMVECTOR ourNormal = XMLoadFloat3(&vertices[vertIndex].Normal);

    // For each vertex in our mesh, we'll check to see if it resides inside our other mesh.
    for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
    {
      XMVECTOR otherVertex = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
      XMVECTOR otherNormal = XMLoadFloat3(&otherVertices[otherVertIndex].Normal);

      XMVECTOR difference = XMVectorSubtract(ourVertex, otherVertex);
      XMFLOAT3 differenceDotValue, normalDotValue;
      XMVECTOR diffLength = XMVector3Length(difference);
      XMVECTOR normLength = XMVector3Length(otherNormal);
      XMVECTOR magnitude = XMVectorMultiply(diffLength, normLength);

      XMStoreFloat3(&differenceDotValue, XMVectorDivide(XMVector3Dot(difference, otherNormal), magnitude));
      // At this point, we should have the cosine of the angle.
      float angleInRads = acosf(differenceDotValue.x);
      float angleInDegs = XMConvertToDegrees(angleInRads);

      XMStoreFloat3(&normalDotValue, XMVector3Dot(ourNormal, otherNormal));

      if (angleInDegs < 90.0f)
      {
        localCollision = false;
      }
    }

    if (localCollision)
    {
      positions.push_back(vertices[vertIndex].Position);
    }
  }

  if (positions.empty())
  {
    // Time to do our second-case checking: is it inside of us?
    for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
    {
      bool localCollision = true;
      XMVECTOR otherVertex = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
      XMVECTOR otherNormal = XMVector3Normalize(XMLoadFloat3(&otherVertices[otherVertIndex].Normal));

      // For each vertex in our mesh, we'll check to see if it resides inside our other mesh.
      for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
      {
        XMVECTOR ourVertex = XMLoadFloat3(&vertices[vertIndex].Position);
        XMVECTOR ourNormal = XMVector3Normalize(XMLoadFloat3(&vertices[vertIndex].Normal));

        XMVECTOR difference = XMVectorSubtract(otherVertex, ourVertex);
        XMFLOAT3 differenceDotValue, normalDotValue;
        XMVECTOR diffLength = XMVector3Length(difference);
        XMVECTOR normLength = XMVector3Length(ourNormal);
        XMVECTOR magnitude = XMVectorMultiply(diffLength, normLength);

        XMStoreFloat3(&differenceDotValue, XMVectorDivide(XMVector3Dot(difference, ourNormal), magnitude));
        // At this point, we should have the cosine of the angle.
        float angleInRads = acosf(differenceDotValue.x);
        float angleInDegs = XMConvertToDegrees(angleInRads);

        XMStoreFloat3(&normalDotValue, XMVector3Dot(ourNormal, otherNormal));

        if (angleInDegs < 90.0f)
        {
          localCollision = false;
        }
      }

      if (localCollision)
      {
        positions.push_back(otherVertices[otherVertIndex].Position);
      }
    }
  }

  if(positions.size())
  {
    mDelegate->CollisionOccurred(otherMesh.mDelegate);
    otherMesh.mDelegate->CollisionOccurred(mDelegate);
  }
  return positions.size();
}
Ejemplo n.º 2
0
void Dx11ObjectGUIStandard::Setup(Dx11Context* _context)
{
	HRESULT hr; 
	ID3D11Device* pd3dDevice = _context->GetDXDevice(); 
	tDAEVERTEX v[4] = {
		{XMFLOAT3( 0.0f,  1.0f, 0.0f) , XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f) , XMFLOAT4(1.0f, 0.0f, 0.0f, 0.0), {0, 0, 0, 0}, XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0), 1.0f, 0.0f}, 
		{XMFLOAT3( 1.0f,  1.0f, 0.0f) , XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f) , XMFLOAT4(1.0f, 0.0f, 0.0f, 0.0), {0, 0, 0, 0}, XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0), 0.0f, 0.0f}, 
		{XMFLOAT3( 1.0f,  0.0f, 0.0f) , XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f) , XMFLOAT4(1.0f, 0.0f, 0.0f, 0.0), {0, 0, 0, 0}, XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0), 0.0f, 1.0f}, 
		{XMFLOAT3( 0.0f,  0.0f, 0.0f) , XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f) , XMFLOAT4(1.0f, 0.0f, 0.0f, 0.0), {0, 0, 0, 0}, XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0), 1.0f, 1.0f}, 
	}; 

	D3D11_BUFFER_DESC vBufferDesc;
	vBufferDesc.Usage          = D3D11_USAGE_DEFAULT; 
	vBufferDesc.ByteWidth      = sizeof(tDAEVERTEX) * 4; 
	vBufferDesc.BindFlags      = D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_STREAM_OUTPUT; 
	vBufferDesc.CPUAccessFlags = 0;
	vBufferDesc.MiscFlags      = 0;
	vBufferDesc.StructureByteStride = 0;

	// 頂点バッファのサブリソースの定義
	D3D11_SUBRESOURCE_DATA vSubData;
	vSubData.pSysMem          = v;  // バッファ・データの初期値
	vSubData.SysMemPitch      = 0;
	vSubData.SysMemSlicePitch = 0;

	// 頂点バッファの作成
	hr = pd3dDevice->CreateBuffer(&vBufferDesc, &vSubData, &m_pVB);
	if (FAILED(hr)) {
		DXTRACE_ERR(L"InitDirect3D pd3dDevice->CreateBuffer", hr);
		return; 
	}

	// **********************************************************
	// インデックス・バッファの定義
	D3D11_BUFFER_DESC idxBufferDesc;
	idxBufferDesc.Usage          = D3D11_USAGE_DEFAULT;     // デフォルト使用法
	idxBufferDesc.ByteWidth      = sizeof(UINT) * 6;       // 2×3頂点
	idxBufferDesc.BindFlags      = D3D11_BIND_INDEX_BUFFER; // インデックス・バッファ
	idxBufferDesc.CPUAccessFlags = 0;
	idxBufferDesc.MiscFlags      = 0;
	idxBufferDesc.StructureByteStride = 0;

	// インデックス・バッファのサブリソースの初期値(頂点ID)
	UINT idxVertexID[] = {
		0,1,2,  0,2,3,
	};

	D3D11_SUBRESOURCE_DATA idxSubData;
	idxSubData.pSysMem          = idxVertexID;  // バッファ・データの初期値
	idxSubData.SysMemPitch      = 0;
	idxSubData.SysMemSlicePitch = 0;

	hr = pd3dDevice->CreateBuffer(&idxBufferDesc, &idxSubData, &m_pIB);
	if (FAILED(hr)) {
		DXTRACE_ERR(L"InitDirect3D g_pD3DDevice->CreateBuffer", hr);
		return; 
	}

	WCHAR filepath[2048];
	MultiByteToWideChar(CP_UTF8, 0, filename.c_str(), -1, filepath, (int)sizeof(filepath));
	hr = CreateDDSTextureFromFile( pd3dDevice, filepath, NULL, &m_pTexture ); 
	if (FAILED(hr)) {
		DXTRACE_ERR(L"D3DX11CreateShaderResourceViewFromFile", hr);
		return; 
	}

}
Ejemplo n.º 3
0
Mesh* SpotlightSample::Plane(ID3D11Device* device, float width, int vertexPerWidth, float depth, int vertexPerDepth)
{
	// Test for minimum number of vertex
	if (vertexPerWidth < 2) vertexPerWidth = 2;
	if (vertexPerDepth < 2) vertexPerDepth = 2;

	std::vector<Vertex> verts;           // Verts we're assembling
	std::vector<UINT> indices;           // Indices of these verts

	// The distance between vertexes in a given axis:
	float widthStep = width / vertexPerWidth;
	float depthStep = depth / vertexPerDepth;

	float planeWidthDesloc = width / 2;
	float planeDepthDesloc = depth / 2;

	// Clear both vectors. Not necesasry, but a good practice.
	verts.clear();
	indices.clear();

	Vertex CurVertex;
	UINT IndicesIndex = 0;

	// Loop though the columns (z-axis)
	for (float k = 0; k < vertexPerDepth - 1; k++)
	{
		// Loop though the lines (x-axis)
		for (float i = 0; i < vertexPerWidth - 1; i++) // May need to change to vertexperwidth.
		{	// Creates a quad. Using two triangles
			// Vertices Position = (vertex position) - (plane dislocation)

			//Top Triangle
			// #1
			CurVertex.Position = XMFLOAT3(i*widthStep - planeWidthDesloc, 0, k*depthStep - planeDepthDesloc);
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)(i / vertexPerWidth - 1), (float)(k / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);

			// #2
			CurVertex.Position = XMFLOAT3(i*widthStep - planeWidthDesloc, 0, (k + 1)*depthStep - planeDepthDesloc);
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)(i / vertexPerWidth - 1), (float)((k + 1) / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);

			// #3
			CurVertex.Position = XMFLOAT3((i + 1)*widthStep - planeWidthDesloc, 0, k*depthStep - planeDepthDesloc);
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)((i + 1) / vertexPerWidth - 1), (float)(k / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);

			//Bottom Triangle
			// #1
			CurVertex.Position = XMFLOAT3((i + 1)*widthStep - planeWidthDesloc, 0, k*depthStep - planeDepthDesloc);
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)((i + 1) / vertexPerWidth - 1), (float)(k / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);

			// #2
			CurVertex.Position = XMFLOAT3(i*widthStep - planeWidthDesloc, 0, (k + 1)*depthStep - planeDepthDesloc);
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)(i / vertexPerWidth - 1), (float)((k + 1) / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);

			// #3
			CurVertex.Position = XMFLOAT3((i + 1)*widthStep - planeWidthDesloc, 0, (k + 1)*depthStep - (planeDepthDesloc));
			CurVertex.Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
			CurVertex.Normal = XMFLOAT3(0, 1, 0);
			CurVertex.UV = XMFLOAT2((float)((i + 1) / vertexPerWidth - 1), (float)((k + 1) / vertexPerDepth - 1));
			verts.push_back(CurVertex);
			indices.push_back(IndicesIndex++);
		}
	}

	Mesh* returnMesh = new Mesh(&verts[0], verts.size(), &indices[0], indices.size(), device);
	return returnMesh;
}
Ejemplo n.º 4
0
bool CollisionMesh::CheckCollisionsGJK1(CollisionMesh& otherMesh)
{
  std::vector<XMFLOAT3> convexHull;
  bool foundOrigin = false;

  std::vector<VPCNTDesc> vertices = GetVertices();
  std::vector<VPCNTDesc> otherVertices = otherMesh.GetVertices();
  XMMATRIX otherWorld = otherMesh.GetWorldTransform();
  XMMATRIX world = GetWorldTransform();

  // Pre-multiply the model's vertices so as to avoid transforming them during comparison.
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    XMVECTOR vertexTransform = XMLoadFloat3(&vertices[vertIndex].Position);
    XMStoreFloat3(&vertices[vertIndex].Position, XMVector3Transform(vertexTransform, world));
  }

  for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
  {
    XMVECTOR vertexTransform = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
    XMStoreFloat3(&otherVertices[otherVertIndex].Position, XMVector3Transform(vertexTransform, otherWorld));
  }

  // Now we get to the fun part; the subtraction.
  for (int vertIndex = 0; vertIndex < vertices.size() && !foundOrigin; vertIndex++)
  {
    XMFLOAT3 vertexValue = vertices[vertIndex].Position;
    XMVECTOR vertexTransform = XMLoadFloat3(&vertexValue);

    for (int otherVertIndex = 0; otherVertIndex < otherVertices.size() && !foundOrigin; otherVertIndex++)
    {
      XMVECTOR otherVertexTransform = XMLoadFloat3(&otherVertices[otherVertIndex].Position);
      XMFLOAT3 convexHullPoint;

      XMVECTOR difference = XMVectorSubtract(vertexTransform, otherVertexTransform);
      XMStoreFloat3(&convexHullPoint, difference);
      convexHull.push_back(convexHullPoint);

      foundOrigin = XMVector3Equal(difference, XMVectorZero());
    }

    convexHull.push_back(vertexValue);
  }

  if (!foundOrigin)
  {
    XMFLOAT3 collisionLine = XMFLOAT3(0.0f, 1250.0f, 500.0f);
    printf("We ain't found shit!");
    bool collision = true;
    int intersections = 0;
    for (int hullVertexIndex = 0; hullVertexIndex < convexHull.size() && convexHull.size() > 3; hullVertexIndex += 3)
    {
      int secondIndex = (hullVertexIndex + 1) % (convexHull.size() - 1);
      int thirdIndex = (hullVertexIndex + 2) % (convexHull.size() - 1);

      XMFLOAT3 firstVert = convexHull[hullVertexIndex];
      XMFLOAT3 secondVert = convexHull[secondIndex];
      XMFLOAT3 thirdVert = convexHull[thirdIndex];
      XMFLOAT3 origin = XMFLOAT3(0.0f, 0.0f, 0.0f);

      // we need to check the normal. Calculate using cross product.
      XMVECTOR firstVector = XMVectorSet(secondVert.x - firstVert.x, secondVert.y - firstVert.y, secondVert.z - firstVert.z, 0.0f);
      XMVECTOR secondVector = XMVectorSet(thirdVert.x - secondVert.x, thirdVert.y - secondVert.y, thirdVert.z - secondVert.z, 0.0f);

      XMFLOAT3 normal;
      XMStoreFloat3(&normal, XMVector3Normalize(XMVector3Cross(firstVector, secondVector)));

      // check to ensure no parallels are detected.
      float firstDot = (normal.x * collisionLine.x) + (normal.y * collisionLine.y) + (normal.z * collisionLine.z);
      if (firstDot < 0)
      {
        float delta = -((normal.x * (origin.x - firstVert.x)) + (normal.y * (origin.y - firstVert.y)) + (normal.z * (origin.z - firstVert.y))) /
          firstDot;

        if (delta < 0)
        {
          break;
        }

        XMFLOAT3 pointToCheck = XMFLOAT3(origin.x - (collisionLine.x * delta), origin.y - (collisionLine.y * delta), origin.z * (collisionLine.z * delta));

        bool firstCheck = CheckWinding(firstVert, secondVert, pointToCheck, normal);
        bool secondCheck = CheckWinding(secondVert, thirdVert, pointToCheck, normal);
        bool thirdCheck = CheckWinding(thirdVert, firstVert, pointToCheck, normal);

        if (firstCheck && secondCheck && thirdCheck)
        {
          intersections++;
        }
        else
        {
          collision = false;
        }
      }
    }

    if ((intersections % 2) == 1)
    {
      foundOrigin = true;
    }
  }

  return foundOrigin;
}
Ejemplo n.º 5
0
    window->KeyDown += 
    ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &MoveLookController::OnKeyDown);

    window->KeyUp += 
    ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &MoveLookController::OnKeyUp);

    // Initialize state of the controller
    m_moveInUse = FALSE;				// no pointer is in the Move control
    m_movePointerID = 0;

    m_lookInUse = FALSE;				// no pointer is in the Look control
    m_lookPointerID = 0;

    //	need to init this as it is reset every frame
	m_moveCommand = XMFLOAT3( 0.0f, 0.0f, 0.0f );
	deltaTime = 0;

    SetOrientation( -(XM_PI/4.0f), 0 );				// look straight ahead when the app starts
	SetPosition(XMFLOAT3(0, 3.0f, -3.0f));
}

void MoveLookController::OnPointerPressed(
_In_ CoreWindow^ sender,
_In_ PointerEventArgs^ args)
{
    // get the current pointer position
    uint32 pointerID = args->CurrentPoint->PointerId;
	XMFLOAT2 position = XMFLOAT2( args->CurrentPoint->Position.X, args->CurrentPoint->Position.Y );

    auto device = args->CurrentPoint->PointerDevice;
Ejemplo n.º 6
0
//===============================================================================================================================
//===============================================================================================================================
ModelEnvironment::ModelEnvironment(EngineOptions* eo)
:   Environment3D(eo)
{
	m_CameraSystem->SetPosition(0.0f, 40.0f, 10.0f);
	
	bEnableShadows = true;

	bEnableDeferredShading = true;
	
	// Not using any reflections
	m_CameraSystem->SetRenderReflectionView( false );
	
	// Create a random plane
	ZShadeSandboxMesh::MeshParameters mp;
	mp.useCustomShader = false;
	mp.vertexType = ZShadeSandboxMesh::EVertexType::VT_NormalTex;
	mp.rotationAxisX = false;
	mp.rotationAxisY = false;
	mp.rotationAxisZ = false;
	mp.pos = XMFLOAT3(0, 0, 0);
	mp.rot = XMFLOAT3(0, 0, 0);
	mp.scale = XMFLOAT3(1, 1, 1);
	mp.shader = 0;
	
	//mp.pos = XMFLOAT3(0, 1, 0);
	mp.scale = XMFLOAT3(20, 1, 20);
	mp.material = MaterialManager::Instance()->GetMaterial("Stone");
	//mPlane = new ZShadeSandboxMesh::PlaneMesh(200.0f, 0.0f, m_D3DSystem, mp, true);
	mPlane = new ZShadeSandboxMesh::PlaneMesh(m_D3DSystem, mp, "Models\\plane01.txt");
	
	//mp.pos = XMFLOAT3(2, 2, 0);
	mp.material = MaterialManager::Instance()->GetMaterial("White");//Red
	mp.scale = XMFLOAT3(1, 1, 1);
	mp.pos = XMFLOAT3(0, 1, 0);
	mPickingSphere = new ZShadeSandboxMesh::SphereMesh(0.2f, 10, 10, m_D3DSystem, mp);

	float size = 10;
	float r = size / 100;
	//mp.pos = XMFLOAT3(4, 2, 0);
	mp.scale = XMFLOAT3(size, size, size);
	mp.pos = XMFLOAT3(50, 5, -45);
	mp.material = MaterialManager::Instance()->GetMaterial("Floor");//Floor
	mSphere = new ZShadeSandboxMesh::SphereMesh(r, size, size, m_D3DSystem, mp);
	
	//mp.pos = XMFLOAT3(0, 2, 2);
	mp.pos = XMFLOAT3(-45, 5, -30);
	mp.material = MaterialManager::Instance()->GetMaterial("Ice");//Ice
	mGeosphereMesh = new ZShadeSandboxMesh::GeosphereMesh(0.5f, 2, m_D3DSystem, mp);

	//mp.pos = XMFLOAT3(4, 2, 2);
	mp.pos = XMFLOAT3(30, 2, 60);
	mp.scale = XMFLOAT3(1, 1, 1);
	mp.material = MaterialManager::Instance()->GetMaterial("White");
	mCylindricalMesh = new ZShadeSandboxMesh::CylindricalMesh(0.5f, 0.5f, 3.0f, 10, 10, m_D3DSystem, mp);

	//mp.pos = XMFLOAT3(-2, 2, 0);
	mp.pos = XMFLOAT3(-50, 5, 40);
	mp.scale = XMFLOAT3(5, 5, 5);
	mp.material = MaterialManager::Instance()->GetMaterial("Wall");//Wall
	ZShadeSandboxMesh::CubeMesh* cubeMesh = new ZShadeSandboxMesh::CubeMesh(m_D3DSystem, mp, "Models\\cube.txt");
	vector<XMFLOAT3> v;
	v.push_back(XMFLOAT3(-50, 0, 40));
	v.push_back(XMFLOAT3(20, 0, 0));
	v.push_back(XMFLOAT3(80, 0, 10));
	v.push_back(XMFLOAT3(-50, 0, 100));
	cubeMesh->AddInstancePositions(v);

	//mp.pos = XMFLOAT3(1, 1, 0);
	//mp.material = MaterialManager::Instance()->GetMaterial("Floor");
	//mCircleMesh = new ZShadeSandboxMesh::CircleMesh(m_D3DSystem, 0.5f, mp);

	//m_SpawnedMeshContainer.push_back(mSphere);
	m_SpawnedMeshContainer.push_back(mGeosphereMesh);
	//m_SpawnedMeshContainer.push_back(mCylindricalMesh);
	//m_SpawnedMeshContainer.push_back(mCircleMesh);
	m_SpawnedMeshContainer.push_back(cubeMesh);
	
	// Enable the capsule lights for this scene
	//ZShadeSandboxLighting::LightManager::Instance()->ToggleCapsuleLights(true);
	
	// spaceCompound
	mSpaceCompound = new ZShadeSandboxMesh::OBJMesh(m_D3DSystem, m_GameDirectory3D);
	mSpaceCompound->Load("Models//spaceCompound.obj", false, false);
	mSpaceCompound->Scale(XMFLOAT3(2.3f, 1.3f, 2.3f));
	mSpaceCompound->Position(XMFLOAT3(100, -1, 100));
	
	// MaleLow.obj
	mHuman = new ZShadeSandboxMesh::OBJMesh(m_D3DSystem, m_GameDirectory3D);
	mHuman->Load("Models//MaleLow.obj", false, true);
	mHuman->Scale(XMFLOAT3(0.3f, 0.3f, 0.3f));
	mHuman->Position(XMFLOAT3(50, 15, 50));
}
Ejemplo n.º 7
0
// INITIALIZE CORE FUNCTIONS
bool RenderEngine::Init(){

	if (!InitWindow()){
		return false; //gick inte att skapa window
	}

	if (!InitDirect3D(hWindow)){
		return false; //gick inte att skapa Direct3D
	}
	// Sets and creates viewport
	SetViewport();

	//Initialize Shaders and triangle data
	Shaders();
	CreatePlaneData();
	TextureFunc();

	//Font
	Fonts();

	//Import
	
	ImportObj("Objects/testPlayer1.obj", "Objects/testPlayer1.mtl", gDevice, true);
	
	ImportObj("Objects/mapPart1.obj", "Objects/mapPart1.mtl", gDevice, false);
	ImportObj("Objects/mapPart2.obj", "Objects/mapPart2.mtl", gDevice, false);
	ImportObj("Objects/mapPart3.obj", "Objects/mapPart3.mtl", gDevice, false);
	ImportObj("Objects/mapPart4.obj", "Objects/mapPart4.mtl", gDevice, false);
	ImportObj("Objects/mapPart5.obj", "Objects/mapPart5.mtl", gDevice, false);
	ImportObj("Objects/mapPart6.obj", "Objects/mapPart6.mtl", gDevice, false);
	ImportObj("Objects/mapPart7.obj", "Objects/mapPart7.mtl", gDevice, false);
	ImportObj("Objects/mapPart7.obj", "Objects/mapPart7.mtl", gDevice, false);

	

	//LIGHT TEST ZONE BITCHES
	/*float l1Int = 1.0f;
	XMFLOAT3 l1Pos = XMFLOAT3(0.0f, 1.0f, -2.0f);
	XMFLOAT4 l1Amb = XMFLOAT4(1.0f, 1.0f, 1.0f,1.0f);
	XMFLOAT4 l1Diff = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	XMFLOAT4 l1Spec = XMFLOAT4(0.5f, 0.2f, 0.2f, 1.0f);
	XMFLOAT3 l1Dir = XMFLOAT3(0.0f, -50.0f, 30.0f);*/



	testLight[0] = LightClass(l_Directional, XMFLOAT3(1.0f, 1.0f, -5.0f), true, true);
	testLight[0].lightObject.Color = XMFLOAT4(Colors::White);
	/*testLight[0].ToggleActive();*/

	LightClass snoppe(l_Point, XMFLOAT3(1.0f, 1.0f, 0.0f), true, true);

	testLight[1] = snoppe;
	snoppe.lightObject.Type = 2;
	testLight[1].lightObject.Position = XMFLOAT4(-4.0f, 8.0f, 1.0f, 1.0f);
	testLight[1].lightObject.Color = XMFLOAT4(Colors::LightGoldenrodYellow);
	testLight[1].lightObject.AttConst = 1.0f;
	testLight[1].lightObject.AttLinear = 0.08f;
	testLight[1].lightObject.AttQuadratic = 0.00000f;
	//testLight[1].ToggleActive();
 	globalAmb = XMFLOAT4(Colors::Black);

	D3D11_BUFFER_DESC lbuffDesc;
	ZeroMemory(&lbuffDesc, sizeof(lbuffDesc));
	lbuffDesc.Usage = D3D11_USAGE_DEFAULT;
	lbuffDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	lbuffDesc.CPUAccessFlags = 0;
	lbuffDesc.MiscFlags = 0;
	lbuffDesc.ByteWidth = sizeof(LightProperties);

	HRESULT hr = gDevice->CreateBuffer(&lbuffDesc, NULL, &lightConstBuff);


	// Material Buffers Init
	ZeroMemory(&lbuffDesc, sizeof(lbuffDesc));
	lbuffDesc.ByteWidth = sizeof(MaterialProperties);
	hr = gDevice->CreateBuffer(&lbuffDesc, NULL, &matConstBuff);



	return true; //om båda funkade så returnera true (y)
}
Ejemplo n.º 8
0
bool Projekt::Init()
{
	if (!D3D11App::Init())
		return false;

	// Initialize effects, input layouts and texture manager
	Effects::InitAll(mDirect3D->GetDevice());
	InputLayouts::InitAll(mDirect3D->GetDevice());
	mTextureMgr.init(mDirect3D->GetDevice());

	// Initialize wireframe render state
	D3D11_RASTERIZER_DESC wireFrameDesc;
	ZeroMemory(&wireFrameDesc, sizeof(D3D11_RASTERIZER_DESC));
	wireFrameDesc.FillMode = D3D11_FILL_WIREFRAME;
	wireFrameDesc.CullMode = D3D11_CULL_BACK;
	wireFrameDesc.FrontCounterClockwise = false;
	wireFrameDesc.DepthClipEnable = true;

	HR(mDirect3D->GetDevice()->CreateRasterizerState(&wireFrameDesc, &WireFrameRS));

	//--------------------------------------------------------
	// Create sky
	//--------------------------------------------------------
	mSky = new Sky(mDirect3D->GetDevice(), L"Data/Textures/snowcube1024.dds", 5000.0f);

	//--------------------------------------------------------
	// Create terrain
	//--------------------------------------------------------
	// Describe terrain
	Terrain::InitInfo tInitInfo;
	tInitInfo.HeightMapFilename = L"Data/Textures/Heightmaps/terrain.raw";
	tInitInfo.LayerMapFilename0 = L"Data/Textures/grass.dds";
	tInitInfo.LayerMapFilename1 = L"Data/Textures/darkdirt.dds";
	tInitInfo.LayerMapFilename2 = L"Data/Textures/stone.dds";
	tInitInfo.LayerMapFilename3 = L"Data/Textures/lightdirt.dds";
	tInitInfo.LayerMapFilename4 = L"Data/Textures/snow.dds";
	tInitInfo.BlendMapFilename = L"Data/Textures/blend.dds";
	tInitInfo.HeightScale = 50.0f;
	tInitInfo.HeightmapWidth = 2049;
	tInitInfo.HeightmapHeight = 2049;
	tInitInfo.CellSpacing = 0.5f;

	// Initialize terrain
	mTerrain.Init(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), tInitInfo);

	//--------------------------------------------------------
	// Particle systems
	//--------------------------------------------------------
	mRandomTexSRV = d3dHelper::CreateRandomTexture1DSRV(mDirect3D->GetDevice());

	std::vector<std::wstring> flares;
	flares.push_back(L"Data\\Textures\\flare0.dds");
	mFlareTexSRV = d3dHelper::CreateTexture2DArraySRV(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), flares);

	mFire.init(mDirect3D->GetDevice(), Effects::FireFX, mFlareTexSRV, mRandomTexSRV, 500);
	mFire.setEmitPos(XMFLOAT3(65.0f, 5.0f, 0.0f));

	//--------------------------------------------------------
	// Create shadow map
	//--------------------------------------------------------
	mShadowMapSize = 2048;
	mShadowMap = new ShadowMap(mDirect3D->GetDevice(), mShadowMapSize, mShadowMapSize);

	//--------------------------------------------------------
	// Load models
	//--------------------------------------------------------
	mGenericModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\duck.dae", L"Data\\Models\\Collada\\");

	//mSkinnedModel = new GenericSkinnedModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\AnimTest\\test_Collada_DAE.dae", L"Data\\Models\\Collada\\AnimTest\\");

	mPlayerModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\OBJ\\Cop\\cop.obj", L"Data\\Models\\OBJ\\Cop\\");

	Player::InitProperties playerProp;

	playerProp.PlayerID = 0;
	playerProp.Nickname = "Hyzor";
	playerProp.Speed = 1.0f;
	playerProp.Health = 1.0f;
	playerProp.Position = XMFLOAT3(0.0f, 0.0f, 0.0f);
	playerProp.Scale = XMFLOAT3(1.0f, 1.0f, 1.0f);
	playerProp.Angle = 0.0f;
	playerProp.Model = mPlayerModel;

	mPlayer.Init(playerProp);
	
	//--------------------------------------------------------
	// Create model instances
	//--------------------------------------------------------

	GenericModelInstance genericInstance;
	genericInstance.model = mGenericModel;

// 	GenericSkinnedModelInstance genSkinnedInstance;
// 	genSkinnedInstance.model = mSkinnedModel;
// 	genSkinnedInstance.FinalTransforms.resize(mSkinnedModel->skinnedData.getBoneCount());
// 	genSkinnedInstance.ClipName = "animation";
// 	genSkinnedInstance.TimePos = 0.0f;

	//--------------------------------------------------------
	// Scale, rotate and move model instances
	//--------------------------------------------------------
	XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, 1.0f);
	XMMATRIX modelRot = XMMatrixRotationY(0.0f);
	XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f);

	//modelScale = XMMatrixScaling(0.1f, 0.1f, 0.1f);
	modelOffset = XMMatrixTranslation(-30.0f, 15.0f, -110.0f);
	XMStoreFloat4x4(&genericInstance.world, modelScale*modelRot*modelOffset);

// 	modelOffset = XMMatrixTranslation(50.0f, 15.0f, -110.0f);
// 	XMStoreFloat4x4(&genSkinnedInstance.world, modelScale*modelRot*modelOffset);

	//--------------------------------------------------------
	// Insert model instances to the vector
	//--------------------------------------------------------
	mGenericInstances.push_back(genericInstance);

/*	mGenSkinnedInstances.push_back(genSkinnedInstance);*/

	//--------------------------------------------------------
	// Compute scene bounding box
	//--------------------------------------------------------
	XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity);
	XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity);

	// Get vertex positions from all models
	for (UINT i = 0; i < mGenericInstances.size(); ++i)
	{
		for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j)
		{
			XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position;

			minPt.x = MathHelper::getMin(minPt.x, vPos.x);
			minPt.y = MathHelper::getMin(minPt.x, vPos.x);
			minPt.z = MathHelper::getMin(minPt.x, vPos.x);

			maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
			maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
			maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
		}
	}

	// Get vertex positions from all skinned models
// 	for (UINT i = 0; i < mGenSkinnedInstances.size(); ++i)
// 	{
// 		for (UINT j = 0; j < mGenSkinnedInstances[i].model->vertices.size(); ++j)
// 		{
// 			XMFLOAT3 vPos = mGenSkinnedInstances[i].model->vertices[j]->position;
// 
// 			minPt.x = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.y = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.z = MathHelper::getMin(minPt.x, vPos.x);
// 
// 			maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
// 		}
// 	}

	// Now continue with terrain vertex positions
	for (UINT i = 0; i < mTerrain.getPatchVertices().size(); ++i)
	{
		XMFLOAT3 vPos = mTerrain.getPatchVertices()[i].position;

		minPt.x = MathHelper::getMin(minPt.x, vPos.x);
		minPt.y = MathHelper::getMin(minPt.x, vPos.x);
		minPt.z = MathHelper::getMin(minPt.x, vPos.x);

		maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
		maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
		maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
	}

	// Sphere center is at half of these new dimensions
	mSceneBounds.Center = XMFLOAT3(	0.5f*(minPt.x + maxPt.x),
		0.5f*(minPt.y + maxPt.y),
		0.5f*(minPt.z + maxPt.z));

	// Calculate the sphere radius
	XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x),
		0.5f*(maxPt.y - minPt.y),
		0.5f*(maxPt.z - minPt.z));

	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);

	OnResize();

	return true;
}
Ejemplo n.º 9
0
LitSkullApp::LitSkullApp(HINSTANCE hInstance)
: D3DApp(hInstance), mShapesVB(0), mShapesIB(0), mSkullVB(0), mSkullIB(0), mSkullIndexCount(0), mLightCount(1),
  mEyePosW(0.0f, 0.0f, 0.0f), mTheta(1.5f*MathHelper::Pi), mPhi(0.1f*MathHelper::Pi), mRadius(15.0f)
{
	mMainWndCaption = L"LitSkull Demo";
	
	mLastMousePos.x = 0;
	mLastMousePos.y = 0;

	XMMATRIX I = XMMatrixIdentity();
	XMStoreFloat4x4(&mGridWorld, I);
	XMStoreFloat4x4(&mView, I);
	XMStoreFloat4x4(&mProj, I);

	XMMATRIX boxScale = XMMatrixScaling(3.0f, 1.0f, 3.0f);
	XMMATRIX boxOffset = XMMatrixTranslation(0.0f, 0.5f, 0.0f);
	XMStoreFloat4x4(&mBoxWorld, XMMatrixMultiply(boxScale, boxOffset));

	XMMATRIX skullScale = XMMatrixScaling(0.5f, 0.5f, 0.5f);
	XMMATRIX skullOffset = XMMatrixTranslation(0.0f, 1.0f, 0.0f);
	XMStoreFloat4x4(&mSkullWorld, XMMatrixMultiply(skullScale, skullOffset));

	for(int i = 0; i < 5; ++i)
	{
		XMStoreFloat4x4(&mCylWorld[i*2+0], XMMatrixTranslation(-5.0f, 1.5f, -10.0f + i*5.0f));
		XMStoreFloat4x4(&mCylWorld[i*2+1], XMMatrixTranslation(+5.0f, 1.5f, -10.0f + i*5.0f));

		XMStoreFloat4x4(&mSphereWorld[i*2+0], XMMatrixTranslation(-5.0f, 3.5f, -10.0f + i*5.0f));
		XMStoreFloat4x4(&mSphereWorld[i*2+1], XMMatrixTranslation(+5.0f, 3.5f, -10.0f + i*5.0f));
	}

	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);

	mGridMat.Ambient  = XMFLOAT4(0.48f, 0.77f, 0.46f, 1.0f);
	mGridMat.Diffuse  = XMFLOAT4(0.48f, 0.77f, 0.46f, 1.0f);
	mGridMat.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f);

	mCylinderMat.Ambient  = XMFLOAT4(0.7f, 0.85f, 0.7f, 1.0f);
	mCylinderMat.Diffuse  = XMFLOAT4(0.7f, 0.85f, 0.7f, 1.0f);
	mCylinderMat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 16.0f);

	mSphereMat.Ambient  = XMFLOAT4(0.1f, 0.2f, 0.3f, 1.0f);
	mSphereMat.Diffuse  = XMFLOAT4(0.2f, 0.4f, 0.6f, 1.0f);
	mSphereMat.Specular = XMFLOAT4(0.9f, 0.9f, 0.9f, 16.0f);

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

	mSkullMat.Ambient  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
	mSkullMat.Diffuse  = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
	mSkullMat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 16.0f);
}
Ejemplo n.º 10
0
void CameraObj::UpdateCBuffer(UINT screenWidth, UINT screenHeight) 
{
	TransformData tDataTemp = transform->transformData;

	//XMVECTOR pos = XMVectorSet(tDataTemp.pos.x, tDataTemp.pos.y, tDataTemp.pos.z, 1.0f);
	//XMVECTOR rotTemp = XMVectorSet(tDataTemp.rot.x, tDataTemp.rot.y, tDataTemp.rot.z, tDataTemp.rot.w);
	

	////Load the stuff
	XMFLOAT4 rotQuad = XMFLOAT4(tDataTemp.rot.x, tDataTemp.rot.y, tDataTemp.rot.z, tDataTemp.rot.w); //använd denna sen
	//XMFLOAT4 rotQuad = XMFLOAT4(0, 0, -1, 0); //hårkodad
	XMVECTOR rotQuadVec = XMLoadFloat4(&rotQuad);
	rotQuadVec = XMVector4Normalize(rotQuadVec);
	XMFLOAT3 pos = XMFLOAT3(tDataTemp.pos.x, tDataTemp.pos.y, tDataTemp.pos.z);
	//XMFLOAT3 pos = XMFLOAT3(0, 0, 200);//hårkodad
	XMVECTOR posVec = XMLoadFloat3(&pos);

	////Load standard vectors
	XMFLOAT3 startUp = XMFLOAT3(0, 1, 0);
	XMVECTOR startUpVec = XMLoadFloat3(&startUp);
	XMFLOAT3 startTar = XMFLOAT3(0, 0, 1);
	XMVECTOR startTarVec = XMLoadFloat3(&startTar);

	XMMATRIX rotMatrix = XMMatrixRotationQuaternion(rotQuadVec);
	startUpVec = XMVector3Transform(startUpVec, rotMatrix);
	startTarVec = XMVector3Transform(startTarVec, rotMatrix);

	XMFLOAT3 derpTar;
	XMStoreFloat3(&derpTar, startTarVec);



	XMMATRIX cameraMat = XMMatrixLookToLH(posVec, startTarVec, startUpVec);


	//XMVECTOR rot = XMVector3Rotate(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), rotTemp); //+ positionen eller nått sånt, se denna
	//XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	//XMMATRIX view = XMMatrixLookAtRH(pos, rot, up);
	
	
	XMMATRIX projection;
	if (cameraData.isOrtho == 0)
	{
		float aspect = (float)screenWidth / (float)screenHeight;
		projection = XMMatrixPerspectiveFovLH(
			cameraData.hAngle,//cameraData.hAngle,
			aspect, //aspect ratio?
			1.0f,
			4000
			);
	}
	else
	{
		float fovinv = (float)screenHeight / (float)screenWidth;
		projection = XMMatrixOrthographicLH(cameraData.hAngle, cameraData.hAngle * fovinv, 1.0f, 4000.0f);
	}
	
	XMMATRIX view = cameraMat;
	XMStoreFloat4x4(&cameraCBufferData.view, XMMatrixTranspose(view));
	XMStoreFloat4x4(&cameraCBufferData.projection, XMMatrixTranspose(projection));
	cameraCBufferData.cameraPos[0] = transform->transformData.pos.x;
	cameraCBufferData.cameraPos[1] = transform->transformData.pos.y;
	cameraCBufferData.cameraPos[2] = transform->transformData.pos.z;
	cameraCBufferData.cameraPos[3] = 1;
	
	gDeviceContext->UpdateSubresource(cameraCbuffer, 0, NULL, &cameraCBufferData, 0, 0);
}
Ejemplo n.º 11
0
void EnemyModel::InitializeModel()
{

    m_directionVector = XMFLOAT3(0.0f,0.0f,1.0f); //face in positive Z direction
	m_upDirectionVector = XMFLOAT3(0.0f, 1.0f, 0.0f);
	torsoLength = 0.5f;
	step = LEFT;
	leftRotationAngle = -XM_PIDIV2;
	rightRotationAngle = -XM_PIDIV2;

    WCHAR * headFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyHeadBack.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyHeadFront.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHeadSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHeadSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHeadTop.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHeadBottom.dds",
	};

	m_Head = new CubeTexturedModel(m_scale * (torsoLength * 0.7f),
									m_scale * (torsoLength * 0.7f),
									m_scale * (torsoLength * 0.7f),
									headFileNames);
	m_Head->orientTranslate(0.0f, m_scale * (torsoLength / 2.0f + (torsoLength * 0.7f) / 2.0f), 0.0f);
	m_Head->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);
	
	WCHAR * torsoFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyTorsoBack.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyTorsoFront.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoTopBot.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoTopBot.dds",
	};

	m_Torso = new CubeTexturedModel(m_scale * (torsoLength / 2.0f),
									m_scale * (torsoLength),
									m_scale * (torsoLength / 2.0f),
									torsoFileNames);
	m_Torso->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);
	
	WCHAR * leftArmFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds",
		 L"../Engine/textures/EnemyTextures/EnemyArmsInsides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds",
		 L"../Engine/textures/EnemyTextures/EnemyShoulders.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHands.dds",
	};

	m_LeftArm = new CubeTexturedModel(m_scale * (torsoLength / 5.0f),
										m_scale * (torsoLength * 0.9f),
										m_scale * (torsoLength / 3.0f),
										leftArmFileNames);
	m_LeftArm->orientTranslate(-m_scale * (torsoLength / 2.0f - (torsoLength / 4.0f) / 2.0f), m_scale * (torsoLength * 0.05f), 0.0f);
	m_LeftArm->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);
	
	WCHAR * rightArmFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds",
		 L"../Engine/textures/EnemyTextures/EnemyArms.dds",
		 L"../Engine/textures/EnemyTextures/EnemyArmsInsides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyShoulders.dds",
		 L"../Engine/textures/EnemyTextures/EnemyHands.dds",
	};
	
	m_RightArm = new CubeTexturedModel(m_scale * (torsoLength / 5.0f),
										m_scale * (torsoLength * 0.9f),
										m_scale * (torsoLength / 3.0f),
										rightArmFileNames);
	m_RightArm->orientTranslate(m_scale * (torsoLength / 2.0f - (torsoLength / 4.0f) / 2.0f), m_scale * (torsoLength * 0.05f), 0.0f);
	m_RightArm->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);
	
	WCHAR * leftLegFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyLegsSides.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyLegsFront.dds",
		 L"../Engine/textures/EnemyTextures/EnemyLegsInsides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyLegsSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyShoulders.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoTopBot.dds",
	};
	
	m_LeftLeg = new CubeTexturedModel(m_scale * (torsoLength / 5.0f),
										m_scale * (torsoLength * 0.9f),
										m_scale * (torsoLength / 2.5f),
										leftLegFileNames);
	m_LeftLeg->orientTranslate(-m_scale * (torsoLength / 8.0f), -m_scale * (torsoLength * 0.8f), 0.0f);
	m_LeftLeg->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);
	
	WCHAR * rightLegFileNames[] = {
		 L"../Engine/textures/EnemyTextures/EnemyLegsSides.dds", 
		 L"../Engine/textures/EnemyTextures/EnemyLegsFront.dds",
		 L"../Engine/textures/EnemyTextures/EnemyLegsSides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyLegsInsides.dds",
		 L"../Engine/textures/EnemyTextures/EnemyShoulders.dds",
		 L"../Engine/textures/EnemyTextures/EnemyTorsoTopBot.dds",
	};
	
	m_RightLeg = new CubeTexturedModel(m_scale * (torsoLength / 5.0f),
										m_scale * (torsoLength * 0.9f),
										m_scale * (torsoLength / 2.5f),
										rightLegFileNames);
	m_RightLeg->orientTranslate(m_scale * (torsoLength / 8.0f), -m_scale * (torsoLength * 0.8f), 0.0f);
	m_RightLeg->worldTranslate(m_InitialPosition.x, m_InitialPosition.y, m_InitialPosition.z);

}
Ejemplo n.º 12
0
bool CameraDemo::LoadContent()
{
	ID3DBlob * vsBuffer = 0;
	
	bool compileResult = CompileD3DShader( "TextureMap.fx" , "VS_Main" , "vs_4_0" , &vsBuffer );

	if( compileResult == false )
	{
		DXTRACE_MSG( "¼ÓÔض¥µã×ÅÉ«Æ÷ʧ°Ü£¡" );
		return false;
	}

	HRESULT d3dResult;

	d3dResult = d3dDevice_ ->CreateVertexShader( vsBuffer ->GetBufferPointer() , vsBuffer ->GetBufferSize() , 0 , &solidColorVS_ );

	if( FAILED( d3dResult ))
	{
		if( vsBuffer )
			vsBuffer ->Release();

		return false ;
	}

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


	unsigned int totalLayoutElements = ARRAYSIZE( solidColorLayout );

	d3dResult =d3dDevice_ ->CreateInputLayout( solidColorLayout , totalLayoutElements , vsBuffer ->GetBufferPointer() , vsBuffer ->GetBufferSize() , &inputLayout_ );
	vsBuffer ->Release();

	if( FAILED( d3dResult ))
	{
		return false;
	}

	ID3DBlob * psBuffer = 0;

	compileResult = CompileD3DShader( "TextureMap.fx" , "PS_Main" , "ps_4_0" , &psBuffer );

	if( compileResult == false )
	{
		DXTRACE_MSG( "¼ÓÔØÏñËØ×ÅÉ«Æ÷ʧ°Ü£¡" );
		return false;
	}

	d3dResult = d3dDevice_ ->CreatePixelShader( psBuffer ->GetBufferPointer() , psBuffer ->GetBufferSize() , 0 , &solidColorPS_ );
	psBuffer ->Release();

	if( FAILED( d3dResult ))
	{
		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;
	}

	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;
	}

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

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

	if( FAILED( d3dResult ))
	{
		return false;
	}

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

	if( FAILED( d3dResult ))
	{
		return false;
	}

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

	if( FAILED( d3dResult ))
	{
		return false;
	}

	XMMATRIX projection_ = XMMatrixPerspectiveLH( XM_PIDIV4 , 800.0f / 600.0f , 0.01f , 100.0f );

	projection_ = XMMatrixTranspose( projection_ );
	

	camera_.SetPositions( XMFLOAT3( 3.0f , 3.0f , -12.0f ) , XMFLOAT3( 0.0f , 0.0f , 0.0f ));

	return true;
}
inline XMFLOAT3 GetPosition(XMMATRIX& matrix)
{
	return XMFLOAT3( matrix._41 , matrix._42 , matrix._43 );
}
Ejemplo n.º 14
0
	void Plane::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
	{
		///////////////////////////Index Buffer ////////////////////////////////
		m_VertexCount = 4;
		std::array<byhj::Vertex, 4> VertexData = 
		{
			byhj::Vertex(-1.0f, 0.0f, -1.0f, 100.0f, 100.0f, 0.0f, 1.0f, 0.0f),
			byhj::Vertex(-1.0f, 0.0f,  1.0f,  0.0f, 100.0f, 0.0f, 1.0f, 0.0f),
			byhj::Vertex( 1.0f, 0.0f,  1.0f,  0.0f, 0.0f, 0.0f, 1.0f, 0.0f),
			byhj::Vertex( 1.0f, 0.0f, -1.0f, 100.0f, 0.0f, 0.0f, 1.0f, 0.0f),
		};

		// Set up the description of the static vertex buffer.
		D3D11_BUFFER_DESC VertexBufferDesc;
		VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		VertexBufferDesc.ByteWidth           = sizeof(byhj::Vertex) * m_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.
		HRESULT hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
		//DebugHR(hr);

		/////////////////////////////////Index Buffer ///////////////////////////////////////
		m_IndexCount = 6;
		std::array<DWORD, 6>  IndexData = 		
		{
			0,  1,  2,
			0,  2,  3,
		};

		// Set up the description of the static index buffer.
		D3D11_BUFFER_DESC IndexBufferDesc;
		IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		IndexBufferDesc.ByteWidth           = sizeof(unsigned long) * m_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);

		////////////////////////////////Const Buffer//////////////////////////////////////

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

		////////////////////////////////////////////////////////////////////////////////
		D3D11_BUFFER_DESC cbLightDesc;
		ZeroMemory(&cbLightDesc, sizeof(D3D11_BUFFER_DESC));
		cbLightDesc.Usage          = D3D11_USAGE_DYNAMIC;
		cbLightDesc.ByteWidth      = sizeof(LightBuffer);
		cbLightDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		cbLightDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		cbLightDesc.MiscFlags      = 0;
		hr = pD3D11Device->CreateBuffer(&cbLightDesc, NULL, &m_pLightBuffer);
		//DebugHR(hr);

		D3D11_MAPPED_SUBRESOURCE mappedResource;
		hr = pD3D11DeviceContext->Map(m_pLightBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		//DebugHR(hr);
		LightBuffer *plightData = (LightBuffer *)mappedResource.pData;

		plightData->ambient   = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
		plightData->diffuse   = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		plightData->lightDir  = XMFLOAT3(0.25f, 0.5f, -1.0f);
		plightData->padding1  = 0.0f;
		plightData->lightPos  = XMFLOAT3(1.0f, 1.0f, 3.0f);
		plightData->range     = 100.0f;
		plightData->att       = XMFLOAT3(0.0f, 0.2f, 0.0f);
		plightData->padding2  = 0.0f;

		pD3D11DeviceContext->Unmap(m_pLightBuffer.Get(), 0);
	}
Ejemplo n.º 15
0
bool scRenderSystem::_LoadScene()
{
	HRESULT hr;

	// 测试场景节点
	scSceneNode* root = mSceneManager.GetRootSceneNode();
	mSceneManager.CreateSceneNode("1", root);
	mSceneManager.CreateSceneNode("2", root);
	scSceneNode* three = mSceneManager.CreateSceneNode("3", root);
	scSceneNode* four = mSceneManager.CreateSceneNode("4", three);
	scSceneNode* five = mSceneManager.CreateSceneNode("5", four);
	scSceneNode* six = mSceneManager.CreateSceneNode("6", five);
	scSceneNode* seven = mSceneManager.CreateSceneNode("7", five);

	scEntity* ent = mSceneManager.CreateEntity("test", "basicshape");
	ent->AddTexture(mTextureManager.GetResourcePtr("saber"));
	six->AttachObject(ent);

	//XMVECTOR rotvec = XMQuaternionRotationRollPitchYaw(0.57f, 0, 0);
	//XMFLOAT4 rot;
	//XMStoreFloat4(&rot, rotvec);
	//six->SetOrientation(rot);
	//seven->AttachObject(ent);

	// 测试viewport和摄像机
	scViewport* vp = mSceneManager.CreateViewport((float)mWindowWidth, (float)mWindowHeight, 0, 0);
	scCamera* camera = mSceneManager.CreateCamera("camera");
	camera->SetPosition(XMFLOAT3(0, 50, 100));
	camera->SetLookAt(XMFLOAT3(0, 0, 0));
	vp->SetCamera(camera);
	seven->AttachObject(camera);

	// 测试。。。
	// const buffers
	D3D11_BUFFER_DESC constDesc;
	ZeroMemory( &constDesc, sizeof( constDesc ) );
	constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	constDesc.ByteWidth = sizeof( XMMATRIX );
	constDesc.Usage = D3D11_USAGE_DEFAULT;

	hr = mDevice->CreateBuffer( &constDesc, 0, &viewCB_ );

	if( FAILED( hr ) )
	{
		return false;
	}

	hr = mDevice->CreateBuffer( &constDesc, 0, &projCB_ );

	if( FAILED( hr ) )
	{
		return false;
	}

	hr = mDevice->CreateBuffer( &constDesc, 0, &worldCB_ );

	if( FAILED( hr ) )
	{
		return false;
	}

	return true;
}
Ejemplo n.º 16
0
void XModel_LoadXModelFromFile( const char *filename, XModel **model )
{
	// --------------- read contents of file
	char *contents;
	unsigned int contentLength = XML_ReadFile( filename, &contents );
	assert( contentLength > 0 );

	XML_TokenList *tokenList = XML_Tokenize( contents, contentLength );

	free( contents );

	XML_Element *root = XML_Parse( tokenList );

	delete tokenList;

	// ---------------- transfer xml elements into xmodel
	assert( strcmp( root->data, "xmodel" ) == 0 );
	XModel *newModel = new XModel();

	XML_ElementAttribute *attributeIterator = root->attributes;
	while ( attributeIterator != NULL )
	{
		if ( strcmp( attributeIterator->key, "vs" ) == 0 )
		{
			size_t len = strlen( attributeIterator->value ) + 1;
			newModel->vertexShaderPath = ( wchar_t * ) malloc( sizeof( wchar_t ) * len );
			MultiByteToWideChar( 0, 0, attributeIterator->value, -1, newModel->vertexShaderPath, len );
		}
		else if ( strcmp( attributeIterator->key, "ps" ) == 0 )
		{
			size_t len = strlen( attributeIterator->value ) + 1;
			newModel->pixelShaderPath = ( wchar_t * ) malloc( sizeof( wchar_t ) * len );
			MultiByteToWideChar( 0, 0, attributeIterator->value, -1, newModel->pixelShaderPath, len );
		}
		attributeIterator = attributeIterator->next;
	}

	XML_Element *xmodelChildIterator = root->child;
	while ( xmodelChildIterator != NULL )
	{
		if ( strcmp( xmodelChildIterator->data, "vertices" ) == 0 )
		{
			unsigned int vertexCount = 0;
			XML_ElementAttribute *vertexAttributeIterator = xmodelChildIterator->attributes;
			while ( vertexAttributeIterator != NULL )
			{
				if ( strcmp( vertexAttributeIterator->key, "count" ) == 0 )
				{
					vertexCount = atoi( vertexAttributeIterator->value );
				}
				vertexAttributeIterator = vertexAttributeIterator->next;
			}

			assert( vertexCount > 0 );

			const char *vertexStringIterator = ( char * ) xmodelChildIterator->child->data;

			newModel->vertices = new XVertex[vertexCount];
			newModel->vertexCount = vertexCount;
			for ( unsigned int i = 0; i < vertexCount; i++ )
			{
				char floatStringBuffer[256];
				unsigned int bufferIndex = 0;
				float x, y, z;

				char *error;

				assert( *vertexStringIterator == '(' );
				vertexStringIterator++;
				while ( *vertexStringIterator != ',' )
				{
					floatStringBuffer[bufferIndex++] = *vertexStringIterator;
					vertexStringIterator++;
				}
				vertexStringIterator++;
				floatStringBuffer[bufferIndex++] = '\0';
				bufferIndex = 0;
				x = strtof( floatStringBuffer, &error );

				while ( *vertexStringIterator != ',' )
				{
					floatStringBuffer[bufferIndex++] = *vertexStringIterator;
					vertexStringIterator++;
				}
				vertexStringIterator++;
				floatStringBuffer[bufferIndex++] = '\0';
				bufferIndex = 0;
				y = strtof( floatStringBuffer, &error );

				while ( *vertexStringIterator != ')' )
				{
					floatStringBuffer[bufferIndex++] = *vertexStringIterator;
					vertexStringIterator++;
				}
				floatStringBuffer[bufferIndex++] = '\0';
				bufferIndex = 0;
				z = strtof( floatStringBuffer, &error );

				newModel->vertices[i].position = XMFLOAT3( x, y, z );

				assert( *vertexStringIterator == ')' );
				vertexStringIterator++;
				if ( i != vertexCount - 1 )
				{
					assert( *vertexStringIterator == ',' );
					vertexStringIterator++;
				}
			}
		}
		else if ( strcmp( xmodelChildIterator->data, "indices" ) == 0 )
		{
			unsigned int indexCount = 0;
			XML_ElementAttribute *indexAttributeIterator = xmodelChildIterator->attributes;
			while ( indexAttributeIterator != NULL )
			{
				if ( strcmp( indexAttributeIterator->key, "count" ) == 0 )
				{
					indexCount = atoi( indexAttributeIterator->value );
				}
				indexAttributeIterator = indexAttributeIterator->next;
			}

			newModel->indices = new WORD[indexCount];
			newModel->indexCount = indexCount;
			char *indexStringIterator = ( char * ) xmodelChildIterator->child->data;
			for ( unsigned int i = 0; i < indexCount; i++ )
			{
				char intStringBuffer[512];
				unsigned int intStringBufferIndex = 0;

				while ( *indexStringIterator != ',' && *indexStringIterator != '\0' )
				{
					intStringBuffer[intStringBufferIndex++] = *indexStringIterator;
					indexStringIterator++;
				}

				assert( intStringBufferIndex > 0 );
				assert( ( i < indexCount - 1 && *indexStringIterator == ',' ) || ( *indexStringIterator == '\0' ) );
				indexStringIterator++;

				newModel->indices[i] = atoi( intStringBuffer );
			}
		}
		xmodelChildIterator = xmodelChildIterator->sibling;
	}

	assert( newModel->vertexShaderPath != NULL );
	assert( newModel->pixelShaderPath != NULL );

	*model = newModel;

	// ------------ free TODO
	//XML_Element_Free(&root);
}
// draws the given message on the screen
bool FontManager::DrawString( char* message, float startX, float startY )
{
    // size in bytes for a single sprite
    const int sizeOfSprite = sizeof( VertexPos ) * 6;

    // dynamic buffer setup for max of 24 letters
    const int maxLetters = 24;

    int length = strlen( message );

    // clamp for strings too long
    if( length > maxLetters )
        length = maxLetters;

    // char's width on screen
	float charWidth = 32.0f / game_->GetScreenWidth( );

    // char's height on screen
	float charHeight = 38.0f / game_->GetScreenHeight( );
    
    // char's texel width
    float texelWidth = 32.0f / 3040.0f;

    // verts per-triangle (3) * total triangles (2) = 6
    const int verticesPerLetter = 6;

    D3D11_MAPPED_SUBRESOURCE mapResource;
    HRESULT d3dResult = d3dContext_->Map( vertexBuffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource );

    if( FAILED( d3dResult ) )
    {
        DXTRACE_MSG( "Failed to map resource!" );
        return false;
    }

    // point to our vertex buffer's internal data
    VertexPos *spritePtr = ( VertexPos* )mapResource.pData;

    const int indexFirst = static_cast<char>( ' ' );
    const int indexLast = static_cast<char>( '~' );

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

		// set the vertex positions
        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 < indexFirst || letter > indexLast )
        {
            // grab the first index, which is a blank space in the texture
            texLookup = 0;
        }
        else
        {
            // space = 0, ! = 1, ~ = 126, etc
            texLookup = ( letter - indexFirst );
        }

        float tuStart = 0.0f + ( texelWidth * static_cast<float>( texLookup ) );
        float tuEnd = tuStart + texelWidth;

		// align the texture
        spritePtr[0].tex0 = XMFLOAT2( tuEnd, 0.0f );
        spritePtr[1].tex0 = XMFLOAT2( tuEnd, 1.0f );
        spritePtr[2].tex0 = XMFLOAT2( tuStart, 1.0f );
        spritePtr[3].tex0 = XMFLOAT2( tuStart, 1.0f );
        spritePtr[4].tex0 = XMFLOAT2( tuStart, 0.0f );
        spritePtr[5].tex0 = XMFLOAT2( tuEnd, 0.0f );

        spritePtr += 6;
    }

	// unmap the buffer and draw all the vertices
    d3dContext_->Unmap( vertexBuffer_, 0 );
    d3dContext_->Draw( 6 * length, 0 );

    return true;
}
Ejemplo n.º 18
0
ManeuverJetpack::ManeuverJetpack(Entity* player) : Jetpack(player)
{
	maxSpeed = 30;
	fuelUseRate = 0;//10;
	forwardAcceleration = 16.0f;
	backwardAcceleration = 16.0f;
	strafeAcceleration = 16.0f;
	ascentAcceleration = 24.0f;
	backSpin = 45 * (PI / 180);
	frontSpin = 45 * (PI / 180);
	sideSpin = 0 * (PI / 180);
	bottomSpin = 15 * (PI / 180);
	//actionsPerSecond = 1.9f;
	
	// Thrusters
	thrusterCount = 8;
	CreateThrusters();
	// Bottom Left
	thrusters[Thruster::BOTTOM_LEFT]->transform.SetLocalTranslation(XMFLOAT3(-0.022f, 0.025f, -0.0215f));
	thrusters[Thruster::BOTTOM_LEFT]->transform.SetLocalRotation(XMFLOAT3(0, 0, PI));
	// Bottom Right
	thrusters[Thruster::BOTTOM_RIGHT]->transform.SetLocalTranslation(XMFLOAT3(0.022f, 0.025f, -0.0215f));
	thrusters[Thruster::BOTTOM_RIGHT]->transform.SetLocalRotation(XMFLOAT3(0, 0, PI));
	// Back Left
	thrusters[Thruster::BACK_LEFT]->transform.SetLocalTranslation(XMFLOAT3(-0.013f, 0.082f, -0.05f));
	thrusters[Thruster::BACK_LEFT]->transform.SetLocalRotation(XMFLOAT3(-PI / 2, 0, 0));
	// Back Right
	thrusters[Thruster::BACK_RIGHT]->transform.SetLocalTranslation(XMFLOAT3(0.013f, 0.082f, -0.05f));
	thrusters[Thruster::BACK_RIGHT]->transform.SetLocalRotation(XMFLOAT3(-PI / 2, 0, 0));
	// Front Left
	thrusters[Thruster::FRONT_LEFT]->transform.SetLocalTranslation(XMFLOAT3(-0.028f, 0.103f, -0.005f));
	thrusters[Thruster::FRONT_LEFT]->transform.SetLocalRotation(XMFLOAT3(PI / 2, 0, 0));
	// Front Right
	thrusters[Thruster::FRONT_RIGHT]->transform.SetLocalTranslation(XMFLOAT3(0.028f, 0.103f, 0.005f));
	thrusters[Thruster::FRONT_RIGHT]->transform.SetLocalRotation(XMFLOAT3(PI / 2, 0, 0));
	// Side Left
	thrusters[Thruster::SIDE_LEFT]->transform.SetLocalTranslation(XMFLOAT3(-0.047f, 0.084f, -0.021f));
	thrusters[Thruster::SIDE_LEFT]->transform.SetLocalRotation(XMFLOAT3(0, 0, PI / 2));
	// Side Right
	thrusters[Thruster::SIDE_RIGHT]->transform.SetLocalTranslation(XMFLOAT3(0.047f, 0.084f, -0.021f));
	thrusters[Thruster::SIDE_RIGHT]->transform.SetLocalRotation(XMFLOAT3(0, 0, -PI / 2));
}
Ejemplo n.º 19
0
bool OrthoWindowClass::InitializeBuffers(ID3D11Device* device, int windowWidth, int windowHeight) {
    float left, right, top, bottom;
    VertexType* vertices;
    unsigned long* indices;
    D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
    D3D11_SUBRESOURCE_DATA vertexData, indexData;
    HRESULT result;
    int i;

    // Calculate screen coordinates
    left = (float)((windowWidth / 2) * -1); //left side of the window.
    right = left + (float)windowWidth; //right
    top = (float)(windowHeight / 2); //top
    bottom = top - (float)windowHeight; //bottom

    // Set the number of vertices in the vertex array.
    m_vertexCount = 6;

    // Set the number of indices in the index array.
    m_indexCount = m_vertexCount;

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

    // Create index array.
    indices = new unsigned long[m_indexCount];
    if (!indices) return false;

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

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

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

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

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

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

    // Load the index array with data.
    for (i = 0; i<m_indexCount; i++) {
        indices[i] = i;
    }

    //setup vertex buffer desc
    vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
    vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexBufferDesc.CPUAccessFlags = 0;
    vertexBufferDesc.MiscFlags = 0;
    vertexBufferDesc.StructureByteStride = 0;

    //give subresource structure a vertex data pointer
    vertexData.pSysMem = vertices;
    vertexData.SysMemPitch = 0;
    vertexData.SysMemSlicePitch = 0;

    //create vertex buffer
    result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
    if (FAILED(result)) return false;

    //setup index buffer desc
    indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
    indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
    indexBufferDesc.CPUAccessFlags = 0;
    indexBufferDesc.MiscFlags = 0;
    indexBufferDesc.StructureByteStride = 0;

    //give subresource structure an index data pointer
    indexData.pSysMem = indices;
    indexData.SysMemPitch = 0;
    indexData.SysMemSlicePitch = 0;

    //create index buffer
    result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
    if (FAILED(result)) return false;

    //release arrays now buffers are completed
    delete[] vertices;
    vertices = 0;
    delete[] indices;
    indices = 0;

    return true;
}
Ejemplo n.º 20
0
bool FontEngine::DrawString(ID3D11DeviceContext* p_DeviceContext, char* p_Text, float p_StartX, float p_StartY)
{
	//Size of a sprite (one)
	const int t_SizeOfSprite = sizeof(VertexType)* 6;

	// Dynamic buffer
	const int t_MaxLetters = 24;

	int t_Length = strlen(p_Text);

	// Make sure that strings are not too long.
	if (t_Length > t_MaxLetters)
		t_Length = t_MaxLetters;

	float t_Width = 1920;
	float t_Height = 1080;

	float t_CharacterSize = 32.0f;

	// A characters width on the screen
	float t_CharWidth = t_CharacterSize / t_Width;

	// A characters height on the screen
	float t_CharHeight = t_CharacterSize / t_Height;

	// cahracters texel width
	float t_TexelWidth = t_CharacterSize / 864.0f;//test

	// Rect amount of vertices
	const int t_VerticesPerLetter = 6;

	D3D11_MAPPED_SUBRESOURCE t_MapResource;
	HRESULT t_HR = p_DeviceContext->Map(m_VertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &t_MapResource);

	if (FAILED(t_HR))
	{
		//MessageBox(nullptr, L"Could not map resource", L"Error", MB_ICONERROR | MB_OK);
		Logger::Log( "Could not map resource", "FontSystem", LoggerType::MSG_ERROR);
		return false;
	}

	// Pointing to internal data of vertex buffer
	VertexType* t_Sprite = (VertexType*)t_MapResource.pData;

	const int t_IndexA = static_cast<char>('A');
	const int t_IndexZ = static_cast<char>('Z');

	for (int i = 0; i < t_Length; ++i)
	{
		float t_CurrentStartX = p_StartX + (t_CharWidth * static_cast<float>(i));
		float t_CurrentEndX = t_CurrentStartX + t_CharWidth;
		float t_CurrentEndY = p_StartY + t_CharHeight;

		t_Sprite[0].position = XMFLOAT3(t_CurrentEndX,	 t_CurrentEndY, 0.0f);
		t_Sprite[1].position = XMFLOAT3(t_CurrentEndX,	 p_StartY, 0.0f);
		t_Sprite[2].position = XMFLOAT3(t_CurrentStartX, p_StartY, 0.0f);
		t_Sprite[3].position = XMFLOAT3(t_CurrentStartX, p_StartY, 0.0f);
		t_Sprite[4].position = XMFLOAT3(t_CurrentStartX, t_CurrentEndY, 0.0f);
		t_Sprite[5].position = XMFLOAT3(t_CurrentEndX,	 t_CurrentEndY, 0.0f);

		int t_Vault = 0;
		int t_Letter = static_cast<char>(p_Text[i]);

		if (t_Letter < t_IndexA || t_Letter > t_IndexZ)
		{
			//Well this is awkward, putting an empty (space) char
			t_Vault = (t_IndexZ - t_IndexA) + 1;
		}
		else
		{
			// A = 0, B = 1, Z = 25, and so on
			t_Vault = (t_Letter - t_IndexA);
		}

		float t_TuStart = 0.0f + (t_TexelWidth * static_cast<float>(t_Vault));
		float t_TuEnd = t_TuStart + t_TexelWidth;

		t_Sprite[0].texture = XMFLOAT2(t_TuEnd,   0.0f);
		t_Sprite[1].texture = XMFLOAT2(t_TuEnd,   1.0f);
		t_Sprite[2].texture = XMFLOAT2(t_TuStart, 1.0f);
		t_Sprite[3].texture = XMFLOAT2(t_TuStart, 1.0f);
		t_Sprite[4].texture = XMFLOAT2(t_TuStart, 0.0f);
		t_Sprite[5].texture = XMFLOAT2(t_TuEnd,   0.0f);

		t_Sprite += 6;
	}

	p_DeviceContext->Unmap(m_VertexBuffer, 0);
	p_DeviceContext->Draw(6 * t_Length, 0);


	return true;
}
Ejemplo n.º 21
0
bool CollisionMesh::CheckCollisionsGJK2(CollisionMesh& otherMesh)
{
  bool collision = false;
  std::vector<XMFLOAT3> convexHull;

  std::vector<VPCNTDesc> vertices = GetVertices();
  std::vector<VPCNTDesc> otherVertices = otherMesh.GetVertices();
  XMMATRIX otherWorld = otherMesh.GetWorldTransform();
  XMMATRIX world = GetWorldTransform();
  XMFLOAT3 origin = XMFLOAT3(0.0f, 0.0f, 0.0f);

  // Pre-multiply the model's vertices so as to avoid transforming them during comparison.
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    XMStoreFloat3(&vertices[vertIndex].Position, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Position), world));
    XMStoreFloat3(&vertices[vertIndex].Normal, XMVector3Transform(XMLoadFloat3(&vertices[vertIndex].Normal), world));
  }

  for (int otherVertIndex = 0; otherVertIndex < otherVertices.size(); otherVertIndex++)
  {
    XMStoreFloat3(&otherVertices[otherVertIndex].Position, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Position), otherWorld));
    XMStoreFloat3(&otherVertices[otherVertIndex].Normal, XMVector3Transform(XMLoadFloat3(&otherVertices[otherVertIndex].Normal), otherWorld));
  }

  std::vector<VPCNTDesc> supportingVertices;
  for (int vertIndex = 0; vertIndex < vertices.size(); vertIndex++)
  {
    VPCNTDesc &firstVertex = vertices[vertIndex];
    VPCNTDesc &secondVertex = vertices[(vertIndex + 1) % vertices.size()];

    supportingVertices.clear();
    supportingVertices = GetSupportingVertices(otherVertices, firstVertex.Normal);

    for (int supportingVertexIndex = 0; supportingVertexIndex < supportingVertices.size(); supportingVertexIndex++)
    {
      XMFLOAT3 firstFormPoint, secondFormPoint;
      XMStoreFloat3(&firstFormPoint, XMVectorSubtract(XMLoadFloat3(&supportingVertices[supportingVertexIndex].Position), XMLoadFloat3(&firstVertex.Position)));
      XMStoreFloat3(&secondFormPoint, XMVectorSubtract(XMLoadFloat3(&supportingVertices[supportingVertexIndex].Position), XMLoadFloat3(&secondVertex.Position)));

      XMFLOAT3 edgeDistValue;
      XMStoreFloat3(&edgeDistValue, XMVector3Dot(XMLoadFloat3(&firstFormPoint), XMLoadFloat3(&firstVertex.Normal)));

      float edgeDist = edgeDistValue.x;

      // project the origin onto our edge.
      XMVECTOR firstToSecondVector = XMVectorSubtract(XMLoadFloat3(&firstFormPoint), XMLoadFloat3(&secondFormPoint));
      XMVECTOR secondToFirstVector = XMVectorSubtract(XMLoadFloat3(&secondFormPoint), XMLoadFloat3(&firstFormPoint));

      XMVECTOR fTSDotVector = XMVector3Dot(firstToSecondVector, XMVectorSet(firstFormPoint.x - origin.x, firstFormPoint.y - origin.y, firstFormPoint.z - origin.z, 0.0f));
      XMVECTOR sTFDotVector = XMVector3Dot(secondToFirstVector, XMVectorSet(secondFormPoint.x - origin.x, secondFormPoint.y - origin.y, secondFormPoint.z - origin.z, 0.0f));
      XMFLOAT3 firstDotValue, secondDotValue;
      XMStoreFloat3(&firstDotValue, fTSDotVector);
      XMStoreFloat3(&secondDotValue, sTFDotVector);

      XMFLOAT3 projectedPoint;

      if (firstDotValue.x > XMConvertToRadians(90.0f))
      {
        projectedPoint = firstFormPoint;
      }
      else if (secondDotValue.x > XMConvertToRadians(90.0f))
      {
        projectedPoint = secondFormPoint;
      }
      else
      {

      }
    }

  }

  return collision;
}
Ejemplo n.º 22
0
void LightClass::SetDirection(float x, float y, float z)
{
	m_direction = XMFLOAT3( x , y, z );
	return;
}
Ejemplo n.º 23
0
	void Text::WriteStringToConstantBuffer(Vertex::SpriteVertex* pTempVertex,int prOffset,wstring prString,int LineNum)
	{
		TextureAtlas *mTexture=mFont->GetTextureAtlas();
		float TexW = ( float )mTexture->GetWidth();
		float TexH = ( float )mTexture->GetHeight();

		sCharset* mCharset=mFont->GetCharset();
		
		int token;
		int index;

		float xOffset= 0.0f, xsOffset= 0.0f, yOffset, ysOffset;

		for( int i = 0; i < (int)prString.length(); i++ )
		{
			token = ( int )prString.at( i );

			yOffset = ( float )mCharset->Chars[token].YOffset;
			xsOffset = xOffset+hAlignOffset;
			ysOffset = yOffset+vAlignOffset+LineNum*mLineSpacing;

			index=(prOffset+i)*6;

			// Vertex Position.
			{
				// First triangle
				pTempVertex[index + 0].Position 
					= XMFLOAT3( xsOffset, ysOffset + ( float )mCharset->Chars[token].Height,  0.0f );

				pTempVertex[index + 1].Position 
					= XMFLOAT3( xsOffset, ysOffset, 0.0f );

				pTempVertex[index + 2].Position 
					= XMFLOAT3( xsOffset + ( float )mCharset->Chars[token].Width, ysOffset,  0.0f );

				// Second triangle
				pTempVertex[index + 3].Position 
					= XMFLOAT3( xsOffset, ysOffset + ( float )mCharset->Chars[token].Height,  0.0f );

				pTempVertex[index + 4].Position 
					= XMFLOAT3( xsOffset + ( float )mCharset->Chars[token].Width, ysOffset,  0.0f );

				pTempVertex[index + 5].Position 
					= XMFLOAT3( xsOffset + ( float )mCharset->Chars[token].Width, ysOffset + ( float )mCharset->Chars[token].Height,  0.0f );
			}

			// Texture Position.
			{
				// First triangle
				pTempVertex[index + 0].TexCoord =
					XMFLOAT2( ( float )mCharset->Chars[token].x / TexW, ( float )( mCharset->Chars[token].y + mCharset->Chars[token].Height ) / TexH );
				pTempVertex[index + 1].TexCoord =
					XMFLOAT2( ( float )mCharset->Chars[token].x / TexW, ( float )mCharset->Chars[token].y / TexH );
				pTempVertex[index + 2].TexCoord =
					XMFLOAT2( ( float )( mCharset->Chars[token].x + mCharset->Chars[token].Width )	/ TexW, ( float )( mCharset->Chars[token].y ) / TexH );

				// Second triangle
				pTempVertex[index + 3].TexCoord =
					XMFLOAT2( ( float )mCharset->Chars[token].x / TexW, ( float )( mCharset->Chars[token].y + mCharset->Chars[token].Height ) / TexH );
				pTempVertex[index + 4].TexCoord =
					XMFLOAT2( ( float )( mCharset->Chars[token].x + mCharset->Chars[token].Width )	/ TexW, ( float )( mCharset->Chars[token].y ) / TexH );
				pTempVertex[index + 5].TexCoord =
					XMFLOAT2( ( float )( mCharset->Chars[token].x + mCharset->Chars[token].Width )	/ TexW, ( float )( mCharset->Chars[token].y + mCharset->Chars[token].Height ) / TexH );
			}

			// Vertex Color Modulation
			{
				pTempVertex[index + 0].Color=ColorModulation;
				pTempVertex[index + 1].Color=ColorModulation;
				pTempVertex[index + 2].Color=ColorModulation;
				pTempVertex[index + 3].Color=ColorModulation;
				pTempVertex[index + 4].Color=ColorModulation;
				pTempVertex[index + 5].Color=ColorModulation;
			}

			xOffset += ( float )mCharset->Chars[token].Width;// + 2.0f;
		}
	}