Jump to content
  • Advertisement
Sign in to follow this  
Fish_tacoz

Raycasting Angle

This topic is 1407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

             Ok, so I've read Permadi's tutorial on Raycasting(http://www.permadi.com/tutorial/raycast/index.html), and I'm having a little bit of confusion over 2 things.

First of all, it mentions that you can calculate the subsequent angles by adding 60/320 to the angle. However, it is also recommended that you put your values into an array that has already rendered all of your cos, sin, and tan values. My question is how can I access the correct value, because the angle that I use as an index (prev+60/320) isn't an integer. Should I just cast the value without regard for accuracy?

Secondly, the tutorial also mentions correcting the fisheye effect by multiplying the distance by beta. Should beta always be 30/-30, or is it simply your current angle/2? -Thanks

Edited by Fish_tacoz

Share this post


Link to post
Share on other sites
Advertisement

It would help a bit if you provide more specific references among the 20 different pages that the tutorial comprises.

 

With regard to pre-calculating values and storing them in an array, I could find nothing that stated the array was to be indexed by angle. It's likely the intent is to provide (e.g.) a table of pre-calculated values indexed by the current loop index during rendering. I.e., something like:

float angle = start_angle;
float deltaAngle = 60.0f/320.0f;
float sinValueArray[320];
float cosValueArray[320];
// calculate 320 values
for(int i=0; i < 320; ++i)
{
   angle = start_angle + i * deltaAngle;
   sinValueArray[i] = sin(angle);
   cosValueArray[i] = cos(angle);
}
...
// later the arrays are used repeatedly
for(int i=0; i < 320; ++i)
{
   // lookup precalculated values
   float sinValue = sinValueArray[i];
   float cosValue = cosValueArray[i];
   // do the rendering calcs using sines and cosines
   ...
}

Share this post


Link to post
Share on other sites

Ah, my bad about the pages. However, I was mentioning most of the pages with trigonometric values in them such as (http://www.permadi.com/tutorial/raycast/rayc7.html). Also, with the method that you mentioned above, would you not have to recalculate those 320  values each time you rotate your start_angle? And the fisheye article is here: http://www.permadi.com/tutorial/raycast/rayc8.html

Edited by Fish_tacoz

Share this post


Link to post
Share on other sites

would you not have to recalculate those 320 values each time you rotate your start_angle?

 

Good point. The array(s) should then be sized for 360 / (60/320) values. I.e., each array size would be 1920, only about 8k each. The index would be (int)( angle / (60/320) ). It you force the user's facing angle to always be a multiple of 60/320 (0.1875 degrees), that should work out fine.

 

WRT to beta being 30/-30, that's due to the FOV being 60 degrees. If you change the FOV to something other than 60, then, yes, it would be +/- FOV/2. N.B., if you do change the FOV, then you'll have to change the size of and recalculate the values in the above mentioned arrays appropriately.

Edited by Buckeye

Share this post


Link to post
Share on other sites


so beta is based on the FOV, instead of the angle of the current ray being cast?

 

No. Read the article. "... where BETA is the angle of the ray that is being cast relative to the viewing angle." As the article itself states, "Because we have 60 degrees field of view, BETA is 30 degrees for the leftmost ray and it is -30 degrees for the rightmost ray." [emphasis mine] The minimum/maximum values of BETA are based on the FOV.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!