Cursor ingame

Get technical support about the C++ source code and about Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Cursor ingame

Post by Haimi » 2012-02-23, 15:27

Hi @ll,

I am trying to make a custom cursor not only visile in GUIs but in the whole game. Seperating the mouse moves from the camera position was not that comlicated, but:
is there an easy way to display an cursor in the whole game?

The Idea: I am using some abstractions under the BaseEntityT, so there will be a SelectableEntityT and derived from this, ActionEntityT, which will rise a GUI on rmb. Selectable Items will be selected via lmb.

I would appreciate any ideas very much.
Greetings!
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Cursor ingame

Post by Carsten » 2012-02-24, 11:40

Hi Haimi,
Haimi wrote:is there an easy way to display an cursor in the whole game?
Not sure what exactly you want to achieve, but did you have a look at the "HUD" (head-up display) GUI?
This GUI is used both for the display of the health and ammo amounts, as well as the active weapons cross-hair, which is technically really the same as a cursor.
Possibly you can modify or extend this to your purposes. :up:
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-24, 15:33

Thanks alot, i Understand the theory now, perhaps I will manage to do this on the Weekend :)
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-25, 15:42

Okay, now I have had this Idea:
- the crosshair is my cursor, the graphic is already changed.
What I try to achive now is, not to move the camera when i move the mouse, but to move the "crosshair" around.
Can you give me a hint, I have tried to figure out where the mouse moving event "lands" in an actual method but I did not find anything.

Combined with the 3rd person view this seems to be going rather fast towards my Game Idea :up:
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Cursor ingame

Post by Carsten » 2012-02-27, 02:29

At this time, we "convert" mouse and keyboard input to PlayerCommandT's directly at [url=http://trac.cafu.de/browser/cafu/trunk/Ca3DE/Client/ClientStateInGame.cpp?rev=482#L326]ClientStateInGameT::ProcessInputEvent()[/url] ...
Well, and this is also the problem: We have no direct way to know the mouse input events in the game code.

I've not thought this though, but you might extend the PlayerCommandT with members for mouse position x and y, and update them in the above function before or after the pitch and heading are updated as well. Then re-use them in the game code to display the cursor at the desired position.

A completely different (and probably better!) alternative is that instead you create a new GUI with translucent background for the same purpose.
See and try out the "chat" GUI that you can open by pressing T while being in-game.
Yes... this is the easier and better and more powerful and recommended method. :up:
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-27, 03:26

I think this might be a good idea, but in the game I want to use the Cursor to interact with World Objects. So is the cursor bound to the gui or is there a possibility to get if the cursor touches an entity?
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-27, 13:58

Okay, i have now tried it out, but on the one Hand, when I use interactive GUI I cannot use the keys to move around, and on the other hand when I use a non-interactive GUI, The Camera still moves with the mouse. And I want to acieve the camera moving only on LMB down while moving. So I think i might have to rewrite the ClientStateInGameT::ProcessInputEvent()...

Another Idea is to make an interactive GUI where the keyboard events are handled to the game... an "half interactive GUI" :D would this be possible without rewriting the GUISys?
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-27, 19:43

A few hours of hacking later i found out that I can use Keyboard events when I change in ClientStateInGame.cpp:847 from

Code: Select all

if (ActiveGui->GetScriptName() == "" && WasLMBOnceUp)
to

Code: Select all

if (/* ActiveGui->GetScriptName() == "" &&*/ WasLMBOnceUp)
and comment out the ActiveGui completely. It's an evil hack, but now I can Use the Keyboard for the Game in an interactive GUI. BUt still the mouse movements are not forwarded to the GUI. Any Ideas?
Or is there even a better way to lead all events from the interactive gut to the game?

Another important question according the GuiSys-game connection is: How complicated can it possibly be to define a class for selectable Entities, so that they callBack into gui oder game code?
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Cursor ingame

Post by Carsten » 2012-02-28, 01:41

Haimi wrote:But still the mouse movements are not forwarded to the GUI. Any Ideas?
Or is there even a better way to lead all events from the interactive gut to the game?
Sorry, I fear you're losing me here...
If I understand you right, you have a "Chat" type GUI active and open which is consuming the mouse events so that the underlying game client GUI doesn't receive the events as well?
Another important question according the GuiSys-game connection is: How complicated can it possibly be to define a class for selectable Entities, so that they callBack into gui oder game code?
I don't think that that is particularly difficult: If I wanted to make the "Chat" GUI be able to click on an entity (e.g. in order to pick whom the message is sent to), I'd add a script method to the GUI scripting implementation that does the job. That is, when a mouse click occurs and our window's OnAction() script method is called, we need another (yet to be written) method like gui:findEntity() that does the job and digs up the details that you want to learn about the clicked entity.

