🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Pannini projection & screen to world

Started by
0 comments, last by ADDMX 3 years, 4 months ago

I'm developing an application that requires wide fields of view (HFOV > 140).

To eliminate the distortion at boundaries I'm using pannini projection (D=2)

http://tksharpless.net/vedutismo/Pannini/panini.pdf

All works as expected, but I have problem with mouse interactions, since the deprojection does not take pannini into account.

Is there something like 'reverse pannini' ?

for projection I use: (code stiched from above document)

//
// ScreenSpacePosition - position in screenspace from -1,-1 to 1,1
// d - Pannini D
// s - Pannini S
// FitScale - scaling factor to fit the result to screen
//
float2 PanniniProjection(float2 ScreenSpacePosition, float d, float s, float FitScale)
{
	float2 OM = ScreenSpacePosition * float2(ProjectionMatrixInverse[0][0], ProjectionMatrixInverse[1][1]);
	float InvL = rsqrt(1.0f + OM.x * OM.x);
	float SinPhi = OM.x * InvL;
	float TanTheta = OM.y * InvL;
	float CosPhi = sqrt(1.0f - SinPhi * SinPhi);
	float S = (d + 1.0f) / (d + CosPhi);

	float2 Result = S * float2(SinPhi, lerp(TanTheta, TanTheta / CosPhi, s));
	return Result * float2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * FitScale;
}

so first my mouse coordinates should go thru something like PanniniUnProjection, then oriceed with the usual way ?

This topic is closed to new replies.

Advertisement