Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Babbie's first software-rendered ray-casting  (Read 18028 times)
0 Members and 1 Guest are viewing this topic.
Offline Mockle
« Posted 2015-06-30 20:50:31 »


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 Smiley

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 Smiley
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #1 - Posted 2015-06-30 22:58:45 »

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/

Offline orange451

JGO Kernel


Medals: 564
Projects: 8
Exp: 8 years


Your face? Your ass? What's the difference?


« Reply #2 - Posted 2015-07-01 17:09:53 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
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)

First Recon. A java made online first person shooter!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KaiHH

JGO Kernel


Medals: 796



« Reply #3 - Posted 2015-07-01 17:29:37 »

Very nice. Keep at it! Raytracing is fun! Cheesy
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?
Offline Mockle
« Reply #4 - Posted 2015-07-01 20:30:51 »

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/

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

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

1  
2  
3  
4  
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 ...


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  Huh

Very nice. Keep at it! Raytracing is fun! Cheesy
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?

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
Online SHC
« Reply #5 - Posted 2015-07-02 04:29:01 »

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

Click to Play


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

Offline jonjava
« Reply #6 - Posted 2015-07-02 04:51:10 »

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/

Offline Mockle
« Reply #7 - Posted 2015-07-02 23:04:35 »

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  Grin
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (583 views)
2019-09-04 15:33:17

hadezbladez (5521 views)
2018-11-16 13:46:03

hadezbladez (2405 views)
2018-11-16 13:41:33

hadezbladez (5783 views)
2018-11-16 13:35:35

hadezbladez (1226 views)
2018-11-16 13:32:03

EgonOlsen (4664 views)
2018-06-10 19:43:48

EgonOlsen (5684 views)
2018-06-10 19:43:44

EgonOlsen (3199 views)
2018-06-10 19:43:20

DesertCoockie (4099 views)
2018-05-13 18:23:11

nelsongames (5116 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!