Sign in to follow this  

Set Oculus Rift matrices in directx

This topic is 1363 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,
 
I am implementing the oculus in directx. Now everything works only I get double vision and I think the matrices are not set correctly. I think I do the exact same thing as in the SDK but I am not sure anymore. Can anyone see what I am doing wrong so the double vision goes away?
 
void RendererDX9::setViewMatrix(float lookAt[3], float up[3], float position[3], const OVR::Util::Render::StereoEyeParams& params, OVR::Util::Render::StereoConfig SConfig)
{
	float viewCenter = SConfig.GetHMDInfo().HScreenSize * 0.25f;
	float halfIPD = SConfig.GetHMDInfo().InterpupillaryDistance * 0.5f;

	D3DXMATRIXA16 viewMatrix;
	if (params.Eye == OVR::Util::Render::StereoEye_Left){
		D3DXMatrixTranslation(&viewMatrix, halfIPD, 0, 0);
		viewMatrix = scalarMultiply(&viewMatrix, viewCenter);
	}
	else{
		D3DXMatrixTranslation(&viewMatrix, -halfIPD, 0, 0);
		viewMatrix = scalarMultiply(&viewMatrix, viewCenter);
	}

	pd3dDevice->SetTransform(D3DTS_VIEW, &viewMatrix);
};
void RendererDX9::setProjectionMatrix(float fov, float nearClippingPlane, float farClippingPlane, float aspectRatio, const OVR::Util::Render::StereoEyeParams& params, OVR::Util::Render::StereoConfig SConfig)
{
	float projectionCenterOffset = SConfig.GetProjectionCenterOffset();
	//float projectionCenterOffset = 0.05;
	D3DXMATRIXA16 projectionCenterMatrix;
	D3DXMatrixPerspectiveFovLH(&projectionCenterMatrix,
		SConfig.GetYFOVRadians(),    // the horizontal field of view
		SConfig.GetAspect(),    // aspect ratio
		0.3f,    // the near view-plane
		farClippingPlane);    // the far view-plane

	D3DXMATRIXA16 projectionMatrix;
	if (params.Eye == OVR::Util::Render::StereoEye_Left){
		D3DXMatrixTranslation(&projectionMatrix, projectionCenterOffset, 0, 0);
		projectionMatrix = projectionMatrix * projectionCenterMatrix;
	}
	else{
		D3DXMatrixTranslation(&projectionMatrix, -projectionCenterOffset, 0, 0);
		projectionMatrix = projectionMatrix * projectionCenterMatrix;
	}

	pd3dDevice->SetTransform(D3DTS_PROJECTION, &projectionMatrix);    // set the projection transform	
};
Thanks in advance!

Share this post


Link to post
Share on other sites

This topic is 1363 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this