Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : 3D Very Simple Raycaster
Author | Message | ||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
Hello, out of interest for a 3D world and inspired by a YouTube tutorial with C and OpenGL, I created this simple "3D Very Simple Raycaster" completely in MMBasicâ„¢. There is still a lot of potential for improvement. But now I wanted to show you the fruits of my work. Have fun with it! [w] [a] [s] [d] to move / [m] toggle map & 3d Unfortunately, the programme does not work with mmb4w, so it can only be used with the original: PicoMiteVGA MMBasic Version 5.08.00 OPTION COLOURCODE ON OPTION KEYBOARD GR OPTION CPUSPEED (KHz) 252000 3d_VSR.zip |
||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
By the way, here is a bug with OPTIONs > option cpuspeed 400000 Error : 400000 is invalid (valid is 126000 to 378000) > option cpuspeed 378000 Error : CpuSpeed 126000, 252000 only > |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4232 |
Hi homa, This is not a bug. Peter has discovered that some RP2040 chips cannot be "overclocked" from 133MHz to 378MHz. To make sure everyone can run his code, he chose to limit the range to 252MHz which has proven to work reliable. A wise decission. I understand the bug in the help text versus the actual OPTION setting. Volhout P.S. your ray caster works nice...slow...but nice... Edited 2024-03-04 18:06 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
yes thanks, any ideas on how to speed this up? maybe with a csub? Although I haven't done anything with it yet, it would be worth a try ... |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
Nice, maybe we can learn from each other 1 1/2 years ago I also started a Raycasting proof of concept from the same source (yt video from 3dsage) I found that 2 casts per column (for horizontal and vertical tests) naturally take twice as much time but I hadn't found anything on how to compress this into one single cast however, i don't think we can create a kind of wolfenstein 3D with it in Basic Cheers Martin Edited 2024-03-04 19:59 by Martin H. 'no comment |
||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
Hi Martin, wow, impressive! Thanks for the link. I'm glad I didn't see this before. At least I was able to look at it in depth, analyse the code, understand it and do it myself. Yes, the speed is a problem. But I think if we could solve that, the even bigger problem would be the lack of colour. That's just not enough. A Pico with 256 colours would be fantastic! I don't think we could do anything decent with textures and those few colours. By the way, 3dsage seems to have changed the code... unfortunately the video didn't match the git code at all. It took me a long time to understand it, but it was all the better for me! Anyway, it was fun and I learnt something. Matthias |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
Of course, by translating the code yourself, you become much more familiar with the functions than by simply typing them out. It would be great if you could find ways to increase the speed.. The number of colors is really not high. Nevertheless, I tried to get the most out of the RGB 121, for example, the graphics for Petsciirobots or for my new Alien Syndrome project. So I'm not worried about that. With clever hatching and dithering, you can achieve an appealing result even with the 16 Pico colors. Cheers Martin Edited 2024-03-05 00:32 by Martin H. 'no comment |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3801 |
A quick glance only. Some things could be calculated fewer times e.g. Rad(ra) John |
||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
Hi Martin, the graphics look impressive , but I don't think you can get the textures that clean with the dithering. But my interest is on the rise. Reducing the viewing angle, and therefore the beam tracking, gives the biggest gain. Then I did a rebuild down from my memory for speed reasons. This resulted in the version with the visualisation. Here you can see which vertical and horizontal lines are hit by the visualisation beam. @martin: You have to check whether the horizontal or vertical ends first ... but it takes place in one loop. A very small tweak compared to the first version. But the throw of the first version was quite okay! The rest of the optimisation doesn't help. However, I have encountered new problems with the optimisations. See the pictures. If you're interested in my wild developer code with comments, just let me know and I'll upload it. Would a routine in CSUB really improve the speed? Can I access the values from there like mapW()? In other words, just pass the angle of the visible steel to be checked to the function, the function will find the GLOBAL variables and can work with them, and then just return the data for drawing? (And later the tile hit for the matching texture?!) How and where can I start learning CSUBs? Is all that explanation? https://www.thebackshed.com/forum/ViewTopic.php?TID=12289&PID=149258#149258 Or is there something special for the pico? Matthias |
||||
homa Guru Joined: 05/11/2021 Location: GermanyPosts: 351 |
YES, YES, YES! The start has been made with CSUB, and I'm grateful for that. BUT there are still many questions and I am not familiar with C. So help is very welcome. So my question of how to access the mapW array still remains :-) Matthias > run 1234567890 0987654321 11111111000000001111111100000001 17 > ' csub demo ' and my try - homa 03/2024 ' start from here ' https://www.thebackshed.com/forum/ViewTopic.php?TID=14126 ' a$="1234567890" Print a$ strrev a$, b$ Print b$ ' 'Dim integer bc=0 t%=&hFF00FF01 Print Bin$(t%) bitcount t%, bc% Print bc% ' ' 'CSub strrev FROM forum '00000000 'B085B480 6078AF00 687B6039 60BB781B B2DA68BB 701A683B 60FB2301 68BAE00D '1AD368FB 687A3301 6839441A 440B68FB 701A7812 330168FB 68BB60FB 68FA3301 'D3EC429A BF00BF00 46BD3714 4770BC80 'End CSub 'File strrev.bas 05-03-2024 22:29:27 - slightly different, but running CSub strrev 00000000 B084B580 6078AF00 687B6039 60BB781B B2DA68BB 701A683B 60FB2301 68BAE00D 1AD368FB 687A3301 683918D2 18CB68FB 701A7812 330168FB 68BB60FB 68FA3301 D3EC429A 46C046C0 B00446BD 4347BD80 End CSub 'File bitcount.bas 05-03-2024 23:29:42 - my try CSub bitcount 00000000 B086B5B0 6078AF00 68796039 68496808 61796138 21002000 60F960B8 6939E01B 40012001 6979000A 40012000 0011000B D0074319 68F968B8 25002401 41691900 60F960B8 07C96979 08406938 61394301 10496979 69396179 43016978 6839D1DF 68FB68BA 604B600A 46BD46C0 BDB0B006 End CSub ' 'void bitcount(long long int *in, long long int *out) { ' ' long long int n; ' long long int b; ' ' n=*in; ' ' for (b = 0; n != 0; n >>= 1) ' if (n & 01) ' b++; ' ' *out=b; ' '} |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3801 |
I would not try to access a global but instead pass it as a parameter. John |
||||
Print this page |