Exemple #1
0
void CDX10Core::RenderMeshObject(CMeshObject *pObj, float dt)
{
	static float timeSpent = 0;
	timeSpent+= dt;
	if(!pObj || !pObj->m_pMesh || !pObj->m_pMesh->m_numVertices)
		return;

	FillBuffers(pObj);	

	D3DXMATRIX rotMatY, rotMatX, translate;
	D3DXMatrixRotationY(&rotMatY, 0.01f * 3.1416f * timeSpent);
	D3DXMatrixRotationX(&rotMatX,  0.3416f );
	D3DXMatrixTranslation(&translate, 0, 0, 80);
	m_matWorld = D3DXMATRIX((float *)pObj->m_matGlobal) * rotMatX * rotMatY * translate ;	

	m_pWorldMatrixEffectVariable->SetMatrix(m_matWorld);
	m_pViewMatrixEffectVariable->SetMatrix(m_matView);
	m_pProjectionMatrixEffectVariable->SetMatrix(m_matProjection);

	// Set the input layout
	m_pDevice->IASetInputLayout( m_pVertexLayout );

	ID3D10Buffer * pVBs[]={ m_pVertexBuffers[VBT_POSITION0], m_pVertexBuffers[VBT_COLOR0], m_pVertexBuffers[VBT_NORMAL0]};
	UINT strides[] = {sizeof(D3DXVECTOR3), sizeof(D3DXVECTOR4), sizeof(D3DXVECTOR3)};
	UINT offsets[] = {0, 0, 0};
	m_pDevice->IASetVertexBuffers( 0, 3, pVBs, strides, offsets );

	// Set index buffer	
	m_pDevice->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

	// Set primitive topology 
	m_pDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );	


	//get technique desc
	D3D10_TECHNIQUE_DESC techDesc;
	m_pBasicTechnique->GetDesc( &techDesc );

	for( UINT p = 0; p < techDesc.Passes; ++p )
	{
		//apply technique
		m_pBasicTechnique->GetPassByIndex( p )->Apply( 0 );

		//draw
		m_pDevice->DrawIndexed( pObj->m_pMesh->m_numIndices, 0, 0 );
	}	
}
peBool proShaderDomain::Set(const proVertHeader &vertHeader, proVertBuff *pVertBuff, void *pConstants)
{
	if(g_pAppDef->m_featureLevel < D3D_FEATURE_LEVEL_11_0)
	{
		return FALSE;
	}
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	peUint bufferNumber;	

	result = g_pAppDef->m_pContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if(FAILED(result))
	{
		return FALSE;
	}

	CB_PER_FRAME_CONSTANTS* pData = static_cast<CB_PER_FRAME_CONSTANTS*>(mappedResource.pData);

	D3DXMATRIX mViewProjection;
	proMat4f proj = proRenderBuffer::Instance()->GetProjMatrix(proRenderBuffer::Instance()->GetLoopRenderPass());
	proMat4f view = proRenderBuffer::Instance()->GetViewMatrix(proRenderBuffer::Instance()->GetLoopRenderPass());
	proMat4f mat = proRenderBuffer::Instance()->GetModelMatrix(proRenderBuffer::Instance()->GetLoopRenderPass());
	proMat4f resultmat = proj * view * mat;
	resultmat.Transpose();
	pData->mViewProjection = D3DXMATRIX(resultmat.data);

	proEngineObj *pCamera = proRenderBuffer::Instance()->GetRenderCamera(proRenderBuffer::kRenderPass3D);
	assert(pCamera);
	if(pCamera)
	{
		proCompMat *pCompMat = pCamera->GetComponent<proCompMat>();
		if(pCompMat)
		{
			proVec4f pos = pCompMat->GetMatrix().pos;
			pData->vCameraPosWorld = D3DXVECTOR3(pos.x, pos.y, pos.z);
		}
	}

	g_pAppDef->m_pContext->Unmap(m_matrixBuffer, 0);

	bufferNumber = 0;	
	g_pAppDef->m_pContext->DSSetConstantBuffers( bufferNumber, 1, &m_matrixBuffer);
	g_pAppDef->m_pContext->DSSetShader(m_pDShader, NULL, 0);
	g_pAppDef->m_pContext->GSSetShader( NULL, NULL, 0 );

	return TRUE;
}
void fbxLoader2::setBindPoseCluster(FbxNode *node)
{
	if( node->GetNodeAttribute())
	{
		switch(node->GetNodeAttribute()->GetAttributeType())
		{
		case FbxNodeAttribute::eMesh: 
			FbxMesh *mesh = node->GetMesh();

			for (int j = 0; j<mesh->GetDeformerCount(); j++)
			{
				FbxSkin *skin = (FbxSkin*) mesh->GetDeformer(j,FbxDeformer::eSkin);
				int clusters = skin->GetClusterCount();
				for(int k = 0; k<clusters; k++)
				{
					FbxCluster* cluster = skin->GetCluster(k);
					FbxNode* boneLink = cluster->GetLink();

					if(boneLink)
					{
						std::string nameLink = boneLink->GetName();
						FbxAMatrix translationM;
						FbxAMatrix invert;
						cluster->GetTransformLinkMatrix(translationM);
						cluster->GetTransformMatrix(invert);

						translationM = translationM * invert.Inverse();

						D3DXMATRIX mat = D3DXMATRIX((float)translationM.mData[0].mData[0], (float)translationM.mData[0].mData[1], (float)translationM.mData[0].mData[2], (float)translationM.mData[3].mData[0],
													(float)translationM.mData[1].mData[0], (float)translationM.mData[1].mData[1], (float)translationM.mData[1].mData[2], (float)translationM.mData[3].mData[1],
													(float)translationM.mData[2].mData[0], (float)translationM.mData[2].mData[1], (float)translationM.mData[2].mData[2], (float)translationM.mData[3].mData[2],
													0,0,0,1);

						skeleton->GetBone(skeleton->GetBoneByName(nameLink))->SetTransformation(mat);
					}
				}
			}
			break;
		}
	}
	for (int i = 0; i<node->GetChildCount(); i++)
	{
		FbxNode* child = node->GetChild(i);
		setBindPoseCluster(child);
	}
}
bool LudoRenderer::ConfigureViewport(const float fieldOfView, const int width, const int height, const float nearPlane, const float farPlane)
{   
    //D3DXMATRIX matProjection;                             // the projection transform matrix
    m_Projection = D3DXMATRIX();
    D3DXMatrixPerspectiveFovLH(&m_Projection,
        D3DXToRadian(fieldOfView),                          // the horizontal field of view
        static_cast<float>(width) / height,                 // the aspect ratio
        nearPlane,                                          // the near view-plane
        farPlane);                                          // the far view-plane
    m_d3DDev->SetTransform(D3DTS_PROJECTION, &m_Projection); // set the projection

    D3DXMATRIX matWorld;                              // a matrix to store the rotation for each triangle
    D3DXMatrixRotationY(&matWorld, 0.0f);             // the rotation matrix
    m_d3DDev->SetTransform(D3DTS_WORLD, &matWorld); // set the world transform

    return true;
}
Exemple #5
0
void Camera::UpdateViewMatrix()
{
	D3DXVec3Normalize(&m_look, &m_look);
	D3DXVec3Cross(&m_up, &m_look, &m_right);
	D3DXVec3Normalize(&m_up, &m_up);
	D3DXVec3Cross(&m_right, &m_up, &m_look);
	D3DXVec3Normalize(&m_right, &m_right);

	float x = -D3DXVec3Dot(&m_right, &m_position);
	float y = -D3DXVec3Dot(&m_up, &m_position);
	float z = -D3DXVec3Dot(&m_look, &m_position);

	m_matView = D3DXMATRIX(
		m_right.x, m_up.x, m_look.x, 0.0f,
		m_right.y, m_up.y, m_look.y, 0.0f,
		m_right.z, m_up.z, m_look.z, 0.0f,
		x,         y,      z,        1.0f);
}
void CameraClass::GetBillboardAlign(D3DXMATRIX& out, D3DXVECTOR3& pos)
{
	D3DXVECTOR3 at, right;
	float mag;

	//at = m_position - pos;
	at = -m_direction;
	mag = sqrtf(at.x*at.x + at.y*at.y + at.z*at.z);
	at /= -mag;

	right.x = -(at.y*m_up.z - at.z*m_up.y);
	right.y = -(at.z*m_up.x - at.x*m_up.z);
	right.z = -(at.x*m_up.y - at.y*m_up.x);

	mag = sqrtf(right.x*right.x + right.y*right.y + right.z*right.z);
	right /= mag;

	out = D3DXMATRIX(right.x, right.y, right.z, 0, m_up.x, m_up.y, m_up.z, 0, at.x, at.y, at.z, 0, 0, 0, 0, 1);
}
Exemple #7
0
void Particle::update(float timePassed)
{
	timePassed = 10;
	if (timePassed < timeLife)
	{
		timeLife -= timePassed;
		D3DXVECTOR3 playerVec =EntityManager::getInstance()->currentPlayer->getPos() -startPosition  ;
		D3DXVec3Normalize(&playerVec,&playerVec);
		velocity += acceleration * timePassed;
		ge3D_position.x += velocity.x * playerVec.x;
		ge3D_position.y += velocity.y * playerVec.y;
		ge3D_position.z += velocity.z * playerVec.z;
		scale.x -= .002f;
		scale.y -= .002f;
	}
	else
	{
	if (type.compare("Faded") == 0)
	{
		timeLife = 2000 + rand() % 4000;
		velocity = D3DXVECTOR3(0.0f,0.0f,0.0f);
		float rando = (float)rand()/RAND_MAX;
		velocity.x += rando * .04f - .02f;
		rando = (float)rand()/RAND_MAX;
		velocity.z += rando *.04f -.02f;
		scale = D3DXVECTOR3(1.2f,1.2f,1.0f);
		ge3D_position=startPosition;
		
		randomPosAdjust();
	}
	}
	D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	D3DXVECTOR3 look =	EntityManager::getInstance()->currentPlayer->getCamera()->position()-ge3D_position;
	look.y = 0.0f; // y-axis aligned, so project to xz-plane
	D3DXVec3Normalize(&look,&look);
	D3DXVECTOR3 right;
	D3DXVec3Cross(&right,&up, &look);
	D3DXMATRIX scaling;
	D3DXMatrixScaling(&scaling,scale.x,scale.y,scale.z);
	 world = D3DXMATRIX(right.x,right.y,right.z,0.0f,up.x,up.y,up.z,0.0f,look.x,look.y,look.z,0.0f,ge3D_position.x,ge3D_position.y,ge3D_position.z,1.0f);
	 world = scaling * world;
}
void CameraClass::GetBillboardXZ(D3DXMATRIX& out, D3DXVECTOR3& pos)
{
	D3DXVECTOR3 at, right;
	float mag;

	at = m_position - pos;
	at.y = 0;
	mag = sqrtf(at.x*at.x + at.y*at.y + at.z*at.z);
	at /= -mag;

	// cross product of at and y axis
	right.x = at.z;//-(at.y*0 - at.z*1);
	right.y = 0;//-(at.z*0 - at.x*0);
	right.z = -at.x;//-(at.x*1 - at.y*0);

	mag = sqrtf(right.x*right.x + right.z*right.z);
	right /= mag;

	out = D3DXMATRIX(right.x, right.y, right.z, 0, m_up.x, m_up.y, m_up.z, 0, at.x, at.y, at.z, 0, 0, 0, 0, 1);
}
Exemple #9
0
	void Camera2D::Render()
	{
		// Update position
		UpdatePos();

		// Set up view Matrix
		D3DXMATRIX viewMatrix = D3DXMATRIX(
			1, 0, 0, 0,
			0, 1, 0, 0,
			0, 0, 1, 0,
			(FLOAT)(-(_position.x)), (FLOAT)(-(_position.y)), 0, 1);

		// Create matrices
		D3DXMatrixOrthoLH(&_projMatrix, (FLOAT)SCREENW * _zoomFactor, (FLOAT)-SCREENH * _zoomFactor, SCREEN_NEAR, SCREEN_DEPTH);
		D3DXMATRIX identityMatrix;
		D3DXMatrixIdentity(&identityMatrix);

		// Set matrices
		g_Engine->GetDevice()->SetTransform(D3DTS_PROJECTION, &_projMatrix);
		g_Engine->GetDevice()->SetTransform(D3DTS_WORLD, &identityMatrix);
		g_Engine->GetDevice()->SetTransform(D3DTS_VIEW, &viewMatrix);
	}
