Exemplo n.º 1
0
void XM_CALLCONV Camera::LookAt( const XMFLOAT3& iPos, const XMFLOAT3& iTarget, const XMFLOAT3& iUp ) {
	XMVECTOR P = XMLoadFloat3( &iPos );
	XMVECTOR T = XMLoadFloat3( &iTarget );
	XMVECTOR U = XMLoadFloat3( &iUp );
	LookAt( P, T, U );
}
Exemplo n.º 2
0
const XMVECTOR Transform::GetScaleXM() const
{
	return XMLoadFloat3(&m_scale);
}
	 XMVECTOR DirectionalLight::upVector()const{ return XMLoadFloat3(&mUp); }
Exemplo n.º 4
0
CSkeleton::ESkeletonStates  CSkeleton::Move(bool _forward)
{
	XMVECTOR vPlayer = XMLoadFloat3(GetPlayer()->GetPosition());
	XMVECTOR vSkeleton = XMLoadFloat3(GetPosition());
	XMVECTOR vVelocity;
	XMFLOAT3 fVelocity3(0.0f, m_f3Velocity.y, 0.0f);

	m_fExitTimer -= DELTA_TIME();
	if (_forward)
		vVelocity = vPlayer - vSkeleton;
	else
		vVelocity = vSkeleton - vPlayer;

	XMVECTOR vDistance = XMVector3Length(vVelocity);
	float fDistance = vDistance.m128_f32[0];

	vVelocity = XMVector3Normalize(vVelocity);
	vVelocity *= 350.0f;
	XMStoreFloat3(&fVelocity3, vVelocity);
	fVelocity3.y = m_f3Velocity.y;



	if (m_eCurrState == BACKING_OUT)
	{

		if (fDistance > 500.0f)
			return MANUVERING;
	}
	if (m_eCurrState == MOVING_IN)
	{
		CPlayer* player = reinterpret_cast<CPlayer*>(GetPlayer());



		/*if (player->IsAttacking() && fDistance < 200.0f && fDistance > 125.0f)
		{
		unsigned int blockChance = (rand() % 100) + 1;
		if (blockChance < GetBlockChance())
		m_eNewState = BLOCKING;
		}
		*/
		if (fDistance <= 125.0f)
		{
			if (m_bIsGrounded)
				SetWorldVelocity({ 0.0f, m_f3Velocity.y, 0.0f });
			return SWINGING;
		}



	}
	if (fDistance > 3000.0f)
	{
		m_eNewState = RETREAT;

	}
	if (fDistance > 1250.0f)
	{
		return FOLLOW;
	}


	//if (m_fExitTimer < 0.0f)
	//return MANUVERING;

	Steering().Seek(*GetPlayer()->GetPosition());
	if (m_bIsGrounded)
	{
		Steering().Update(false, m_fScale);
		SetWorldVelocity(fVelocity3);
	}
	else
		SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z });

	if (_forward)
		return MOVING_IN;

	return BACKING_OUT;

}
Exemplo n.º 5
0
CSkeleton::ESkeletonStates CSkeleton::Follow()
{

	if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.05f))
	{
		AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition());
	}
	if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.5f))
	{
		AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition());
	}

	if (m_bIsGrounded)
		SetWorldVelocity({ 0, m_f3Velocity.y, 0 });
	else
		SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z });

	// Get the current path
	vector<XMFLOAT3>& vPath = GetPath(); // path here from group

	// Get the current velocity
	//XMVECTOR currentVelocity; XMLoadFloat3(&m_f3vel);

	if (DistanceToPlayer() < 500.0f)
	{
		return MOVING_IN;
	}

	// Node that I'm on along the path
	int nCurrentNode = GetCurNodeOnPath();


	if (nCurrentNode < 0 || vPath.empty())
	{

		BuildPathToPlayer();
		vPath = GetPath();

		if (vPath.size() < 2)
		{
			return FOLLOW;
		}
	}

	nCurrentNode = GetCurNodeOnPath();

	// Get the current positions
	XMFLOAT3 curPos = *GetPosition();
	XMFLOAT3 targetPos = vPath[nCurrentNode];

	// Convert them for math
	XMVECTOR mathPos = XMLoadFloat3(&curPos);
	XMVECTOR mathTarget = XMLoadFloat3(&targetPos);

	// Find the vector between the two points
	XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos);

	//XMFLOAT3 toVec; XMStoreFloat3(&toVec, mathToVec);

	// Normalize the toVector to get the direction
	XMVECTOR mathVelocity = XMVector3Normalize(mathToVec);



	// Add the separation factor
	//	mathVelocity += GetParentGroup()->CalculateSeparation(this);

	mathVelocity *= MOVE_SPEED;

	XMFLOAT3 realVelocity; XMStoreFloat3(&realVelocity, mathVelocity);
	realVelocity.y = m_f3Velocity.y;

	// Get the distance to target - ANY XYZ HOLDS THE LENGTH
	XMVECTOR mathDistToTarget = XMVector3Length(mathToVec);
	XMFLOAT3 distToTarget; XMStoreFloat3(&distToTarget, mathDistToTarget);

	// Offset the current node

	float nNextNodeDistance = 300.0f;



	// If i reached the node, move on the next one
	if (distToTarget.x < nNextNodeDistance && nCurrentNode >= 0)
	{
		nCurrentNode--;

	}
	Steering().Seek(targetPos);

	if (m_bIsGrounded)
	{
		Steering().Update(false, m_fScale);

		SetWorldVelocity(realVelocity);
	}
	SetNodeOnPath(nCurrentNode);
	return FOLLOW;
}
Exemplo n.º 6
0
XMVECTOR Camera::GetUpXM()const
{
	return XMLoadFloat3(&mUp);
}
Exemplo n.º 7
0
void CameraClass::Render()
{
	XMFLOAT3 up, position, lookAt;
	XMVECTOR upVector, positionVector, lookAtVector;
	float yaw, pitch, roll;
	XMMATRIX rotationMatrix;

	// Setup the vector that points upwards.
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Load it into a XMVECTOR structure.
	upVector = XMLoadFloat3(&up);

	float playerX = m_playerPos.x;
	float playerY = m_playerPos.y;

	if (playerX >= (m_positionX + (m_screenWidth / 2) - m_screenBarrier)) // (ScreenWidth / 2) - screenBarrier
	{
		m_cameraIsMovingX = true;
		m_cameraPosGoTo.x = playerX;
		if (m_cameraVelocity < 0.0f)
		{
			m_cameraVelocity *= -1.0f;
		}
	}
	else if (playerX <= (m_positionX - (m_screenWidth / 2) + m_screenBarrier))
	{
		m_cameraIsMovingX = true;
		m_cameraPosGoTo.x = playerX;
		if (m_cameraVelocity > 0.0f)
		{
			m_cameraVelocity *= -1.0f;
		}
	}

	if (playerY >= (m_positionY + (m_screenHeight / 2) - m_screenBarrier)) // (ScreenHeight / 2 ) - screenBarrier
	{
		m_cameraIsMovingY = true;
		m_cameraPosGoTo.y = playerY;
		if (m_cameraVelocity < 0.0f)
		{
			m_cameraVelocity *= -1.0f;
		}
	}
	else if (playerY <= (m_positionY - (m_screenHeight / 2) + m_screenBarrier))
	{
		m_cameraIsMovingY = true;
		m_cameraPosGoTo.y = playerY;
		if (m_cameraVelocity > 0.0f)
		{
			m_cameraVelocity *= -1.0f;
		}
	}

	// Setup the position of the camera in the world.
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Load it into a XMVECTOR structure.
	positionVector = XMLoadFloat3(&position);

	// Setup where the camera is looking by default.
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 1.0f;

	// Load it into a XMVECTOR structure.
	lookAtVector = XMLoadFloat3(&lookAt);

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
	upVector = XMVector3TransformCoord(upVector, rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAtVector = XMVectorAdd(positionVector, lookAtVector);

	// Finally create the view matrix from the three updated vectors.
	m_viewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);

	return;
}
Exemplo n.º 8
0
MyListener::MyListener(AaSceneManager* mSceneMgr, AaPhysicsManager* mPhysicsMgr)
{
	zp=zm=xp=xm = false;

	cameraMan = new FreeCamera(mSceneMgr->getCamera());
	mSceneMgr->getCamera()->setPosition(XMFLOAT3(-1.8f,10,-6));

	this->mPhysicsMgr = mPhysicsMgr;
	this->mSceneMgr = mSceneMgr;
	continue_rendering = true;

	AaRenderSystem* rs=mSceneMgr->getRenderSystem();
	voxelScene = new AaVoxelScene(mSceneMgr);
	voxelScene->initScene(128);
	mShadowMapping = new AaShadowMapping(mSceneMgr);

	mSceneMgr->loadMaterialFiles(MATERIAL_DIRECTORY);

	pp = new AaBloomPostProcess(mSceneMgr);

	AaMaterial* mat=mSceneMgr->getMaterial("Green");
	/*ent= mSceneMgr->createEntity("testEnt",mat);
	ent->setModel("angel");
	ent->setScale(XMFLOAT3(10,10,10));
	ent->setPosition(0,-15,30);


	ent= mSceneMgr->createEntity("testEnt22",mat);
	ent->setModel("angel");
	ent->setScale(XMFLOAT3(10,10,10));
	ent->setPosition(-15,-15,30);
	//ent->yaw(-2.0f);
	AaSceneNode* node= new AaSceneNode(XMFLOAT3(-15,-15,30));
	node->attachEntity(ent);


	ent= mSceneMgr->createEntity("testEnt33",mat);
	ent->setModel("angel");
	ent->setScale(XMFLOAT3(10,10,10));
	ent->setPosition(15,-15,30);
	//ent->yaw(0.7f);
	ent->pitch(-1.0f);	
	AaSceneNode* node2 = node->createChild();
	node2->setPosition(XMFLOAT3(15,-15,30));
	node2->attachEntity(ent);

	node->move(XMFLOAT3(0,10,0));
	node->yawPitchRoll(0.4,0.2,0);
	node->localPitch(1);*/

	/*ent= mSceneMgr->createEntity("testEnt2",mat);
	ent->setModel("teapot.obj");
	ent->yaw(0.7f);
	ent->pitch(-1.7f);
	ent->yaw(-2.7f);
	ent->setPosition(3,-1,10);*/
	
	/*PxMaterial* mMaterial;
	mMaterial = mPhysicsMgr->getPhysics()->createMaterial(0.7f, 1.7f, 0.2f);    //static friction, dynamic friction, restitution
	PxShape* aSphereShape;

	AaEntity* ent= mSceneMgr->createEntity("testEnt3",mat);
	ent->setModel("ball24.mesh");
	ent->setPosition(0,20,0);
	ent->setScale(XMFLOAT3(0.4,1.4,1.4));
	mPhysicsMgr->createSphereBodyDynamic(ent,0.4);//->setLinearVelocity(physx::PxVec3(1,15,0));

	ent= mSceneMgr->createEntity("testEnt6",mat);
	ent->setModel("ball24.mesh");
	ent->setPosition(0,20,0);
	mPhysicsMgr->createConvexBodyDynamic(ent);//->setLinearVelocity(physx::PxVec3(1,15,0));
	
	ent= mSceneMgr->createEntity("testEnt63",mat);
	ent->setModel("ball32.mesh");
	ent->setPosition(5,35,20);
	ent->setScale(XMFLOAT3(4,1,4));
	ent->yaw(0.5);
	ent->roll(0.5);
	mPhysicsMgr->createTreeBodyStatic(ent);

	ent= mSceneMgr->createEntity("testEnt61",mat);
	ent->setModel("ball24.mesh");
	ent->setPosition(5,25,20);
	ent->setScale(XMFLOAT3(2,1,2));
	ent->roll(0.5);
	mPhysicsMgr->createConvexBodyDynamic(ent)->setLinearVelocity(physx::PxVec3(1,15,0));
	*/
	Light* l = new Light();
	l->color = XMFLOAT3(1,1,1);
	l->direction = XMFLOAT3(0.0f,-2,1.6);
	XMStoreFloat3(&l->direction,XMVector2Normalize(XMLoadFloat3(&l->direction)));
	

	mSceneMgr->mShadingMgr->directionalLight = l;

	mPhysicsMgr->createPlane(0);

	loadScene("test.scene",mSceneMgr,mPhysicsMgr);

	mRS=rs;

	setupInputSystem();

	debugWindow = new TestGuiWindow(mSceneMgr->getGuiManager()->getContext(),mSceneMgr);
 
	
}
Exemplo n.º 9
0
XMVECTOR Engine::Model::getPosition(void) const
{
	return XMLoadFloat3(_position);
}
Exemplo n.º 10
0
XMVECTOR Camera::GetPosXM() const {
	return XMLoadFloat3( &pos );
}
Exemplo n.º 11
0
bool MathHelper::CompareVector3WithEpsilon(const XMFLOAT3& lhs, const XMFLOAT3& rhs)
{
	return XMVector3NearEqual(XMLoadFloat3(&lhs), XMLoadFloat3(&rhs), XMLoadFloat3(&vector3Epsilon)) == TRUE;
}
Exemplo n.º 12
0
void XM_CALLCONV Camera::RotateY( float angle ) {
	XMMATRIX R = XMMatrixRotationY( angle );
	XMStoreFloat3( &right, XMVector3TransformNormal( XMLoadFloat3( &right ), R ) );
	XMStoreFloat3( &up, XMVector3TransformNormal( XMLoadFloat3( &up ), R ) );
	XMStoreFloat3( &look, XMVector3TransformNormal( XMLoadFloat3( &look ), R ) );
}
Exemplo n.º 13
0
void XM_CALLCONV Camera::Walk( float distance ) {
	XMVECTOR s = XMVectorReplicate( distance );
	XMVECTOR l = XMLoadFloat3( &look );
	XMVECTOR p = XMLoadFloat3( &pos );
	XMStoreFloat3( &pos, XMVectorMultiplyAdd( s, l, p ));
}
Exemplo n.º 14
0
void XM_CALLCONV Camera::Strafe( float distance ) {
	XMVECTOR s = XMVectorReplicate( distance );
	XMVECTOR r = XMLoadFloat3( &right );
	XMVECTOR p = XMLoadFloat3( &pos );
	XMStoreFloat3( &pos, XMVectorMultiplyAdd( s, r, p ) );
}
Exemplo n.º 15
0
XMVECTOR Camera::GetPositionXM()const
{
	return XMLoadFloat3(&mPosition);
}
Exemplo n.º 16
0
XMVECTOR Engine::Model::getRotation(void) const
{
	return XMLoadFloat3(_rotation);
}
Exemplo n.º 17
0
XMVECTOR Camera::GetRightXM()const
{
	return XMLoadFloat3(&mRight);
}
Exemplo n.º 18
0
XMVECTOR Engine::Model::getScale(void) const
{
	return XMLoadFloat3(_scale);
}
Exemplo n.º 19
0
XMVECTOR Camera::GetLookXM()const
{
	return XMLoadFloat3(&mLook);
}
void InstancingAndCullingApp::BuildSkullGeometryBuffers()
{
	std::ifstream fin("Models/skull.txt");
	
	if(!fin)
	{
		MessageBox(0, L"Models/skull.txt not found.", 0, 0);
		return;
	}

	UINT vcount = 0;
	UINT tcount = 0;
	std::string ignore;

	fin >> ignore >> vcount;
	fin >> ignore >> tcount;
	fin >> ignore >> ignore >> ignore >> ignore;
	
	XMFLOAT3 vMinf3(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
	XMFLOAT3 vMaxf3(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
	
	XMVECTOR vMin = XMLoadFloat3(&vMinf3);
	XMVECTOR vMax = XMLoadFloat3(&vMaxf3);
	std::vector<Vertex::Basic32> vertices(vcount);
	for(UINT i = 0; i < vcount; ++i)
	{
		fin >> vertices[i].Pos.x >> vertices[i].Pos.y >> vertices[i].Pos.z;
		fin >> vertices[i].Normal.x >> vertices[i].Normal.y >> vertices[i].Normal.z;
		
		XMVECTOR P = XMLoadFloat3(&vertices[i].Pos);
		
		vMin = XMVectorMin(vMin, P);
		vMax = XMVectorMax(vMax, P);
	}
	
	XMStoreFloat3(&mSkullBox.Center, 0.5f*(vMin+vMax));
	XMStoreFloat3(&mSkullBox.Extents, 0.5f*(vMax-vMin));

	fin >> ignore;
	fin >> ignore;
	fin >> ignore;

	mSkullIndexCount = 3*tcount;
	std::vector<UINT> indices(mSkullIndexCount);
	for(UINT i = 0; i < tcount; ++i)
	{
		fin >> indices[i*3+0] >> indices[i*3+1] >> indices[i*3+2];
	}

	fin.close();

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex::Basic32) * vcount;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mSkullVB));

	//
	// Pack the indices of all the meshes into one index buffer.
	//

	D3D11_BUFFER_DESC ibd;
    ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof(UINT) * mSkullIndexCount;
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA iinitData;
	iinitData.pSysMem = &indices[0];
    HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mSkullIB));
}
bool DX10Renderer::InitializeScene()
{
    //set light params
    //==================================================================

    lightPos = XMFLOAT3(0, 20, -30);

    //light volume proj
    //XMMATRIX pm = XMMatrixOrthographicLH(75, 75, 20.0f, 80.f);
    XMMATRIX pm = XMMatrixPerspectiveFovLH( XM_PIDIV4, 4.0f/3, 20.0f, 80.f );
    XMStoreFloat4x4(&lightProjMatrix, pm);

    //view
    XMFLOAT3 o = XMFLOAT3(0,0,0), up = XMFLOAT3(0,1,0);
    XMVECTOR e = XMLoadFloat3( &lightPos ), fp = XMLoadFloat3( &o ), u = XMLoadFloat3( &up );
    XMMATRIX vm = XMMatrixLookAtLH( e, fp, u );
    pm = XMMatrixMultiply(vm,pm);
    XMStoreFloat4x4(&lightViewProjMatrix, pm);

    //Load rendering techniques
    //==================================================================

    if ( FAILED( D3DX10CreateEffectFromFile( L"ShadowMap.fx", 0, 0, (LPCSTR) "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, pD3DDevice, 0, 0, &pEffect, 0, 0) ) ) return false;

    pRenderTechnique = pEffect->GetTechniqueByName("RenderPassStandard");
    pRenderShadowMapTechnique = pEffect->GetTechniqueByName("ShadowMapRenderPassFrontFaces");
    pBillboardTechnique = pEffect->GetTechniqueByName("RenderBillboard");

    //create input layout
    D3D10_PASS_DESC passDesc;
    pRenderTechnique->GetPassByIndex( 0 )->GetDesc( &passDesc );

    D3D10_INPUT_ELEMENT_DESC inLayoutDesc[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0 }
    };

    if ( FAILED( pD3DDevice->CreateInputLayout( inLayoutDesc, 4, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &pInputLayout ) ) ) return false;

    pD3DDevice->IASetInputLayout(pInputLayout);

    //load scene elements
    //==================================================================
    MeshData md;

    loadMeshDataFromOBJ("models\\floor.obj", &md);
    meshes.push_back( DX10Mesh() );
    meshes.back().CreateMesh(pD3DDevice, &md);

    loadMeshDataFromOBJ("models\\girl.obj", &md);
    meshes.push_back( DX10Mesh() );
    meshes.back().CreateMesh(pD3DDevice, &md);

    RenderMessage rm;
    XMMATRIX mat = XMMatrixIdentity();
    rm.modelID = 0;
    XMStoreFloat4x4(&rm.world, mat);

    //add floor to scene
    scene.push_back(rm);

    //add 9 meshes to scene
    float y = 0.0f;
    XMFLOAT3 a(1,0,0);
    XMVECTOR axis = XMLoadFloat3( &a);

    for (float z = -10; z <= 10; z+=5)
    {
        for (float x = -10; x <= 10; x+=5 )
        {
            mat = XMMatrixRotationAxis( axis, -XM_PIDIV2) * XMMatrixTranslation(x,y,z);

            scene.push_back( rm );
            scene.back().modelID = 1;
            XMStoreFloat4x4(&scene.back().world, mat);
        }
    }

    return true;
}
Exemplo n.º 22
0
bool initDirectx()
{
	//create direct3d device and the swap chain for it
	HRESULT hr = S_OK;

	RECT rc = { 0, 0, 1280, 800 };

	//get dimensions of the window
	GetClientRect(g_hWnd, &rc);
	UINT width = rc.right - rc.left;
	UINT height = rc.bottom - rc.top;

	UINT createDeviceFlags = 0;

	//swapchain stuff
	DXGI_SWAP_CHAIN_DESC sd;
	ZeroMemory(&sd, sizeof(sd));
	sd.BufferCount = 1;
	sd.BufferDesc.Width = width;
	sd.BufferDesc.Height = height;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.OutputWindow = g_hWnd;
	sd.SampleDesc.Count = 1;
	sd.SampleDesc.Quality = 0;
	sd.Windowed = TRUE;

	D3D_FEATURE_LEVEL featureLevels[] =
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
	};
	UINT numFeatureLevels = ARRAYSIZE(featureLevels);

	//create the device and swap chain command does what it says it does
	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
		D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);

	//make render target view
	ID3D11Texture2D* pBackBuffer = NULL;
	hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
	if (FAILED(hr))
		return hr;

	hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView);
	pBackBuffer->Release();
	if (FAILED(hr))
		return hr;

	//create depth stencil texture
	D3D11_TEXTURE2D_DESC descDepth;
	ZeroMemory(&descDepth, sizeof(descDepth));
	descDepth.Width = width;
	descDepth.Height = height;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D11_USAGE_DEFAULT;
	descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencil);
	if (FAILED(hr))
		return hr;

	//create the depth stencil view out of the depth stencil texture
	D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
	ZeroMemory(&descDSV, sizeof(descDSV));
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;
	hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencil, &descDSV, &g_pDepthStencilView);
	if (FAILED(hr))
		return hr;

	g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);

	//setup the viewport
	D3D11_VIEWPORT vp;
	vp.Width = (FLOAT)width;
	vp.Height = (FLOAT)height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	g_pImmediateContext->RSSetViewports(1, &vp);

	//that's pretty much everything needed to create the device and other stuff to make it work
	//now we gotta make the shaders

	//compile vertex shader
	ID3DBlob* pVSBlob = NULL;
	hr = CompileShaderFromFile("shader.fx", "VS", "vs_4_0", &pVSBlob); //this function is from one of microsoft's directx 11 demos, it just makes stuff easier
	if (FAILED(hr))
	{
		MessageBox(NULL, "The fx file didn't compile, run this application in the location with the fx file", "Error", MB_OK);
		return hr;
	}

	//create the vertex shader
	hr = g_pd3dDevice->CreateVertexShader(pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, &g_pVertexShader);
	if (FAILED(hr))
	{
		pVSBlob->Release();
		return hr;
	}

	//Define the input layout
	D3D11_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	UINT numElements = ARRAYSIZE(layout);

	//create the input layout
	hr = g_pd3dDevice->CreateInputLayout(layout, numElements, pVSBlob->GetBufferPointer(),
		pVSBlob->GetBufferSize(), &g_pVertexLayout);

	pVSBlob->Release();

	if (FAILED(hr))
		return hr;

	//set the input layout
	g_pImmediateContext->IASetInputLayout(g_pVertexLayout);

	// Compile the pixel shader
	ID3DBlob* pPSBlob = NULL;
	hr = CompileShaderFromFile("shader.fx", "PS", "ps_5_0", &pPSBlob);
	if (FAILED(hr))
	{
		MessageBox(NULL,
			"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.", "Error", MB_OK);
		return hr;
	}

	hr = g_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, &g_pPixelShader);

	pPSBlob->Release();

	if (FAILED(hr))
		return hr;

	//make the sphere model
	std::vector<XMFLOAT3> verts;
	std::vector<WORD> indices;
	std::vector<XMFLOAT2> uvs;

	CreateSphere(1.0f, 100, 100, &verts, &indices, &uvs);

	num_sphere_indices = indices.size();

	Vertex* Vertices = static_cast<Vertex*>(std::malloc(verts.size() * sizeof(Vertex))); //this is some of the data we will pass to the Directx 11 machine to make the vertex buffer

	for (int i = 0; i < verts.size(); i++)
	{
		Vertex v;
		v.Pos = verts[i];
		XMVECTOR n = XMLoadFloat3(&verts[i]);
		XMStoreFloat3(&v.Norm, XMVector3Normalize(n));

		Vertices[i] = v;
	}

	WORD* Indices = static_cast<WORD*>(std::malloc(indices.size() * sizeof(WORD))); //this is some of the data we will pass to the Directx 11 machine to make the index buffer

	for (int i = 0; i < indices.size(); i++)
	{
		Indices[i] = indices[i];
	}

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.ByteWidth = sizeof(Vertex) * verts.size();
	bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = 0;
	D3D11_SUBRESOURCE_DATA InitData;
	ZeroMemory(&InitData, sizeof(InitData));
	InitData.pSysMem = Vertices;
	hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, &g_pVertexBuffer);

	ZeroMemory(&bd, sizeof(bd));
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.ByteWidth = sizeof(WORD) * indices.size();
	bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	bd.CPUAccessFlags = 0;
	InitData.pSysMem = Indices;
	g_pd3dDevice->CreateBuffer(&bd, &InitData, &g_pIndexBuffer);

	free(Vertices);
	free(Indices);

	// Set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);

	// Set index buffer
	g_pImmediateContext->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);

	// Set primitive topology
	g_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Create the constant buffer
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.ByteWidth = sizeof(cBufferShader1);
	bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	bd.CPUAccessFlags = 0;
	hr = g_pd3dDevice->CreateBuffer(&bd, NULL, &g_pcBufferShader1);
	if (FAILED(hr))
		return hr;

	// Initialize the view matrix
	XMVECTOR Eye = XMVectorSet(0.0f, 5.0f, -5.0f, 0.0f);
	XMVECTOR At = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	XMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	g_View = XMMatrixLookAtLH(Eye, At, Up);

	// Initialize the projection matrix
	g_Projection = XMMatrixPerspectiveFovLH(XM_PIDIV4, width / (FLOAT)height, 0.01f, 1000.0f);

	return true;
}
Exemplo n.º 23
0
CSkeleton::ESkeletonStates CSkeleton::Retreating()
{
	if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.05f))
		AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition());
	if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.5f))
		AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition());

	if (m_bIsGrounded)
		SetWorldVelocity({ 0, m_f3Velocity.y, 0 });
	else
		SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z });

	// Get the current path
	vector<XMFLOAT3>& vPath = GetPath(); // path here from group

	// Node that I'm on along the path
	int nCurrentNode = GetCurNodeOnPath();

	// Clamp CurNode to 0 and max
	if (nCurrentNode < 0)
		return DEATH;

	// If no path was generated, then return
	if (vPath.size() <= 0)
	{
		nCurrentNode = -1;
		return DEATH;
	}
	// Get the current positions
	XMFLOAT3 curPos = *GetPosition();
	XMFLOAT3 targetPos = vPath[nCurrentNode];

	// Convert them for math
	XMVECTOR mathPos = XMLoadFloat3(&curPos);
	XMVECTOR mathTarget = XMLoadFloat3(&targetPos);

	// Find the vector between the two points
	XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos);

	// Normalize the toVector to get the direction
	XMVECTOR mathVelocity = XMVector3Normalize(mathToVec);

	// Add the separation factor
	//mathVelocity += GetParentGroup()->CalculateSeparation(this);
	//mathVelocity += GetParentGroup()->CalculateAlignment();
	mathVelocity *= MOVE_SPEED;

	XMFLOAT3 realVelocity; XMStoreFloat3(&realVelocity, mathVelocity);
	realVelocity.y = m_f3Velocity.y;

	// Get the distance to target - ANY XYZ HOLDS THE LENGTH
	XMVECTOR mathDistToTarget = XMVector3Length(mathToVec);
	XMFLOAT3 distToTarget; XMStoreFloat3(&distToTarget, mathDistToTarget);

	float nNextNodeDistance = 125.0f;

	Steering().Seek(targetPos);
	// If i reached the node, move on the next one
	if (distToTarget.x < nNextNodeDistance && nCurrentNode >= 0)
		nCurrentNode--;

	if (m_bIsGrounded)
	{
		Steering().Update(false, m_fScale);
		SetWorldVelocity(realVelocity);
	}
	else
		SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z });

	SetNodeOnPath(nCurrentNode);

	return RETREAT;
}
Exemplo n.º 24
0
void d3d::Geometry::CreateSphere(float radius, UINT sliceCount, UINT stackCount, MeshData& meshData)
{
	//
	// 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,  0.0f, 0.0f);
	Vertex bottomVertex(0.0f, -radius, 0.0f,  0.0f, -1.0f, 0.0f,  0.0f, 1.0f);

	meshData.VertexData.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.Pos.x = radius * sinf(phi) * cosf(theta);
			v.Pos.y = radius * cosf(phi);
			v.Pos.z = radius * sinf(phi) * sinf(theta);

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

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

			meshData.VertexData.push_back( v );
		}
	}
	// 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.IndexData.push_back(0);
		meshData.IndexData.push_back(i+1);
		meshData.IndexData.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.IndexData.push_back(baseIndex + i*ringVertexCount + j);
			meshData.IndexData.push_back(baseIndex + i*ringVertexCount + j+1);
			meshData.IndexData.push_back(baseIndex + (i+1)*ringVertexCount + j);
				
			meshData.IndexData.push_back(baseIndex + (i+1)*ringVertexCount + j);
			meshData.IndexData.push_back(baseIndex + i*ringVertexCount + j+1);
			meshData.IndexData.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.VertexData.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.IndexData.push_back(southPoleIndex);
		meshData.IndexData.push_back(baseIndex+i);
		meshData.IndexData.push_back(baseIndex+i+1);
	}
}
Exemplo n.º 25
0
/*****************************************************************
* CollisionResponse()	Responds to collision
*
* Ins:					IObject*
*
* Outs:					None
*
* Returns:				void
*
* Mod. Date:		    08/20/2015
* Mod. Initials:	    NS
*****************************************************************/
void CSkeleton::CollisionResponse(IObject * _cCollidedObject)
{
	
		if (_cCollidedObject->GetTag() == "PlayerAttack" && !m_bInvincible && m_fCurrentHealth > 0.0f)
		{
			m_bInvincible = true;
			m_fInvincibilityTimer = 0.35f;
			m_fCurrentHealth -= ((CAttack*)_cCollidedObject)->GetDamage();
			m_eNewState = HURT;
			m_eCurrState = HURT;
			EnterSubState();
		}
		else if (_cCollidedObject->GetTag() == "TrapPrefab")
		{
			for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++)
			{
				if (_cCollidedObject->GetColliders()[i]->GetCollided())
				{
					if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::AABB)
					{
						CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
						_cCollidedObject->GetColliders()[i]->SetCollided(false);
					}
					else if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::Plane)
					{
						if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f)
						{
							CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
							_cCollidedObject->GetColliders()[i]->SetCollided(false);
							m_bIsGrounded = true;
						}
					}
				}
			}
		}
	
		else if (_cCollidedObject->GetTag() == "Wall" || _cCollidedObject->GetTag() == "Door" || _cCollidedObject->GetTag() == "CrackedWall" || _cCollidedObject->GetTag() == "SafeHaven" || _cCollidedObject->GetTag() == "MinotaurSpawn")
		{
			if (m_eCurrState == ESkeletonStates::BACKING_OUT || m_eCurrState == ESkeletonStates::MANUVERING)
			{
				m_eNewState = ESkeletonStates::MOVING_IN;
			}

			for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++)
			{
				if (_cCollidedObject->GetColliders()[i]->GetCollided())
				{
					if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::AABB)
					{
						CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
						_cCollidedObject->GetColliders()[i]->SetCollided(false);
					}
					else if (_cCollidedObject->GetColliders()[i]->GetType() == Bounds::Plane)
					{
						if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f)
						{
							CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
							_cCollidedObject->GetColliders()[i]->SetCollided(false);
							m_bIsGrounded = true;
						}
					}
				}
			}
			if (_cCollidedObject->GetTag() == "SafeHaven")
			{
				m_eNewState = RETREAT;
			}
		}
		else if (_cCollidedObject->GetTag() == "SmallPit")
		{
			if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f)
			{
				for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++)
				{
					CCollider* tested = _cCollidedObject->GetColliders()[i];
					if (tested->GetCollided())
					{
						if (tested->GetType() == Bounds::Plane)
						{
							if (((CPlane*)(tested->GetBounds()))->GetCenter().y < 0.0f)
							{
								CapsuleToFloor(this, m_pvColliders[1], tested);
								tested->SetCollided(false);
								m_bIsGrounded = true;
							}
						}
						else
						{
							CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
							_cCollidedObject->GetColliders()[i]->SetCollided(false);
							m_bIsGrounded = true;
						}
					}
				}
			}
			else if (m_f3Velocity.y < 0.0f)
			{
				for (size_t i = 1; i < _cCollidedObject->GetColliders().size() - 2; i++)
				{
					if (_cCollidedObject->GetColliders()[i]->GetCollided())
					{
						CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
						_cCollidedObject->GetColliders()[i]->SetCollided(false);
					}

				}
			}
		}
		else if (_cCollidedObject->GetTag() == "BigPit")
		{
			if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f)
			{
				for (size_t i = 1; i < _cCollidedObject->GetColliders().size(); i++)
				{
					CCollider* tested = _cCollidedObject->GetColliders()[i];
					if (tested->GetCollided())
					{
						CapsuleToFloor(this, m_pvColliders[1], tested);
						tested->SetCollided(false);
						m_bIsGrounded = true;
					}
				}
			}
			else if (m_f3Velocity.y < 0.0f)
			{
				for (size_t i = 1; i < _cCollidedObject->GetColliders().size() - 1; i++)
				{
					CCollider* collider = _cCollidedObject->GetColliders()[i];
					if (collider->GetCollided())
					{
						CapsuleToWall(this, m_pvColliders[1], collider);
						collider->SetCollided(false);
					}
				}
			}
		}
		else if (_cCollidedObject->GetTag() == "Skeleton")
		{
			//Need capsule to capulse to make slide off eachother
			CapsuleToCapsule(this, m_pvColliders[1], _cCollidedObject->GetColliders()[1]);
		}
		else if (_cCollidedObject->GetTag() == "Floor" || _cCollidedObject->GetTag() == "SafeHavenFloor")
		{
			if (m_mWorld.m[3][1] > -20.0f && m_f3Velocity.y < 0.0f)
			{
				CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[0]);
				m_bIsGrounded = true;
			}
		}

		else if (_cCollidedObject->GetTag() == "SpikeTrap")
		{

			if (m_fCurrentHealth > 0.0f)
			{
				CSpikeTrap* curTrap = reinterpret_cast<CSpikeTrap*>(_cCollidedObject);

				if (curTrap->GetActive() || curTrap->GetReset())
				{
					SetWorldVelocity({ 0.0f, 0.0f, 0.0f });
				}

				if (curTrap->GetActive() && !m_bInvincible)
				{
					TakeDamage(curTrap->GetTrapDamage());
					SetWorldVelocity({ 0, 1000.0f, 0 });
					//ChangeState(ESkeletonStates::eIdleState);
				}
				else
				{
					CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[0]);
				}
			}


		}
		else if (_cCollidedObject->GetTag() == "FireTrap")
		{
			if (m_fCurrentHealth > 0.0f)
			{
				CFireTrap* curTrap = reinterpret_cast<CFireTrap*>(_cCollidedObject);

				if (curTrap->GetActive() && !m_bInvincible)
				{
					TakeDamage(curTrap->GetTrapDamage());
				}
			}
		}
		else if (_cCollidedObject->GetTag() == "SpinningBlade")
		{
			if (m_fCurrentHealth > 0.0f && !m_bInvincible)
			{
				CSpinningBlade* curTrap = reinterpret_cast<CSpinningBlade*>(_cCollidedObject);

				XMVECTOR mathTarget = XMVector3Normalize(XMLoadFloat3(GetPosition()) - XMLoadFloat3(curTrap->GetPosition()));

				mathTarget *= 1000.0f;

				XMFLOAT3 toTarget; XMStoreFloat3(&toTarget, mathTarget);

				SetWorldVelocity(toTarget);

				TakeDamage(curTrap->GetTrapDamage());
			}
		}
		else if (_cCollidedObject->GetTag() == "PressurePlate")
		{
			_cCollidedObject->CollisionResponse(this);
		}
		else if (_cCollidedObject->GetTag() == "Bridge")
		{
			CBridge* curBridge = reinterpret_cast<CBridge*>(_cCollidedObject);
			curBridge->SetCollided(true);

			if (curBridge->IsActive() && curBridge->IsIntact())
			{
				if (_cCollidedObject->GetColliders()[1]->GetCollided())
				{
					if (_cCollidedObject->GetColliders()[1]->GetCollided())
						_cCollidedObject->GetColliders()[1]->SetCollided(false);
				}

				for (size_t i = 2; i < 10; i++)
				{
					if (_cCollidedObject->GetColliders()[i]->GetCollided())
					{
						if (GetPosition()->y < 20.0f)
						{
							CapsuleToFloor(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
							_cCollidedObject->GetColliders()[i]->SetCollided(false);
							m_bIsGrounded = true;
						}
						else
						{
							CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
							_cCollidedObject->GetColliders()[i]->SetCollided(false);
						}
					}
				}
				for (size_t i = 10; i < _cCollidedObject->GetColliders().size(); i++)
				{
					if (_cCollidedObject->GetColliders()[i]->GetCollided())
					{
						CapsuleToWall(this, m_pvColliders[1], _cCollidedObject->GetColliders()[i]);
						_cCollidedObject->GetColliders()[i]->SetCollided(false);
					}
				}
			}
		}
		else if (_cCollidedObject->GetTag() == "Minotaur")
		{
			TakeDamage(200.0f);
		}
		else if (_cCollidedObject->GetTag() == "MinotaurZone")
		{
			if (m_pDayNight->IsNight())
			{
				if (m_eNewState != DEATH && m_eCurrState != DEATH)
				{
					m_eNewState = RETREAT;
				}
			}
		}
	
}
Exemplo n.º 26
0
void d3d::Geometry::CreateGeosphere(float radius, UINT numSubdivisions, MeshData& meshData)
{
	// Put a cap on the number of subdivisions.
	numSubdivisions = numSubdivisions < 5u ? 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.VertexData.resize(12);
	meshData.IndexData.resize(60);

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

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

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

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

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

		XMStoreFloat3(&meshData.VertexData[i].Pos, p);
		XMStoreFloat3(&meshData.VertexData[i].Normal, n);

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

		float phi = acosf(meshData.VertexData[i].Pos.y / radius);

		meshData.VertexData[i].Tex.x = theta/XM_2PI;
		meshData.VertexData[i].Tex.y = phi/XM_PI;
	}
}
	 XMVECTOR  DirectionalLight::directionVector()const{ return XMLoadFloat3(&mDirection); }
