Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Raycasting help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
killjoy1337




PostPosted: Tue Apr 20, 2010 12:51 pm   Post subject: Raycasting help

I am trying to design a basic raycasting engine in turing, I am using the tutorial at http://www.permadi.com/tutorial/raycast/


My problem is that when I try to do the equation:

A.x = Px + (Py-A.y)/tan(ALPHA)

When I get the tangent of the angle of the ray it varies greatly and is obviously not the right answer, sometimes it gets into the thousands. I am not sure what the problem is, if it is turing (with it's x,y plane being down-up incresing instead of the other way around) or my math itself, any help would be appreciated

Note: I have tried tand(ALPHA) and tan(ALPHA) in turing
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Tue Apr 20, 2010 1:39 pm   Post subject: RE:Raycasting help

tan is messed up in Turing, make your own function that returns sin(a) / cos(a)
Hope that helps!
The_Bean




PostPosted: Tue Apr 20, 2010 6:49 pm   Post subject: Re: Raycasting help

The tan function works perfectly fine for me in Turing.

Getting results in the thousands is reasonable
code:

tand(89.)=           57.289962
tand(89.9)=          572.957213
tand(89.99)=         5729.577893
tand(89.999)=        57295.779508
tand(89.9999)=       572957.795157
tand(89.99999)=      5.729578e6
tand(89.999999)=     5.729578e7
tand(89.9999999)=    5.729578e8
tand(89.99999999)=   5.729577e9
tand(89.999999999)=  5.729439e10
tand(89.9999999999)= 5.729368e11


Which is visible by the graph of tan and better explained here http://www.wolframalpha.com/input/?i=lim+n-%3E+(pi/2)+tan(n)
CodeMonkey2000




PostPosted: Tue Apr 20, 2010 8:15 pm   Post subject: RE:Raycasting help

Are you sure your ALPHA is correct?

EDIT: Try drawing the grid and the basic ray to see what's going on. And if you are using arc tan to compute alpha, you could just not take the arc tan altogether and remember the ratio instead of the angle.
killjoy1337




PostPosted: Wed Apr 21, 2010 9:09 am   Post subject: Re: Raycasting help

Here is my code so far, I just have it printing the value of x_step which is 64/tan(a), at some values it looks correct but then it shoots way up into the thousands around 360/0 and 180 and 90 and 270, any help would be appreciated. Also if there is a better way of doing raycasting in turing please let me know, thanks for the suggestions so fars


RayCasting.t
 Description:
Raycasting problem

Download
 Filename:  RayCasting.t
 Filesize:  3 KB
 Downloaded:  93 Time(s)

DemonWasp




PostPosted: Wed Apr 21, 2010 9:29 am   Post subject: RE:Raycasting help

Well, tan ( 90 ) = 0, tan ( 180 ) = 0, ... you do remember what happens when you divide by zero, right?
CodeMonkey2000




PostPosted: Wed Apr 21, 2010 11:02 am   Post subject: RE:Raycasting help

From the looks of your cast ray procedure, I don't know if you are doing it correctly. Like I said before, draw the ray to make sure. And you missed the step of getting a.x and a.y. Just by looking at the numbers, it is basically impossible to tell if you are right or wrong. And for angles 360,90,270 and 180, like DemonWasp pointed out, these are special cases. You have to understand how raycasting works to resolve them properly.

Also search for other raycasting engines, like mine or asiansensation's. The one I did ages had 4 versions, a 2d version to make sure my rays were correct, a non textured version, a textured version and a high resolution version.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: