Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Ray cast from centre of camera

Author
Message
PixHil
5
Years of Service
User Offline
Joined: 10th Mar 2019
Location:
Posted: 10th Mar 2019 13:22 Edited at: 11th Mar 2019 00:38
Hey guys,

I'm developing a simple map editor using AGK's 3d commands and i'm found myself at a particular challenge.

note: My math skills aren't amazing...

Below, I've illustrated (poorly) what I'm sort of going for.
So basically, I want to be able to create an object indicator before placing the object of where it would go and how it would look in the 3d scene.

So I've been doing a little research and it looks like ray casting is the way to achieve this. I've never done anything like this not i'm not 100% sure.
In the screenshot you can see the grid I've established which will act as the base for the scene.

What i'm having difficulty with is finding a formula to cast a ray from the centre of the screen/camera to the grid (which is made up of objects).
More specifically the grid cell i'm looking at.



Any help would be greatly appreciated.

EDIT: The file link seemed to have been removed to I've attached the image instead.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th Mar 2019 13:44 Edited at: 10th Mar 2019 13:49
if you want to be able to move an object around
here is an example


raycasting is great for checking collision between two objects ie


If you just want to be able to select an object with the mouse
fubar
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Mar 2019 15:55
The simplest way without the math is to grab the position of the camera (this is the raycast start point), moveCameraLocalZ the distance you want the ray to reach, grab the camera position (this is the raycast end point, moveCameraLocalZ negative distance to return it to the start point. Now you cast the ray between the two points.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 10th Mar 2019 17:11
Yeah ...I use the same as Ortu point out . This is the way we do in Dbpro

I'm not a grumpy grandpa
PixHil
5
Years of Service
User Offline
Joined: 10th Mar 2019
Location:
Posted: 11th Mar 2019 00:45
Quote: "The simplest way without the math is to grab the position of the camera (this is the raycast start point), moveCameraLocalZ the distance you want the ray to reach, grab the camera position (this is the raycast end point, moveCameraLocalZ negative distance to return it to the start point. Now you cast the ray between the two points."


Quote: "Yeah ...I use the same as Ortu point out . This is the way we do in Dbpro"


Thanks guys, that's exactly what I was after.
Chafari, your example is very helpful.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 11th Mar 2019 12:54
Seems were all doing 3d placement editors these days. Lol.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Mar 2019 14:07
@PixHil I'm glad you like it .
I'm not a grumpy grandpa

Login to post a reply

Server time is: 2024-04-26 04:28:46
Your offset time is: 2024-04-26 04:28:46