Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
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  
  RayCasting Explained - source samples included  (Read 15102 times)
0 Members and 1 Guest are viewing this topic.
Offline jmguillemette
« Posted 2013-12-09 07:21:13 »

Ok.. so i only recently got this working and im sure there is some optomization that can be done. but I promised on another thread to post a vid and source on this once it was working Smiley

This video walks through the theory and specifics of raycasting.
<a href=";hl=en_US&amp;start=" target="_blank">;hl=en_US&amp;start=</a>

This is the code utils i created. all code is using LWJGL.



there are three main steps in raycasting

Unproject the mouse coords for the 0 and 1 depth values
Calculate intersects with a plane for the surface you want to test against
Calculate the area of the surface (as a triangle) and then of the intersect point using the same triangle points.. if the sum of the triangles  - the original area of the full triangle == 0 (or < 0.00001) then you are inside the triangle.

EDIT updated to include video link Smiley
EDIT corrected typo Smiley

<a href=";hl=en_US&amp;start=" target="_blank">;hl=en_US&amp;start=</a>

Revised code

This paste bin has my fully working Raycastingutil

-=Like a post.. give the author a medal!=-
Offline jmguillemette
« Reply #1 - Posted 2013-12-09 13:16:00 »

looks like the vid for this post is finally available via youtube.

-=Like a post.. give the author a medal!=-
Offline Simn
« Reply #2 - Posted 2013-12-09 16:43:41 »

Freaking awesome stuff man!  Grin

The video was very clear and you learned away the theory on a great way! The only thing I would *pick* about is that not everybody is using GLU (or deprecated functionality of OpenGL).

Other than that, great work!

- Simn
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Opiop
« Reply #3 - Posted 2013-12-09 23:01:28 »

Awesome, I'll take a look at this later tonight! Thank you! Smiley
Offline tom_mai78101
« Reply #4 - Posted 2013-12-31 02:01:41 »

Replying just for the sake of bookmarking.

Probably might help me understand the logic behind Notch's Prelude of the Chambered.
Offline kpars
« Reply #5 - Posted 2013-12-31 10:21:07 »

Prelude of the Chambered doesn't use RayCasting, but rather Perspective-Based Projection.
Offline tom_mai78101
« Reply #6 - Posted 2013-12-31 12:28:18 »

EDIT: Really? Well, awkward...
Offline Opiop
« Reply #7 - Posted 2013-12-31 14:29:34 »

Off topic, but I'm getting sick of people saying welp. Please, no more. Its not funny.
Offline tom_mai78101
« Reply #8 - Posted 2013-12-31 14:46:50 »

Ah, I hate it when simple typos like this can make one angry, especially when viewing/typing on phone. I'll go ahead and fix it, for the sake of it.
Offline jmguillemette
« Reply #9 - Posted 2013-12-31 17:10:01 »

Just a heads up to anyone following this code.

I've been evolving my implementation to support "what if" situations.. ie.. what if the camera is rotated, what if the model is rotated.. ect..
This has not resulted in a large change to the original code i submitted but a few minor tweaks in places to add this support.

Once the revised version of the utility is done I will post it again here for anyone to pick a part and use as they will.


-=Like a post.. give the author a medal!=-
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jmguillemette
« Reply #10 - Posted 2014-01-07 16:15:41 »


I finally got the full functionality of my raycast util working last night.

Expect an updated video and sample code later this evening.


-=Like a post.. give the author a medal!=-
Offline jmguillemette
« Reply #11 - Posted 2014-01-09 00:56:24 »

updated the paste bin with new sample code.

new code adjusts for model rotation and normal correction in the math calculation.

-=Like a post.. give the author a medal!=-
Offline wessles
« Reply #12 - Posted 2014-01-09 01:26:11 »

Great job man!

I remember pondering on this, and coming up with the first step, but I never knew enough about collisions to find the second and third step! Thanks for solidifying it for me!

Will help for when I venture into 3D!

Pages: [1]
  ignore  |  Print  

mercenarius (4 views)
2020-06-04 19:26:01

mercenarius (2 views)
2020-06-04 19:13:43

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

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

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

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

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

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

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

EgonOlsen (3282 views)
2018-06-10 19:43:20
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 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!