I have a trouble in gluperspective method.
I want to implement the gluperspective method, but I failed.
Could you help me? many thanks!
this method has some bugs which I couldn’t find.
_3DPoint _sysPerspective(double fovy,
double aspect,
double zNear, double zFar,
double x,double y,double z)
{
_3DPoint point;
printf("x=%f y=%f z=%f",x,y,z);
double sine, cotangent, deltaZ;
double radians = fovy / 2 * PI / 180;
deltaZ = zFar - zNear;
sine = sin(radians);
if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
return point;
}
cotangent = cos(radians) / sine;
point.x= (cotangent/aspect)*x/z;
point.y = cotangent*y/z;
point.z = z/deltaZ-zNear/deltaZ;
printf(" ->x=%f y=%f z=%f",x,y,z);
return point;
}
fovy=60 aspect=800/600 zNear=5 zFar=100
I try to execute the following args.
x=50 y=50 z=50 ->x=1.732051 y=1.732051 z=0.473684
x=100 y=50 z=50 ->x=3.464102 y=1.732051 z=0.473684
x=50 y=100 z=50 ->x=1.732051 y=3.464102 z=0.473684
x=100 y=100 z=50 ->x=3.464102 y=3.464102 z=0.473684
x=50 y=50 z=100 ->x=0.866025 y=0.866025 z=1.000000
x=100 y=50 z=100 ->x=1.732051 y=0.866025 z=1.000000
x=50 y=100 z=100 ->x=0.866025 y=1.732051 z=1.000000
x=100 y=100 z=100 ->x=1.732051 y=1.732051 z=1.000000
x=300 y=300 z=300 ->x=1.732051 y=1.732051 z=3.105263
x=500 y=300 z=300 ->x=2.886751 y=1.732051 z=3.105263
x=300 y=500 z=300 ->x=1.732051 y=2.886751 z=3.105263
x=500 y=500 z=300 ->x=2.886751 y=2.886751 z=3.105263
x=300 y=300 z=500 ->x=1.039230 y=1.039230 z=5.210526
x=500 y=300 z=500 ->x=1.732051 y=1.039230 z=5.210526
x=300 y=500 z=500 ->x=1.039230 y=1.732051 z=5.210526
x=500 y=500 z=500 ->x=1.732051 y=1.732051 z=5.210526
I get the error results. what’s the right results?
how can I modify it?
how can I get the real screen pixel point? which method or ways?