void ForwardRenderer::DrawScene()
{
    DrawShadowMap();

    RendererCore::Instance()->SetOriginalRenderTargetDepth();

    float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f };

    // Set constants
    XMMATRIX view = XMLoadFloat4x4( RendererCore::Instance()->GetView() );
    XMMATRIX proj = XMLoadFloat4x4( RendererCore::Instance()->GetProj() );

    XMMATRIX shadowTransform = XMLoadFloat4x4( &m_ShadowTransform );


    int iCount = m_vDrawElements.size();
    for ( int i = 0; i < iCount; ++i )
    {
        DrawElement* pElem = m_vDrawElements[i];
        if ( !pElem )
            continue;

        UINT stride = pElem->stride;
        UINT offset = pElem->offset;

        GetD3D11DeviceImmContext()->IASetInputLayout( pElem->m_pInputLayout );
        GetD3D11DeviceImmContext()->IASetPrimitiveTopology( pElem->ePrimitiveTopology );

        pElem->m_spShader->SetDirLight( m_DirLights[0] );
        pElem->m_spShader->SetDirLights( m_DirLights );
        pElem->m_spShader->SetPointLight( m_PointLight );
        pElem->m_spShader->SetSpotLight( m_SpotLight );
        pElem->m_spShader->SetEyePosW( RendererCore::Instance()->GetEyePosW() );
        pElem->m_spShader->SetFogStart( 15.0f );
        pElem->m_spShader->SetFogRange( 300.0f );
        pElem->m_spShader->SetFogColor( Colors::Silver );

        for ( auto itor = pElem->m_vecSubElement.begin(); itor != pElem->m_vecSubElement.end() ; ++itor )
        {
            ID3DX11EffectTechnique* pTech = pElem->m_spShader->GetTech( (*itor).m_iTechIndex );
            if ( !pTech )
                continue;


            ID3D11Buffer* pVB = pElem->m_spVB->GetVB();
            GetD3D11DeviceImmContext()->IASetVertexBuffers( 0, 1, &pVB, &stride, &offset );

            if ( pElem->m_spIB )
                GetD3D11DeviceImmContext()->IASetIndexBuffer( pElem->m_spIB->GetIB(), DXGI_FORMAT_R32_UINT, 0 );

            if ( pElem->m_pRasterS )
                GetD3D11DeviceImmContext()->RSSetState( pElem->m_pRasterS );
            if ( pElem->m_pBlendS )
                GetD3D11DeviceImmContext()->OMSetBlendState( pElem->m_pBlendS, blendFactor, 0xffffffff );
            if ( pElem->m_pDepthStencilS )
                GetD3D11DeviceImmContext()->OMSetDepthStencilState( pElem->m_pDepthStencilS, pElem->m_uiStencilRef );

            XMMATRIX world;
            XMFLOAT3 oldLightDirections;
            if ( pElem->m_bStencilReflect )
            {
                XMVECTOR mirrorPlane = XMVectorSet( 0.0f, 0.0f, 1.0f, 0.0f ); // xy plane
                XMMATRIX R = XMMatrixReflect( mirrorPlane );
                world = XMLoadFloat4x4( &pElem->m_vecSubElement[0].m_World ) * R;

                oldLightDirections = m_DirLights[0].Direction;

                XMVECTOR lightDir = XMLoadFloat3( &m_DirLights[0].Direction );
                XMVECTOR reflectedLightDir = XMVector3TransformNormal( lightDir, R );
                XMStoreFloat3( &m_DirLights[0].Direction, reflectedLightDir );

                //ÀӽùæÆí
                pElem->m_spShader->SetDirLight( m_DirLights[0] );
            }
            else if ( pElem->m_bShadowmap )
            {
                XMVECTOR shadowPlane = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); // xz plane
                XMVECTOR toMainLight = -XMLoadFloat3( &m_DirLights[0].Direction );
                XMMATRIX S = XMMatrixShadow( shadowPlane, toMainLight );
                XMMATRIX shadowOffsetY = XMMatrixTranslation( 0.0f, 0.001f, 0.0f );

                world = XMLoadFloat4x4( &pElem->m_vecSubElement[0].m_World )*S*shadowOffsetY;
            }
            else
            {
                world = XMLoadFloat4x4( &pElem->m_vecSubElement[0].m_World );
            }

            TexturePtr spDiffuseMap = (*itor).m_spDiffuseMap;
            TexturePtr spCubeMap = (*itor).m_spCubeMap;
            TexturePtr spNormalMap = (*itor).m_spNormalMap;
            TexturePtr spShadowMap = (*itor).m_spShadowMap;

            world = XMLoadFloat4x4( &(*itor).m_World );

            XMMATRIX worldInvTranspose = MathHelper::InverseTranspose( world );
            XMMATRIX viewProj = view*proj;
            XMMATRIX worldViewProj = world*view*proj;

            XMMATRIX texTransform = XMLoadFloat4x4( &(*itor).m_TexTransform );

            D3DX11_TECHNIQUE_DESC techDesc;
            pTech->GetDesc( &techDesc );

            for ( UINT p = 0; p < techDesc.Passes; ++p )
            {

                pElem->m_spShader->SetWorld( world );
                pElem->m_spShader->SetWorldViewProj( worldViewProj );
                pElem->m_spShader->SetViewProj( viewProj );
                pElem->m_spShader->SetWorldInvTranspose( worldInvTranspose );
                pElem->m_spShader->SetTexTransform( texTransform );
                pElem->m_spShader->SetShadowTransform( world*shadowTransform );
                pElem->m_spShader->SetMaterial( (*itor).m_mat );

                if ( spDiffuseMap )
                {
                    if ( !spDiffuseMap->IsArray() )
                        pElem->m_spShader->SetDiffuseMap( spDiffuseMap->GetSRV() );
                    else
                        pElem->m_spShader->SetDiffuseMapArray( spDiffuseMap->GetSRV() );
                }

                if ( spCubeMap )
                {
                    pElem->m_spShader->SetCubeMap( spCubeMap->GetSRV() );
                }

                if ( spNormalMap )
                {
                    pElem->m_spShader->SetNormalMap( spNormalMap->GetSRV() );
                }

                if ( spShadowMap )
                {
                    pElem->m_spShader->SetShadowMap( spShadowMap->GetSRV() );
                }

                pTech->GetPassByIndex( p )->Apply( 0, GetD3D11DeviceImmContext() );

                if ( pElem->m_bDrawIndex )
                {

                    GetD3D11DeviceImmContext()->DrawIndexed( (*itor).m_IndexCount, (*itor).m_StartIndexLocation, (*itor).m_BaseVertexLocation );
                }
                else
                {
                    GetD3D11DeviceImmContext()->Draw( (*itor).m_VertexCount, (*itor).m_StartVertexLocation );
                }
            }


            if ( pElem->m_bStencilReflect )
            {
                m_DirLights[0].Direction = oldLightDirections;
            }
        }
    }

    DrawScreenQuad();
}
Example #2
0
void Game::Update()
{
	m_pCube->Update();
	XMVECTOR cameraPos = XMLoadFloat3(&m_pCamera->GetCameraPos());
	/*cameraPos += XMVectorSet(0.0001f,0.0f,0.0f,0.0f);
	XMFLOAT3 newCameraPos;
	XMStoreFloat3(&newCameraPos,cameraPos);*/
	//cameraPos * XMMatrixRotationY(XM_PIDIV2/9.0f);

	//Camera Rotation code
	/*XMFLOAT3 newCameraPos;
	cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY(-(XM_PIDIV2/9000.0f))));
	XMStoreFloat3(&newCameraPos,cameraPos);
	m_pCamera->SetCameraPos(newCameraPos);
	m_pCamera->UpdateViewMatrix();*/

	//keyboard input test code
	//bool pressed = ENGINE->GetInputManager()->IsKeyDown(VK_UP);

	//cout << pressed;
	XMFLOAT3 newCameraPos;
	if(ENGINE->GetInputManager()->IsKeyDown(VK_UP))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationX((XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(VK_DOWN))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationX(-(XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(VK_LEFT))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY((XM_PIDIV2/9000.0f))));
	}
	//if(ENGINE->GetInputManager()->IsKeyDown(VK_RIGHT))
	if(ENGINE->GetInputManager()->IsCommandDown(L"RIGHT"))
	{
		cameraPos = XMVector3Rotate(cameraPos,XMQuaternionRotationMatrix(XMMatrixRotationY(-(XM_PIDIV2/9000.0f))));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x57))//W
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0,0.01f));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x53))//S
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0,-0.01f));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x41))//A
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(-0.01f,0,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x44))//D
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0.01f,0,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x51))//Q
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,-0.01f,0));
	}
	if(ENGINE->GetInputManager()->IsKeyDown(0x45))//E
	{
		cameraPos = XMVector3Transform(cameraPos,XMMatrixTranslation(0,0.01f,0));
	}
	
	XMStoreFloat3(&newCameraPos,cameraPos);
	m_pCamera->SetCameraPos(newCameraPos);
	m_pCamera->UpdateViewMatrix();
}
void Terrain::InitVB(ID3D11Device* device)
{
	std::vector<Vertex::TerrainVertex> vertexData(mTerrainData.width *
		mTerrainData.height);

	UINT cellsWide = mTerrainData.width - 1;
	UINT cellsHigh = mTerrainData.height - 1;

	for (int row = 0; row < mTerrainData.height; ++row)
	{
		for (int col = 0; col < mTerrainData.width; ++col)
		{
			UINT index = row * mTerrainData.width + col;
			vertexData[index].pos = XMFLOAT3(col * mTerrainData.cellWidth,
				mHeightMap[index],
				row * mTerrainData.cellHeight);

			float u = mTerrainData.texTilesWide / mTerrainData.width;
			u *= col;

			float v = mTerrainData.texTilesHigh / mTerrainData.height;
			v *= row;

			vertexData[index].tiledTex.x = u;
			vertexData[index].tiledTex.y = v;

			u = (float)col / (mTerrainData.width - 1);
			v = (float)row / (mTerrainData.height - 1);

			vertexData[index].tex.x = u;
			vertexData[index].tex.y = v;

		}
	}

	std::vector<XMFLOAT3> normals;
	for (int row = 0; row < cellsHigh; ++row)
	{
		for (int col = 0; col < cellsWide; ++col)
		{
			//determine the row and column in terms of vertices given the 
			//cell row and column
			UINT top = row + 1;
			UINT right = col + 1;
			UINT bot = row;
			UINT left = col;

			XMVECTOR A = XMVectorSet(0.0f, mHeightMap[top * mTerrainData.width + left] -
				mHeightMap[bot * mTerrainData.width + left], mTerrainData.cellHeight, 0.0f);

			XMVECTOR B = XMVectorSet(mTerrainData.cellWidth, mHeightMap[bot * mTerrainData.width + right] -
				mHeightMap[bot * mTerrainData.width + left], 0.0f, 0.0f);

			XMVECTOR C = XMVectorSet(mTerrainData.cellWidth, mHeightMap[top * mTerrainData.width + right] -
				mHeightMap[top * mTerrainData.width + left], 0.0f, 0.0f);

			XMVECTOR D = XMVectorSet(0.0f, mHeightMap[top * mTerrainData.width + right] -
				mHeightMap[bot * mTerrainData.width + right], mTerrainData.cellHeight, 0.0f);

			XMVECTOR topNormal = XMVector3Cross(D, C);

			XMVECTOR botNormal = XMVector3Cross(A, B);

			topNormal = XMVector3Normalize(topNormal);
			botNormal = XMVector3Normalize(botNormal);

			XMFLOAT3 topNormalF3, botNormalF3;

			XMStoreFloat3(&topNormalF3, topNormal);
			XMStoreFloat3(&botNormalF3, botNormal);

			normals.push_back(topNormalF3);
			normals.push_back(botNormalF3);
		}
	}

	for (int row = 0; row < mTerrainData.height; ++row)
	{
		for (int col = 0; col < mTerrainData.width; ++col)
		{
			UINT index = row * mTerrainData.width + col;

			int top = row;
			int bot = row - 1;
			int left = col - 1;
			int right = col;

			int normalCounter = 0;
			XMVECTOR normsCombined = XMVectorZero();
			//get the two top left normals
			if (top < cellsHigh && left >= 0)
			{
				UINT topLeftIndex = (top * cellsWide + left) * 2;

				normsCombined = normsCombined + XMLoadFloat3(&normals[topLeftIndex]);
				normsCombined = normsCombined + XMLoadFloat3(&normals[topLeftIndex + 1]);
				normalCounter += 2;
			}

			//get the bottom left normal
			if (bot >= 0 && left >= 0)
			{
				UINT botLeftIndex = (bot * cellsWide + left) * 2;

				normsCombined = normsCombined + XMLoadFloat3(&normals[botLeftIndex]);
				normalCounter++;
			}

			//get the top right normal
			if (top < cellsHigh && right < cellsWide)
			{
				UINT topRightIndex = (top * cellsWide + right) * 2;

				normsCombined = normsCombined + XMLoadFloat3(&normals[topRightIndex]);
				normalCounter++;
			}

			//get the two bot right normals
			if (bot >= 0 && right < cellsWide)
			{
				UINT botRightIndex = (bot * cellsWide + right) * 2;

				normsCombined = normsCombined + XMLoadFloat3(&normals[botRightIndex]);
				normsCombined = normsCombined + XMLoadFloat3(&normals[botRightIndex + 1]);
				normalCounter += 2;
			}

			normsCombined = normsCombined / (float)normalCounter;
			XMStoreFloat3(&(vertexData[index].normal), normsCombined);
		}
	}

	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex::TerrainVertex) * vertexData.size();
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	vbd.StructureByteStride = 0;

	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertexData[0];
	HR(device->CreateBuffer(&vbd, &vinitData, &mVB));

}
void GeometryGenerator::CreateCylinder(float bottomRadius, float topRadius, float height, UINT sliceCount, UINT stackCount, MeshData& meshData)
{
	meshData.Vertices.clear();
	meshData.Indices.clear();

	//
	// Build Stacks.
	// 

	float stackHeight = height / stackCount;

	// Amount to increment radius as we move up each stack level from bottom to top.
	float radiusStep = (topRadius - bottomRadius) / stackCount;

	UINT ringCount = stackCount+1;

	// Compute vertices for each stack ring starting at the bottom and moving up.
	for(UINT i = 0; i < ringCount; ++i)
	{
		float y = -0.5f*height + i*stackHeight;
		float r = bottomRadius + i*radiusStep;

		// vertices of ring
		float dTheta = 2.0f*XM_PI/sliceCount;
		for(UINT j = 0; j <= sliceCount; ++j)
		{
			Vertex vertex;

			float c = cosf(j*dTheta);
			float s = sinf(j*dTheta);

			vertex.Position = XMFLOAT3(r*c, y, r*s);

			vertex.TexC.x = (float)j/sliceCount;
			vertex.TexC.y = 1.0f - (float)i/stackCount;

			// Cylinder can be parameterized as follows, where we introduce v
			// parameter that goes in the same direction as the v tex-coord
			// so that the bitangent goes in the same direction as the v tex-coord.
			//   Let r0 be the bottom radius and let r1 be the top radius.
			//   y(v) = h - hv for v in [0,1].
			//   r(v) = r1 + (r0-r1)v
			//
			//   x(t, v) = r(v)*cos(t)
			//   y(t, v) = h - hv
			//   z(t, v) = r(v)*sin(t)
			// 
			//  dx/dt = -r(v)*sin(t)
			//  dy/dt = 0
			//  dz/dt = +r(v)*cos(t)
			//
			//  dx/dv = (r0-r1)*cos(t)
			//  dy/dv = -h
			//  dz/dv = (r0-r1)*sin(t)

			// This is unit length.
			vertex.TangentU = XMFLOAT3(-s, 0.0f, c);

			float dr = bottomRadius-topRadius;
			XMFLOAT3 bitangent(dr*c, -height, dr*s);

			XMVECTOR T = XMLoadFloat3(&vertex.TangentU);
			XMVECTOR B = XMLoadFloat3(&bitangent);
			XMVECTOR N = XMVector3Normalize(XMVector3Cross(T, B));
			XMStoreFloat3(&vertex.Normal, N);

			meshData.Vertices.push_back(vertex);
		}
	}

	// Add one because we duplicate the first and last vertex per ring
	// since the texture coordinates are different.
	UINT ringVertexCount = sliceCount+1;

	// Compute indices for each stack.
	for(UINT i = 0; i < stackCount; ++i)
	{
		for(UINT j = 0; j < sliceCount; ++j)
		{
			meshData.Indices.push_back(i*ringVertexCount + j);
			meshData.Indices.push_back((i+1)*ringVertexCount + j);
			meshData.Indices.push_back((i+1)*ringVertexCount + j+1);

			meshData.Indices.push_back(i*ringVertexCount + j);
			meshData.Indices.push_back((i+1)*ringVertexCount + j+1);
			meshData.Indices.push_back(i*ringVertexCount + j+1);
		}
	}

	BuildCylinderTopCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
	BuildCylinderBottomCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
}
	void PinholeCamera::update(const GameTimer & timer)
	{
		RayTraceCamera::update(timer);
		XMFLOAT3 movementAmount = { 0.0f, 0.0f, 0.0f };

		if (mKeyboard != nullptr)
		{
			if (mKeyboard->isKeyDown(DIK_W))
			{
				movementAmount.y = 1.0f;
			}
			if (mKeyboard->isKeyDown(DIK_S))
			{
				movementAmount.y = -1.0f;
			}
			if (mKeyboard->isKeyDown(DIK_A))
			{
				movementAmount.x = -1.0f;
			}
			if (mKeyboard->isKeyDown(DIK_D))
			{
				movementAmount.x = 1.0f;
			}


			if (mKeyboard->isKeyDown(DIK_R))
			{
				movementAmount.z = -1.0f ;
			}
			if (mKeyboard->isKeyDown(DIK_F))
			{
				movementAmount.z = 1.0f;
			}

			if (mKeyboard->isKeyDown(DIK_Q))
			{
				mViewPlaneDistance -= 10.0f * timer.elapsedGameTime();
			}
			if (mKeyboard->isKeyDown(DIK_E))
			{
				mViewPlaneDistance += 10.0f * timer.elapsedGameTime();
			}
		}

		float rotationAmount = 0;
		if ((mMouse != nullptr))
		{
			if ((mMouse->isButtonDown(MouseButtons::MouseButtonsLeft)))
			{

				LPDIMOUSESTATE mouseState = mMouse->currentState();
				rotationAmount = -mouseState->lX ;
				//rotationAmount.y = -mouseState->lY * mMouseSensitivity;
			}
		}
		//XMStoreFloat3(&mUp,XMVector3Transform(upVector(), XMMatrixRotationZ(rotationAmount/180.0f * 3.14)));
		XMVECTOR position = eyeVector();
		XMVECTOR movement = XMLoadFloat3(&movementAmount) * mMovementRate * timer.elapsedGameTime();

		/*XMVECTOR strafe = right * XMVectorGetX(movement);
		position += strafe;

		XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement);
		position += forward;*/

		XMStoreFloat3(&mPosition, position + movement);
		
	}