Implementing this script method should not be overly difficult, but please forgive me that I cannot come up with an example at this time in the night. ;-) :oops:
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-28, 13:37

Carsten wrote:
Haimi wrote:But still the mouse movements are not forwarded to the GUI. Any Ideas?
Or is there even a better way to lead all events from the interactive gut to the game?
Sorry, I fear you're losing me here...
If I understand you right, you have a "Chat" type GUI active and open which is consuming the mouse events so that the underlying game client GUI doesn't receive the events as well?
Yes, exactly. That is the Problem.

I will try to figure out how I can realize the gui:findeEntitiy()... No need for you to do it after Midnight :)
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Cursor ingame

Post by Carsten » 2012-02-29, 00:01

Haimi wrote:
Carsten wrote:If I understand you right, you have a "Chat" type GUI active and open which is consuming the mouse events so that the underlying game client GUI doesn't receive the events as well?
Yes, exactly. That is the Problem.
In the engine, mouse events are distributed to the GUIs in the GUI Manager starting at [url=http://trac.cafu.de/browser/cafu/trunk/Ca3DE/MainCanvas.cpp?rev=483#L669]MainCanvasT::OnMouseMove()[/url].

(Except for the "Client" GUI with the 3D world, which is handled specially in the MainCanvasT::OnIdle() just above MainCanvasT::OnMouseMove().)

Normally, only the topmost active and interactive GUI receives the event, so that it is processed only a single time. Starting from here, e.g. by giving your GUI a specific name that you treat specially in these methods similar to the "Client" GUI, you should be able to let multiple GUIs have the same mouse event.
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-02-29, 09:10

Okay, I see i misunderstood something. The Problem by example:

I have an interactive GUI (Like the Chat GUI) all over the Screen. I need that to be able to move the Cursor over the whole screen.
Now I cannot move the player around or anything, I can't even press ESC to reach the main menu...
If I do my little dirty Hack from 2 of my posts above, I can at least move around using the WASD Keys, but no moving the camera around...
So the Idea was to use the mouse using the cursor, but if I hold down the LMB i stop moving the mouse and instead move the camera - as with a non-interactive GUI like the HUD.
But My Events are consumed by the GUI and I cannot get the commands as far as the Command recognition in ClientStateIngame.cpp would be able to handle them aswell.
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-03-06, 15:04

The main thing I would need to know: how can I prevent the GUI from consuming the events? I tried some code where events are handled to the GUI, but still I cannot change a thing.

And I tried to implement the gui:findEntity[/id] method, but I cannot figure out how I can check if there is an entity at the mouse position at click time. Can you give me a hint please?
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Cursor ingame

Post by Carsten » 2012-03-07, 01:45

Haimi wrote:The main thing I would need to know: how can I prevent the GUI from consuming the events? I tried some code where events are handled to the GUI, but still I cannot change a thing.
The main problem is probably in MainCanvas.cpp: whereever the code has to distribute events, it calls

Code: Select all

    cf::GuiSys::GuiI* ActiveGui=cf::GuiSys::GuiMan->GetTopmostActiveAndInteractive();
and then distributes events to ActiveGui only.
You may wish to alternatively or additionally distribute the same events to another GUI in the GuiMan as well, e.g. you could identify the relevant GUI by giving one of it's windows a "magic" name, as the code does with the "Client" root window.
And I tried to implement the gui:findEntity[/id] method, but I cannot figure out how I can check if there is an entity at the mouse position at click time. Can you give me a hint please?[/quote]
The key idea is to trace a ray through the "eye" into the world: The ray originates from the "eye" of the player, into the direction of and "through" the position of the mouse pointer. The problem is probably to learn the players current eye position, and especially the directional vector of the ray.
Once you have these, it's the same as if the player was firing a gunshot: whatever is hit is the desired entity.

(By the way, the world editor CaWE solves the same problem all the time, and is has very nice and clean code for the related math starting at http://trac.cafu.de/browser/cafu/trunk/CaWE/ChildFrameViewWin3D.cpp?rev=490#L156)

Please let me know if that is enough info. If it isn't, I'll look more deeply into it. :up:
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Cursor ingame

Post by Haimi » 2012-03-07, 02:13

Okay, I understand the theory now, but I am still not in deep enough to figure out by myself where I should get the camera Position (Okay, first Guess: EyePos(MatSys::Renderer->GetCurrentEyePosition());) and the Stack of elements to Iterate over...
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests