Raycasting Angle

Started by
6 comments, last by Fish_tacoz 9 years, 6 months ago

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

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
   ...
}

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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

the fisheye beta angle is from absolute -30 to 30.


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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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


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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Ok, I see. So I can increment the beta(starting from the left) by FOV/rays casting to get the correct beta angle.

This topic is closed to new replies.

Advertisement