Exemple #10
0
const D3DXMATRIX ViewMatrix( const D3DXVECTOR3& eye, const D3DXVECTOR3& at, const D3DXVECTOR3& up )
{
	D3DXVECTOR3 c, _c = at-eye;
	D3DXVec3Normalize( &c, &_c );

	D3DXVECTOR3 a, _a;
	D3DXVec3Cross( &_a, &up, &c );
	D3DXVec3Normalize( &a, &_a );

	D3DXVECTOR3 b;
	D3DXVec3Cross( &b, &c, &a );
	c /= 2.0f;

	D3DXVECTOR3 d(	-D3DXVec3Dot(&eye, &a),
					-D3DXVec3Dot(&eye, &b),
					-D3DXVec3Dot(&eye, &c) );

	return D3DXMATRIX(	a.x,	a.y,	a.z,	d.x,
						b.x,	b.y,	b.z,	d.y,
						c.x,	c.y,	c.z,	d.z,
						0.0f,	0.0f,	0.0f,	1.0f );
}
	D3DXMATRIX Matrix::Adjoint(const D3DXMATRIX& m)
	{
		return D3DXMATRIX(
			Minor(m, 1, 2, 3, 1, 2, 3),
			-Minor(m, 0, 2, 3, 1, 2, 3),
			Minor(m, 0, 1, 3, 1, 2, 3),
			-Minor(m, 0, 1, 2, 1, 2, 3),

			-Minor(m, 1, 2, 3, 0, 2, 3),
			Minor(m, 0, 2, 3, 0, 2, 3),
			-Minor(m, 0, 1, 3, 0, 2, 3),
			Minor(m, 0, 1, 2, 0, 2, 3),

			Minor(m, 1, 2, 3, 0, 1, 3),
			-Minor(m, 0, 2, 3, 0, 1, 3),
			Minor(m, 0, 1, 3, 0, 1, 3),
			-Minor(m, 0, 1, 2, 0, 1, 3),

			-Minor(m, 1, 2, 3, 0, 1, 2),
			Minor(m, 0, 2, 3, 0, 1, 2),
			-Minor(m, 0, 1, 3, 0, 1, 2),
			Minor(m, 0, 1, 2, 0, 1, 2));
	}
	//-----------------------------------------------------------------------
	void gkMovableShape::_update(const float& delta_time)
	{
		Shape::_update(delta_time);

		const Matrix& mat = getWorldMatrix();

		mWorldMatrix = D3DXMATRIX(
			mat.m[0][0], -mat.m[0][1], 0,  mat.m[0][2], 
			-mat.m[1][0], mat.m[1][1], 0, -mat.m[1][2], 
			0,		  0,		   1,				0,
			0,		  0,		   0,				1);

		D3DXMatrixTranspose(&mWorldMatrix, &mWorldMatrix);

		mMULcolor = mTransform.getColor().mul;
		mADDcolor = mTransform.getColor().add;

		if (getParentContainer() && !(getParentContainer()->getVisible()))
		{
			mMULcolor.a = 0;
			mADDcolor.a = 0;
		}
	}
