Original Post
I am writing a raycaster for GBA and I having a problem with one of the functions. The function in question finds out if a point is in the field-of-view or not, the field of view is represented by a camera position (x,y), maximum distance from camera to display (md), look direction (l), and viewing angle (va).
The function works when it just tests distance, but when I try to test with the viewing-angle strange things occur.
Here is the code and code for related functions:
Thanks for all help! ~SPH
[edited by - ShmeeBegek on March 11, 2003 4:53:00 PM]
struct fov_type{
/*
Position (x,y), maximum distance, look angle, viewing angle
*/
float x,y,md,l,v;
};
float f_angleFromPoints(float x1,float y1,float x2,float y2)
{
if(x1==x2 && y1==y2)
return 0.0f;
return atan2(y2 - y1,x2 - x1);
}
bool R_pointInFov(struct fov_type fov,struct point op)
{
float halfv=fov.v/2.0f;
float amin=fov.l-halfv;
float amax=fov.l+halfv;
float acat=0.0f;
float dist=0.0f;
if(fov.x == op.x && fov.y == op.y)
return false;
// This part tests viewing-angle... (problematic)
acat=f_angleFromPoints(fov.x,fov.y,op.x,op.y);
if(acat < amin || acat > amax)
return false;
// This part is working well, it tests maximum distance
dist=f_distance(fov.x,fov.y,op.x,op.y);
if(dist > fov.md)
return false;
return true;
}