Advertisement

Problem transforming vertices in RHW projection

Started by October 21, 2017 12:36 AM
0 comments, last by scragglypoo 7 years, 3 months ago

Hello,

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;
}

 

 

This topic is closed to new replies.

Advertisement