# Raycasting Angle

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

## 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 on other sites

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 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 on other sites

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

##### 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 on other sites

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

##### 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 on other sites
Ok, I see. So I can increment the beta(starting from the left) by FOV/rays casting to get the correct beta angle.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×