Exemple #13
0
Lighting::Lighting()
{
	int				i;
	float			Bias,X,Y;
	unsigned int	Range;

	for(i=0; i < SHADER_LIGHT_MAX; i++)
	{
		m_VertexHandle[i] = NULL;
		m_PixelHandle[i]  = NULL;
	}

	m_Atten		 = NULL;
	m_Spot		 = NULL;
	m_CubeNormal = NULL;
	m_InitDone	 = false;
	m_Ready		 = false;

	//
	//	Set a default projection matrix
	//	
	X	  = 0.5f + (0.5f / 512.0f);
	Y	  = 0.5f + (0.5f / 512.0f);
	Range = 0xFFFFFFFF >> (32 - 24);
	Bias  = -0.001f * (float)Range;

	m_MatScaleBias = D3DXMATRIX(0.5f,  0.0f,  0.0f,         0.0f,
							    0.0f, -0.5f,  0.0f,         0.0f,
							    0.0f,  0.0f,  (float)Range, 0.0f,
							    X,     Y,     Bias,         1.0f);

	m_forceUpdate = true;
	sceneLights.SetCount(0);
	//build the initial list of lights
//	GetLightsFromScene();
	
}
Exemple #14
0
Vector4 Matrix::translation( const Vector4& vec, const Matrix& mat ){
	D3DXVECTOR4 v( vec.x, vec.y, vec.z, vec.w );
	D3DXVec4Transform( &v, &v, &D3DXMATRIX( &mat.m.m11 ) );
	return Vector4( v.x, v.y, v.z, v.w );
}
Exemple #15
0
/**
* Gathers a matrix to be used in modifications.
***/
void ViewAdjustment::GatherMatrix(D3DXMATRIX& matrixLeft, D3DXMATRIX& matrixRight)
{
	matGatheredLeft = D3DXMATRIX(matrixLeft);
	matGatheredRight = D3DMATRIX(matrixRight);
}
bool CD3DGraphics11::RenderColorShader(D3DXMATRIX world, int numIndices)
{
	return m_colorShader.Render(*this, world, m_matrices.view, m_matrices.projection, D3DXMATRIX(), numIndices);
}
// Deform the vertex array in classic linear way.
void fbxLoader2::ComputeLinearDeformation(FbxAMatrix& pGlobalPosition, FbxMesh* pMesh,  FbxTime& pTime, FbxPose* pPose, int frame)
{
	// All the links must have the same link mode.
	FbxCluster::ELinkMode lClusterMode = ((FbxSkin*)pMesh->GetDeformer(0, FbxDeformer::eSkin))->GetCluster(0)->GetLinkMode();

	int lVertexCount = pMesh->GetControlPointsCount();
	FbxAMatrix* lClusterDeformation = new FbxAMatrix[lVertexCount];
	memset(lClusterDeformation, 0, lVertexCount * sizeof(FbxAMatrix));

	double* lClusterWeight = new double[lVertexCount];
	memset(lClusterWeight, 0, lVertexCount * sizeof(double));

	if (lClusterMode == FbxCluster::eAdditive)
	{
		for (int i = 0; i < lVertexCount; ++i)
		{
			lClusterDeformation[i].SetIdentity();
		}
	}

	// For all skins and all clusters, accumulate their deformation and weight
	// on each vertices and store them in lClusterDeformation and lClusterWeight.
	int lSkinCount = pMesh->GetDeformerCount(FbxDeformer::eSkin);
	for ( int lSkinIndex=0; lSkinIndex<lSkinCount; ++lSkinIndex)
	{
		FbxSkin * lSkinDeformer = (FbxSkin *)pMesh->GetDeformer(lSkinIndex, FbxDeformer::eSkin);
		
		int lClusterCount = lSkinDeformer->GetClusterCount();
		for ( int lClusterIndex=0; lClusterIndex<lClusterCount; ++lClusterIndex)
		{
			FbxCluster* lCluster = lSkinDeformer->GetCluster(lClusterIndex);
			if (!lCluster->GetLink())
				continue;

			FbxAMatrix lVertexTransformMatrix;

			ComputeClusterDeformation(pGlobalPosition, pMesh, lCluster, lVertexTransformMatrix, pTime, pPose, frame);

			//lVertexTransformMatrix.Transpose();
			FbxAMatrix identityM;
			identityM.SetIdentity();

			FbxVector4 rotation = lVertexTransformMatrix.GetROnly();
			FbxVector4 translation = lVertexTransformMatrix.GetT();
			FbxVector4 scaling = lVertexTransformMatrix.GetS();

			//rotation = FbxVector4(rotation.mData[0], rotation.mData[1], rotation.mData[2], rotation.mData[3]);
			//translation = FbxVector4 (translation.mData[0], translation.mData[1], translation.mData[2], translation.mData[3]);
			//scaling = FbxVector4 (scaling.mData[0], scaling.mData[1], scaling.mData[2], scaling.mData[3]);

			//lVertexTransformMatrix = FbxAMatrix(translation, rotation, scaling);			
			//lVertexTransformMatrix = FbxAMatrix(translation, rotation, scaling);	


			identityM = lVertexTransformMatrix * identityM;

			D3DXMATRIX convert = D3DXMATRIX(1,0,0,0,
											0,0,1,0,
											0,1,0,0,
											0,0,0,1);

			D3DXMATRIX setMatrix = D3DXMATRIX(	(float)identityM.mData[0].mData[0], (float)identityM.mData[1].mData[0], (float)identityM.mData[2].mData[0], (float)identityM.mData[3].mData[0],
												(float)identityM.mData[0].mData[1], (float)identityM.mData[1].mData[1], (float)identityM.mData[2].mData[1], (float)identityM.mData[3].mData[1],
												(float)identityM.mData[0].mData[2], (float)identityM.mData[1].mData[2], (float)identityM.mData[2].mData[2], (float)identityM.mData[3].mData[2],
												(float)identityM.mData[0].mData[3], (float)identityM.mData[1].mData[3], (float)identityM.mData[2].mData[3],1);

			//setMatrix *=0.5f;

			setMatrix = D3DXMATRIX(	(float)identityM.mData[0].mData[0], (float)identityM.mData[1].mData[0], (float)identityM.mData[2].mData[0], (float)identityM.mData[3].mData[0],
									(float)identityM.mData[0].mData[1], (float)identityM.mData[1].mData[1], (float)identityM.mData[2].mData[1], (float)identityM.mData[3].mData[1],
									//(float)identityM.mData[0].mData[2], (float)identityM.mData[1].mData[2], (float)identityM.mData[2].mData[2], (float)identityM.mData[3].mData[1],
									(float)identityM.mData[0].mData[2], (float)identityM.mData[1].mData[2], (float)identityM.mData[2].mData[2], (float)identityM.mData[3].mData[2],
									(float)identityM.mData[0].mData[3], (float)identityM.mData[1].mData[3], (float)identityM.mData[2].mData[3], 1);

			//setMatrix = setMatrix*convert;

			///////// juz prawie dziala. sprawdz jeszcze te addytywne itp.
			/// generalnie dodaj to do włosów i dorzuć poprzednią macierz, żeby liczyć przesunięcia.


			//setMatrix /= 2.54f; //skala jedna jest w cm, druga w inchach, nieważne czy zmieniam system skali ręcznie... bzdurka fbxa
			

			std::string nametype = lCluster->GetLink()->GetName();	

			animationStructure->GetSkeleton(frame)->GetBone(animationStructure->GetSkeleton(frame)->GetBoneByName(lCluster->GetLink()->GetName()))->SetTransformation(setMatrix);
		}//lClusterCount
	}

	delete [] lClusterDeformation;
	delete [] lClusterWeight;
}
#include "Geometry.h"
#include "math.h"

