Jump to content
  • Advertisement
Sign in to follow this  

3D Problem transforming vertices in RHW projection

This topic is 425 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


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
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!