Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
theadder
Dec 30, 2011


Adbot
ADBOT LOVES YOU

echinopsis
Apr 13, 2004

by Fluffdaddy



screenshot of my starfield (made in the most moronic way possible, but makes it look super awesome and work even better)
and the beginnings of my procedural level gen.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Doc Block posted:

You have to keep track of which direction you're casting the ray in relative to the world. If the ray was going left and up when it hit then round both X and Y down to get the correct tile coordinates. If it was going right and up, then round X up and Y down. If it was going left and down then round X down and Y up. If the ray was going right and down, round both X and Y up.

I don't know how this particular ray caster does it, but a lot of raycasters used in actual games cast two rays for each vertical slice. One that only checks for intersections with vertical walls, and one that only checks for intersections with horizontal walls. Then compare the distance and choose whichever one is closer. Makes the code easier when deciding whether or not to round up or down, and there are some other benefits but I forget what they are.

This link and this one were pretty much considered to be the on-line resources for info about writing ray casting engines back when I was playing around and wrote one.

hmm, well I know the angle that the ray was cast at and I know whether my intersection is vertical or horizontal (X or Y is always a whole number) but it doesn't seem to be adding up. a ray moving at an angle of 234 degrees should be going left and down (I pointed my player in that direction and went forward and that's what happened to my coordinates) but flooring x and ceiling y doesn't give me a valid tile and it draws Tazz. I set up the whole set:

code:
				ray_angle = math.degrees(rotation + angle) #the ray is cast at (player.rotation+angle)

				if(ray_angle >= 0 and ray_angle < 90):
					texture = tilemap.tilemap[int(math.ceil(step.x))][int(math.floor(step.y))].texture
				elif(ray_angle >= 90 and ray_angle < 180):
					texture = tilemap.tilemap[int(math.floor(step.x))][int(math.floor(step.y))].texture
				elif(ray_angle >= 180 and ray_angle < 270):
					texture = tilemap.tilemap[int(math.floor(step.x))][int(math.ceil(step.y))].texture
				elif(ray_angle >= 270 and ray_angle <= 360):
					texture = tilemap.tilemap[int(math.ceil(step.x))][int(math.ceil(step.y))].texture
				else:
					raise AttributeError("ray_angle invalid: " + str(ray_angle))

				if texture is None:
					texture = Image(IMAGES["texture_tazz"])
				else:
					True
					pass
but it keeps trying to figure out angles over 360 degrees and under 0 degrees? and the texture will flip to Tazz on random columns when my angle to them changes? something's hosed up. uh, also the geometry makes no sense to me because i have one of those math learning disorders so i don't know what it's doing to cause that. i think my coordinate system is rotated or something as well but i don't know how to fix that

graphics are hard

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

is it possible for rotation + angle to be outside 0-360 degrees? i haven't looked at the full code yet

how is the tilemap laid out, exactly? looking at the floors and ceils in that piece of code i'd switch around the ones in the x-coordinate, since it kind of looks like a ray going from the origin to the right (an angle between -180 degs and +180 degs) will look at the texture on the right-hand side of the tile, since it's getting ceil'd, and vice versa

computer toucher
Jan 8, 2012

hows my spare time project doing? glad you asked! https://kyber.ninja is looking a lot better. I've spent some (tens of) hours on it and finally fixed the horrible database I first made, improved a lot of stuff and have been gathering the latest relevant news to the site to have content. it's waiting to be bumrushed by hundreds of active users any minute now!. it also got some more memory and a new free "home" behind cloudflare. thanks cloudflare!

It might be a piece of poo poo php/bootstrap forum but at least it's mine!

echinopsis
Apr 13, 2004

by Fluffdaddy

computer toucher posted:

hows my spare time project doing? glad you asked! https://kyber.ninja is looking a lot better. I've spent some (tens of) hours on it and finally fixed the horrible database I first made, improved a lot of stuff and have been gathering the latest relevant news to the site to have content. it's waiting to be bumrushed by hundreds of active users any minute now!. it also got some more memory and a new free "home" behind cloudflare. thanks cloudflare!

It might be a piece of poo poo php/bootstrap forum but at least it's mine!

what is it and should i be an admin

computer toucher
Jan 8, 2012

echinopsis posted:

what is it and should i be an admin

it's a web site for infosec stuff I made from scratch to teach myself some server & webapp janitoring. I got inspired on a SANS pentesting course to learn this poo poo to better be able to break it (when it's legitimate or asked for).

Maybe if you register and post good poo poo and work hard some day you might get the office near the corner office?

echinopsis
Apr 13, 2004

by Fluffdaddy
i know nothing about any of that poo poo

echinopsis
Apr 13, 2004

by Fluffdaddy