//
// Our custom FVF, which describes our custom vertex structure
// These were #define'd in the book - now they are static constants.
//
DWORD TRANSFORMED_VERTEX::FVF = D3DFVF_XYZRHW;
DWORD UNTRANSFORMED_VERTEX::FVF = D3DFVF_XYZ;
DWORD UNTRANSFORMED_LIT_VERTEX::FVF = (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_SPECULAR);
DWORD UNTRANSFORMED_UNLIT_VERTEX::FVF =
	(D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_SPECULAR);		
DWORD COLORED_TEXTURED_VERTEX::FVF = (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
DWORD COLORED_VERTEX::FVF = (D3DFVF_XYZ|D3DFVF_DIFFUSE);

Mat4x4 Mat4x4::g_Identity(D3DXMATRIX(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1));
Quaternion Quaternion::g_Identity(D3DXQUATERNION(0,0,0,1));

Mat4x4::Mat4x4(D3DXMATRIX &mat)
{
	memcpy(&m, &mat.m, sizeof(mat.m));
}

Quaternion::Quaternion(D3DXQUATERNION &quat)
{
	x = quat.x;
	y = quat.y;
	z = quat.z;
	w = quat.w;
}
	// This is the main render function. Only one model can be rendered at a time. The world matrix of the model to be
	// rendered is required as a parameter. Also the texture ID needs to be passed in for the model.
	void CRender::RenderModel(const CMatrix4x4* worldMatrix, ID3D10ShaderResourceView* texture)
	{
		m_pWorldMatrixVar->SetMatrix( D3DXMATRIX( &worldMatrix->e00 ) );

		m_pModelTextureVar->SetRawValue( texture, 0, 1 );
	}
void Graphics::TransformSprite(const Matrix* m) const
{
	m_sprite->SetTransform(&D3DXMATRIX(m->GetD3DMatrix()));
}
Exemple #21
0
void Matrix::setInverse( const Matrix& mat ){
	D3DXMATRIX a;
	D3DXMatrixInverse( &a, NULL, &D3DXMATRIX((float*)&mat.m ) );
	m.set( a );
}
Exemple #22
0
D3DXMATRIX Light::getViewProj()
{
	return D3DXMATRIX();
}
Exemple #23
0
bool Lighting::LoadSpotTexture(TSTR &Name, LPDIRECT3DDEVICE9 Device)
{		
	HRESULT			Hr;
	void			*Data;
	unsigned long	Size;
	D3DSURFACE_DESC	Desc;
	float			Bias,X,Y;
	unsigned int	Range;
	TCHAR error[256];
	_stprintf(error,_T("%s"),GetString(IDS_ERROR));

	Hr = S_OK;

	SAFE_RELEASE(m_Spot);

	if(GetFileResource(MAKEINTRESOURCE(IDR_SPOTLIGHT),_T("RT_RCDATA"),
					   &Data,Size))
	{
		Hr = D3DXCreateTextureFromFileInMemoryEx(Device, 
												 Data,
												 Size,
												 D3DX_DEFAULT,
												 D3DX_DEFAULT,
												 1,
												 0,
												 D3DFMT_A8R8G8B8,
												 D3DPOOL_MANAGED,
												 D3DX_FILTER_NONE,
												 D3DX_FILTER_NONE,
												 0,
												 NULL,
												 NULL,
												 (IDirect3DTexture9 **)&m_Spot);


	}
	else
	{
		Hr = E_FAIL;
	}

	if(Hr != S_OK)
	{
		TSTR	Str;
		Str = TSTR(GetString(IDS_LOAD_FILES)) + Name + TSTR(GetString(IDS_CHECK_PATHS)) + 
			  TSTR(GetString(IDS_ERROR_CODE)) + TSTR(DXGetErrorString(Hr));

		MessageBox(NULL,Str,error,MB_OK | MB_ICONERROR | MB_SETFOREGROUND | 
				   MB_APPLMODAL);

		return(false);
	}

	//
	//	Set projection matrix
	//	
	((LPDIRECT3DTEXTURE9)m_Spot)->GetLevelDesc(0,&Desc);

	X	  = 0.5f + (0.5f / (float)Desc.Width);
	Y	  = 0.5f + (0.5f / (float)Desc.Height);
	Range = 0xFFFFFFFF >> (32 - 24);
	Bias  = -0.001f * (float)Range;

	m_MatScaleBias = D3DXMATRIX(0.5f,  0.0f,  0.0f,         0.0f,
							    0.0f, -0.5f,  0.0f,         0.0f,
							    0.0f,  0.0f,  (float)Range, 0.0f,
							    X,     Y,     Bias,         1.0f);

	return(true);

}
Exemple #24
0
/*==============================================
 * 2D Sprite for directX
 *
 * Written by Mark Gossage
 *==============================================*/
#include <d3dx9tex.h>
#include "SpriteUtils.h"
#include "Fail.h"

const D3DXMATRIX IDENTITY_MAT=*D3DXMatrixIdentity(&D3DXMATRIX());


LPD3DXSPRITE CreateSpriteBatch(LPDIRECT3DDEVICE9 pDev)
{
	LPD3DXSPRITE pSprite=0;
	D3DXCreateSprite(pDev,&pSprite);
	return pSprite;
}

LPDIRECT3DTEXTURE9 LoadSpriteTex(LPDIRECT3DDEVICE9 pDev,const char *filename)
{
	LPDIRECT3DTEXTURE9 pTex=0;
	if (FAILED(D3DXCreateTextureFromFileEx(pDev,filename,D3DX_DEFAULT_NONPOW2,D3DX_DEFAULT_NONPOW2,
								D3DX_DEFAULT,0,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,
								D3DX_DEFAULT,D3DX_DEFAULT,
								0,NULL,NULL,&pTex)))
	{
		FAIL(filename,"Cannot load texture");
		return NULL;
	}
	return pTex;
};

float textvertices[36] =
{
	9.5f,			9.5f,	0, 1,	0, 0,
	809.5f,			9.5f,	0, 1,	1, 0,
	9.5f,	512.0f + 9.5f,	0, 1,	0, 1,

	9.5f,	512.0f + 9.5f,	0, 1,	0, 1,
	809.5f,			9.5f,	0, 1,	1, 0,
	809.5f,	512.0f + 9.5f,	0, 1,	1, 1
};

SceneObject objects[] =
{
	{ D3DXMATRIX(), D3DXVECTOR3(0, 0.05f, 1.2f), D3DXVECTOR3(0.2f, 0.2f, 0.2f), D3DXVECTOR3(D3DX_PI / 3, 0, 0), SKULL, 3 },
	{ D3DXMATRIX(), D3DXVECTOR3(0, 0, 0), D3DXVECTOR3(5, 0.1f, 5), D3DXVECTOR3(0, 0, 0), FLOOR, 3 },

	{ D3DXMATRIX(), D3DXVECTOR3(0.5f, 0.38f, -1), D3DXVECTOR3(1.2f, 0.75f, 0.75f), D3DXVECTOR3(-0.3f, 0, 0), CRATE, 3 },
	{ D3DXMATRIX(), D3DXVECTOR3(0.55f, 1.005f, -0.85f), D3DXVECTOR3(0.5f, 0.5f, 0.5f), D3DXVECTOR3(-0.3f, 0, 0), CRATE, 3 },

	{ D3DXMATRIX(), D3DXVECTOR3(-1.75f, 0.38f, 0.4f), D3DXVECTOR3(0.75f, 0.75f, 1.5f), D3DXVECTOR3(-0.15f, 0, 0), CRATE, 3 },
};

const int numobjects = sizeof(objects) / sizeof(objects[0]);

HRESULT InitScene()
{
	HRESULT hr;
	
	D3DVERTEXELEMENT9 elem[] =
void MegaExtrudeOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    float distance = getFloatProperty(0);
    unsigned char count = getByteProperty(1);
    D3DXVECTOR3 scaleVector = getVectorProperty(2);
    D3DXVECTOR3 rotationVector = getVectorProperty(3);
    D3DXMATRIX scaleMatrix;
    D3DXMatrixScaling(&scaleMatrix,
                      scaleVector.x,
                      scaleVector.y,
                      scaleVector.z);
    D3DXMATRIX rotationXMatrix;
    D3DXMatrixRotationX(&rotationXMatrix, rotationVector.x);
    D3DXMATRIX rotationYMatrix;
    D3DXMatrixRotationY(&rotationYMatrix, rotationVector.y);
    D3DXMATRIX rotationZMatrix;
    D3DXMatrixRotationZ(&rotationZMatrix, rotationVector.z);
    D3DXMATRIX translationMatrix;
    D3DXMatrixTranslation(&translationMatrix,
                          0.0f,
                          distance / (float)count,
                          0.0f);
    D3DXMATRIX extrudeMatrix = scaleMatrix * rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;

    Mesh *srcMesh = getInput(0)->mesh;

    int numberOfVertices = srcMesh->getNumVertices();
    int numberOfQuads = srcMesh->getNumQuads();

    // Calculate the new number of quads and vertices.
    // The number of triangles will be unchanged.
    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        if (srcMesh->faceSelected(i))
        {
            numberOfQuads += n * count;
            numberOfVertices += n * count;
        }
    }

    mesh = new Mesh(numberOfVertices, srcMesh->getNumTriangles(), numberOfQuads, 1);

    int triangleIndex = 0;
    int quadIndex = 0;

    // Copy the src mesh vertices.
    for (int i = 0; i < srcMesh->getNumVertices(); i++)
    {
        mesh->pos(i) = srcMesh->pos(i);
    }

    int vertexIndex = srcMesh->getNumVertices();
    // Extrude each selected face and add triangles and quads.

    Vec3* lastPositions = new Vec3[4];
    int* lastIndices = new int[4];
    int* currentIndices = new int[4];

    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        for (int f = 0; f < n; f++)
        {
            lastPositions[f] = srcMesh->pos(face[f]);
            lastIndices[f] = face[f];
        }

        if (srcMesh->faceSelected(i))
        {
            // Get our base vectors.
            Vec3 pos1 = srcMesh->pos(face[1]);
            Vec3 pos0 = srcMesh->pos(face[0]);
            Vec3 faceBase1 = normalize(pos1 - pos0);
            Vec3 faceBase2 = normalize(srcMesh->getFaceNormal(i));
            Vec3 faceBase3 = normalize(cross(faceBase2, faceBase1));

            D3DXMATRIX fromFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase1.y, faceBase1.z, 0.0f,
                                            faceBase2.x, faceBase2.y, faceBase2.z, 0.0f,
                                            faceBase3.x, faceBase3.y, faceBase3.z, 0.0f,
                                            0.0f,               0.0f,        0.0f, 1.0f);
            D3DXMATRIX toFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase2.x, faceBase3.x, 0.0f,
                                          faceBase1.y, faceBase2.y, faceBase3.y, 0.0f,
                                          faceBase1.z, faceBase2.z, faceBase3.z, 0.0f,
                                          0.0f,               0.0f,        0.0f, 1.0f);

            D3DXMATRIX toFaceBaseAndOrigoMatrix = toFaceBaseMatrix;
            D3DXMATRIX fromFaceBaseAndToFaceMatrix = extrudeMatrix * fromFaceBaseMatrix;

            for (int c = 0; c < count; c++)
            {
                for (int f = 0; f < n; f++)
                {
                    Vec3 pos = lastPositions[f];
                    Vec3 posInFaceBase;
                    D3DXVec3TransformCoord(&posInFaceBase, &pos, &toFaceBaseAndOrigoMatrix);
                    Vec3 posTransformed;
                    D3DXVec3TransformCoord(&posTransformed, &posInFaceBase, &fromFaceBaseAndToFaceMatrix);
                    mesh->pos(vertexIndex) = posTransformed;
                    currentIndices[f] = vertexIndex;
                    lastPositions[f] = posTransformed;
                    vertexIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    mesh->setQuad(quadIndex,
                                  lastIndices[f],
                                  lastIndices[(f + 1) % n],
                                  currentIndices[(f + 1) % n],
                                  currentIndices[f]);
                    quadIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    lastIndices[f] = currentIndices[f];
                }
            }
        }


        if (n == 3)
        {
            mesh->setTriangle(triangleIndex, lastIndices[0], lastIndices[1], lastIndices[2]);
            triangleIndex++;
        }
        else
        {
            mesh->setQuad(quadIndex, lastIndices[0], lastIndices[1], lastIndices[2],  lastIndices[3]);
            quadIndex++;
        }
    }

    delete[] lastIndices;
    delete[] currentIndices;
    delete[] lastPositions;

    mesh->recalculateNormals();
}
Exemple #27
0
void Matrix::setMul( const Matrix& a, const Matrix& b ){
	D3DXMATRIX mul;
	D3DXMatrixMultiply( &mul, &D3DXMATRIX((float*)&a.m), &D3DXMATRIX((float*)&b.m) );
	m.set( mul );
}
/**
* Render the Virtual Cinema Theatre.
***/
void* OculusTracker::Provoke(void* pThis, int eD3D, int eD3DInterface, int eD3DMethod, DWORD dwNumberConnected, int& nProvokerIndex)
{
	// update game timer
	m_cGameTimer.Tick();

	static UINT unFrameSkip = 200;
	if (unFrameSkip > 0)
	{
		unFrameSkip--;
		return nullptr;
	}

	// #define _DEBUG_OTR
#ifdef _DEBUG_OTR
	{ wchar_t buf[128]; wsprintf(buf, L"[OTR] ifc %u mtd %u", eD3DInterface, eD3DMethod); OutputDebugString(buf); }
#endif

	// save ini file ?
	if (m_nIniFrameCount)
	{
		if (m_nIniFrameCount == 1)
			SaveIniSettings();
		m_nIniFrameCount--;
	}

	// main menu update ?
	if (m_sMenu.bOnChanged)
	{
		// set back event bool, set ini file frame count
		m_sMenu.bOnChanged = false;
		m_nIniFrameCount = 300;

		// loop through entries
		for (size_t nIx = 0; nIx < m_sMenu.asEntries.size(); nIx++)
		{
			// entry index changed ?
			if (m_sMenu.asEntries[nIx].bOnChanged)
			{
				m_sMenu.asEntries[nIx].bOnChanged = false;

				// touch entries ?
				if (nIx < 25)
				{
					// set new vk code by string
					m_aaunKeys[1][nIx] = GetVkCodeByString(m_sMenu.asEntries[nIx].astrValueEnumeration[m_sMenu.asEntries[nIx].unValue]);
				}
			}
		}
	}

	if (m_hSession)
	{
#pragma region controller
		// controller indices
		static const uint32_t s_unIndexRemote = 0;
		static const uint32_t s_unIndexTouch = 1;
		static const uint32_t s_unIndexXBox = 2;

		// get all connected input states
		ovrInputState sInputState[3] = {};
		unsigned int unControllersConnected = ovr_GetConnectedControllerTypes(m_hSession);
#pragma region Remote
		if (unControllersConnected & ovrControllerType_Remote)
		{
			ovr_GetInputState(m_hSession, ovrControllerType_Remote, &sInputState[s_unIndexRemote]);

			// handle all remote buttons except Oculus private ones
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Up)
				m_sMenu.bOnUp = true;
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Down)
				m_sMenu.bOnDown = true;
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Left)
				m_sMenu.bOnLeft = true;
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Right)
				m_sMenu.bOnRight = true;
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Enter)
				m_sMenu.bOnAccept = true;
			if (sInputState[s_unIndexRemote].Buttons & ovrButton_Back)
				m_sMenu.bOnBack = true;
		}
