Advertisement

3D maths problems

Started by February 22, 2003 08:17 AM
3 comments, last by Zax 21 years, 8 months ago
Hello, I found some code on some obscure site for a very simple 3D raycasting engine for metal basic (a basic variant for macintosh), but I''m having a lot of trouble trying to understand the maths behind it (haven''t covered stuff like radians in class yet), and I''d greatly appreciate it if anyone could help me out. here''s the code

pi = 3.14
rdns = pi/180
sw = screen width
sh = screen height
dist = sqr(100^2+100^2)
cw = 640
ch = 480
resize console 0,0,sw,sh
scratch = init screen(0,0,cw,ch)
set screen to scratch
raystep = 60/cw
dim level(10,10)
for i = 1 to 10
for j = 1 to 10 
read level(i,j) 
if level (i,j) = 3 then 
playerx = i*10
playerz = j*10
end if
next j 
next i
starter = timer
look:
cls
forecolor 0,45535,0
for i = 0 to 60 step 1
for x = 1 to dist
rayx = round(sin((i-30+playerangle)*rdns)*x)+playerx 
rayz = round(cos((i-30+playerangle)*rdns)*x)+playerz 
scl = 1000/sqr((rayx-playerx)^2 + (rayz-playerz)^2)
if level(rayx/10,rayz/10) = 1  then
drawx = round(i*cw/60) 
df=drawy
df2=drawy2
drawy = ch/2-scl/2*2
drawy2= ch/2+scl/2*2
if drawy>dy or drawy 

p.s: if this in the wrong forum, sorry, but I guessed that this would be the right place to post it.


Thanks     
Dear God, that code is a mess.

No indentations, gotos...

You might want to find a better example of a raycasting engine.
Advertisement
quote: Original post by glassJAw
Dear God, that code is a mess.

No indentations, gotos...

You might want to find a better example of a raycasting engine.




It was the simplest one I could find. I know it''s inneficient, but I just want to grasp the basics, and then move onto something more complex.
Where is this obscure website?
http://hem.spray.se/axeln/metal/3dpage.html (the one I'm using is Raycaster 2, since the origional raycaster link is botched).

[edit]ack, ubb is off![/edit]

[edited by - Zax on February 22, 2003 11:43:57 AM]

This topic is closed to new replies.

Advertisement