Exemplo n.º 28
0
void d3d::Geometry::CreateCylinder(float bottomRadius, float topRadius, float height, UINT sliceCount, UINT stackCount, MeshData& meshData)
{
	meshData.VertexData.clear();
	meshData.IndexData.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.Pos = XMFLOAT3(r*c, y, r*s);

			vertex.Tex.x = (float)j/sliceCount;
			vertex.Tex.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.
			XMFLOAT3 tangent = XMFLOAT3(-s, 0.0f, c);

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

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

			meshData.VertexData.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.IndexData.push_back(i*ringVertexCount + j);
			meshData.IndexData.push_back((i+1)*ringVertexCount + j);
			meshData.IndexData.push_back((i+1)*ringVertexCount + j+1);
					 
			meshData.IndexData.push_back(i*ringVertexCount + j);
			meshData.IndexData.push_back((i+1)*ringVertexCount + j+1);
			meshData.IndexData.push_back(i*ringVertexCount + j+1);
		}
	}

	BuildCylinderTopCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
	BuildCylinderBottomCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
}
	 XMVECTOR DirectionalLight::rightVector()const{ return XMLoadFloat3(&mRight); }
Exemplo n.º 30
0
void Enemy::move(FLOAT dt)
{


	bool dontUpdate = false;

	XMMATRIX startingworldMatrix = XMLoadFloat4x4(&mEnemyStartingWorld);
	XMVECTOR S;
	XMVECTOR P;
	XMVECTOR Q;

	XMMatrixDecompose(&S, &Q, &P, startingworldMatrix);


	XMVECTOR enemyPosition = XMLoadFloat3(&mEnemyPosition);



	FLOAT newPos = XMVectorGetZ(enemyPosition);
	FLOAT oldPos = XMVectorGetZ(P);

	direction = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);



	FLOAT diffX;
	FLOAT diffY;
	FLOAT diffZ;

	diffX = 0;
	diffY = 0;
	diffZ = 0;





	if (travelToPoint == 2)
	{


		diffX = mEnemyPosition.x - mEnemyPositionTwo.x;
		diffY = mEnemyPosition.y - mEnemyPositionTwo.y;
		diffZ = mEnemyPosition.z - mEnemyPositionTwo.z;
		mEnemyPositionThree.x;

	
	
	

		int nothing = 0;
		if (diffX < 0.0f)
		{

			diffX *= -1;
		}
		if (diffY < 0.0f)
		{

			diffY *= -1;
		}
		if (diffZ < 0.0f)
		{

			diffZ *= -1;
		}

		//////////////////////////////////
		if (diffX < 0.01)
		{

			mEnemyPosition.x = mEnemyPositionTwo.x;
		}
		if (diffY < 0.01)
		{

			mEnemyPosition.y = mEnemyPositionTwo.y;
		}
		if (diffZ < 0.01)
		{

			mEnemyPosition.z = mEnemyPositionTwo.z;
		}
		////////////////////////////////


		if (mEnemyPosition.x > mEnemyPositionTwo.x)
		{

			direction += XMVectorSet(-1.0f, 0.0f, 0, 0.0f);


		}
		else if (mEnemyPosition.x < mEnemyPositionTwo.x)
		{

			direction += XMVectorSet(1.0f, 0.0f, 0, 0.0f);

		}



		if (mEnemyPosition.z > mEnemyPositionTwo.z)
		{

			direction += XMVectorSet(0.0f, 0.0f, -1.0f, 0.0f);


		}
		else if (mEnemyPosition.z < mEnemyPositionTwo.z)
		{

			direction += XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

		}


		if (mEnemyPosition.y > mEnemyPositionTwo.y)
		{

			direction += XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f);


		}
		else if (mEnemyPosition.y < mEnemyPositionTwo.y)
		{

			direction += XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

		}
		if (diffX < 0.05f && diffY < 0.05f && diffZ < 0.05f)
		{

		
			if (timesThrough == 0)
			{
				if (mEnemyPositionThree.x == 0)
				{

					dontUpdate = true;
					travelToPoint = 1;

					lastPoint = mEnemyPositionTwo;

				}
				else if (mEnemyPositionThree.x != 0)
				{
					dontUpdate = true;
					travelToPoint = 3;

					lastPoint = mEnemyPositionTwo;

				}
			}
			else
			{
				dontUpdate = true;

				travelToPoint = 1;
				lastPoint = mEnemyPositionTwo;
			}

			int something = 1;
		}

	}



	/////////////////////////////////////////
	else if (travelToPoint == 1)
	{

		timesThrough = 0;

		diffX = mEnemyPosition.x - mEnemyPositionOne.x;
		diffY = mEnemyPosition.y - mEnemyPositionOne.y;
		diffZ = mEnemyPosition.z - mEnemyPositionOne.z;



		if (diffX < 0.0f)
		{

			diffX *= -1;
		}
		if (diffY < 0.0f)
		{

			diffY *= -1;
		}
		if (diffZ < 0.0f)
		{

			diffZ *= -1;
		}


		//////////////////////////////////
		if (diffX < 0.01)
		{

			mEnemyPosition.x = mEnemyPositionOne.x;
		}
		if (diffY < 0.01)
		{

			mEnemyPosition.y = mEnemyPositionOne.y;
		}
		if (diffZ < 0.01)
		{

			mEnemyPosition.z = mEnemyPositionOne.z;
		}
		////////////////////////////////



		if (mEnemyPosition.x > mEnemyPositionOne.x)
		{

			direction += XMVectorSet(-1.0f, 0.0f, 0, 0.0f);


		}
		if (mEnemyPosition.x < mEnemyPositionOne.x)
		{

			direction += XMVectorSet(1.0f, 0.0f,0, 0.0f);

		}



		if (mEnemyPosition.z > mEnemyPositionOne.z && diffZ > 0.01)
		{

			direction += XMVectorSet(0.0f, 0.0f, -1.0f, 0.0f);


		}
		if (mEnemyPosition.z < mEnemyPositionOne.z && diffZ > 0.01)
		{

			direction += XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

		}


		if (mEnemyPosition.y > mEnemyPositionOne.y)
		{

			direction += XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f);


		}
		if (mEnemyPosition.y < mEnemyPositionOne.y)
		{

			direction += XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

		}
		if (diffX < 0.05f && diffY < 0.05f && diffZ < 0.05f)
		{
			
			travelToPoint = 2;

			lastPoint = mEnemyPositionOne;

		}
	}



	////////////////////////////////////////////////////////////////////////////////
	else if (travelToPoint == 3 && timesThrough == 0)
	{


		diffX = mEnemyPosition.x - mEnemyPositionThree.x;
		diffY = mEnemyPosition.y - mEnemyPositionThree.y;
		diffZ = mEnemyPosition.z - mEnemyPositionThree.z;


		int nothing;
		if (diffX < 0.0f)
		{

			diffX *= -1;
		}
		if (diffY < 0.0f)
		{

			diffY *= -1;
		}
		if (diffZ < 0.0f)
		{

			diffZ *= -1;
		}


		//////////////////////////////////
		if (diffX < 0.01)
		{

			mEnemyPosition.x = mEnemyPositionThree.x;
		}
		if (diffY < 0.01)
		{

			mEnemyPosition.y = mEnemyPositionThree.y;
		}
		if (diffZ < 0.01)
		{

			mEnemyPosition.z = mEnemyPositionThree.z;
		}
		////////////////////////////////



		if (mEnemyPosition.x > mEnemyPositionThree.x)
		{

			direction += XMVectorSet(-1.0f, 0.0f, 0, 0.0f);


		}
		if (mEnemyPosition.x < mEnemyPositionThree.x)
		{

			direction += XMVectorSet(1.0f, 0.0f, 0, 0.0f);

		}



		if (mEnemyPosition.z > mEnemyPositionThree.z)
		{

			direction += XMVectorSet(0.0f, 0.0f, -1.0f, 0.0f);


		}
		if (mEnemyPosition.z < mEnemyPositionThree.z)
		{

			direction += XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

		}


		if (mEnemyPosition.y > mEnemyPositionThree.y)
		{

			direction += XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f);


		}
		if (mEnemyPosition.y < mEnemyPositionThree.y)
		{

			direction += XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

		}
		if (diffX < 0.05f && diffY < 0.05f && diffZ < 0.05f)
		{

			if (mEnemyPositionFour.x == NULL)
			{
					


				travelToPoint = 2;
				timesThrough = 1;
			}
			else
			{
				
				travelToPoint = 4;
		
			}
		}
	}


	else if (travelToPoint == 4)
	{


		diffX = mEnemyPosition.x - mEnemyPositionFour.x;
		diffY = mEnemyPosition.y - mEnemyPositionFour.y;
		diffZ = mEnemyPosition.z - mEnemyPositionFour.z;

		if (diffX < 0.0f)
		{

			diffX *= -1;
		}
		if (diffY < 0.0f)
		{

			diffY *= -1;
		}
		if (diffZ < 0.0f)
		{

			diffZ *= -1;
		}

		//////////////////////////////////
		if (diffX < 0.001)
		{

			mEnemyPosition.x = mEnemyPositionFour.x;
		}
		if (diffY < 0.001)
		{

			mEnemyPosition.y = mEnemyPositionFour.y;
		}
		if (diffZ < 0.001)
		{

			mEnemyPosition.z = mEnemyPositionFour.z;
		}
		////////////////////////////////



		if (mEnemyPosition.x > mEnemyPositionFour.x)
		{

			direction += XMVectorSet(-1.0f, 0.0f, 0, 0.0f);


		}
		if (mEnemyPosition.x < mEnemyPositionFour.x)
		{

			direction += XMVectorSet(1.0f, 0.0f,0, 0.0f);

		}



		if (mEnemyPosition.z > mEnemyPositionFour.z && diffZ > 0.01)
		{

			direction += XMVectorSet(0.0f, 0.0f, -1.0f, 0.0f);


		}
		if (mEnemyPosition.z < mEnemyPositionFour.z && diffZ > 0.01)
		{

			direction += XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

		}


		if (mEnemyPosition.y > mEnemyPositionFour.y)
		{

			direction += XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f);


		}
		if (mEnemyPosition.y < mEnemyPositionFour.y)
		{

			direction += XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

		}
		if (diffX < 0.05f && diffY < 0.05f && diffZ < 0.05f)
		{

			
			travelToPoint = 1;

			lastPoint = mEnemyPositionFour;
		}
	}












	XMMATRIX worldMatrix = XMLoadFloat4x4(&mEnemyWorld);
	XMVECTOR r = XMLoadFloat3(&mEnemyPosition);



	// Normalize our destinated direction vector
	direction = XMVector3Normalize(direction);





	/////character spinning make it more smooth

	if (XMVectorGetX(XMVector3Dot(direction, oldCharDirection)) == -1)
	{
		oldCharDirection += XMVectorSet(1.11f, 1.0f, 0.0f, 0.0f);
	}


	///////get characters position in world space
	charPosition = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	charPosition = XMVector3TransformCoord(charPosition, worldMatrix);



	///// rotate the character
	float destDirLength = 10.0f * dt;



	currCharDirection = (oldCharDirection)+(direction * destDirLength);
	currCharDirection = XMVector3Normalize(currCharDirection);


	// get the angle 
	float charDirAngle = XMVectorGetX(XMVector3AngleBetweenNormals(XMVector3Normalize(currCharDirection), XMVector3Normalize(EnemyForward)));



	if (XMVectorGetY(XMVector3Cross(currCharDirection, EnemyForward)) > 0.0f)
	{
		charDirAngle = -charDirAngle;
	}



	float Speed = speed * dt;



	direction = direction * Speed;



	charPosition = charPosition + direction;



	XMMATRIX rotationMatrix;





	XMMATRIX Translation = XMMatrixTranslation(XMVectorGetX(charPosition), XMVectorGetY(charPosition), XMVectorGetZ(charPosition));

	rotationMatrix = XMMatrixRotationY(charDirAngle - 3.14159265f);		// Subtract PI from angle so the character doesn't run backwards



	worldMatrix = rotationMatrix * Translation;


	XMMatrixDecompose(&S, &Q, &P, worldMatrix);


	XMStoreFloat3(&mEnemyPosition, P);

	XMStoreFloat4(&mEnemyRotationQuad, Q);




	XMStoreFloat4x4(&mEnemyWorld, worldMatrix);



	oldCharDirection = currCharDirection;



}