#pragma endregion
#pragma region touch
		if (unControllersConnected & ovrControllerType_Touch)
		{
			// get input state
			ovr_GetInputState(m_hSession, ovrControllerType_Touch, &sInputState[s_unIndexTouch]);

			// loop through controller buttons
			for (UINT unButtonIx = 0; unButtonIx < unButtonNo; unButtonIx++)
			{
				// cast keyboard event
				if (sInputState[s_unIndexTouch].Buttons & aunButtonIds[unButtonIx])
				{
					if (!m_aabKeys[s_unIndexTouch][unButtonIx])
						MapButtonDown(s_unIndexTouch, unButtonIx);
				}
				else
				if (m_aabKeys[s_unIndexTouch][unButtonIx])
					MapButtonUp(s_unIndexTouch, unButtonIx);
			}
		}
#pragma endregion
		if (unControllersConnected & ovrControllerType_XBox)
			ovr_GetInputState(m_hSession, ovrControllerType_XBox, &sInputState[s_unIndexXBox]);



#pragma endregion
#pragma region hmd
		/*// Start the sensor which informs of the Rift's pose and motion   .... obsolete for SDK 1.3.x ??
		ovr_ConfigureTracking(m_hSession, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection |
		ovrTrackingCap_Position, 0);*/

		// get the current tracking state
		ovrTrackingState sTrackingState = ovr_GetTrackingState(m_hSession, ovr_GetTimeInSeconds(), false);

		if (TRUE)//(sTrackingState.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked))
		{
			// get pose
			ovrPoseStatef sPoseState = sTrackingState.HeadPose;
			m_sPose = sPoseState.ThePose;
			m_sOrientation.x = m_sPose.Orientation.x;
			m_sOrientation.y = m_sPose.Orientation.y;
			m_sOrientation.z = m_sPose.Orientation.z;
			m_sOrientation.w = m_sPose.Orientation.w;

			// backup old euler angles and velocity
			float fEulerOld[3];
			float fEulerVelocityOld[3];
			memcpy(&fEulerOld[0], &m_fEuler[0], sizeof(float)* 3);
			memcpy(&fEulerVelocityOld[0], &m_fEulerVelocity[0], sizeof(float)* 3);

			// predicted euler angles ? for Oculus, due to ATW, we do not predict the euler angles
			if (FALSE)
			{
				// get angles
				m_sOrientation.GetEulerAngles<Axis::Axis_Y, Axis::Axis_X, Axis::Axis_Z, RotateDirection::Rotate_CW, HandedSystem::Handed_R >(&m_fEuler[1], &m_fEuler[0], &m_fEuler[2]);

				// quick fix here...
				m_fEuler[1] *= -1.0f;
				m_fEuler[0] *= -1.0f;
				m_fEuler[2] *= -1.0f;

				// get euler velocity + acceleration
				float fEulerAcceleration[3];
				for (UINT unI = 0; unI < 3; unI++)
				{
					// get the velocity
					m_fEulerVelocity[unI] = (m_fEuler[unI] - fEulerOld[unI]) / (float)m_cGameTimer.DeltaTime();

					// get the acceleration
					fEulerAcceleration[unI] = (m_fEulerVelocity[unI] - fEulerVelocityOld[unI]) / (float)m_cGameTimer.DeltaTime();
				}

				// get predicted euler
				for (UINT unI = 0; unI < 3; unI++)
				{
					// compute predicted euler
					m_fEulerPredicted[unI] = (0.5f * fEulerAcceleration[unI] * ((float)m_cGameTimer.DeltaTime() * (float)m_cGameTimer.DeltaTime())) + (m_fEulerVelocity[unI] * (float)m_cGameTimer.DeltaTime()) + m_fEuler[unI];
				}
			}
			else
			{
				// get angles
				m_sOrientation.GetEulerAngles<Axis::Axis_Y, Axis::Axis_X, Axis::Axis_Z, RotateDirection::Rotate_CW, HandedSystem::Handed_R >(&m_fEulerPredicted[1], &m_fEulerPredicted[0], &m_fEulerPredicted[2]);

				// quick fix here...
				m_fEulerPredicted[1] *= -1.0f;
				m_fEulerPredicted[0] *= -1.0f;
				m_fEulerPredicted[2] *= -1.0f;
			}

			// set the drawing update to true
			m_bControlUpdate = true;

			// set position
			m_afPosition[0] = (float)-m_sPose.Position.x - m_afPositionOrigin[0];
			m_afPosition[1] = (float)-m_sPose.Position.y - m_afPositionOrigin[1];
			m_afPosition[2] = (float)m_sPose.Position.z + m_afPositionOrigin[2];

			// get eye render pose and other fields
			ovrEyeRenderDesc asEyeRenderDesc[2];
			asEyeRenderDesc[0] = ovr_GetRenderDesc(m_hSession, ovrEye_Left, m_sHMDDesc.DefaultEyeFov[0]);
			asEyeRenderDesc[1] = ovr_GetRenderDesc(m_hSession, ovrEye_Right, m_sHMDDesc.DefaultEyeFov[1]);
			ovrPosef asHmdToEyePose[2] = { asEyeRenderDesc[0].HmdToEyePose,asEyeRenderDesc[1].HmdToEyePose };
			//ovrVector3f      asHmdToEyeViewOffset[2] = { asEyeRenderDesc[0].HmdToEyePose, asEyeRenderDesc[1].HmdToEyePose };
			ovrPosef         asEyeRenderPose[2];
			static long long s_frameIndex = 0;
			static double s_sensorSampleTime = 0.0;    // sensorSampleTime is fed into the layer later
			ovr_GetEyePoses(m_hSession, s_frameIndex, ovrTrue, asHmdToEyePose, asEyeRenderPose, &s_sensorSampleTime);
			// ovr_CalcEyePoses(sTrackingState.HeadPose.ThePose, asHmdToEyePose, asEyeRenderPose);

			// create rotation matrix from euler angles
			D3DXMATRIX sRotation;
			D3DXMATRIX sPitch, sYaw, sRoll;
			D3DXMatrixRotationX(&sPitch, m_fEulerPredicted[0]);
			D3DXMatrixRotationY(&sYaw, m_fEulerPredicted[1]);
			D3DXMatrixRotationZ(&sRoll, -m_fEulerPredicted[2]);
			sRotation = sYaw * sPitch * sRoll;

			// create per eye view matrix from rotation and position
			D3DXMATRIX sView[2];
			for (UINT unEye = 0; unEye < 2; unEye++)
			{
				D3DXMATRIX sTranslation;
				D3DXMatrixTranslation(&sTranslation, (float)-asEyeRenderPose[unEye].Position.x - m_afPositionOrigin[0], (float)-asEyeRenderPose[unEye].Position.y - m_afPositionOrigin[1], (float)asEyeRenderPose[unEye].Position.z + m_afPositionOrigin[2]);
				sView[unEye] = sTranslation * sRotation;
			}

			// create head pose view matrix
			D3DXMATRIX sTranslation;
			D3DXMatrixTranslation(&sTranslation, (float)-sTrackingState.HeadPose.ThePose.Position.x - m_afPositionOrigin[0], (float)-sTrackingState.HeadPose.ThePose.Position.y - m_afPositionOrigin[1], (float)sTrackingState.HeadPose.ThePose.Position.z + m_afPositionOrigin[2]);
			m_sView = sTranslation * sRotation;

			// create inverse view matrix
			D3DXMATRIX sVInv = {};
			D3DXMatrixInverse(&sVInv, nullptr, &m_sView);

			// get projection matrices left/right
			D3DXMATRIX asToEye[2];
			D3DXMATRIX asProjection[2];
			for (UINT unEye = 0; unEye < 2; unEye++)
			{
				// get ovr projection
				ovrMatrix4f sProj = ovrMatrix4f_Projection(m_sHMDDesc.DefaultEyeFov[unEye], 0.01f, 30.0f, ovrProjection_LeftHanded);

				// create dx projection
				asProjection[unEye] = D3DXMATRIX(&sProj.M[0][0]);
				D3DXMatrixTranspose(&asProjection[unEye], &asProjection[unEye]);

				// create eventual projection using inverse matrix of the head pose view matrix
				m_asProjection[unEye] = sVInv * sView[unEye] * asProjection[unEye];
			}
		}
