Join us on Discord!
You can help CodeWalrus stay online by donating here.

[code-golf] Pure TI-Basic Raycaster.

Started by _iPhoenix_, March 19, 2017, 08:50:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

_iPhoenix_


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


litrosaist had a speed modification. x2
womp shows me I cannot type. x2


Code here, but movement is all screwed up:
Degree
0→Xmin
{BLACK,DARKGRAY,GRAY,MEDGRAY,LTGRAY,WHITE,WHITE→L₁
70→Xmax
-­20→Ymin
20→Ymax
310→R
119→S
219→T
Lbl RD


ClrDraw
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
DelVar N
For(A,70-R,1-R,­1
N+1→N
DelVar C
cos(A→P
sin(A→Q
Repeat Ans
C+1→C
pxl-Test(int(S+CP),int(T+CQ
End
If C<20:Then
int(C/3→V




For(B,­int(40/C)/2,int(40/C)/2
For(D,1,2
Pt-On(N,B,D,L₁(V
End
End
End
End
Pxl-On(S,T
Repeat Ans
getKey
End
If K=24
R-2→R
If K=26
R+2→R
If K=25
Then
int(S+5cos(R→S
int(T+5sin(R→T
Else
If K=34
Then
int(S-5cos(R→S
int(T-5sin(R→T
End
End
If K=45:Stop
Goto RD



Also: There is now a code golf happening with this code!! Who ever can get it the fastest wins a small banner (for sig) and (maybe) some karma or something.
Formula (for score):
speed^2+2size
  • Calculators owned: Two TI-84+ CE's
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me
Evolution of my avatar:

Ranman

Fantastic work _iPhoenix_.  :thumbsup:

Optimizing will be fun and challenging.
  • Calculators owned: TI-89 HW1, TI-92+, Casio 9860G Slim, Casio fx6300, Tandy PC7
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.

_iPhoenix_

Agreed. I might do a code golf on it, I don't know.


After a bit of thinking, I think I will.


Whoever can get the program the fastest wins. Also, size counts, but not as much as speed.


Formula:
speed^2+2size
  • Calculators owned: Two TI-84+ CE's
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me
Evolution of my avatar:

Dream of Omnimaga

#3
Interesting. About the frame rate, I think it could probably be improved but it depends of how you made the program. Calc84maniac once made a TI-BASIC raycaster that ran at 1 frame per minute on the TI-84 Plus but it used a brick texture (although no shading). The 84+ drew pixels faster, though. It's a nice proof of concept, though. Do you think this program would be easy to convert to ICE Compiler? The language is somewhat similar to TI-BASIC and xLIBC, but it doesn't have a Sin() command nor any other trigonometry command, so you would need to find a way to do 3D without trig
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

_iPhoenix_

I believe I would have to use binary space partitioning, as Raycasting requires trig, and decimals. However, it would remove all speed benefits of using ICE.
  • Calculators owned: Two TI-84+ CE's
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me
Evolution of my avatar:

c4ooo

#5
You could use lookup tables of trig functions ;)
Look up tables are bigger but on the other hand faster than Axe's (and probably ICE's trig functions.)

ordelore

Or Taylor approximations instead of Trig functions
  • Calculators owned: TI-84+SE, TI_Nspire CX
Calc Wars is still alive (I hope)

c4ooo

@_iPhoenix_  can you explain in detail how the minimap is used to project the 3D image? Seems pretty interesting/clever for TI-BASIC. :)

As for increasing speed, i heard Lists are faster than Matrixes, but i may be wrong. ALso since you use the minimap to project it probably won't make an improvement.

Ranman

Quote from: _iPhoenix_ on March 20, 2017, 12:55:52 AM
Agreed. I might do a code golf on it, I don't know.

What is a code golf?
  • Calculators owned: TI-89 HW1, TI-92+, Casio 9860G Slim, Casio fx6300, Tandy PC7
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.

_iPhoenix_

Quote from: c4ooo on March 20, 2017, 10:53:04 PM
@_iPhoenix_  can you explain in detail how the minimap is used to project the 3D image? Seems pretty interesting/clever for TI-BASIC. :)

As for increasing speed, i heard Lists are faster than Matrixes, but i may be wrong. ALso since you use the minimap to project it probably won't make an improvement.
Yes. I draw the minimap, then used pxl test, at different angles for the raycasting.

And a code golf is where users try to shorten or speed up a section of code, in a competitive fashion.

Golf: smallest score wins
Code Golf: smallest size/time wins.
  • Calculators owned: Two TI-84+ CE's
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me
Evolution of my avatar:

Powered by EzPortal