Skip to main content
gamedev.net
🔒 Locked

Something wrong using atan2...

Started by ShmeeBegek Mar 11, 2003 at 3:51 PM 4 replies 400+ views
Original Post
ShmeeBegek
ShmeeBegek
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:
    
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;
}
    
Thanks for all help! ~SPH [edited by - ShmeeBegek on March 11, 2003 4:53:00 PM]
AIM ME: aGaBoOgAmOnGeR
Zipster
Zipster
The trigometric functions all work in radians, not degrees, so that might be where you''re getting caught up.
ShmeeBegek
ShmeeBegek

Nope, that doesn''t seem to be it primarily since there are no defined angles here, its all inputted from a structure, and that structure is correct.

Thanks again, ~SPH
AIM ME: aGaBoOgAmOnGeR
Zipster
Zipster
That has nothing to do with it, if those inputted values are in degrees, either the correct measurements or not, then atan2 won''t give you what you want. As a small test, after you get acat, convert it into degrees by scaling it by (180 / PI) - ya know, just to make sure
ShmeeBegek
ShmeeBegek
Here is a picture of the pattern this function should create if graphed.



This is the fov I am trying to acheive (this is at about 60 degrees viewing angle, and in the implementation it is of course in radiens).

Thanks, ~SPH


[edited by - ShmeeBegek on March 11, 2003 7:09:42 PM]

[edited by - ShmeeBegek on March 11, 2003 7:11:27 PM]

[edited by - ShmeeBegek on March 11, 2003 7:12:05 PM]
AIM ME: aGaBoOgAmOnGeR
ShmeeBegek
ShmeeBegek

I out of interest compiled the source in MSVC++ with OpenGL''s GL_POINTS shape type, lo-and-behold the function worked perfectly. I guess this says something about my emulator compiler or GBA itself... I''m not sure.

I''d appriciate any insight into this but it is not expected ~SPH
AIM ME: aGaBoOgAmOnGeR

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.