#pragma endregion
	}
	else
	{
		// Initialize LibOVR, and the Rift... then create hmd handle
		ovrResult result = ovr_Initialize(nullptr);
		if (!OVR_SUCCESS(result))
		{
			OutputDebugString(L"[OVR] Failed to initialize libOVR.");
			return nullptr;
		}

		result = ovr_Create(&m_hSession, &m_sLuid);
		if (!OVR_SUCCESS(result))
		{
			OutputDebugString(L"[OVR] Failed to retreive HMD handle.");
			return nullptr;
		}
		else
			OutputDebugString(L"[OVR] HMD handle initialized !");

		if (m_hSession)
		{
			// get the description and set pointers
			m_sHMDDesc = ovr_GetHmdDesc(m_hSession);

			// Configure Stereo settings.
			ovrSizei sRecommenedTex0Size = ovr_GetFovTextureSize(m_hSession, ovrEye_Left,
				m_sHMDDesc.DefaultEyeFov[0], 1.0f);
			ovrSizei sRecommenedTex1Size = ovr_GetFovTextureSize(m_hSession, ovrEye_Right,
				m_sHMDDesc.DefaultEyeFov[1], 1.0f);

			ovrSizei sTextureSize;
			sTextureSize.w = max(sRecommenedTex0Size.w, sRecommenedTex1Size.w);
			sTextureSize.h = max(sRecommenedTex0Size.h, sRecommenedTex1Size.h);
			m_unRenderTextureWidth = (UINT)sTextureSize.w;
			m_unRenderTextureHeight = (UINT)sTextureSize.h;

			// get view offset
			ovrEyeRenderDesc asEyeRenderDesc[2];
			asEyeRenderDesc[0] = ovr_GetRenderDesc(m_hSession, ovrEye_Left, m_sHMDDesc.DefaultEyeFov[0]);
			asEyeRenderDesc[1] = ovr_GetRenderDesc(m_hSession, ovrEye_Right, m_sHMDDesc.DefaultEyeFov[1]);
			ovrVector3f asViewOffset[2] = { asEyeRenderDesc[0].HmdToEyePose.Position, asEyeRenderDesc[1].HmdToEyePose.Position };

			// get projection matrices left/right
			D3DXMATRIX asToEye[2];
			D3DXMATRIX asProjection[2];
			for (UINT unEye = 0; unEye < 2; unEye++)
			{
				// get ovr projection
				ovrMatrix4f sProj = ovrMatrix4f_Projection(m_sHMDDesc.DefaultEyeFov[unEye], 0.01f, 30.0f, ovrProjection_LeftHanded);

				// create dx projection
				asProjection[unEye] = D3DXMATRIX(&sProj.M[0][0]);
				D3DXMatrixTranspose(&asProjection[unEye], &asProjection[unEye]);

				// create view offset translation matrix
				D3DXMatrixTranslation(&asToEye[unEye], -asViewOffset[unEye].x, -asViewOffset[unEye].y, -asViewOffset[unEye].z);

				// create eventual projection
				m_asProjection[unEye] = asToEye[unEye] * asProjection[unEye];
			}
		}
	}

	return nullptr;
}
Exemple #29
0
void Matrix::setTranspose( const Matrix& mat ){
	D3DXMATRIX a;
	D3DXMatrixTranspose( &a, &D3DXMATRIX((float*)&mat.m ) );
	m.set( a );
}