Jump to content
  • Advertisement
Sign in to follow this  

3D Problem transforming vertices in RHW projection

Recommended Posts


I have a big old project that cannot be converted from D3D_XYZRHW to D3D_XYZ.

The problem is whatever polygons around me distort, but everything in the distance is good.

It seems to happen when NDC space vertex.x <= 0.  I guess clipping must be the solution; but I don't know how.

Here is my current code.

VERTEX_DECL LocalToScreen( const Vector& vector ) {
	VERTEX_DECL vertex;
	vertex.xyz = vector - Game::Eye;
	vertex.xyz = Game::CameraOrientation * Game::ProjectionMatrix * vertex.xyz;

	vertex.xyz.x = vertex.xyz.x / vertex.xyz.z;
	vertex.xyz.y = vertex.xyz.y / vertex.xyz.z;
	vertex.xyz.z = 1.0 / vertex.xyz.z;
        // This stops polygons around camera distorting; but it fully removes them which
    	//  is not a proper solution.  I think I need some kind of clamping.
	if ( vertex.z <= 0.0 ) {
		return vertex;

	vertex.xyz.x = vertex.xyz.x * Game::HalfViewportWidth + Game::HalfViewportWidth;
	vertex.xyz.y = vertex.xyz.y * -Game::HalfViewportHeight + Game::HalfViewportHeight;
	vertex.rhw = vertex.xyz.z;
	vertex.xyz.z = vertex.xyz.z * 0.000588; // Legacy.  This doesn't seem to do anything.

	return vertex;



Edited by scragglypoo

Share this post

Link to post
Share on other sites

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  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!