Author Topic: Raycaster from Planet Disco  (Read 8970 times)

0 Members and 2 Guests are viewing this topic.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Raycaster from Planet Disco
« Reply #15 on: February 20, 2012, 06:55:46 pm »
Yeah, if you have a 96 byte table stored in 0.8 fixed point, you could just do Dist**{X+Table}.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Raycaster from Planet Disco
« Reply #16 on: February 20, 2012, 07:42:47 pm »
By the way, Axe internally calculates sine by the following pseudo code:

Mod the argument X by 256 (Sine is cyclic)
If X < 128 return X*(128-X)/32 (An approximation of a sine hump)
If X > 128 return (256-X)*(128-X)/32 (An approximation of a negative sine hump)

Cosine is just sin(X+64) of course.  Each of these use only a single multiplication so it's going to be fairly fast.  If you want the result to be in the full range [-32768 to 32767] instead of [-128 to 127] multiply by 8 instead of dividing by 32 in your custom routine.  Or for 8.8 format, just divide by 16 instead.
« Last Edit: February 20, 2012, 07:46:40 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #17 on: February 20, 2012, 08:00:47 pm »
Why didn't you divide by 16 in the first place?  8.8 format seems a lot more useful than the current range of the trig functions.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #18 on: February 20, 2012, 08:55:35 pm »
yeah, but that's compressed programs, with ununderstable code (what, I'm a newbie ?)
Compressed programs? Neither of the three have any sort of compression going on (that I know of), it's just regular Axe.
Yeah, but I meant without any explication of how it work (bad English powaaa)
The term you're looking for is "optimized," not "compressed." Compression is where a set of data is encoded in such a way that the resulting data is smaller in size than the original data. Optimization is when a program is modified so it runs faster or uses less memory, or otherwise becomes more efficient than before.
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Raycaster from Planet Disco
« Reply #19 on: February 20, 2012, 09:10:48 pm »
@Quigibo: Wow, that is nice O.O

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Raycaster from Planet Disco
« Reply #20 on: February 20, 2012, 10:50:10 pm »
I believe to fix the fishbowl effect you just need to multiply the ray distance by the Cos() of the angle between your front view and the angle of the ray.

What does this mean???
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #21 on: February 20, 2012, 11:39:30 pm »
Let's say you cast a ray.  Your player will already be facing a certain angle, and the ray will be cast at an angle that is at an offset to the angle the player is facing.  You take the cosine of the difference between the ray's angle and the player's angle, and then you multiply that by the ray's distance.  This new value is the new ray distance.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Raycaster from Planet Disco
« Reply #22 on: February 21, 2012, 02:49:42 am »
Why didn't you divide by 16 in the first place?  8.8 format seems a lot more useful than the current range of the trig functions.
I wish I had.  I added the sin/cos routines before I introduced 8.8 operations and so at the time, I chose the range because it would be convenient to be able to store the result into a single byte in memory.  Its too late to make a change like that now unfortunately, but when it comes down to it, it only costs 1 byte to convert it in Axe and the resolution you lose is small since the routine is an approximation anyway.

Also, the pseudo code is not literal to how Axe does the operation.  Its far more optimized without multiplication or division, but rather a single routine that does everything together bit by bit.
« Last Edit: February 21, 2012, 02:52:16 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Raycaster from Planet Disco
« Reply #23 on: February 21, 2012, 04:56:48 pm »
OK Builder, I think I get it.

Is it possible to take the inverse cosine of an 8.8 number in Axe? If not, I'd like to request that feature.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #24 on: February 21, 2012, 05:10:42 pm »
Not that I know of, but you should probably check the commands list, that will tell you anything you need to know.  What do you need inverse cosine for?

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Raycaster from Planet Disco
« Reply #25 on: February 21, 2012, 07:01:28 pm »
More 3D related stuff - I'm trying to set up some code that detects whether or not a given object on the unit circle (centered at your character, radius=distance between you and object) is in your FOV.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #26 on: February 21, 2012, 07:42:10 pm »
Hmm there is probably a way to do that with dot products to avoid a large amount of trig, but couldn't you just use inverse tangent?

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Raycaster from Planet Disco
« Reply #27 on: February 21, 2012, 08:09:57 pm »
Explain how to do stuff with dot products? (I've never even heard of them)
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Raycaster from Planet Disco
« Reply #28 on: February 21, 2012, 08:51:21 pm »
If you have two vectors A and B, the dot product returns this computation:

Code: [Select]
Dot(A,B) = Mag(A)*Mag(B)*Cos(Angle between A and B).
Not only is this an interesting and potentially useful value, the dot product can also be calculated using simple multiplication and addition:

Code: [Select]
Dot(A,B) = Ax*Bx + Ay*By
Roughly speaking, the dot product returns how much the vectors point in the same direction.  If the vectors point in the exact same direction, the result will be positive.  If the vectors are at right angles to each other, the dot product will return zero.  And if the vectors are pointing in opposite directions, the dot product will return a negative number.