Scripts / Detect MouseClick on Object from lua script

Author
Message
mvdhoning
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 6th Sep 2017 18:24 Edited at: 6th Sep 2017 18:30
Recently i managed to find out how to disable mouselook and display a cursor on sceen. Right mouse pressed now does mouselook.
Also i am now able to display the objects name under it via scripting.

Next i would like to click on an entity and display a sprite and or text on a specific entity.

For now it seems that when detecting mouseclick all scripts do their work and somehow entity 7 is always shown. So next to detecting mousclick i should also check if x,y coords of mouse when raycasted hit an entity. But i am clueless for now as for lack of documentation.

Maybe IntersectAll might be of use but i am not sure how to feed the x,y coord to it and dont feel like doing a lot of trial and error on.
Looking on the forums did not find me anything direct useable other then the above IntersectAll command.

Hope that i am over complicating things and that there is an easy way that i just have not found yet.

Some background on what i am trying to accomplish: think of a 3d point and click adventure game.

When i get this working next challege would be to add a waypoint at mouse coords translated to world coordinates.

The script i have now using a crosshair on the center of the screen:



in pobj i now get the 'internal' object id of the object the crosshair is on, but preceded by 7000 and not a number like in e. so when i collect names in init i should also collect the 'internal' id's there.

But still not sure how to add g_MouseX and g_MouseY to that.
I think that when the position where the mouse cursor is on the screen would be the center of where the camera looks at the the camera would have changed angles.

Looking at gameplayercontrol.lua i detect some more unknown functions like: GetGamePlayerStateCamMouseMoveX() maybe those might be usefull but for now i feel a bit lost.

Hope some of the clever people here can shine a light on this.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Sep 2017 19:23
https://forum.game-guru.com/thread/218548#msg2585248
Been there, done that, got all the T-Shirts!
PM
mvdhoning
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 6th Sep 2017 21:17 Edited at: 6th Sep 2017 21:19
Most of my current version comes from your scripts i found on the forum here .

Will look further in your hidden object example, but there you also depend on a crosshair in the middle of the screen. Your zone thing looks most interesting.

But what i want to achieve is the camera not to move, but only the crosshair/mouspointer. So the mouspointer/crosshair could be in the lower right of the screen and still find the object that is there 'under' it.

So somehow i think i should rotate the camera angles i found some more with the mouse offset from the center of the screen. But not sure.

Meanwhile i found out that the last 0 in intersectAll could be an entity you want to exclude so a third person camera should work also.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Sep 2017 21:53
Calculating from mouse X,Y to 3d angles is rather complicated and you need to take the field of view value into account, I ended up 'cheating' with the Moose script (where I need to have the gun aiming point displayed whilst the player can look around) by just trying different constant 'frigs' until I found a reasonable result but then it will only work properly at one specific FOV setting.
Been there, done that, got all the T-Shirts!
PM
mvdhoning
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 8th Sep 2017 15:07 Edited at: 8th Sep 2017 15:46
That moose looks amazing. But i fear i am lost and better stick to crosshair in center of screen.

looking on the internet for ray and fov found me this:
https://www.mvps.org/directx/articles/rayproj.htm
sounds like it could be what i want to make a ray for useage with IntersectAll
but inverse matrix seem unreacheable

Sounds like i should post a request for you or Lee to implement a 2d mouse coord to ray function.
PM
mvdhoning
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 12th Sep 2017 12:39 Edited at: 12th Sep 2017 12:53
Here is my attempt sofar:


MATRIX is from https://github.com/davidm/lua-matrix
and is intialized as:


projectionMatrix function:


It goes broken on the result of the invert call in the lua matrix library. Maybe i dont feed it a proper matrix from my projection matrix calculations. What on its own may totaly be wrong because opengl vs directx.
Thanks for your hints and tips in advance.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Sep 2017 19:33
Can't see any player coordinates in there, plus ASPECT should be simply width/height rather than a constant. Oh and the player Y value is not the same as the players eye-line so you need to adjust according to whether the player is crouched or not, and take into account the player angles as well unless you've frozen the camera at zero angles.

Still don't really get what you are trying to achieve here to be honest, the end position for the ray cast will depend on how far away you assume the player is looking, the mouse coordinates could represent a point way off on the horizon or a point 5 feet away, how do you decide which it is?
Been there, done that, got all the T-Shirts!
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 13th Sep 2017 00:10 Edited at: 16th Sep 2017 11:29
This is one way to determine the map coordinates that are under the screen cursor.
It should give you some idea to build off.
I have kept it simple and it should be easy to follow.





Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 10, 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)

Attachments

Login to view attachments
mvdhoning
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location:
Posted: 13th Sep 2017 14:52 Edited at: 13th Sep 2017 14:57
@amenmoses Now i calculate the aspect ratio. Also i am not woried about the player as i intended to use the camera what will be independend on the player so crouching wont affect anything. What is was aiming for is to implement something like in the directx tutorial i refered in a post here. https://www.mvps.org/directx/articles/rayproj.htm

@perelect using your code to calculate new camera positions and using that together with the code from my first post and multiply Cursor3D_X * 4 and add 60 to that i get roughly to select the items i expect to. But when doing much camera rotation that will fail again What are your magic numbers like the 1000 and 50 you divide with? Also you dont seem to use the aspect ratio?
PM

Login to post a reply

Server time is: 2024-12-23 00:47:23
Your offset time is: 2024-12-23 00:47:23