Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  2D Raycasting and Lighting  (Read 4663 times)
0 Members and 1 Guest are viewing this topic.
Offline bcsharp

Senior Newbie

Exp: 6 years

« Posted 2014-01-07 22:19:13 »

Hello, I am wondering how I could implement 2D ray-casting in a Slick2D game, for lighting purposes. I realize that Slick2D is somewhat dead but that is irrelevant to ray-casting, as far as I know.

The "map" would consist of either rectangles or line segments.

I've read the article at but I can't seem to figure out how this is implemented in Java.

My best guess is to have a Ray class and a Line class and determine where intersections lie, and then create triangles from those points. Also, on a slightly irrelevant note, I have not learned how to create radial gradients in Slick2D, any help there would be appreciated too. I'm also wondering if efficiency would be an issue in a situation where there are a large number of lines. I hope my question makes sense.  Undecided

One other question: how would I combine the lights from multiple sources? I'm thinking additive blending or perhaps transparency would be the solution.

Any help would be appreciated!

Offline Varkas
« Reply #1 - Posted 2014-01-07 23:45:40 »

Once I've implemented the following method:

Take the octant aligned to the positive x-axis and the y-axis with (y < x). Scan it left to right. Keep track of shadowed intervals. Merge overlapping shadow intervals.


Now use affine transforms to map the other 7 octants on the first one, and you can do a full field of view calculation.

if (error) throw new Brick(); // Blog (german):
Offline Varkas
« Reply #2 - Posted 2014-01-08 11:29:31 »

You can find my code here:

Ready to use, but it assumes a grid-based map. The algorithm is fairly easy to extend for other map types, though.

if (error) throw new Brick(); // Blog (german):
Pages: [1]
  ignore  |  Print  

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

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

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

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

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!