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.

Author
Message
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 9th May 2018 20:24
Hi all,
I would like to implement a 3D gizmo, and be able to move it in the 3D space using the mouse.
Is it possible to create such a control without using any raycast method?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th May 2018 21:27
Is this possibly for rotating a camera around a 3D object? Or is it moving an object in 3D space
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 10th May 2018 06:29 Edited at: 10th May 2018 06:39
I am looking for this functionality


I tried to use the PAUL's solution:
https://forum.thegamecreators.com/thread/217477
but it seems the
parameter is not valid in my case
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th May 2018 06:44 Edited at: 10th May 2018 06:46
Ok. I'm not very savvy with that but in my experience you cannot detect mouse/object collision without raycasting. Maybe you could post your code so the community could take a look at it
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th May 2018 07:15
Heres an example moving an object in 3d space with a mouse using raycasting
fubar
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 10th May 2018 07:19
Yes you are are right.
Here is my work so far:


the output of the code is the following video:

As you can see when the camera is looking towards the z-axis the Get3DPointFromScreen(x as float, y as float, z as float) function gives correct results, but when the camera is looking the origin from a different point, then the coordinates of the mouse pointer are not translated correctly.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 10th May 2018 22:15 Edited at: 10th May 2018 22:21
I implemented a widget (gizmo) into my 3D editor but it still uses raycasting and it took quite a bit of work to get right and is deeply embedded into the project, I will try and extract a working demo from it over the weekend, but if I remember right you need to get the intersect point and subtract the offset from the widget position on each axis.

Attachments

Login to view attachments
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 11th May 2018 06:45 Edited at: 11th May 2018 06:46
Quote: " but if I remember right you need to get the intersect point and subtract the offset from the widget position on each axis."

This is my approach:

- The first step is to find if the mouse pointer lies over on any axis of the widget. (the widget should be visible even if there is an object at the same place)
- In case of a user click, you need to determine the axis of the widget and the point that has been clicked. This is the intersection of two rays, one from camera to mouse pointer and another one: the axis of the widget that has been clicked
- As long as the user holds the mouse button down you need to translate mouse coordinates to 3D coordinates along the widget axis

Paul has helped me in the past to find the intersection point of the mouse with a surface:
https://forum.thegamecreators.com/thread/219443
If I manage to find the intersection of the mouse pointer with the X-Z, X-Y and Z-Y planes then I will be able to post a working code for the forum

Login to post a reply

Server time is: 2024-11-23 20:08:35
Your offset time is: 2024-11-23 20:08:35