So basically i have a near plane in distance 2.0 and far plane in distance 28.0 * 1000.0
Now when i click a screen i want to make a ray from mouse position to far plane (perspective projection)
i just tested 4 ways of doing that, none worked i am not sure wheres bug maybei shouldn't apply aspect ratio to screen height when calculating the size of near and fra plane?
so from start: (the idea top view)
HERES ANOTHER IMAGE SEE ctg(B) -<<< this is what i calc
to calc screen_w i use contanget function (with the fov angle divided by 2)
float a = fov / 2.0;
float cotangent = 1.0 / tan( a * imopi ); (since a is in degrees i must convert it by multiplying (pi/180.0) and ctg(x) is 1.0 / tg(x)
float ax = z_near / cotangent;
float screen_w = 2.0*ax; //multiple by two to get plane width
float yratio = 1.0 / aspect; //then use aspect ratio to find the plane height
float screen_h = screen_w * yratio;
//this is from the input (i calculate the percentage of the coord on screen)
float scr_coord_x = float(x) / float(screen_width);
float scr_coord_y = float(y) / float(screen_height);
//now to calculate the
FPP_CAM is a class that stores position of camera, and direction vectors such front, right and up
dir is froward direction
dirX is right direction
dirY is up direction;
vec3 start_pos = (FPP_CAM->pos + dir * z_near) + (-dirX * (screen_w / 2.0)) + (-dirY * (screen_h/2.0)); //basically here i am going to center of near plane and then go to the bottom left corner
ray.start = start_pos + (dirX * (screen_w * scr_coord_x)) + (dirY * (screen_h * scr_coord_y)); //then after calcing the (near plane in this case dimensions) i scale direction (right and up) by coordinate on the screen multiplied by corresponding near plane dimension.
do the analog for far plane
seems that only when i hit center of the screen i see proper result....