- Pure TI-BASIC Raycaster!
- 19 Mar 2017 02:18:33 pm
- Last edited by iPhoenix on 20 Mar 2017 02:40:44 pm; edited 10 times in total
I was told it couldn't be done. albeit by the non-programmer types
That got me agitated, so I did it.
I made the first (to my knowledge) completely pure TI-Basic raycaster.
For those who don't know what raycasting is, it is a method of drawing a 3D environment from a 2D map. It is also my area of expertise
Just input any 10x10 matrix in to [A], then it will render the first screen.
For example, I loaded the matrix displayed as a demo on the CC19 thread into [A], and got this:
There are a few things to notice:
The minimap, on the bottom right. Believe it or not, this is essential to the program, as it does all of its detection and ray projection on it. I also spent more time making the bevel look right then anything else. (This is an old version, and I forgot to put a marker for where the player is.)
The shading, which represents distance. I chose this color shading, as it was easier on the eyes. In theory, you could easily edit the program to do any color of shading you want.
The glitch, slightly left of center. This is a WIP, but I doubt I will be able to fix that. (as it is due to the way I am calculating my rays' paths/intersections, and there is no other efficient way.)
This program is not complete and I have a bit left to implement. Here we go:
1) Optimization. Currently, the 'game' is unplayable, as it takes it like 2 min to render a screen. Most of this is due to the programming language, but some of it can probably be sped up.
2) Key recognition. Not only is the 'game' too slow to be played, it does not recognize any keypresses. This is due to the fact that I wanted to post this early so you guys could all see it. Compared to the main bits, this should be really easy. (but still take awhile, arbitrary rotation measurements are not fun to work with. For example, looking forward (right on minimap) is 310 degrees. Don't ask me why.) Complete! (wow that was quick!)
3) Prettifying the code. Perhaps.
4) You tell me. I don't really know where to go with this...
I have submitted my program to the archives (for approval), if you want to play around with it.
litrosaist had a speed modification. x2
womp shows me I cannot type. x2
_iPhoenix_ (yay that's me) fixesstuff everything (i.e. movement, rotation).
_iPhoenix_ did some speed modification. x3
Code is currently ~628 bytes, which is really cool!
Code here:
Code:
That got me agitated, so I did it.
I made the first (to my knowledge) completely pure TI-Basic raycaster.
For those who don't know what raycasting is, it is a method of drawing a 3D environment from a 2D map. It is also my area of expertise
Just input any 10x10 matrix in to [A], then it will render the first screen.
For example, I loaded the matrix displayed as a demo on the CC19 thread into [A], and got this:
There are a few things to notice:
The minimap, on the bottom right. Believe it or not, this is essential to the program, as it does all of its detection and ray projection on it. I also spent more time making the bevel look right then anything else. (This is an old version, and I forgot to put a marker for where the player is.)
The shading, which represents distance. I chose this color shading, as it was easier on the eyes. In theory, you could easily edit the program to do any color of shading you want.
The glitch, slightly left of center. This is a WIP, but I doubt I will be able to fix that. (as it is due to the way I am calculating my rays' paths/intersections, and there is no other efficient way.)
This program is not complete and I have a bit left to implement. Here we go:
1) Optimization. Currently, the 'game' is unplayable, as it takes it like 2 min to render a screen. Most of this is due to the programming language, but some of it can probably be sped up.
3) Prettifying the code. Perhaps.
4) You tell me. I don't really know where to go with this...
litrosaist had a speed modification. x2
womp shows me I cannot type. x2
_iPhoenix_ (yay that's me) fixes
_iPhoenix_ did some speed modification. x3
Code is currently ~628 bytes, which is really cool!
Code here:
Code:
Degree
0→Xmin
{BLACK,DARKGRAY,GRAY,MEDGRAY,LTGRAY,WHITE,WHITE→L₁
70→Xmax
-20→Ymin
20→Ymax
90→θ
310→R
119→S
219→T
For(A,1,51,-1
For(B,1,100,50
Pxl-On(163-A,263-B,GRAY
Pxl-On(163-B,263-A,GRAY
Pxl-On(164-A,264-B,GRAY
Pxl-On(110+A,210+B,MEDGRAY
Pxl-On(110+B,210+A,MEDGRAY
Pxl-On(109+B,209+A,MEDGRAY
Pxl-On(109+A,209+B,MEDGRAY
End
End
For(A,1,10
For(B,1,10
If [A](A,B
Then
For(C,1,5
For(D,1,5
Pxl-On(110+(5A-4+C),210+(5B-4+D),BLACK
End
End
End
End
End
Repeat Ans
For(A,6,13.5,.45
Line(Xmin,A,Xmax,A,WHITE
End
DelVar N
Pxl-Off(S,T
For(A,70-R,1-R,-1
N+1→N
DelVar C
cos(A→P
sin(A→Q
Repeat K=45 or C>20
C+1→C
pxl-Test(int(S+CP),int(T+CQ
End
If C<20:Then
int(C/3→V
int(40/C)/2→W
If W>4
4→W
For(B,-W,W
For(D,1,2
Pt-On(N,B,D,L₁(V
End
End
End
End
Pxl-On(S,T
Repeat Ans
getKey
End
Pxl-Off(S,T
Ans→K
If K=24
R-45→R
If K=26
R+45→R
R-220→θ
If K=25
Then
int(S-3cos(θ→S
int(T+3sin(θ→T
Else
If K=34
Then
int(S+3cos(θ→S
int(T-3sin(θ→T
End
End
Pxl-On(S,T
Pause
End