Doc Block
Apr 15, 2003
Fun Shoe
tl;dr: just read this for how to do a ray casting engine with multiple textures. There's also this series which doesn't have code samples but explains the math on how to do multi-height walls, as well as textured floors and ceilings.

Doc Block fucked around with this message at 04:32 on Jan 15, 2015

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

i want to write a raycaster now

Doc Block
Apr 15, 2003
Fun Shoe
LOL I tried to download PyGame so I could help out Luigy Thirty (he rewrote the article's raycaster in Python) and the PyGame website is not only eye-gougingly ugly, the whole site is broken as gently caress. There isn't a single download that's post-2010. Welp.

GameCube
Nov 21, 2006

pip install pygame hth

Doc Block
Apr 15, 2003
Fun Shoe
Thx except that's broken, I don't have SDL installed. LOL this is some lovely Linux and/or Ruby dependency hell poo poo.

edit: brew install sdl etc will hopefully fix it. I hope you appreciate that I'm dirtying my precious Appel Mackintosh eyeMac with awful Linux-version of DirectDraw so I can install PyGame so I can help you out, Luigy Thirty :argh:

GameCube
Nov 21, 2006

thats actually the same version on the site, guess they perfected it in 2009 and there's nothing more to be done

Luigi Thirty
Apr 30, 2006

Emergency confection port.

e: double

Luigi Thirty fucked around with this message at 01:15 on Jan 15, 2015

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Doc Block posted:

LOL I tried to download PyGame so I could help out Luigy Thirty (he rewrote the article's raycaster in Python) and the PyGame website is not only eye-gougingly ugly, the whole site is broken as gently caress. There isn't a single download that's post-2010. Welp.

someone had (badly) ported it from JavaScript to Python, I cleaned up some of the code they made and pasted it into a new repo

and yeah, that makes sense considering I figured out my X or Y was always off by one but I couldn't make the connection to that being the next tile the ray would pass through. I can go hook that up later

Doc Block
Apr 15, 2003
Fun Shoe
Reading through your Python code, it seems you are casting two separate rays or some poo poo, IDK. I hate "Pythonic" code, it's always so unclear.

Doc Block
Apr 15, 2003
Fun Shoe
What the code should do is just have the raycaster return the X and Y of the block it hit, so you don't have the big if-else statement checking the angle of the ray. Especially since for some cases it won't ever be right.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

I didn't touch the actual ray casting itself other than making it semi-readable instead of unreadable.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Luigi Thirty posted:

hmm, well I know the angle that the ray was cast at and I know whether my intersection is vertical or horizontal (X or Y is always a whole number) but it doesn't seem to be adding up. a ray moving at an angle of 234 degrees should be going left and down (I pointed my player in that direction and went forward and that's what happened to my coordinates) but flooring x and ceiling y doesn't give me a valid tile and it draws Tazz. I set up the whole set:

code:
				ray_angle = math.degrees(rotation + angle) #the ray is cast at (player.rotation+angle)

				if(ray_angle >= 0 and ray_angle < 90):
					texture = tilemap.tilemap[int(math.ceil(step.x))][int(math.floor(step.y))].texture
				elif(ray_angle >= 90 and ray_angle < 180):
					texture = tilemap.tilemap[int(math.floor(step.x))][int(math.floor(step.y))].texture
				elif(ray_angle >= 180 and ray_angle < 270):
					texture = tilemap.tilemap[int(math.floor(step.x))][int(math.ceil(step.y))].texture
				elif(ray_angle >= 270 and ray_angle <= 360):
					texture = tilemap.tilemap[int(math.ceil(step.x))][int(math.ceil(step.y))].texture
				else:
					raise AttributeError("ray_angle invalid: " + str(ray_angle))

				if texture is None:
					texture = Image(IMAGES["texture_tazz"])
				else:
					True
					pass
but it keeps trying to figure out angles over 360 degrees and under 0 degrees? and the texture will flip to Tazz on random columns when my angle to them changes? something's hosed up. uh, also the geometry makes no sense to me because i have one of those math learning disorders so i don't know what it's doing to cause that. i think my coordinate system is rotated or something as well but i don't know how to fix that

graphics are hard

ok I changed this

code:
				ray_angle = math.degrees(rotation + angle) % 360
and I guess it solved the problem

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Doc Block posted:

What the code should do is just have the raycaster return the X and Y of the block it hit, so you don't have the big if-else statement checking the angle of the ray. Especially since for some cases it won't ever be right.

aha, i dug through it and it figures this out when retrieving wall height but doesn't save it anywhere. now it writes down the tile that the point is inside and the texture lookup system checks that to find the texture. Tazz has been banished.

Luigi Thirty fucked around with this message at 02:12 on Jan 15, 2015

Doc Block
Apr 15, 2003
Fun Shoe
Ok, good. Still, this renderer really sucks and is super slow.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

it is extremely slow but i haven't broken out the profiler on it. it sure does look like 1994 though

Luigi Thirty fucked around with this message at 02:35 on Jan 15, 2015

Doc Block
Apr 15, 2003
Fun Shoe
Creating a new array of Point objects for every slice is probably a big one.

Having the map etc be a 2D array instead of a 1D array.

Does any of it use NumPy/CPython/Whatever math or is it all Python?

The fact that moving drops the framerate down to about 12, and then it shoots back up to 28-30 when I let go is also LOL tastic.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

using numpy for the math would probably be a million times faster since it has support for things like statically typed multidimensional arrays. the original python implementation of the map was a dict full of tuples containing an int lol

Luigi Thirty fucked around with this message at 02:53 on Jan 15, 2015

echinopsis
Apr 13, 2004

by Fluffdaddy

Doc Block posted:

Reading through your Python code, it seems you are casting two separate rays or some poo poo, IDK. I hate "Pythonic" code, it's always so unclear.

curious why is pythonic code so unclear to you when pythonic code means basically clarity

echinopsis
Apr 13, 2004

by Fluffdaddy
maybe the problem is you can't read?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

echinopsis posted:

curious why is pythonic code so unclear to you when pythonic code means basically clarity

pythonic is a dumb adjective but yeah saving some special cases (I'm looking at for-else bullshit) python code is supposed to be clear instead of too clever

Doc Block
Apr 15, 2003
Fun Shoe
since when? when i was learning python a few years ago pythonic basically meant "the clever solution" and all "pythonic" code that i saw was full of lambdas and maps and poo poo when there didn't need to be.

Trig Discipline
Jun 3, 2008

Please leave the room if you think this might offend you.
Grimey Drawer
well isn't that pythonic? don't you think?
a little too pythonic?

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp
still dont get lambdas at allllll

echinopsis
Apr 13, 2004

by Fluffdaddy

Trig Discipline posted:

well isn't that pythonic? don't you think?
a little too pythonic?

lol


Jonny 290 posted:

still dont get lambdas at allllll
come to nz we got poo poo loads of them everywehere

Trig Discipline
Jun 3, 2008

Please leave the room if you think this might offend you.
Grimey Drawer
yeah my brain keeps bouncing off of large chunks of functional programming going nopenopenopenope

echinopsis
Apr 13, 2004

by Fluffdaddy

Doc Block posted:

since when? when i was learning python a few years ago pythonic basically meant "the clever solution" and all "pythonic" code that i saw was full of lambdas and maps and poo poo when there didn't need to be.

since forever man. go read

pythonic means "not clever".

http://blog.startifact.com/posts/older/what-is-pythonic.html
tjats from 2005


pythonic means it should be very clear. python by itself makes this easy coz python is the best and is very easy to read and understand

quote:

To be Pythonic is to use the Python constructs and datastructures with clean, readable idioms. It is Pythonic is to exploit dynamic typing for instance, and it's definitely not Pythonic to introduce static-type style verbosity into the picture where not needed. To be Pythonic is to avoid surprising experienced Python programmers with unfamiliar ways to accomplish a task.

Glorgnole
Oct 23, 2012

you aren't expected to understand this

Doc Block
Apr 15, 2003
Fun Shoe

Jonny 290 posted:

still dont get lambdas at allllll

functional programming doesn't work with my brain. saw somebody on twitter or wherever say that functional programming fits their mental model better and i was like :aaaaa:

Doc Block
Apr 15, 2003
Fun Shoe

echinopsis posted:

since forever man. go read

pythonic means "not clever".

http://blog.startifact.com/posts/older/what-is-pythonic.html
tjats from 2005


pythonic means it should be very clear. python by itself makes this easy coz python is the best and is very easy to read and understand

nowhere does it say pythonic means very clear. while the article doesn't outright encourage writing unreadable code, it only says that it should be written the way an "experienced" python programmer would write it, and also that you should use every imaginable language feature. so yeah, try to be clever and figure out a way that particular thing could be done with lambdas or something instead of a simple for-each block.

echinopsis
Apr 13, 2004

by Fluffdaddy
what you're describing goes against everything I understand pythonic to mean, maybe I'm wrong but I suspect it's you who is wrong

Adbot
ADBOT LOVES YOU

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp
ok here. it's just function sugar evidently

code:

>>> foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
>>> 
>>> print filter(lambda x: x % 3 == 0, foo)
[18, 9, 24, 12, 27]
>>> 
>>> print map(lambda x: x * 2 + 10, foo)
[14, 46, 28, 54, 44, 58, 26, 34, 64]
>>> 
>>> print reduce(lambda x, y: x + y, foo)
139

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply