You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

[code-golf] Pure TI-Basic Raycaster.

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/Calculator Development publicado por u/_iPhoenix_ March 19, 2017, 08:50:31 PM

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
Last Edit: March 20, 2017, 12:59:53 AM by _iPhoenix_
Inicia sesión o crea una cuenta para dejar un comentario
u/Ranman March 19, 2017, 10:58:04 PM
Fantastic work _iPhoenix_.  :thumbsup:

Optimizing will be fun and challenging.
u/_iPhoenix_ March 20, 2017, 12:55:52 AM
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
u/Dream of Omnimaga March 20, 2017, 06:02:17 AM
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
Last Edit: March 20, 2017, 06:07:15 AM by DJ Omnimaga
u/_iPhoenix_ March 20, 2017, 11:04:27 AM
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.
u/c4ooo March 20, 2017, 10:39:35 PM
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.)
Last Edit: March 20, 2017, 10:47:00 PM by c4ooo
u/ordelore March 20, 2017, 10:43:06 PM
Or Taylor approximations instead of Trig functions
u/c4ooo 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.
u/Ranman March 20, 2017, 10:55:54 PM
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?
u/_iPhoenix_ March 20, 2017, 11:23:00 PM
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.
Start a Discussion

b/Calculator Development

Showcase your newest TI, Casio, HP, Numworks or Sharp calculator projects here, discuss programming and share or browse user tutorials!

320
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal