CodeWalrus

General => General Help & Troubleshooting => Topic started by: ACagliano on March 17, 2017, 10:02:59 PM

Title: C Programmers, Help With Raycasting Algorithm Needed
Post by: ACagliano on March 17, 2017, 10:02:59 PM
Cross-post

So I'm looking for someone decently skilled with C programming to help me learn the ropes of designing a textured raycaster. I have a textured raycaster in C++ that I've been trying to port, but my skills aren't sufficient enough to percieve differences between C and C++ and implement proper substitution, so I am asking for help.

ps: the C++ snippet im looking at is http://lodev.org/cgtutor/files/raycaster_textured.cpp
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Ranman on March 18, 2017, 03:42:56 AM
Change
   #include <cmath>
to
   #include <math.h>
_____________________________________________

I did not see anywhere in your single C++ file that makes use of the following headers.
   #include <string>
   #include <iostream>
so comment these lines out and see if it still compiles.

I presume though that there are more files in your project that will make use of them. So your going to have some work here.
  For instance: cout << "hello world" will need to be change to printf("hello world")
_____________________________________________

C does not make use of namespaces... so get rid of them in all of your files
   using namespace QuickCG;
_____________________________________________

Your file is also using the Vector container from the Standard Template Library (STL)
The Vector container is basically an array with a dynamic size.

You may or may not have quite a bit of work to do here.
   std::vector<Uint32> texture[8];
will need to be changed to something like this:
   Uint32 texture[8][max_value];
everything that reference or acts upon 'texture' will need to be modified to act like a static sized C array.
you are going to need to know the 'max_value' before hand.
 
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: ACagliano on March 21, 2017, 01:09:54 PM
Thanks! I've started working on making modifications. Now, for this raycaster, on a 320x240 screen, what sprite sizes would you guys recommend? This algo uses 64x64, but also for a larger screen size
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Ranman on March 22, 2017, 01:37:37 AM
Quote from: ACagliano on March 21, 2017, 01:09:54 PM
Thanks! I've started working on making modifications. Now, for this raycaster, on a 320x240 screen, what sprite sizes would you guys recommend? This algo uses 64x64, but also for a larger screen size
I've never attempted a first-person shooter. Your 320x240 lcd game will possibly need a combination of sprite sizes: 16x16 for very far away, 32x32 for far away, 64x64 medium distance, maybe larger. Some of the games I've played, when the enemies are right in your face, they take up the entire screen. You'll probably need to look into some scaling routines.
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: kotu on March 22, 2017, 01:59:04 AM
Quote from: ACagliano on March 21, 2017, 01:09:54 PM
Thanks! I've started working on making modifications. Now, for this raycaster, on a 320x240 screen, what sprite sizes would you guys recommend? This algo uses 64x64, but also for a larger screen size

Are you making a game for the TI-84+CE ??

You will have nowhere near enough power for a raycaster I am afraid, if that is what you are doing.

Even if you just make a simple polygon renderer I doubt you will have enough FPS for a First person shooter D: soz. And it would have to be in assembler.

*edit*
you might want to look at gLib
https://codewalr.us/index.php?topic=199.msg53456#msg53456 (https://codewalr.us/index.php?topic=199.msg53456#msg53456)
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Dream of Omnimaga on March 22, 2017, 04:47:04 PM
Kotu the TI-83+ can run Gemini perfectly fine at 6 MHz. The CE has 48 MHz ez80 and screen resolution is not such a sserious issue with the 8 bits mode. The SNES also runs Wolfeinstein 3D somewhat fine
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: p4nix on March 22, 2017, 04:49:27 PM
Quote from: kotu on March 22, 2017, 01:59:04 AM
You will have nowhere near enough power for a raycaster I am afraid, if that is what you are doing.

Even if you just make a simple polygon renderer I doubt you will have enough FPS for a First person shooter D: soz. And it would have to be in assembler.
You know that ray casting != ray tracing? Also, if you have trouble with fps just take half the slices, but even in C I don't think making a fast raytracer is that big of a problem if you got efficient algorithms - same goes for asm ofc.
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: TheMachine02 on March 22, 2017, 04:53:52 PM
Raycasting should definitly be faster than polygon engine, if done right. Just totally different use  :P
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: tr1p1ea on March 22, 2017, 08:57:15 PM
Yes I imagine that a raycaster would be quite doable on the CE, even in C (with asm libs for drawing etc however).
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Dream of Omnimaga on March 23, 2017, 05:25:21 AM
Could the Gemini 3D engine just be ported over or would it require heavy modifications due to the Z80->ez80 transition? Someone re-used it for a full screen grayscale FPS once so I'm sure the source code is still available.
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: _iPhoenix_ on March 24, 2017, 11:10:23 PM
Quote from: kotu on March 22, 2017, 01:59:04 AM
Quote from: ACagliano on March 21, 2017, 01:09:54 PM
Thanks! I've started working on making modifications. Now, for this raycaster, on a 320x240 screen, what sprite sizes would you guys recommend? This algo uses 64x64, but also for a larger screen size

Are you making a game for the TI-84+CE ??

You will have nowhere near enough power for a raycaster I am afraid, if that is what you are doing.

Even if you just make a simple polygon renderer I doubt you will have enough FPS for a First person shooter D: soz. And it would have to be in assembler.

*edit*
you might want to look at gLib
https://codewalr.us/index.php?topic=199.msg53456#msg53456 (https://codewalr.us/index.php?topic=199.msg53456#msg53456)

If I can make one in pure TI-basic, he can make one in C. (https://www.cemetech.net/forum/viewtopic.php?t=13579&highlight=)
Also, I ran it at about 2000 times faster (cemu plus timelapse), and it was playable. This is in an unpublished test version that has monsters (with exactly zero sprites, the code treats it like a wall), inventory panels, and guns. It was actually playable.

Considering ASM and C are much faster then basic, I'd say it's possible.
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Snektron on March 25, 2017, 12:28:39 AM
I made a nice raycaster a while back: https://github.com/QuantumInfinity/AntiCaster It needs some updating though, since i could optimize out a square root.
Also i should change to a better build system than eclipse project builder... IF i ever get around to it. Anyway maybe you could learn something from the source, though its probably quite complicated and
not very well commented (read: not at all).
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Dream of Omnimaga on March 25, 2017, 05:40:00 AM
@Snektron was this your Euclidian raycaster thing? That was kinda cool.
Title: Re: C Programmers, Help With Raycasting Algorithm Needed
Post by: Snektron on March 25, 2017, 02:50:33 PM
Non euclidean, but yes