Babbie's first software-rendered ray-casting

Download
Link to GitHub Repository

This is my first, albeit small project I have worked on in a while, as I have been tied up with school. Thankfully now that Summer is here I can finally knuckle-down and get some work done :slight_smile:

The title is pretty self-explanitory, I hope. This is basically a project started so I could learn about the mathematics and practice the implementation of Raycasting, I am following This excellent article by F. Permadi : http://www.permadi.com/tutorial/raycast/index.html

As the title also suggests, I am new to the realm of Raycasting, so any suggestions or help you could provide would be most appreciated :wink:

If you too are new to raycasting, please feel free to ask any questions as to how I went about implementing it in this little demo

Controls : WASD to move, Q and E to rotate view

PS : I am aware of the ‘flashing white screen’ observed while moving, The way I achieve rendering in this project is, every time the player’s position/rotation changes, to use 3D maths to calculate a 1-dimensional int array of length (window_width * window_height) which will act as a ‘pixel-buffer’, update an image using the pixel buffer and use the Component.repaint() to re-draw the image(which is streched accross the window). This probably isn’t the best way to render, but if anyone can suggest a better way, please let me know and I will see if I can implement it :wink:
[EDIT]
nvm, its fixed now :slight_smile:

That would be ray casting, not tracing, as your linked article says.
This is ray tracing: https://en.wikipedia.org/wiki/Ray_tracing_(graphics)
Some also make the subtle distinction of path tracing: http://home.lagoa.com/2014/04/ray-tracing-vs-path-tracing-in-plain-english/

I get this error when running it. I am running on Mac OS X Yosemite

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 692378
	at gui.ProjectionPlane.updatePixels(ProjectionPlane.java:80)
	at main.GameCanvas.paint(GameCanvas.java:25)
	at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
	at sun.lwawt.LWRepaintArea.paintComponent(LWRepaintArea.java:59)
	at sun.awt.RepaintArea.paint(RepaintArea.java:240)
	at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1312)
	at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1196)
	at java.awt.Component.dispatchEventImpl(Component.java:4959)
	at java.awt.Component.dispatchEvent(Component.java:4705)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
	at java.awt.EventQueue.access$400(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:697)
	at java.awt.EventQueue$3.run(EventQueue.java:691)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.awt.EventQueue$4.run(EventQueue.java:719)
	at java.awt.EventQueue$4.run(EventQueue.java:717)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


Very nice. Keep at it! Raytracing is fun! :smiley:
Maybe we will see a (first?) complete raytraced game of yours soon?
Maybe also with some reflective and translucent objects in your scene, so that your raytracer can really shine?

Ahh, of course. I can never think of the difference between the two. If anyone can come up with a rhyme to help me remember I would be most grateful :wink:

Hmm, strange. Unfortunately I do not have regular access to a Mac machine, but judging from the error report, I think I know what went wrong, and have updated the download link with a new “version” which handles array index out of bound exceptions better. I would appreciate it if you could try it out and see if it works. This may just be a Mac problem but I’m not sure ???

Haha, thanks :wink:
As for a complete game, I’m not so sure. This was only ever meant to be a project to mess around with.
And as for the reflective and translucent objects, maybe I’ll delve into that black magic sometime in the future, but not with this engine, as BurntPizza noted It is ray-casting, not ray-tracing (my mistake, it seems that I have some renaming to do)

I also intended to set up a public GitHub repository for this project, but I’ll need another day or so to mess around with Git to see how it works

I’m getting severe flickering when I run this. Here’s a GIF showing it.

My PC specs are Intel i7-4790k, NVIDIA GTX 750 Ti, and 16 gigs of RAM. Running Windows 10 Insider Preview, and Java 8.

Played around with raycasting myself a few months back in javascript. Never had the time to delve into transparent walls (windows) and variable height walls though - so keep us updated if you ever play around with that.

source: https://github.com/hannyajin/raycast
demo: http://ray.jin.fi/

Impressive, did you follow any tutorial / book by any chance? That line-of-sight indicator raytracing thing in your minimap has been on my backlog of things to program for a while now, I’ll get around to doing it someday ;D