void Enemies::CreateBoundingBox()
{


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



	for (UINT i = 0; i < mEnemyInstances.size(); ++i)
	{
		minPt.x = 0.0f;
		minPt.y = 0.0f;
		minPt.z = 0.0f;

		maxPt.x = 0.0f;
		maxPt.y = 0.0f;
		maxPt.z = 0.0f;

		for (UINT j = 0; j < mEnemyInstances[i].Model->BasicVertices.size(); ++j)
		{

			XMFLOAT3 P = mEnemyInstances[i].Model->BasicVertices[j].Pos;


			//////multiply all these by 7

			minPt.x = MathHelper::Min(minPt.x, P.x);
			minPt.y = MathHelper::Min(minPt.y, P.y);
			minPt.z = MathHelper::Min(minPt.z, P.z);

			maxPt.x = MathHelper::Max(maxPt.x, P.x);
			maxPt.y = MathHelper::Max(maxPt.y, P.y);
			maxPt.z = MathHelper::Max(maxPt.z, P.z);


		}

		XMMATRIX temp = XMLoadFloat4x4(&mEnemyInstances[i].World);

		enemyclass[i]->setWorld(mEnemyInstances[i].World);

		XMVECTOR Scale;
		XMVECTOR Position;
		XMVECTOR Rotation;


		XMMatrixDecompose(&Scale, &Rotation, &Position, temp);

		XMFLOAT3 tempPos;
		XMStoreFloat3(&tempPos, Position);

		LevelCollisions[i].Center = tempPos;


		LevelCollisions[i].Extents = XMFLOAT3(0.5f*(maxPt.x - minPt.x),
			0.5f*(maxPt.y - minPt.y),
			0.5f*(maxPt.z - minPt.z));

		LevelCollisions[i].collisionType = enemyclass[i]->getcollisiontype();


		FLOAT scale = enemyclass[i]->getScale();

		LevelCollisions[i].Extents.x = LevelCollisions[i].Extents.x * scale;
		LevelCollisions[i].Extents.y = LevelCollisions[i].Extents.y * scale;
		LevelCollisions[i].Extents.z = LevelCollisions[i].Extents.z * scale;

		EnemyBox.collisionType = 1;


		enemyclass[i]->setAABB(&LevelCollisions[i]);

	}
}
Example #7
0
VOID
Font::BuildSpriteQuad( Sprite *sprite, SpriteVertex v[ 4 ] )
{
    FLOAT vertLeft = 2.0f * (float) sprite->DestRect.left / ScreenWidth - 1.0f;
    FLOAT vertRight = 2.0f * (float) sprite->DestRect.right / ScreenWidth - 1.0f;
    FLOAT vertTop = 1.0f - 2.0f * (float) sprite->DestRect.top / ScreenHeight;
    FLOAT vertBottom = 1.0f - 2.0f * (float) sprite->DestRect.bottom / ScreenHeight;
    float tx, ty;
    int i;
    XMVECTOR scaling, origin, translation;
    XMMATRIX T;

    v[ 0 ].x        = vertLeft;
    v[ 0 ].y        = vertBottom;
    v[ 0 ].z        = sprite->Z;
    v[ 0 ].Tex.x    = (float)sprite->SrcRect.left  / m_dwTexWidth;
    v[ 0 ].Tex.y    = (float)sprite->SrcRect.bottom / m_dwTexHeight;
    v[ 0 ].Color    = sprite->Color;

    v[ 1 ].x        = vertLeft;
    v[ 1 ].y        = vertTop;
    v[ 1 ].z        = sprite->Z;
    v[ 1 ].Tex.x    = (float)sprite->SrcRect.left  / m_dwTexWidth;
    v[ 1 ].Tex.y    = (float)sprite->SrcRect.top    / m_dwTexHeight;
    v[ 1 ].Color    = sprite->Color;

    v[ 2 ].x        = vertRight;
    v[ 2 ].y        = vertTop;
    v[ 2 ].z        = sprite->Z;
    v[ 2 ].Tex.x    = (float)sprite->SrcRect.right / m_dwTexWidth;
    v[ 2 ].Tex.y    = (float)sprite->SrcRect.top    / m_dwTexHeight;
    v[ 2 ].Color    = sprite->Color;

    v[ 3 ].x        = vertRight;
    v[ 3 ].y        = vertBottom;
    v[ 3 ].z        = sprite->Z;
    v[ 3 ].Tex.x    = (float)sprite->SrcRect.right / m_dwTexWidth;
    v[ 3 ].Tex.y    = (float)sprite->SrcRect.bottom / m_dwTexHeight;
    v[ 3 ].Color    = sprite->Color;

    tx = 0.5f * ( v[ 0 ].x + v[ 3 ].x );
    ty = 0.5f * ( v[ 0 ].y + v[ 1 ].y );

    scaling        = XMVectorSet( sprite->Scale, sprite->Scale, 1.0f, 0.0f );
    origin            = XMVectorSet( tx, ty, 0.0f, 0.0f );
    translation    = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
    T = XMMatrixAffineTransformation2D( scaling, origin, sprite->Angle, translation );

    for( i = 0; i < 4; ++i )
    {
        XMFLOAT3 xmfloat;
        XMVECTOR p;

        xmfloat.x = v[ i ].x;
        xmfloat.y = v[ i ].y;
        xmfloat.z = v[ i ].z;

        p = XMLoadFloat3( &xmfloat );
        p = XMVector3TransformCoord( p, &T );
        XMStoreFloat3( &xmfloat, p );
        v[ i ].x = xmfloat.x;
        v[ i ].y = xmfloat.y;
        v[ i ].z = xmfloat.z;
    }
}
Example #8
0
void D3DAnimation::Update(float dt) {
	if( GetAsyncKeyState('W') & 0x8000 )
		Cam.Walk(10.0f * dt);

	if( GetAsyncKeyState('S') & 0x8000 )
		Cam.Walk(-10.0f * dt);

	if( GetAsyncKeyState('A') & 0x8000 )
		Cam.Strafe(-10.0f * dt);

	if( GetAsyncKeyState('D') & 0x8000 )
		Cam.Strafe(10.0f * dt);
	/*
	for (int i = 0; i < 10; ++i) {
		if (GetAsyncKeyState(VK_F1 + i) & 0x8000 ) {
			if (pointLightsw[i] == true) {
				pointLightsw[i] = false;
			} else {
				pointLightsw[i] = true;
			}
		}
	}
	for (int i = 0; i < 2; ++i) {
		if (GetAsyncKeyState('4' + i) & 0x8000 ) {
			if (SpotLightsw[i] == true) {
				SpotLightsw[i] = false;
			} else {
				SpotLightsw[i] = true;
			}
		}
	}
	for (int i = 0; i < 3; ++i) {
		if ((GetAsyncKeyState('1' + i) & 0x8000) && (!GetKeyState('1' + i) &0x8000)) {
			if (dirLightsw[i] == true) {
				dirLightsw[i] = false;
			} else {
				dirLightsw[i] = true;
			}
		}

	}
	*/
	Object3DInstance* player = list->getPlayer("player");	
		if (GetAsyncKeyState(VK_UP) & 0x8000 ) {
			XMMATRIX world = XMLoadFloat4x4(&(list->getPlayer("player")->mWorld));
			XMMATRIX translation;
			XMFLOAT4X4 offset = { 1.0f, 0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f, 0.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f, 0.0f, -45.0f * dt, 1.0f};
			translation = XMLoadFloat4x4(&offset);
			XMStoreFloat4x4(&list->getPlayer("player")->mWorld, translation * world);
			//list->getPlayer("player")->mWorld._43 -= 2.5f * dt;
			list->Update(dt);
		} else if (GetAsyncKeyState(VK_DOWN) & 0x8000 ) {
			XMMATRIX world = XMLoadFloat4x4(&(list->getPlayer("player")->mWorld));
			XMMATRIX translation;
			XMFLOAT4X4 offset = { 1.0f, 0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f, 0.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f, 0.0f, 45.0f * dt, 1.0f};
			translation = XMLoadFloat4x4(&offset);
			XMStoreFloat4x4(&list->getPlayer("player")->mWorld, translation * world);
			list->Update(-dt);
		} else if (GetAsyncKeyState(VK_LEFT) & 0x8000 ) {
			XMMATRIX world = XMLoadFloat4x4(&(list->getPlayer("player")->mWorld));
			world = XMMatrixRotationY(0.004f * XM_PI) * world;
			XMStoreFloat4x4(&(list->getPlayer("player")->mWorld), world);
			list->Update(dt);
		} else if (GetAsyncKeyState(VK_RIGHT) & 0x8000 ) {
			XMMATRIX world = XMLoadFloat4x4(&(list->getPlayer("player")->mWorld));
			world = XMMatrixRotationY(-0.004f * XM_PI) * world;
			XMStoreFloat4x4(&(list->getPlayer("player")->mWorld), world);
			list->Update(dt);
	} else {
		list->Update(0);
	}
		XMStoreFloat3(&player->mUP, XMVector3Transform(XMLoadFloat3(&player->mUP), XMLoadFloat4x4(&player->mWorld)));
		XMStoreFloat3(&player->mForward, XMVector3Transform(XMLoadFloat3(&player->mForward), XMLoadFloat4x4(&player->mWorld)));
		XMStoreFloat3(&player->mRight, XMVector3Transform(XMLoadFloat3(&player->mRight), XMLoadFloat4x4(&player->mWorld)));	

		Cam.UpdateViewMatrix();


	/*
	XMFLOAT3 eye = Cam.GetPosition();
	XMFLOAT3 focus = Cam.GetLook();
	std::wostringstream outs;
	outs.precision(6);
	outs << mMainWndCaption << L"                                                              " << L"eyeX = " << eye.x << L"  eyeY = " << eye.y << L"    eyeZ = "<<eye.z << L"   focusX = "<<focus.x <<L"   focusY = "<<focus.y <<L"    focusZ = "<< focus.z;
	SetWindowText(mMainWnd, outs.str().c_str());*/
}
Example #9
0
bool D3DAnimation::Init() {
	if (!D3DBase::Init()) {
		return false;
	}
	
	mLastMousePos.x = 0;
	mLastMousePos.y = 0;

	BOX_DESC box = {1.0f, 1.0f, 1.0f, 3};
	GRID_DESC grid = {20.0f, 30.0f, 60, 40};
	SPHERE_DESC sphere = {0.5f, 20, 20};
	CYLINDER_DESC cylinder = { 0.5f, 0.3f, 3.0f, 20, 20 };

	Material mGridMat;
	Material mBoxMat;
	Material mCylinderMat;
	Material mSphereMat;



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

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

	mSphereMat.Ambient  = XMFLOAT4(0.6f, 0.8f, 0.9f, 1.0f);
	mSphereMat.Diffuse  = XMFLOAT4(0.6f, 0.8f, 0.9f, 1.0f);
	mSphereMat.Specular = XMFLOAT4(0.9f, 0.9f, 0.9f, 16.0f);

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

	fogenable = true;
	
	XMFLOAT4X4 I;
	XMFLOAT4X4 rotation;
	XMStoreFloat4x4(&rotation, XMMatrixRotationY(XM_PI));
	XMStoreFloat4x4(&I, XMMatrixIdentity());
	//instanceName;translation;rotation;scale;modelName;modelFilename;texturePath;VShaderName;PShaderName;LayoutName; vertexTypeName;
	std::vector<ObjectInstance_M3dModelList_DESC> objlist = {
		{"player", {0.0f, 0.0f, -100.0f}, rotation, {0.05f, 0.05f, -0.05f}, "soldier", ".\\Models\\soldier.m3d", ".\\Textures\\","BasicAnimationVS","FixFunctionLightPS","PosNormalTexTanSkinned","PosNormalTexTanAnimation"}
	};
	std::vector<ObjectInstance_BOXLIST_DESC> boxlist = {
		{ "podium",{0.0f, 0.5f, 0.0f}, I, {3.0f,1.0f,3.0f}, "box", mBoxMat, ".\\Textures\\", "stone.dds", "stones_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan",box} 
	};
	std::vector<ObjectInstance_GRIDLIST_DESC> gridlist = {
		{ "land", {0.0f, 0.0f,0.0f}, I, {1.0f,1.0f,1.0f}, "grid", mGridMat, ".\\Textures\\", "floor.dds", "floor_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan",grid}
	};
	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);
	dirLightsw[0] = true;
	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);
	dirLightsw[1] = true;
	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);
	dirLightsw[2] = true;
	mSpotLights[0].Ambient = XMFLOAT4(0.2f, 1.0f, 0.2f, 1.0f);
	mSpotLights[0].Diffuse = XMFLOAT4(0.5f, 1.0f, 0.5f, 1.0f);
	mSpotLights[0].Specular = XMFLOAT4(0.5f, 1.0f, 0.5f, 1.0f);
	mSpotLights[0].Position = XMFLOAT3(0.0f, 5.0f, 0.0f);
	mSpotLights[0].Range = 25.0f;
	mSpotLights[0].Att = XMFLOAT3(0.0f, 0.15f, 0.0f);
	XMFLOAT3 dir;
	XMStoreFloat3(&dir, XMVector3Normalize(XMLoadFloat3(&XMFLOAT3(0.0f, -5.0f, -100.0f))));
	mSpotLights[0].Direction = dir;
	mSpotLights[0].Spot = 56.0f;
	SpotLightsw[0] = true;
	mSpotLights[1].Ambient = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mSpotLights[1].Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mSpotLights[1].Specular = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mSpotLights[1].Position = XMFLOAT3(0.0f, 2.5f, -100.0f);
	mSpotLights[1].Range = 15.0f;
	mSpotLights[1].Att = XMFLOAT3(0.0f, 0.15f, 0.0f);
	mSpotLights[1].Direction = XMFLOAT3(0.0f, 0.0f, -1.0f);
	mSpotLights[1].Spot = 50.0f;
	SpotLightsw[1] = true;
	std::vector<ObjectInstance_SPHERELIST_DESC> spherelist;
	std::vector<ObjectInstance_CYLINDERLIST_DESC> cylinderlist;
	for(int i = 0; i < 5; ++i)
	{
		ObjectInstance_CYLINDERLIST_DESC item1 = { "pillar" + std::to_string(i * 2 + 1), {-5.0f, 1.5f, -10.0f + i*5.0f}, I, {1.0f,1.0f,1.0f}, "cylinder", mCylinderMat, ".\\Textures\\", "bricks.dds", "bricks_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan", cylinder};
		ObjectInstance_CYLINDERLIST_DESC item2 = { "pillar" + std::to_string(i * 2 + 2), {+5.0f, 1.5f, -10.0f + i*5.0f}, I, {1.0f,1.0f,1.0f}, "cylinder", mCylinderMat, ".\\Textures\\", "bricks.dds", "bricks_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan",cylinder};
		cylinderlist.push_back(item1);
		cylinderlist.push_back(item2);
		ObjectInstance_SPHERELIST_DESC item3 = { "ball" + std::to_string(i * 2 + 1), {-5.0f, 3.5f, -10.0f + i*5.0f}, I, {1.0f,1.0f,1.0f}, "sphere", mCylinderMat, ".\\Textures\\", "stone.dds", "stones_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan",sphere};
		ObjectInstance_SPHERELIST_DESC item4 = { "ball" + std::to_string(i * 2 + 2), {+5.0f, 3.5f, -10.0f + i*5.0f}, I, {1.0f,1.0f,1.0f}, "sphere", mCylinderMat, ".\\Textures\\", "stone.dds", "stones_nmap.dds", "BasicVS","FixFunctionLightPS","PosNormTexTan","PosNormalTexTan",sphere};
		spherelist.push_back(item3);
		spherelist.push_back(item4);

		mPointLights[i * 2].Ambient = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2].Diffuse = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2].Specular = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2].Position = XMFLOAT3(-5.0f, 3.5f, -10.0f + i * 5.0f);
		mPointLights[i * 2].Att = XMFLOAT3(0.0f, 0.0f, 0.9f);
		mPointLights[i * 2].Range = 4.0f;
		pointLightsw[i * 2] = true;
		mPointLights[i * 2 + 1].Ambient = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2 + 1].Diffuse = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2 + 1].Specular = XMFLOAT4(1.f, 0.9f, 0.3f, 1.0f);
		mPointLights[i * 2 + 1].Position = XMFLOAT3(+5.0f, 3.5f, -10.0f + i * 5.0f);
		mPointLights[i * 2 + 1].Att = XMFLOAT3(0.0f, 0.9f, 0.0f);
		mPointLights[i * 2 + 1].Range = 4.0f;
		pointLightsw[i * 2 + 1] = true;
	}
	list = new Object3DList(this,objlist);
	list->AddBoxist(boxlist);
	list->AddGridList(gridlist);
	list->AddCylinderList(cylinderlist);
	list->AddSphereList(spherelist);
	list->Init();
	Cam.SetLens(0.25f * XM_PI, getAspectRatio(), 1.0f, 1000.0f);
	return true;
}
Example #10
0
/*--------------------------------------------
	画面の描画処理
--------------------------------------------*/
HRESULT Render(void)
{
	HRESULT hr;

    // 描画ターゲットのクリア
    g_pImmediateContext->ClearRenderTargetView(
                       g_pRenderTargetView, // クリアする描画ターゲット
                       g_ClearColor);         // クリアする値

	// 深度/ステンシルのクリア
	g_pImmediateContext->ClearDepthStencilView(
			g_pDepthStencilView, // クリアする深度/ステンシル・ビュー
			D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,   // 深度値とステンシル値をクリアする
			1.0f,                // 深度バッファをクリアする値
			0);                  // ステンシル・バッファをクリアする値

	// ***************************************
	// 定数バッファを更新
	// ビュー変換行列
	XMVECTORF32 eyePosition   = { 0.0f, g_fEye, -g_fEye, 1.0f };  // 視点(カメラの位置)
	XMVECTORF32 focusPosition = { 0.0f, 0.0f,  0.0f, 1.0f };  // 注視点
	XMVECTORF32 upDirection   = { 0.0f, 1.0f,  0.0f, 1.0f };  // カメラの上方向
	XMMATRIX mat = XMMatrixLookAtLH(eyePosition, focusPosition, upDirection);
	XMStoreFloat4x4(&g_cbCBuffer.View, XMMatrixTranspose(mat));
	// 点光源座標
	XMVECTOR vec = XMVector3TransformCoord(XMLoadFloat3(&g_vLightPos), mat);
	XMStoreFloat3(&g_cbCBuffer.Light, vec);
	// ワールド変換行列
	XMFLOAT3 center = g_wfObjKuma.GetBoundingSphereCenter();
	XMMATRIX matTrans = XMMatrixTranslation(-center.x, -center.y, -center.z);

	float scale = 1.0f / g_wfObjKuma.GetBoundingSphereRadius();
	XMMATRIX matScale = XMMatrixScaling(scale, scale, scale);

	FLOAT rotate = (FLOAT)(XM_PI * (timeGetTime() % 3000)) / 1500.0f;
	XMMATRIX matY = XMMatrixRotationY(rotate);

	XMStoreFloat4x4(&g_cbCBuffer.World, XMMatrixTranspose(matTrans * matScale * matY));

	// **********************************************************
	// RSにビューポートを設定
	g_pImmediateContext->RSSetViewports(1, g_ViewPort);

	// OMに描画ターゲット ビューと深度/ステンシル・ビューを設定
	g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);

	// VSに定数バッファを設定
	g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pCBuffer);

	// GSに定数バッファを設定
	g_pImmediateContext->GSSetConstantBuffers(0, 1, &g_pCBuffer);

	// PSに定数バッファを設定
	g_pImmediateContext->PSSetConstantBuffers(0, 1, &g_pCBuffer);
	// PSにサンプラーを設定
	g_pImmediateContext->PSSetSamplers(0, 1, &g_pTextureSampler);

	// 3Dオブジェクトの描画
	RenderObj();
	// シャドウ・ボリュームの描画
	RenderSV();
	// シャドウの描画
	RenderS();

	// ***************************************
	// バック バッファの表示
	hr = g_pSwapChain->Present(	0,	// 画面を直ぐに更新する
								0);	// 画面を実際に更新する

	return hr;
}
void Game::UpdateScene(float dt)
{

	addDeltaTime(dt);

	theEnemies->update(dt);

	int levelColsize = LevelCollisions.size();
	int tempOtherObject;

	//////updates the enemy collisions as they move
	std::vector <XNA::AxisAlignedBox> temp;
	//original value = 3
	temp = theEnemies->getEnemyCollisions();

	std::vector <XNA::AxisAlignedBox> tempObject;
	//original value = 5
	tempObject = Objects->getObjectCollisions();

	std::vector <XNA::AxisAlignedBox> tempLevel;
	//original value = 26
	tempLevel = Level1->getLevelPartsCollisions();

	tempOtherObject = tempObject.size() + temp.size() + tempLevel.size();


	int tempSize = temp.size();


	int sizeDifference = 0;

	sizeDifference = LevelCollisions.size() - tempOtherObject;


	if (sizeDifference > 0)
	{

		int something = 0;
		LevelCollisions.pop_back();

		int j = 0;
		for (UINT i = tempLevel.size(); i < (tempLevel.size() + tempObject.size()); i++, j++)
		{

			LevelCollisions[i] = tempObject[j];

		}

		if (temp.size() >= 0)
		{

			j = 0;
			for (UINT i = (tempLevel.size() + tempObject.size()); i < (tempLevel.size() + tempObject.size() + temp.size()); i++, j++)
			{

				LevelCollisions[i] = temp[j];
				LevelCollisions[i].Center = temp[j].Center;
			}
		}

	}
	else
	{
		int	j = 0;
		for (UINT i = tempObject.size() + tempLevel.size(); i < tempOtherObject; i++, j++)
		{
			LevelCollisions[i] = temp[j];
		}
	}

	/////////////////////////////

	PlayerOne->setLevelCollisions(LevelCollisions);

	/////////////////////////////

	XMVECTOR desiredCharDir = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);

	XMVECTOR playerPos = XMLoadFloat3(&mPlayerPosition);


	XMVECTOR camRight = XMLoadFloat3(&mCam.GetRight());
	XMVECTOR camForward = XMLoadFloat3(&mCam.GetLook());
	XMVECTOR camUp = XMLoadFloat3(&mCam.GetUp());

	XMVECTOR multiply = XMVectorSet(0.0f, 2.0f, 0.0f, 0.0f);

	camUp = XMVectorAdd(camUp, multiply);

	bool jumpChar = false;


	bool moveChar = false;


	if (GetAsyncKeyState('W') & 0x8000)
	{
		desiredCharDir += (camForward);

		moveChar = true;
	}

	if (GetAsyncKeyState('S') & 0x8000)
	{
		desiredCharDir += -(camForward);

		moveChar = true;
	}
	if (GetAsyncKeyState('A') & 0x8000)
	{
		desiredCharDir += (camRight);

		moveChar = true;
	}



	if (GetAsyncKeyState('D') & 0x8000)
	{
		desiredCharDir += -(camRight);

		moveChar = true;
	}


	if (GetAsyncKeyState('Q') & 0x8000)
	{
		float dy = 1.5 * dt;
		mCam.RotateY(-dy);
	}

	if (GetAsyncKeyState('E') & 0x8000)
	{

		float dy = 1.5 * dt;
		mCam.RotateY(dy);
	}


	if (GetAsyncKeyState('R') & 0x8000)
	{
		float dy = 0.25 * dt;
		mCam.Pitch(dy);
	}

	if (GetAsyncKeyState('F') & 0x8000)
	{
		float dy = 0.25 * dt;
		mCam.Pitch(-dy);
	}

	if (PlayerOne->getOnGround() == true)
	{
		if (GetAsyncKeyState( VK_SPACE ))
		{
			desiredCharDir += camUp;
			moveChar = true;
			SoundSystem::Play(QUACK);
		}

	}

	XMVECTOR addGravity = XMVectorSet(0.0f, -30.f * DeltaTimeF, 0.0f, 0.0f);
	XMFLOAT3 tGrav;
	XMStoreFloat3(&tGrav, addGravity);

	XMVECTOR tGravity = XMLoadFloat3(&tGrav);

	if (PlayerOne->getOnGround() == true)
	{

	}
	else if (PlayerOne->getOnGround() == false)
	{

		desiredCharDir += addGravity;
	}

	//		
	// Switch the number of lights based on key presses.
	//
	if (GetAsyncKeyState('0') & 0x8000)
	{
		mLightCount = 0;
	}
	if (GetAsyncKeyState('1') & 0x8000)
		mLightCount = 1;

	if (GetAsyncKeyState('2') & 0x8000)
		mLightCount = 2;

	if (GetAsyncKeyState('3') & 0x8000)
		mLightCount = 3;



	////send player information to the camera

	mCam.getPlayerPos(PlayerOne->getPlayerPosition());
	mCam.getDeltaTime(dt);

	mCam.moveCam();

	PlayerOne->move(dt, desiredCharDir, theEnemies, Objects);

	PlayerOne->update();

}
Example #12
0
IActor *CreateObject(XMVECTOR const &xvPos, XMCOLOR const &Color, 
	E_ACTOR_TYPE const eActorType, E_RIGID_BODY_FLAG const eBodyFlag)
{
	const float fBoxSize = 0.4f;

	if (!g_pWireBoxModelRenderer)
	{
		g_pWireBoxModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pWireBoxModelRenderer->SetRenderMethod(E_RENDERMETHOD::WIREFRAMED);
		g_pWireBoxModelRenderer->SetRigidBodyFlag(E_RIGID_BODY_FLAG::DYNAMIC);

		CRawModel RawModel;
		RawModel.m_eRidigBodyFlag = E_RIGID_BODY_FLAG::DYNAMIC;
		RawModel.m_vScale = XMFLOAT3(fBoxSize, fBoxSize, fBoxSize);
		ContructBoxVertexBuffer(&RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pWireBoxModelRenderer->VAddMesh(iMesh, iMesh);
	}

	if (!g_pSolidBoxModelRenderer)
	{
		g_pSolidBoxModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pSolidBoxModelRenderer->SetRenderMethod(E_RENDERMETHOD::SOLID);
		g_pSolidBoxModelRenderer->SetRigidBodyFlag(E_RIGID_BODY_FLAG::DYNAMIC);

		CRawModel RawModel;
		RawModel.m_eRidigBodyFlag = E_RIGID_BODY_FLAG::DYNAMIC;
		RawModel.m_vScale = XMFLOAT3(fBoxSize, fBoxSize, fBoxSize);
		ContructBoxVertexBuffer(&RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pSolidBoxModelRenderer->VAddMesh(iMesh, iMesh);
	}

	if (!g_pWireSphereModelRenderer)
	{
		g_pWireSphereModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pWireSphereModelRenderer->SetRenderMethod(E_RENDERMETHOD::WIREFRAMED);
		g_pWireSphereModelRenderer->SetRigidBodyFlag(E_RIGID_BODY_FLAG::DYNAMIC);

		CRawModel RawModel;
		RawModel.m_eRidigBodyFlag = E_RIGID_BODY_FLAG::DYNAMIC;
		RawModel.m_vScale = XMFLOAT3(fBoxSize, fBoxSize, fBoxSize);
		ContructSphereVertexBuffer(&RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pWireSphereModelRenderer->VAddMesh(iMesh, iMesh);
	}

	if (!g_pSolidSphereModelRenderer)
	{
		g_pSolidSphereModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pSolidSphereModelRenderer->SetRenderMethod(E_RENDERMETHOD::SOLID);
		g_pSolidSphereModelRenderer->SetRigidBodyFlag(E_RIGID_BODY_FLAG::DYNAMIC);

		CRawModel RawModel;
		RawModel.m_eRidigBodyFlag = E_RIGID_BODY_FLAG::DYNAMIC;
		RawModel.m_vScale = XMFLOAT3(fBoxSize, fBoxSize, fBoxSize);
		ContructSphereVertexBuffer(&RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pSolidSphereModelRenderer->VAddMesh(iMesh, iMesh);
	}

	if (!g_pWirePlaneModelRenderer)
	{
		g_pWirePlaneModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pWirePlaneModelRenderer->SetRenderMethod(E_RENDERMETHOD::WIREFRAMED);

		CRawModel RawModel;
		RawModel.m_vScale = XMFLOAT3(500.0f, 500.0f, 500.0f);
		ContructRegularGrid(XMINT2(5, 5), &RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pWirePlaneModelRenderer->VAddMesh(iMesh, iMesh);
	}

	if (!g_pSolidPlaneModelRenderer)
	{
		g_pSolidPlaneModelRenderer = CDistributedObjectCreator::GetInstance()->CreateModelRenderer();
		g_pSolidPlaneModelRenderer->SetRenderMethod(E_RENDERMETHOD::SOLID);

		CRawModel RawModel;
		RawModel.m_vScale = XMFLOAT3(500.0f, 500.0f, 500.0f);
		ContructRegularGrid(XMINT2(5, 5), &RawModel);

		for (auto iMesh : RawModel.m_RawMeshes)
			g_pSolidPlaneModelRenderer->VAddMesh(iMesh, iMesh);
	}

	IActor *pActor = nullptr;

	//CObject *pObject;

	switch (eActorType)
	{
	case E_ACTOR_TYPE::CUBE:
		{
			// g_pWireBoxModelRenderer g_pSolidBoxModelRenderer

		pActor = new CBox(xvPos - XMVectorReplicate(fBoxSize / 2), xvPos + XMVectorReplicate(fBoxSize / 2),
			g_pWireBoxModelRenderer);
		}
		break;
	case E_ACTOR_TYPE::SPHERE:
	{
		XMFLOAT3 vPos;
		XMStoreFloat3(&vPos, xvPos);

		pActor = new CSphere(vPos, 1.0f, g_pWireSphereModelRenderer);
	}
		break;
	case E_ACTOR_TYPE::PLANE:
		pActor = new CPlane(g_pSolidPlaneModelRenderer);
		((CPlane *)pActor)->GetPlane().x = XMVectorGetX(xvPos);
		((CPlane *)pActor)->GetPlane().y = XMVectorGetY(xvPos);
		((CPlane *)pActor)->GetPlane().z = XMVectorGetZ(xvPos);
		((CPlane *)pActor)->GetPlane().w = XMVectorGetW(xvPos);
		
		break;
	}

	pActor->VInit();

	for (auto iObject : pActor->GetObjects())
	{
		iObject->SetColor(Color);
	}

	return pActor;
}
Example #13
0
/*--------------------------------------------
	画面の描画処理
--------------------------------------------*/
HRESULT Render(void)
{
	HRESULT hr;

    // 描画ターゲットのクリア
    g_pImmediateContext->ClearRenderTargetView(
                       g_pRenderTargetView, // クリアする描画ターゲット
                       g_ClearColor);         // クリアする値

	// 深度/ステンシルのクリア
	g_pImmediateContext->ClearDepthStencilView(
			g_pDepthStencilView, // クリアする深度/ステンシル・ビュー
			D3D11_CLEAR_DEPTH,   // 深度値だけをクリアする
			1.0f,                // 深度バッファをクリアする値
			0);                  // ステンシル・バッファをクリアする値(この場合、無関係)

	// ***************************************
	// 立方体の描画

	// 定数バッファ�Aを更新
	// ビュー変換行列
	XMVECTORF32 eyePosition   = { 0.0f, 5.0f, -5.0f, 1.0f };  // 視点(カメラの位置)
	XMVECTORF32 focusPosition = { 0.0f, 0.0f,  0.0f, 1.0f };  // 注視点
	XMVECTORF32 upDirection   = { 0.0f, 1.0f,  0.0f, 1.0f };  // カメラの上方向
	XMMATRIX mat = XMMatrixLookAtLH(eyePosition, focusPosition, upDirection);
	XMStoreFloat4x4(&g_cbCBuffer.View, XMMatrixTranspose(mat));
	// 点光源座標
	XMVECTOR vec = XMVector3TransformCoord(XMLoadFloat3(&g_vLightPos), mat);
	XMStoreFloat3(&g_cbCBuffer.Light, vec);
	// ワールド変換行列
	XMMATRIX matY, matX;
	FLOAT rotate = (FLOAT)(XM_PI * (timeGetTime() % 3000)) / 1500.0f;
	matY = XMMatrixRotationY(rotate);
	rotate = (FLOAT)(XM_PI * (timeGetTime() % 1500)) / 750.0f;
	matX = XMMatrixRotationX(rotate);
	XMStoreFloat4x4(&g_cbCBuffer.World, XMMatrixTranspose(matY * matX));
	// 定数バッファのマップ取得
	D3D11_MAPPED_SUBRESOURCE MappedResource;
	hr = g_pImmediateContext->Map(
	                  g_pCBuffer,              // マップするリソース
	                  0,                       // サブリソースのインデックス番号
	                  D3D11_MAP_WRITE_DISCARD, // 書き込みアクセス
	                  0,                       //
	                  &MappedResource);        // データの書き込み先ポインタ
	if (FAILED(hr))
		return DXTRACE_ERR(L"InitBackBuffer  g_pImmediateContext->Map", hr);  // 失敗
	// データ書き込み
	CopyMemory(MappedResource.pData, &g_cbCBuffer, sizeof(cbCBuffer));
	// マップ解除
	g_pImmediateContext->Unmap(g_pCBuffer, 0);

	// ***************************************
	// IAに頂点バッファを設定
	// IAに入力レイアウト・オブジェクトを設定(頂点バッファなし)
	g_pImmediateContext->IASetInputLayout(NULL);
	// IAにプリミティブの種類を設定
	g_pImmediateContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// VSに頂点シェーダを設定
	g_pImmediateContext->VSSetShader(g_pVertexShader, NULL, 0);
	// VSに定数バッファを設定
	g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pCBuffer);

	// GSにジオメトリ・シェーダを設定
	g_pImmediateContext->GSSetShader(g_pGeometryShader, NULL, 0);
	// GSに定数バッファを設定
	g_pImmediateContext->GSSetConstantBuffers(0, 1, &g_pCBuffer);

	// RSにビューポートを設定
	g_pImmediateContext->RSSetViewports(1, g_ViewPort);
	// RSにラスタライザ・ステート・オブジェクトを設定
	g_pImmediateContext->RSSetState(g_pRasterizerState);

	// PSにピクセル・シェーダを設定
	g_pImmediateContext->PSSetShader(g_pPixelShader, NULL, 0);
	// PSに定数バッファを設定
	g_pImmediateContext->PSSetConstantBuffers(0, 1, &g_pCBuffer);
	// PSにシェーダ・リソース・ビューを設定
	g_pImmediateContext->PSSetShaderResources(
        0,                // 設定する最初のスロット番号
        1,                // 設定するシェーダ・リソース・ビューの数
        &g_pTextureSRV);  // 設定するシェーダ・リソース・ビューの配列
	// PSにサンプラーを設定
	g_pImmediateContext->PSSetSamplers(0, 1, &g_pTextureSampler);

	// OMに描画ターゲット ビューと深度/ステンシル・ビューを設定
	g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_bDepthMode ? g_pDepthStencilView : NULL);
	// OMにブレンド・ステート・オブジェクトを設定
	FLOAT BlendFactor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
	g_pImmediateContext->OMSetBlendState(g_pBlendState, BlendFactor, 0xffffffff);
	// OMに深度/ステンシル・ステート・オブジェクトを設定
	g_pImmediateContext->OMSetDepthStencilState(g_pDepthStencilState, 0);

	// ***************************************
	// 頂点バッファとインデックス・バッファを使わずに描画する
	g_pImmediateContext->Draw(
			36, // 描画する頂点数
			0); // 最初の頂点ID

	// ***************************************
	// バック バッファの表示
	hr = g_pSwapChain->Present(	0,	// 画面を直ぐに更新する
								0);	// 画面を実際に更新する

	return hr;
}
Example #14
0
void CineCameraClass::SetUpDirection(float x, float y, float z)
{
	XMFLOAT3 newUpDirection = XMFLOAT3(x, y, z);
	XMStoreFloat3(&upDirection, XMVector3Normalize(XMLoadFloat3(&newUpDirection)));

}
VOID DebugDraw::DrawConeWireframe( const XMFLOAT3& CenterBase, const XMFLOAT3& Axis, FLOAT fBaseRadius,
                                   FLOAT fTopRadius, D3DCOLOR Color )
{
    XMVECTOR vAxis = XMLoadFloat3( &Axis );
    XMVECTOR vAxisNorm = XMVector3Normalize( vAxis );

    // compute orthogonal vectors for the base of the cone
    XMVECTOR vBaseVectorX = XMVector3Normalize( XMVector3Orthogonal( vAxisNorm ) );
    XMVECTOR vBaseVectorZ = XMVector3Cross( vAxisNorm, vBaseVectorX );
    XMVECTOR vBaseVectorXScale = XMVectorScale( vBaseVectorX, fBaseRadius );
    XMVECTOR vBaseVectorZScale = XMVectorScale( vBaseVectorZ, fBaseRadius );

    // draw base ring
    if( fBaseRadius != 0 )
    {
        XMFLOAT3 BaseRingAxisX, BaseRingAxisZ;
        XMStoreFloat3( &BaseRingAxisX, vBaseVectorXScale );
        XMStoreFloat3( &BaseRingAxisZ, vBaseVectorZScale );
        DrawRing( CenterBase, BaseRingAxisX, BaseRingAxisZ, Color );
    }

    // compute center top location
    XMVECTOR vCenterTop = XMLoadFloat3( &CenterBase );
    vCenterTop = XMVectorAdd( vCenterTop, vAxis );

    // compute orthogonal vectors for the top of the cone
    XMVECTOR vTopVectorXScale = XMVectorScale( vBaseVectorX, fTopRadius );
    XMVECTOR vTopVectorZScale = XMVectorScale( vBaseVectorZ, fTopRadius );

    // build top ring
    if( fTopRadius != 0 )
    {
        XMFLOAT3 CenterTop;
        XMStoreFloat3( &CenterTop, vCenterTop );
        XMFLOAT3 TopRingAxisX, TopRingAxisZ;
        XMStoreFloat3( &TopRingAxisX, vTopVectorXScale );
        XMStoreFloat3( &TopRingAxisZ, vTopVectorZScale );
        DrawRing( CenterTop, TopRingAxisX, TopRingAxisZ, Color );
    }

    // build walls
    XMVECTOR vCenterBase = XMLoadFloat3( &CenterBase );
    const DWORD dwDivisions = 8;
    XMFLOAT3 WallVerts[ dwDivisions * 2 ];
    for( DWORD i = 0; i < dwDivisions; ++i )
    {
        FLOAT fTheta = ( ( FLOAT )i * XM_2PI ) / ( FLOAT )dwDivisions;
        XMVECTOR vSin, vCos;
        XMVectorSinCos( &vSin, &vCos, XMVectorReplicate( fTheta ) );
        XMVECTOR vBottom = vCenterBase + vBaseVectorXScale * vSin + vBaseVectorZScale * vCos;
        XMVECTOR vTop = vCenterTop + vTopVectorXScale * vSin + vTopVectorZScale * vCos;
        XMStoreFloat3( &WallVerts[ i * 2 ], vBottom );
        XMStoreFloat3( &WallVerts[ i * 2 + 1 ], vTop );
    }

    // draw walls
    SimpleShaders::SetDeclPos();
    SimpleShaders::BeginShader_Transformed_ConstantColor( g_matViewProjection, Color );
    g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST, dwDivisions, WallVerts, sizeof( XMFLOAT3 ) );
    SimpleShaders::EndShader();
}
Example #16
0
 void PointLight::SetPosition(FXMVECTOR position)
 {
     XMStoreFloat3(&mPosition, position);
 }
VOID DebugDraw::DrawFrustum( const Frustum& frustum, D3DCOLOR Color )
{
    // compute corner points

    XMVECTOR Origin = XMVectorSet( frustum.Origin.x, frustum.Origin.y, frustum.Origin.z, 0 );
    FLOAT Near = frustum.Near;
    FLOAT Far = frustum.Far;
    FLOAT RightSlope = frustum.RightSlope;
    FLOAT LeftSlope = frustum.LeftSlope;
    FLOAT TopSlope = frustum.TopSlope;
    FLOAT BottomSlope = frustum.BottomSlope;

    XMFLOAT3 CornerPoints[8];
    CornerPoints[0] = XMFLOAT3( RightSlope * Near, TopSlope * Near, Near );
    CornerPoints[1] = XMFLOAT3( LeftSlope * Near, TopSlope * Near, Near );
    CornerPoints[2] = XMFLOAT3( LeftSlope * Near, BottomSlope * Near, Near );
    CornerPoints[3] = XMFLOAT3( RightSlope * Near, BottomSlope * Near, Near );

    CornerPoints[4] = XMFLOAT3( RightSlope * Far, TopSlope * Far, Far );
    CornerPoints[5] = XMFLOAT3( LeftSlope * Far, TopSlope * Far, Far );
    CornerPoints[6] = XMFLOAT3( LeftSlope * Far, BottomSlope * Far, Far );
    CornerPoints[7] = XMFLOAT3( RightSlope * Far, BottomSlope * Far, Far );

    XMVECTOR Orientation = XMLoadFloat4( &frustum.Orientation );
    XMMATRIX Mat = XMMatrixRotationQuaternion( Orientation );
    for( UINT i = 0; i < 8; i++ )
    {
        XMVECTOR Result = XMVector3Transform( XMLoadFloat3( &CornerPoints[i] ), Mat );
        Result = XMVectorAdd( Result, Origin );
        XMStoreFloat3( &CornerPoints[i], Result );
    }

    XMFLOAT3 Lines[12 * 2];

    Lines[0] = CornerPoints[0];
    Lines[1] = CornerPoints[1];
    Lines[2] = CornerPoints[1];
    Lines[3] = CornerPoints[2];
    Lines[4] = CornerPoints[2];
    Lines[5] = CornerPoints[3];
    Lines[6] = CornerPoints[3];
    Lines[7] = CornerPoints[0];

    Lines[8] = CornerPoints[0];
    Lines[9] = CornerPoints[4];
    Lines[10] = CornerPoints[1];
    Lines[11] = CornerPoints[5];
    Lines[12] = CornerPoints[2];
    Lines[13] = CornerPoints[6];
    Lines[14] = CornerPoints[3];
    Lines[15] = CornerPoints[7];

    Lines[16] = CornerPoints[4];
    Lines[17] = CornerPoints[5];
    Lines[18] = CornerPoints[5];
    Lines[19] = CornerPoints[6];
    Lines[20] = CornerPoints[6];
    Lines[21] = CornerPoints[7];
    Lines[22] = CornerPoints[7];
    Lines[23] = CornerPoints[4];

    // draw frustum

    SimpleShaders::SetDeclPos();
    SimpleShaders::BeginShader_Transformed_ConstantColor( g_matViewProjection, Color );
    g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST, 12, Lines, sizeof( XMFLOAT3 ) );
    SimpleShaders::EndShader();
}
void MirrorApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};

	UINT stride = sizeof(Vertex::Basic32);
    UINT offset = 0;
 
	XMMATRIX view  = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX viewProj = view*proj;

	// Set per frame constants.
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mEyePosW);
	Effects::BasicFX->SetFogColor(Colors::Black);
	Effects::BasicFX->SetFogStart(2.0f);
	Effects::BasicFX->SetFogRange(40.0f);
 
	// Skull doesn't have texture coordinates, so we can't texture it.
	ID3DX11EffectTechnique* activeTech;
	ID3DX11EffectTechnique* activeSkullTech;

	switch(mRenderOptions)
	{
	case RenderOptions::Lighting:
		activeTech = Effects::BasicFX->Light3Tech;
		activeSkullTech = Effects::BasicFX->Light3Tech;
		break;
	case RenderOptions::Textures:
		activeTech = Effects::BasicFX->Light3TexTech;
		activeSkullTech = Effects::BasicFX->Light3Tech;
		break;
	case RenderOptions::TexturesAndFog:
		activeTech = Effects::BasicFX->Light3TexFogTech;
		activeSkullTech = Effects::BasicFX->Light3FogTech;
		break;
	}

	D3DX11_TECHNIQUE_DESC techDesc;

	//
	// Draw the floor and walls to the back buffer as normal.
	//
	
	activeTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mRoomVB, &stride, &offset);

		// Set per object constants.
		XMMATRIX world = XMLoadFloat4x4(&mRoomWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
		Effects::BasicFX->SetMaterial(mRoomMat);

		// Floor
		Effects::BasicFX->SetDiffuseMap(mFloorDiffuseMapSRV);
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(6, 0);

		// Wall
		Effects::BasicFX->SetDiffuseMap(mWallDiffuseMapSRV);
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(18, 6);
	}

	//
	// Draw the skull to the back buffer as normal.
	//

	activeSkullTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeSkullTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mSkullVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mSkullIB, DXGI_FORMAT_R32_UINT, 0);

		XMMATRIX world = XMLoadFloat4x4(&mSkullWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetMaterial(mSkullMat);

		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mSkullIndexCount, 0, 0);
	}

	//
	// Draw the mirror to stencil buffer only.
	//

	activeTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mRoomVB, &stride, &offset);

		// Set per object constants.
		XMMATRIX world = XMLoadFloat4x4(&mRoomWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(XMMatrixIdentity());

		// Do not write to render target.
		md3dImmediateContext->OMSetBlendState(RenderStates::NoRenderTargetWritesBS, blendFactor, 0xffffffff);

		// Render visible mirror pixels to stencil buffer.
		// Do not write mirror depth to depth buffer at this point, otherwise it will occlude the reflection.
		md3dImmediateContext->OMSetDepthStencilState(RenderStates::MarkMirrorDSS, 1);
		
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(6, 24);

		// Restore states.
		md3dImmediateContext->OMSetDepthStencilState(0, 0);
		md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	}


	//
	// Draw the skull reflection.
	//
	activeSkullTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeSkullTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mSkullVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mSkullIB, DXGI_FORMAT_R32_UINT, 0);

		XMVECTOR mirrorPlane = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
		XMMATRIX R = XMMatrixReflect(mirrorPlane);
		XMMATRIX world = XMLoadFloat4x4(&mSkullWorld) * R;
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetMaterial(mSkullMat);

		// Cache the old light directions, and reflect the light directions.
		XMFLOAT3 oldLightDirections[3];
		for(int i = 0; i < 3; ++i)
		{
			oldLightDirections[i] = mDirLights[i].Direction;

			XMVECTOR lightDir = XMLoadFloat3(&mDirLights[i].Direction);
			XMVECTOR reflectedLightDir = XMVector3TransformNormal(lightDir, R);
			XMStoreFloat3(&mDirLights[i].Direction, reflectedLightDir);
		}

		Effects::BasicFX->SetDirLights(mDirLights);

		// Cull clockwise triangles for reflection.
		md3dImmediateContext->RSSetState(RenderStates::CullClockwiseRS);

		// Only draw reflection into visible mirror pixels as marked by the stencil buffer. 
		md3dImmediateContext->OMSetDepthStencilState(RenderStates::DrawReflectionDSS, 1);
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mSkullIndexCount, 0, 0);

		// Restore default states.
		md3dImmediateContext->RSSetState(0);	
		md3dImmediateContext->OMSetDepthStencilState(0, 0);	

		// Restore light directions.
		for(int i = 0; i < 3; ++i)
		{
			mDirLights[i].Direction = oldLightDirections[i];
		}

		Effects::BasicFX->SetDirLights(mDirLights);
	}

	//
	// Draw the mirror to the back buffer as usual but with transparency
	// blending so the reflection shows through.
	// 

	activeTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mRoomVB, &stride, &offset);

		// Set per object constants.
		XMMATRIX world = XMLoadFloat4x4(&mRoomWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
		Effects::BasicFX->SetMaterial(mMirrorMat);
		Effects::BasicFX->SetDiffuseMap(mMirrorDiffuseMapSRV);

		// Mirror
		md3dImmediateContext->OMSetBlendState(RenderStates::TransparentBS, blendFactor, 0xffffffff);
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(6, 24);
	}

	//
	// Draw the skull shadow.
	//
	activeSkullTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3DX11EffectPass* pass = activeSkullTech->GetPassByIndex( p );

		md3dImmediateContext->IASetVertexBuffers(0, 1, &mSkullVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mSkullIB, DXGI_FORMAT_R32_UINT, 0);

		XMVECTOR shadowPlane = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); // xz plane
		XMVECTOR toMainLight = -XMLoadFloat3(&mDirLights[0].Direction);
		XMMATRIX S =  XMMatrixShadow(shadowPlane, toMainLight);
		XMMATRIX shadowOffsetY = XMMatrixTranslation(0.0f, 0.001f, 0.0f);

		// Set per object constants.
		XMMATRIX world = XMLoadFloat4x4(&mSkullWorld)*S*shadowOffsetY;
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetMaterial(mShadowMat);

		md3dImmediateContext->OMSetDepthStencilState(RenderStates::NoDoubleBlendDSS, 0);
		pass->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mSkullIndexCount, 0, 0);

		// Restore default states.
		md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
		md3dImmediateContext->OMSetDepthStencilState(0, 0);
	}

	HR(mSwapChain->Present(0, 0));
}
Example #19
0
	void LightPoint::set_position(FXMVECTOR position) {
		XMStoreFloat3(&m_position, position);
	}
Example #20
0
void Entity::Update(const Camera& camera, float dt)
{
	if (mSpinning)		{Yaw(dt*movementMult);}
	if (mUpDown)		{GoUpDown(dt);}
	if (mFlipping)		{Pitch(dt*movementMult);}
	if (mRolling)		{Roll(dt*movementMult);}
	if (mSideToSide)	{GoSideToSide(dt);}
	if (mBackAndForth)	{GoBackAndForth(dt);}
	if (mOrbit)			{ Yaw(dt*movementMult); Walk(dt*movementMult*100); }

	XMVECTOR R = XMLoadFloat3(&mRight);
	XMVECTOR U = XMLoadFloat3(&mUp);
	XMVECTOR L = XMLoadFloat3(&mLook);
	XMVECTOR P = XMLoadFloat3(&mPosition);

	
	// Keep axes orthogonal to each other and of unit length.
	L = XMVector3Normalize(L);
	U = XMVector3Normalize(XMVector3Cross(L, R));

	// U, L already ortho-normal, so no need to normalize cross product.
	R = XMVector3Cross(U, L);

	
	// Fill in the world matrix entries.
// 	float x = XMVectorGetX(XMVector3Dot(P, R));
// 	float y = XMVectorGetX(XMVector3Dot(P, U));
// 	float z = XMVectorGetX(XMVector3Dot(P, L));

	float x = XMVectorGetX(P);
	float y = XMVectorGetY(P);
	float z = XMVectorGetZ(P);

	XMStoreFloat3(&mRight, R);
	XMStoreFloat3(&mUp, U);
	XMStoreFloat3(&mLook, L);

	mWorld(0, 0) = mRight.x;
	mWorld(1, 0) = mRight.y;
	mWorld(2, 0) = mRight.z;
	mWorld(3, 0) = x;

	mWorld(0, 1) = mUp.x;
	mWorld(1, 1) = mUp.y;
	mWorld(2, 1) = mUp.z;
	mWorld(3, 1) = y;

	if (reverseLook){
	mWorld(0, 2) = -mLook.x;
	mWorld(1, 2) = -mLook.y;
	mWorld(2, 2) = -mLook.z;
	mWorld(3, 2) = z;}
	else
	{	mWorld(0, 2) = mLook.x;
		mWorld(1, 2) = mLook.y;
		mWorld(2, 2) = mLook.z;
		mWorld(3, 2) = z;}


	mWorld(0, 3) = 0.0f;
	mWorld(1, 3) = 0.0f;
	mWorld(2, 3) = 0.0f;
	mWorld(3, 3) = 1.0f;

	if (hovering)
	{
		XMMATRIX M = XMLoadFloat4x4(&mWorld);
		XMMATRIX scaling = XMMatrixScaling(1.3f, 1.3f, 1.3f);
		XMStoreFloat4x4(&mWorld, scaling * M);
	}


	//GROWING MOVEMENTS
	if (mPulse)	{ Pulse(dt); }
	if (mGrowIn){ GrowIn(dt); }
	if (mGrowOut){ GrowOut(dt); }
	if (mSquishX || mSquishY || mSquishZ){ Squish(dt); 
	if (mSquishX){  ScaleX(currProgress); }
	if (mSquishY){  ScaleY(currProgress); }
	if (mSquishZ){  ScaleZ(currProgress); }}


	if (progressBar)
	{
		ScaleX(currProgress);
	}

	if (billboard)
	{
		XMMATRIX M		= XMLoadFloat4x4(&mWorld);
		XMVECTOR L		= XMVector3Normalize(XMVectorSubtract(camera.GetPositionXM(), GetPositionXM()));
		XMVECTOR Look	= XMLoadFloat3(&mLook);
		XMVECTOR angle	= XMVector3AngleBetweenNormals(L, Look);
		float theAngle	= XMVectorGetY(angle);

		XMMATRIX rotY;
		camera.GetPosition().x < mPosition.x ? rotY = XMMatrixRotationY(-theAngle) : rotY = XMMatrixRotationY(theAngle);

		XMStoreFloat4x4(&mWorld, rotY * M); 
	}

	if (goToPos)
	{
		if (mDistanceLeft <= 0){ goToPos = false; }
	}

	if (mUseAnimation){ mAnim->Update(dt);}

	//update sphere collider
	mSphereCollider.Center	= mPosition;
	if (mUseAAB){ UpdateAAB(); }
	if (mUseAABOnce){ UpdateAAB(); mUseAABOnce = false; }
}
Example #21
0
void Unit::Update(float DeltaTime, Terrain* TerrainInstance)
{
	if ( IsAlive() && gHealth.first <= 0 )
	{
		SetWeaponState( Hold );
		DropWeapon();
		Kill();
		StopAllAnimations();
		PlayAnimation("Death");
		PlayAnimationAfter("Death", "Dead");
		SoundManager::GetInstance()->Play( gDeathSound, SFX, false );

		if (!PlayingAnimation("Death"))
		{
			SetState( Dead );
			return;
		}		
	}

	GameObject::Update(DeltaTime, TerrainInstance);

	if ( GetState() == Dying )
		return;

	XMVECTOR vel = XMLoadFloat3(&GetFloat3Value( Velocity ));
	if (!XMVector3Equal(vel, XMVectorZero()))
	{
		XMVECTOR dir  = XMLoadFloat3(&GetFloat3Value( Direction ));
		XMVECTOR angleV = XMVector3AngleBetweenVectors(dir, vel);

		float angle;
		XMStoreFloat(&angle, angleV);

		XMVECTOR crossV = XMVector3Cross(dir, vel);

		if (XMVectorGetY(crossV) < 0)
			angle *= -1;

		//cout << 180 * angle / PI << endl;

		if (fabs(angle) <= PI * 0.25f)
			gMoveDirection = Forward;

		else if (fabs(angle) > PI * 0.75f)
			gMoveDirection = Back;

		else if (angle < 0)
			gMoveDirection = Left;

		else if (angle > 0)
			gMoveDirection = Right;

		XMVECTOR L = XMVector3Length(vel);
		float speed;
		XMStoreFloat(&speed, L);
		speed /= UnitsPerMeter;

		switch (gMoveDirection)
		{
		case Forward:
			if (speed > 1.05f * gWalkSpeed)
			{
				SetMoveState(Run);	
				SetAnimationSpeed("Run", speed);
				SetAnimationSpeed(GetAnimation("UpperRun"), speed);							
			}
			else
			{
				SetMoveState(Walk);
				SetAnimationSpeed("Walk", speed);
			}
			break;
		case Back:
			SetMoveState(Walk);
			SetAnimationSpeed("Back", speed);
			break;
		case Right:
			SetMoveState(Walk);
			SetAnimationSpeed("SideStepRight", speed);
			break;
		case Left:
			SetMoveState(Walk);
			SetAnimationSpeed("SideStepLeft", speed);
			break;
		}
	}
	else
	{
		gMoveDirection = None;

		if (!Crouching())
			SetMoveState(Stand);
	}

	if ( gCurrentWeapon )
	{
		XMFLOAT3 handPos;
		XMFLOAT4 handRot;
		
		XMVECTOR pos = XMLoadFloat3(&GetFloat3Value( Position ));
		XMVECTOR dir = XMLoadFloat3(&GetFloat3Value( Direction ));
		XMVECTOR lv = XMVector3Length(dir);

		bool gotJointPos = false;
		bool gotJointRot = false;
		if (m_ModelInstance)
		{
			gotJointPos = GetJointPosition("RightHand", handPos);
			gotJointRot = GetJointRotation("RightHand", handRot);
		}

		if (!gotJointPos)
		{
			pos += dir * (GetRadius() - 10);
			XMStoreFloat3(&handPos, pos);
		}
		
		if (gCurrentWeapon->NeedReload())
		{
			ReloadWeapon();
		}
		
		//gWeapon->Update(DeltaTime);
		//gWeapon->MoveTo( position );
		gCurrentWeapon->MoveTo( handPos );

		XMFLOAT3 weaponPos;
		if (gCurrentWeapon->GetJointPosition("RightHand", weaponPos))
		{
			XMStoreFloat3(&handPos, XMLoadFloat3(&handPos) + (XMLoadFloat3(&handPos) - XMLoadFloat3(&weaponPos)));
			gCurrentWeapon->MoveTo( handPos );
		}
		
		if (gotJointRot)
		{
			gCurrentWeapon->SetRotation( handRot );
		}
		else
			gCurrentWeapon->SetRotation( GetQuaternation() );
	}
	/*
	else
	{
		LoopAnimation("PistolUpperWalk");
	}
	*/
}
void ForwardPlusRenderer::RenderFinal(const RenderView& view, const RenderTarget& renderTarget)
{
    auto& pass = (MsaaEnabled) ? FinalPassMsaa : FinalPass;

    if (!MsaaEnabled)
    {
        pass->SetRenderTarget(0, renderTarget.Texture->GetRTV());
    }

    pass->Begin();

    XMMATRIX worldToView = XMLoadFloat4x4(&view.WorldToView);
    XMMATRIX worldToProjection = XMMatrixMultiply(worldToView, XMLoadFloat4x4(&view.ViewToProjection));

    // Directional Lights are shared for all objects, so fill up front
    FinalPassPSConstants psConstants{};
    psConstants.NumLights = 0;
    psConstants.TileSize = NUM_PIXELS_PER_GROUP_X;
    psConstants.NumTilesX = RTWidth / NUM_PIXELS_PER_GROUP_X;

    for (auto& light : Lights)
    {
        if (light->GetType() == LightType::Directional)
        {
            psConstants.Lights[psConstants.NumLights].Color = light->GetColor();

            XMFLOAT4X4 localToWorld = light->GetLocalToWorld();
            XMVECTOR lightDir = XMVectorNegate(XMVectorSet(localToWorld.m[2][0], localToWorld.m[2][1], localToWorld.m[2][2], 0.f));
            lightDir = XMVector3TransformNormal(lightDir, worldToView);
            XMStoreFloat3(&psConstants.Lights[psConstants.NumLights].Direction, lightDir);

            ++psConstants.NumLights;
        }
    }

    FinalPassPSCB->Update(&psConstants, sizeof(psConstants));

    // Remainder of data is object-specific
    FinalPassVSConstants constants{};

    for (auto& visual : Visuals)
    {
        XMMATRIX localToWorld = XMLoadFloat4x4(&visual->GetLocalToWorld());
        XMStoreFloat4x4(&constants.LocalToView, XMMatrixMultiply(localToWorld, worldToView));
        XMStoreFloat4x4(&constants.LocalToProjection, XMMatrixMultiply(localToWorld, worldToProjection));

        HRESULT hr = FinalPassVSCB->Update(&constants, sizeof(constants));
        if (FAILED(hr))
        {
            assert(false);
            continue;
        }

        pass->SetPSResource(3, visual->GetAlbedoTexture() ? visual->GetAlbedoTexture()->GetSRV() : nullptr);
        pass->SetPSResource(4, visual->GetNormalTexture() ? visual->GetNormalTexture()->GetSRV() : nullptr);

        pass->Draw(visual);
    }

    pass->End();

    if (MsaaEnabled)
    {
        Context->ResolveSubresource(renderTarget.Texture->GetTexture().Get(), 0, FinalRTMsaa->GetTexture().Get(), 0, FinalRTMsaa->GetDesc().Format);
    }
}
void GeometryGenerator::CreateSphere(float radius, UINT sliceCount, UINT stackCount, MeshData& meshData)
{
	meshData.Vertices.clear();
	meshData.Indices.clear();

	//
	// Compute the vertices stating at the top pole and moving down the stacks.
	//

	// Poles: note that there will be texture coordinate distortion as there is
	// not a unique point on the texture map to assign to the pole when mapping
	// a rectangular texture onto a sphere.
	Vertex topVertex(0.0f, +radius, 0.0f, 0.0f, +1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	Vertex bottomVertex(0.0f, -radius, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);

	meshData.Vertices.push_back( topVertex );

	float phiStep   = XM_PI/stackCount;
	float thetaStep = 2.0f*XM_PI/sliceCount;

	// Compute vertices for each stack ring (do not count the poles as rings).
	for(UINT i = 1; i <= stackCount-1; ++i)
	{
		float phi = i*phiStep;

		// Vertices of ring.
		for(UINT j = 0; j <= sliceCount; ++j)
		{
			float theta = j*thetaStep;

			Vertex v;

			// spherical to cartesian
			v.Position.x = radius*sinf(phi)*cosf(theta);
			v.Position.y = radius*cosf(phi);
			v.Position.z = radius*sinf(phi)*sinf(theta);

			// Partial derivative of P with respect to theta
			v.TangentU.x = -radius*sinf(phi)*sinf(theta);
			v.TangentU.y = 0.0f;
			v.TangentU.z = +radius*sinf(phi)*cosf(theta);

			XMVECTOR T = XMLoadFloat3(&v.TangentU);
			XMStoreFloat3(&v.TangentU, XMVector3Normalize(T));

			XMVECTOR p = XMLoadFloat3(&v.Position);
			XMStoreFloat3(&v.Normal, XMVector3Normalize(p));

			v.TexC.x = theta / XM_2PI;
			v.TexC.y = phi / XM_PI;

			meshData.Vertices.push_back( v );
		}
	}

	meshData.Vertices.push_back( bottomVertex );

	//
	// Compute indices for top stack.  The top stack was written first to the vertex buffer
	// and connects the top pole to the first ring.
	//

	for(UINT i = 1; i <= sliceCount; ++i)
	{
		meshData.Indices.push_back(0);
		meshData.Indices.push_back(i+1);
		meshData.Indices.push_back(i);
	}
	
	//
	// Compute indices for inner stacks (not connected to poles).
	//

	// Offset the indices to the index of the first vertex in the first ring.
	// This is just skipping the top pole vertex.
	UINT baseIndex = 1;
	UINT ringVertexCount = sliceCount+1;
	for(UINT i = 0; i < stackCount-2; ++i)
	{
		for(UINT j = 0; j < sliceCount; ++j)
		{
			meshData.Indices.push_back(baseIndex + i*ringVertexCount + j);
			meshData.Indices.push_back(baseIndex + i*ringVertexCount + j+1);
			meshData.Indices.push_back(baseIndex + (i+1)*ringVertexCount + j);

			meshData.Indices.push_back(baseIndex + (i+1)*ringVertexCount + j);
			meshData.Indices.push_back(baseIndex + i*ringVertexCount + j+1);
			meshData.Indices.push_back(baseIndex + (i+1)*ringVertexCount + j+1);
		}
	}

	//
	// Compute indices for bottom stack.  The bottom stack was written last to the vertex buffer
	// and connects the bottom pole to the bottom ring.
	//

	// South pole vertex was added last.
	UINT southPoleIndex = (UINT)meshData.Vertices.size()-1;

	// Offset the indices to the index of the first vertex in the last ring.
	baseIndex = southPoleIndex - ringVertexCount;
	
	for(UINT i = 0; i < sliceCount; ++i)
	{
		meshData.Indices.push_back(southPoleIndex);
		meshData.Indices.push_back(baseIndex+i);
		meshData.Indices.push_back(baseIndex+i+1);
	}
}
void RayTracingDemo::update(const GameTimer & timer)
{
	mBlueColor = (0.5f) * static_cast<float>(sin(timer.totalGameTime())) + 0.5f;

	XMFLOAT3 movementAmount = { 0, 0, 0 };
	if (mKeyboard != nullptr)
	{
		if (mKeyboard->isKeyDown(DIK_J))
		{
			movementAmount.x = -1.0f;
		}

		if (mKeyboard->isKeyDown(DIK_L))
		{
			movementAmount.x = 1.0f;
		}
		
		if (mKeyboard->isKeyDown(DIK_K))
		{
			movementAmount.y = 1.0f;
		}

		if (mKeyboard->isKeyDown(DIK_I))
		{
			movementAmount.y = -1.0f;

		}

		if (mKeyboard->isKeyDown(DIK_U))
		{
			movementAmount.z = -1.0f;

		}

		if (mKeyboard->isKeyDown(DIK_O))
		{
			movementAmount.z = 1.0f;

		}

		float elapsedTime = (float)timer.elapsedGameTime();
		XMVECTOR position = XMLoadFloat3(&mPosition) + (XMLoadFloat3(&movementAmount) * 100.0f * timer.elapsedGameTime());
		XMStoreFloat3(&mPosition, position);
		
	}

	XMFLOAT3 lightMovementAmount = { 0, 0, 0 };
	if (mKeyboard != nullptr)
	{
		if (mKeyboard->isKeyDown(DIK_A))
		{
			lightMovementAmount.x = -1.0f;
		}

		if (mKeyboard->isKeyDown(DIK_D))
		{
			lightMovementAmount.x = 1.0f;
		}

		if (mKeyboard->isKeyDown(DIK_W))
		{
			lightMovementAmount.y = 1.0f;
		}

		if (mKeyboard->isKeyDown(DIK_S))
		{
			lightMovementAmount.y = -1.0f;

		}

		if (mKeyboard->isKeyDown(DIK_R))
		{
			lightMovementAmount.z = -1.0f;

		}

		if (mKeyboard->isKeyDown(DIK_F))
		{
			lightMovementAmount.z = 1.0f;

		}

		float elapsedTime = (float)timer.elapsedGameTime();

		XMVECTOR lightPosition = XMLoadFloat3(&mLightPosition) + (XMLoadFloat3(&lightMovementAmount) * 20.0f* timer.elapsedGameTime());
		XMStoreFloat3(&mLightPosition, lightPosition);
	}

	



}
Example #25
0
bool DX11::ModelShader::SetParameters(ID3D11DeviceContext * direct3Dcontext, Gpu::Model * model, Gpu::Camera * camera, Gpu::Light ** lights, unsigned numLights, float aspect, Gpu::Effect * effect)
{
	if(!model || !camera) return false;
	if(camera->position == camera->target)
	{
		OutputDebugString(L"Cannot construct view matrix!");
		return false;
	}

	// MATRIX OPS - SIGNIFICANT COST - ~9us //

	glm::mat4 modelMatrix = model->GetMatrix();
	XMMATRIX world((float*)&modelMatrix);

	XMStoreFloat4x4(&vertexConstData.world, world);

	glm::mat4 camMatrix = camera->GetProjMatrix(aspect) * camera->GetViewMatrix();
	XMMATRIX viewProj((float*)&camMatrix);

	XMStoreFloat4x4(&vertexConstData.viewProjection, viewProj);

	XMMATRIX wit = XMMatrixInverse(0, XMMatrixTranspose(world));
	XMStoreFloat4x4(&vertexConstData.worldInverseTranspose, wit);

	vertexConstData.materialColor = XMFLOAT4(model->color.r, model->color.g, model->color.b, model->color.a);

	ID3D11ShaderResourceView * nullResource = 0;

	if(model->texture)
	{
		DX11::Texture* texture = static_cast<DX11::Texture*>(model->texture);
		direct3Dcontext->PSSetShaderResources(0, 1, &texture->shaderView);
	}
	else
	{
		direct3Dcontext->PSSetShaderResources(0, 1, &nullResource);
	}
	
	// BEGIN LIGHTING - VARIABLE COST //

	if(model->cubeMap)
	{
		DX11::CubeMap * cubeMap = static_cast<DX11::CubeMap*>(model->cubeMap);
		direct3Dcontext->PSSetShaderResources(1, 1, &cubeMap->shaderView);
		pixelConstData.cubeMapAlpha = 1.0f;
	}
	else
	{
		direct3Dcontext->PSSetShaderResources(1, 1, &nullResource);
		pixelConstData.cubeMapAlpha = 0.0f;
	}
	if(model->normalMap)
	{
		DX11::Texture * normalMap = static_cast<DX11::Texture*>(model->normalMap);
		direct3Dcontext->PSSetShaderResources(2, 1, &normalMap->shaderView);
	}
	else
	{
		direct3Dcontext->PSSetShaderResources(2, 1, &nullResource);
	}

	pixelConstData.numLights = numLights;
	if(numLights > 0)
	{
		pixelConstData.ambient = 0.0f;
		pixelConstData.cameraPosition = XMFLOAT3(camera->position.x, camera->position.y, camera->position.z);
		pixelConstData.specularPower = model->specPower;
		pixelConstData.specularFactor = model->specFactor;
		pixelConstData.diffuseFactor = model->diffuseFactor;

		for(unsigned i = 0; i < numLights && i < MAX_LIGHTS; ++i)
		{
			// Hmm, really the specular highlight should be calculated
			// from the light's size, position and intensity.
			// Do a little more investigation into Physically Based Lighting

			lightConstData.positionSpecs[i].specPower = 12.0f;

			Gpu::LightType lightType = lights[i]->GetType();
			if(lightType == Gpu::LightType_Directional)
			{
				Gpu::DirectionalLight * dirLight = static_cast<Gpu::DirectionalLight*>(lights[i]);
				XMVECTOR lightDirVec = XMLoadFloat3(&XMFLOAT3(dirLight->direction.x, dirLight->direction.y, dirLight->direction.z));
				XMStoreFloat3(&(lightConstData.positionSpecs[i].position), XMVectorScale(lightDirVec, 10.0e+10f));
				lightConstData.colorAttenuations[i].color = XMFLOAT3(dirLight->color.r, dirLight->color.g, dirLight->color.b);
				lightConstData.colorAttenuations[i].attenuation = 0.0f;
				lightConstData.spotDirPowers[i].direction = XMFLOAT3(0.0f, 0.0f, 0.0f);
				lightConstData.spotDirPowers[i].spotPower = 0.0f;
			}
			if(lightType == Gpu::LightType_Point)
			{
				Gpu::PointLight * pointLight = static_cast<Gpu::PointLight*>(lights[i]);
				lightConstData.positionSpecs[i].position = XMFLOAT3(pointLight->position.x, pointLight->position.y, pointLight->position.z);
				lightConstData.colorAttenuations[i].color = XMFLOAT3(pointLight->color.r, pointLight->color.g, pointLight->color.b);
				lightConstData.colorAttenuations[i].attenuation = pointLight->atten;
				lightConstData.spotDirPowers[i].direction = XMFLOAT3(0.0f, 0.0f, 0.0f);
				lightConstData.spotDirPowers[i].spotPower = 0.0f;
			}
			if(lightType == Gpu::LightType_Spot)
			{
				Gpu::SpotLight * spotLight = static_cast<Gpu::SpotLight*>(lights[i]);
				lightConstData.positionSpecs[i].position = XMFLOAT3(spotLight->position.x, spotLight->position.y, spotLight->position.z);
				lightConstData.colorAttenuations[i].color = XMFLOAT3(spotLight->color.r, spotLight->color.g, spotLight->color.b);
				lightConstData.colorAttenuations[i].attenuation = spotLight->atten;
				XMStoreFloat3(&lightConstData.spotDirPowers[i].direction, XMVector3Normalize(XMLoadFloat3(
					&XMFLOAT3(spotLight->direction.x, spotLight->direction.y, spotLight->direction.z))));
				lightConstData.spotDirPowers[i].spotPower = spotLight->power;

				if(i == 0)
				{
					float lightFOV = XM_PI * 0.15f;

					glm::mat4 lightGlmMatrix = spotLight->GetMatrix(lightFOV, glm::vec3(0.0f, 1.0f, 0.0f));
					XMMATRIX lightXMMatrix((float*)&lightGlmMatrix);

					//XMMATRIX lightView = XMMatrixLookToLH(
					//	XMLoadFloat3(&lightConstData.positionSpecs[i].position),
					//	XMLoadFloat3(&lightConstData.spotDirPowers[i].direction),
					//	XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.0f)));

					//XMMATRIX lightLens = XMMatrixPerspectiveFovLH(lightFOV, 1.0f, 1.0f, 200.0f);

					XMStoreFloat4x4(&vertexConstData.lightViewProjection, lightXMMatrix);
				}
			}
		}

		static unsigned setCount = 0;

		setCount++;

		direct3Dcontext->UpdateSubresource(lightParamsBuffer, 0, 0, &lightConstData, sizeof(LightConstants), sizeof(LightConstants));

		setCount++;

		direct3Dcontext->PSSetConstantBuffers(1, 1, &lightParamsBuffer);
	}
	else
	{
		pixelConstData.lightPosition = XMFLOAT3(0.0f, 0.0f, 0.0f);
		pixelConstData.lightColor = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		pixelConstData.cameraPosition = XMFLOAT3(camera->position.x, camera->position.y, camera->position.z);
		pixelConstData.spotPower = 0.0f;
		pixelConstData.specularPower = FLT_MAX;
		pixelConstData.spotDirection = XMFLOAT3(0.0f, 0.0f, 0.0f);
		pixelConstData.ambient = 1.0f;
	}

	// END LIGHTING //

	// UPDATING CONSTANT BUFFERS - SIGNIFICANT COST - 17us //

	direct3Dcontext->UpdateSubresource(pixelConstBuffer, 0, 0, &pixelConstData, sizeof(PixelConstants), sizeof(PixelConstants));
	direct3Dcontext->PSSetConstantBuffers(0, 1, &pixelConstBuffer);

	direct3Dcontext->UpdateSubresource(vertexConstBuffer, 0, 0, &vertexConstData, sizeof(VertexConstants), sizeof(VertexConstants));
	direct3Dcontext->VSSetConstantBuffers(0, 1, &vertexConstBuffer);

	// SETTING EXTRA PARAMS - VARIABLE COST //

	if(effect)
	{
		return currentTechnique->SetExtraParameters(direct3Dcontext, effect);
	}
	else
	{
		return true;
	}
}
void PrismTexturedModel::InitializeModel(float height, float radius, int nFaces, WCHAR** pTextureFileNames)
{

	/*
	pTextureFileNames is expected to be an array of 3 items
	pTextureFileName[0] is the texture applied to the side faces of the prism
	pTextureFileName[1] is the texture applied to the top end of the prism
	pTextureFileName[2] is the texture applied to the bottom end of the prism
	*/

	int numberOfFaces = nFaces;

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

	//keep number of faces in a reasonable range
	if(numberOfFaces < 3) numberOfFaces = 3;
	if(numberOfFaces > 24) numberOfFaces = 24;
	
	//changing the sign of angle will affect whether the inside or outside of the prism
	//is visible
	float angle = -XM_PI * 2 / nFaces; //slice angle of each face



	//temporary vertices for top and bottom
 	XMFLOAT3* topVertices = new XMFLOAT3[numberOfFaces + 1];
 	XMFLOAT3* bottomVertices = new XMFLOAT3[numberOfFaces + 1];


	
    XMFLOAT3 v0top(radius, height/2, 0); 
    XMFLOAT3 v0bottom(radius, -height/2, 0);

    XMFLOAT3 topCenter(0, height/2, 0);
    XMFLOAT3 bottomCenter(0, -height/2, 0);

    topVertices[0] = v0top;
    topVertices[numberOfFaces] = v0top;
    bottomVertices[0] = v0bottom;
    bottomVertices[numberOfFaces] = v0bottom;


    //define the vertices around the top and bottom of prism

    XMFLOAT4X4 rotationMatrix;
    for (int i = 1; i < numberOfFaces; i++)
    {
		XMStoreFloat4x4(&rotationMatrix, XMMatrixRotationY(angle * i));
	    XMStoreFloat3( &topVertices[i],  XMVector3Transform( XMLoadFloat3(&v0top), XMLoadFloat4x4(&rotationMatrix) ));
	    XMStoreFloat3( &bottomVertices[i],  XMVector3Transform( XMLoadFloat3(&v0bottom), XMLoadFloat4x4(&rotationMatrix) ));

    }

 
	int numberOfFaceVertices = numberOfFaces * 6;
	int numberOfTopVertices = numberOfFaces * 3;
	int numberOfBottomVertices = numberOfFaces * 3;

	m_textureVertices = new TextureVertexType[numberOfFaceVertices];
	m_topTextureVertices = new TextureVertexType[numberOfTopVertices];
	m_bottomTextureVertices = new TextureVertexType[numberOfBottomVertices];

	m_faceTextures = 0; 

	m_indices = new unsigned long[numberOfFaceVertices];
	m_topIndices = new unsigned long[numberOfTopVertices];
	m_bottomIndices = new unsigned long[numberOfBottomVertices];

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

	m_VertexModelArray = new Model*[NUMBER_OF_TEXTURES]; 

	float faceWidth = 1.0f/numberOfFaces;

	//define the triangle pairs that make up each face
    for (int i = 0; i < numberOfFaces; i++)
    {

           //face vertices -in clockwise render order
 	       m_textureVertices[6*i+0].position = topVertices[i];  //top left
	       m_textureVertices[6*i+0].texture = XMFLOAT2(faceWidth * i, 0.0f);	
	       m_textureVertices[6*i+1].position = topVertices[i+1];   //top right
	       m_textureVertices[6*i+1].texture = XMFLOAT2(faceWidth * (i + 1), 0.0f);
	       m_textureVertices[6*i+2].position = bottomVertices[i];   //bottom left
	       m_textureVertices[6*i+2].texture = XMFLOAT2(faceWidth * i, 1.0f);

		   m_textureVertices[6*i+3].position = bottomVertices[i];  //bottom left
	       m_textureVertices[6*i+3].texture = XMFLOAT2(faceWidth * i, 1.0f);	
	       m_textureVertices[6*i+4].position = topVertices[i + 1];   //top right
	       m_textureVertices[6*i+4].texture = XMFLOAT2(faceWidth * (i + 1), 0.0f);
	       m_textureVertices[6*i+5].position = bottomVertices[i+1];   //bottom right
	       m_textureVertices[6*i+5].texture = XMFLOAT2(faceWidth * (i + 1), 1.0f);

		   //top slice triangle
		   m_topTextureVertices[3*i+0].position = topVertices[i];  
	       m_topTextureVertices[3*i+0].texture = XMFLOAT2((radius + topVertices[i].x)/(2.0f * radius) , (radius - topVertices[i].z)/(2.0f * radius));
	       m_topTextureVertices[3*i+1].position = topCenter;   //center
	       m_topTextureVertices[3*i+1].texture = XMFLOAT2(0.5f , 0.5f);
	       m_topTextureVertices[3*i+2].position = topVertices[i + 1];   
	       m_topTextureVertices[3*i+2].texture = XMFLOAT2((radius + topVertices[i+1].x)/(2.0f * radius), (radius - topVertices[i+1].z)/(2.0f * radius));

		   //bottom slice triangle
		   m_bottomTextureVertices[3*i+0].position = bottomCenter;  //center
	       m_bottomTextureVertices[3*i+0].texture = XMFLOAT2(0.5f , 0.5f);
	       m_bottomTextureVertices[3*i+1].position = bottomVertices[i];  
	       m_bottomTextureVertices[3*i+1].texture = XMFLOAT2((radius + bottomVertices[i].x) /(2.0f * radius) , (radius - bottomVertices[i].z)/(2.0f * radius));
	       m_bottomTextureVertices[3*i+2].position = bottomVertices[i + 1];  
	       m_bottomTextureVertices[3*i+2].texture = XMFLOAT2((radius + bottomVertices[i+1].x)/(2.0f * radius), (radius - bottomVertices[i+1].z)/(2.0f * radius));


     }

	//release memory for temporary arrays
    delete [] topVertices;
 	delete [] bottomVertices;


    //---------------------------------------------
	

	// 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.
	for(int i=0; i<numberOfFaceVertices; i++)
	     m_indices[i] = i;  // map vertices directly to indices

	for(int i=0; i<numberOfTopVertices; i++)
	     m_topIndices[i] = i;  // map vertices directly to indices

	for(int i=0; i<numberOfBottomVertices; i++)
	     m_bottomIndices[i] = i;  // map vertices directly to indices




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


    m_VertexModelArray[0] = new Model(
			     m_textureVertices, 
				 numberOfFaceVertices,  //vertex count
				 m_indices, 
				 numberOfFaceVertices, //index count
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	m_VertexModelArray[1] = new Model(
			     m_topTextureVertices, 
				 numberOfTopVertices,  //vertex count
				 m_topIndices, 
				 numberOfTopVertices, //index count
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	m_VertexModelArray[2] = new Model(
			     m_bottomTextureVertices, 
				 numberOfBottomVertices,  //vertex count
				 m_bottomIndices, 
				 numberOfBottomVertices, //index count
				 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


}
Example #27
0
	void Camera::SetPosition(FXMVECTOR position)
	{
		XMStoreFloat3(&mPosition, position);
	}
Example #28
0
void MyApp::updateScene() 
{
	static float alienCreation = 5.5f;
	static float aliensCreated = 0;
	static int currentAlienType = 0;

	float step_view = 0.01f;

	if(GetAsyncKeyState(0x26) & 0x8000) m_camera.rotateX(-step_view);	// up
	if(GetAsyncKeyState(0x28) & 0x8000) m_camera.rotateX(+step_view);	// down
	if(GetAsyncKeyState(0x25) & 0x8000) m_camera.rotateY(-step_view);		// left
	if(GetAsyncKeyState(0x27) & 0x8000) m_camera.rotateY(+step_view);		// right

	float scale = 20.0f;
	if (GetAsyncKeyState('W') & 0x8000) m_camera.walkForward(+step_view*scale);
	if (GetAsyncKeyState('S') & 0x8000) m_camera.walkForward(-step_view*scale);
	if (GetAsyncKeyState('A') & 0x8000) m_camera.walkSide(-step_view*scale);
	if (GetAsyncKeyState('D') & 0x8000) m_camera.walkSide(+step_view*scale);		


	mySphere.setPos(glb_sphereX, glb_sphereY, glb_sphereZ);

	
	if(!m_bPaused)
	{
		int spheresLanded = 0;

		// update spheres
		for (unsigned int i=0; i<m_spheres.size(); i++) 
		{
			m_spheres[i].updatePos(0.5f);
			
			if (animationStarted && m_spheres[i].isInMotion() == false) 
				spheresLanded++;
		}

		// update aliens
		for (unsigned int i=0; i<m_aliens.size(); i++)
		{
			m_aliens[i].updatePos(0.01f);

			if (!m_aliens[i].isInMotion()) {
				// compute new target pos
				if (m_aliens[i].type == AlienTypes::VS_ALIEN && m_aliens[i].type == AlienTypes::HS_ALIEN) {
					XMFLOAT3 targetPos;
					targetPos.x = rand() % (unsigned int)GRID_WIDTH - GRID_WIDTH / 2.0f;
					targetPos.y = m_aliens[i].getPos().y;
					targetPos.z = rand() % (unsigned int)GRID_WIDTH - GRID_WIDTH / 2.0f;
					m_aliens[i].setTargetPos(targetPos.x, targetPos.y, targetPos.z);
					m_aliens[i].start();
				}
				else if (m_aliens[i].type == AlienTypes::GS_ALIEN) {
					// if it's a GS_Alien just make it explode
					m_aliens[i].type = AlienTypes::EXP_ALIEN;
					m_aliens[i].expl_time = 0.0f;
				}

			}
		}

		// Create Alien
		if (spheresLanded == N_SPHERES && aliensCreated <= 12) 
		{
			alienCreation -= /*0.005f*/ 1.0f; // create all aliens immediately 

			if (alienCreation <= 0.0f) {
				// pick sphere 
				int s = rand() % N_SPHERES;
				// Alien
				Alien myAlien;
				XMFLOAT3 pos = m_spheres[s].getPos();
				pos.y -= 5.0f;
				myAlien.setPos(pos.x, pos.y, pos.z);
				// Alien type
				int alientype = (int)(currentAlienType / 2);
				//alientype = 1;
				if (alientype == 0)
					myAlien.type = AlienTypes::VS_ALIEN;
				else if (alientype == 1)
					myAlien.type = AlienTypes::GS_ALIEN;
				else if (alientype == 2)
					myAlien.type = AlienTypes::EXP_ALIEN;
				else if (alientype == 3)
					myAlien.type = AlienTypes::HS_ALIEN;
				else if (alientype == 4)
					myAlien.type = AlienTypes::BEZ_ALIEN;
				else if (alientype == 5)
					myAlien.type = AlienTypes::PSP_ALIEN;


				myAlien.mesh = alienMesh;
				// target pos
				XMFLOAT3 targetPos;
				targetPos.x = rand() % (unsigned int)GRID_WIDTH - GRID_WIDTH / 2.0f;
				targetPos.y = myAlien.getPos().y;
				targetPos.z = rand() % (unsigned int)GRID_WIDTH - GRID_WIDTH / 2.0f;
				myAlien.setTargetPos(targetPos.x, targetPos.y, targetPos.z);

				myAlien.start();
				m_aliens.push_back(myAlien);
				alienCreation = 5.0f;
				aliensCreated++;
				currentAlienType++;
			}
		}
	}

	// GUI 
	if (glb_bSingleTessFactor) {
		glb_insideTess = glb_edgeTess = glb_SingleTessFactor;
	}

	light.dir = XMFLOAT3(glb_lightDir[0], glb_lightDir[1], glb_lightDir[1]);
	XMVECTOR v = XMLoadFloat3(&light.dir);
	v = XMVector3Normalize(v);
	XMStoreFloat3(&light.dir, v);

	light.diffuse = XMFLOAT3(glb_lightColor[0]/256.0f, glb_lightColor[1]/256.0f, 
								glb_lightColor[2]/256.0f);

}
void GeometryGenerator::CreateGeosphere(float radius, UINT numSubdivisions, MeshData& meshData)
{
	// Put a cap on the number of subdivisions.
	numSubdivisions = MathHelper::Min(numSubdivisions, 5u);

	// Approximate a sphere by tessellating an icosahedron.

	const float X = 0.525731f;
	const float Z = 0.850651f;

	XMFLOAT3 pos[12] =
	{
		XMFLOAT3(-X, 0.0f, Z), XMFLOAT3(X, 0.0f, Z),
		XMFLOAT3(-X, 0.0f, -Z), XMFLOAT3(X, 0.0f, -Z),
		XMFLOAT3(0.0f, Z, X), XMFLOAT3(0.0f, Z, -X),
		XMFLOAT3(0.0f, -Z, X), XMFLOAT3(0.0f, -Z, -X),
		XMFLOAT3(Z, X, 0.0f), XMFLOAT3(-Z, X, 0.0f),
		XMFLOAT3(Z, -X, 0.0f), XMFLOAT3(-Z, -X, 0.0f)
	};

	DWORD k[60] =
	{
		1, 4, 0, 4, 9, 0, 4, 5, 9, 8, 5, 4, 1, 8, 4,
		1, 10, 8, 10, 3, 8, 8, 3, 5, 3, 2, 5, 3, 7, 2,
		3, 10, 7, 10, 6, 7, 6, 11, 7, 6, 0, 11, 6, 1, 0,
		10, 1, 6, 11, 0, 9, 2, 11, 9, 5, 2, 9, 11, 2, 7
	};

	meshData.Vertices.resize(12);
	meshData.Indices.resize(60);

	for (UINT i = 0; i < 12; ++i)
		meshData.Vertices[i].Position = pos[i];

	for (UINT i = 0; i < 60; ++i)
		meshData.Indices[i] = k[i];

	for (UINT i = 0; i < numSubdivisions; ++i)
		Subdivide(meshData);

	// Project vertices onto sphere and scale.
	for (UINT i = 0; i < meshData.Vertices.size(); ++i)
	{
		// Project onto unit sphere.
		XMVECTOR n = XMVector3Normalize(XMLoadFloat3(&meshData.Vertices[i].Position));

		// Project onto sphere.
		XMVECTOR p = radius*n;

		XMStoreFloat3(&meshData.Vertices[i].Position, p);
		XMStoreFloat3(&meshData.Vertices[i].Normal, n);

		// Derive texture coordinates from spherical coordinates.
		float theta = MathHelper::AngleFromXY(
			meshData.Vertices[i].Position.x,
			meshData.Vertices[i].Position.z);

		float phi = acosf(meshData.Vertices[i].Position.y / radius);

		meshData.Vertices[i].TexC.x = theta / XM_2PI;
		meshData.Vertices[i].TexC.y = phi / XM_PI;

		// Partial derivative of P with respect to theta
		meshData.Vertices[i].TangentU.x = -radius*sinf(phi)*sinf(theta);
		meshData.Vertices[i].TangentU.y = 0.0f;
		meshData.Vertices[i].TangentU.z = +radius*sinf(phi)*cosf(theta);

		XMVECTOR T = XMLoadFloat3(&meshData.Vertices[i].TangentU);
		XMStoreFloat3(&meshData.Vertices[i].TangentU, XMVector3Normalize(T));
	}
}
Example #30
0
void CMeshNodePanel::updateSelectedObjectTransform(f32 delta)
{
	EditorScene* scene = EditorScene::getInstance();
	if (!scene)
		return;

	SNodeInfo* info = scene->GetSelectedNodeInfo();
	if (!info)
		return;

	const f32 MOVE_UNIT = 10.0f;
	const f32 SCALING_UNIT = 5.0f;
	
	ICameraNode* camera = scene->GetCamera();
	XMFLOAT3 look = camera->getLookVector();
	XMFLOAT3 up(0, 1.0f, 0);
	XMFLOAT3 right = camera->getRightVector();

	XMVECTOR look_v = XMVectorSet(look.x, 0, look.z, 0);
	look_v = XMVector4Normalize(look_v);

	XMStoreFloat3(&look, look_v);

	XMFLOAT3 movement(0, 0, 0);
	XMFLOAT3 scaling(0, 0, 0);

	if (GetAsyncKeyState('W') & 0x8000)
	{
		movement = math::VectorMultiply(look, delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState('S') & 0x8000)
	{
		movement = math::VectorMultiply(look, -delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState('A') & 0x8000)
	{
		movement = math::VectorMultiply(right, -delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState('D') & 0x8000)
	{
		movement = math::VectorMultiply(right, delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState('R') & 0x8000)
	{
		movement = math::VectorMultiply(up, delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState('F') & 0x8000)
	{
		movement = math::VectorMultiply(up, -delta * MOVE_UNIT);
	}

	if (GetAsyncKeyState(VK_ADD) & 0x8000)
	{
		scaling = XMFLOAT3(1.0f, 1.0f, 1.0f);
	}

	if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000)
	{
		scaling = XMFLOAT3(-1.0f, -1.0f, -1.0f);
	}

	scaling = math::VectorMultiply(scaling, delta * SCALING_UNIT);

	info->Position = math::VectorAdd(info->Position, movement);
	info->Scaling = math::VectorAdd(info->Scaling, scaling);

	scene->UpdateNodeInfo(info);
	ShowNodeInfo(info);
}