Author Topic: Nspire Raycaster  (Read 95000 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
Re: Nspire Raycaster
« Reply #225 on: April 16, 2010, 05:44:25 pm »
You may want to post the source in case certain people may be able to help. SirCmpwn did stuff with C-like languages before and Critor did the java raycaster

I have worked with high-level C# and z80 assembly, and have never done raycasting.  I am flattered you think I can help, though.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Nspire Raycaster
« Reply #226 on: April 16, 2010, 06:58:13 pm »
aaah ok ^^
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: Nspire Raycaster
« Reply #227 on: April 18, 2010, 12:14:35 am »
bwang, any time you write data to floats, if you write integer type values like

float var;

var = 1;

then the compiler could possibly see 1 as an integer and tries to treat "var" as such.

try something like this instead

float var;

var = 1.0;

C can be very frustrating in that regard.

I really didn't see anything else that stuck out to me why it would only happen when you changed datatypes though.

Also, I had great difficulty following parts of your code at first, it would really help me if you went through and commented sections of your code describing what each chunk is supposed to accomplish, so that I may be able to spot whats going on.

Good job so far with what you're doing. If you want me to look at anything else then please let me know. You can pm me with code snippets and general questions and such. Good luck.
« Last Edit: April 18, 2010, 12:24:36 am by AaroneusTheGreat »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Nspire Raycaster
« Reply #228 on: April 18, 2010, 12:49:35 am »
It didn't work when the data was ints, either.
EDIT: I will post some commented code on Monday, as I am a bit busy right now.
« Last Edit: April 18, 2010, 12:53:40 am by bwang »

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: Nspire Raycaster
« Reply #229 on: April 18, 2010, 12:27:33 pm »
I may have found the issue, I don't know for sure though.

in this section of code,

Code: [Select]
for (y = sfstart; y <= sfend; y++) {
            setPixelBuf(scrbuf, x, y, 8);
            //very large value since sprites always cover floors
            zbuf[x][y] = 1000;
            if (res == 2 && x < w - 1) {
              setPixelBuf(scrbuf, x + 1, y, 8);
              zbuf[x + 1][y] = 1000;
            }
          }

you are testing if the "res" variable is equal to 2 after you assign a value to "zbuf", which is addressed with the var "x" which is incremented by res, so potentially, if you're incrementing by two, you could possibly step out of the bounds of the array, maybe if you restructure it like so:

Code: [Select]
for (y = sfstart; y <= sfend; y++) {
            //very large value since sprites always cover floors
            
            if (res == 2 && x < w - 1) {
              // i did it this way because it appears that you're wanting it to set the z buffer and the pixelbuf thingy at both x and x+1 on res == 2
              setPixelBuf(scrbuf, x , y, 8);
              zbuf[x][y] = 1000;

              setPixelBuf(scrbuf, x + 1, y, 8);
              zbuf[x + 1][y] = 1000;
            }
            else if (res == 1 && x < w) // it only seems to be either or, but I decided to use an else if in case it wasn't
            {
              setPixelBuf(scrbuf, x , y, 8);
              zbuf[x][y] = 1000;
            }
          }


You do something similar here:

Code: [Select]
for (y = swstart; y <= swend; y++) {
            int color = tex[(int) texY][texX];
            if (side == 1) color = color / 2;
            setPixelBuf(scrbuf, x, y, color);
            //set the zbuffer
            zbuf[x][y] = perpWallDist;
            if (res == 2 && x < w - 1) {
              setPixelBuf(scrbuf, x + 1, y, color);
              zbuf[x + 1][y] = perpWallDist;
            }
            texY += texD;
          }

I would change it in the same manner as the one above:

Code: [Select]
for (y = swstart; y <= swend; y++) {
            int color = tex[(int) texY][texX];
            if (side == 1) color = color / 2;
            
            //set the zbuffer and the pixel buffer
          
            if (res == 2 && x < w - 1) {
              // same as above, I assumed that you wanted to set both x and x+1 in the pixelbuffer thingy and the zbuffer.
              setPixelBuf(scrbuf, x, y, color);
              zbuf[x][y] = perpWallDist;

              setPixelBuf(scrbuf, x + 1, y, color);
              zbuf[x + 1][y] = perpWallDist;
            }
            else if (res == 1 && x < w)
            {
              setPixelBuf(scrbuf, x, y, color);
              zbuf[x][y] = perpWallDist;
            }

            texY += texD;
          }

Seeing as you're only adjusting the variable "zbuf" at two points in your code, I think these two places are going to be where the problem lies.

hope this helps.
« Last Edit: April 18, 2010, 12:33:13 pm by AaroneusTheGreat »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Nspire Raycaster
« Reply #230 on: April 18, 2010, 11:33:49 pm »
Lionel Debroux suggested here that I allocate zbuf with malloc. It kind of works (see last post on UTI thread).

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Nspire Raycaster
« Reply #231 on: April 18, 2010, 11:40:42 pm »
Aaah ok ^^

Good luck!
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: Nspire Raycaster
« Reply #232 on: April 19, 2010, 01:16:41 am »
I'm not really sure why that would work, but if it does I guess roll with it. You said it "kind of works" what do you mean by kind of?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Nspire Raycaster
« Reply #233 on: April 19, 2010, 02:27:38 pm »
It doesn't crash, but doesn't give correct results either. I'm probably doing something wrong when putting values into zbuf.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Nspire Raycaster
« Reply #234 on: April 19, 2010, 05:08:11 pm »
Sprite clipping fixed! New demo attached.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Nspire Raycaster
« Reply #235 on: April 19, 2010, 11:22:39 pm »
Cool glad to hear ^^
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Nspire Raycaster
« Reply #236 on: April 20, 2010, 02:06:40 am »
It looks awesome :) can't wait to see it run on hardware ^^

SirCmpwn

  • Guest
Re: Nspire Raycaster
« Reply #237 on: April 20, 2010, 11:35:46 am »
What I would like to see next out of this is collision detection with variable-height walls and the current player height.  I shouldn't be stopped by an invisible wall that is just an extention of the one below me, right?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Nspire Raycaster
« Reply #238 on: April 20, 2010, 01:10:57 pm »
yeah I would like that. I wonder how hard it would be to implement?
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Nspire Raycaster
« Reply #239 on: April 20, 2010, 06:13:04 pm »
Nearly trivial, but that's low on my priority list. I want to re-organize the code to make it usable as a graphics engine right now. Collision detection and such would be handled by the client program.