Need help with getting mouse control ingame.

Grab your favourite IDE and tinker with the innards of game engines

Need help with getting mouse control ingame.

Postby NZNobody on Thu Jul 07, 2011 4:03 pm

Hey,
So basically I am creating a mod based of the WC3 map Warlocks and want to implement a mouse control system similar Alienswarm. My mod is based off the 2007 HL2MP engine and up until now I’ve managed to lock the camera to a top down view and make it so you can't look up or down. However no matter what I try (been at it for like 15 hours :( ) I cannot 'free' the cursor up from being the central crosshair. (Although I did manage once by commenting out the code below, but that let me move the mouse (i think) but had no cursor so I’m not sure)
Code: Select all
void CInput::ControllerMove( float frametime, CUserCmd *cmd )
{
   if ( IsPC() )
   {
      if ( !m_fCameraInterceptingMouse && m_fMouseActive )
      {
         MouseMove( cmd);
      }
   }
   
   JoyStickMove( frametime, cmd);
}


Ultimately i plan to replace above code with code similar to this:
Code: Select all
Pseudo code:
QAngle angFaceThisWay;
float yawFacethisWay = tan( yGetMousePos() / xGetMousePos() );
angFaceThisWay = QAngle(yawFaceThisWay,0,0);
engine->SetViewAngles( angFaceThisWay );

NOTE: the GetMousePos returns the cursor position relative to the centre of screen in this case.

Anyways, if i could get hints / help / mini-tutorials on how to achieve this 'freeing' of the cursor I would be very grateful as it is a make or break for my mod :(
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help with getting mouse control ingame.

Postby zombie@computer on Thu Jul 07, 2011 4:27 pm

The cursor shows like normally in windoz when you show a popupped panel.

e.g.

Code: Select all
vgui::Panel *p = new Panel(g_pClientMode->GetViewport());//create new panel, parent to viewport
p->SetSize(p->GetParent()->GetWide(), p->GetParent()->GetTall());//resize to max
p->MakePopup(false, false);//woot, popupped!


Code goes on client ofcourse. My suggestion: as part of the HUD.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Need help with getting mouse control ingame.

Postby Zecrah on Thu Jul 07, 2011 4:54 pm

Could you take a look at the Alien Swarm code perhaps?
Major Banter wrote:Zecrah, you've come from nowhere yet have rapidly become a Hammer God.

Wtf.


Check out my weapons tutorial
Zecrah
Design Section Moderator
 
Joined: Sat Sep 27, 2008 10:56 am

Re: Need help with getting mouse control ingame.

Postby NZNobody on Thu Jul 07, 2011 10:59 pm

zombie@computer wrote:The cursor shows like normally in windoz when you show a popupped panel.

e.g.

Code: Select all
vgui::Panel *p = new Panel(g_pClientMode->GetViewport());//create new panel, parent to viewport
p->SetSize(p->GetParent()->GetWide(), p->GetParent()->GetTall());//resize to max
p->MakePopup(false, false);//woot, popupped!


Code goes on client ofcourse. My suggestion: as part of the HUD.


If its not too much to ask could you explain a little more? I still struggle to understand how to 'tie' things i crate into th engine. Wher do i call this panel and where do i put the code for it? (Nub coder here)
EDIT: Tried implementing this here: void CBaseViewport::CreateDefaultPanels( void ) But get mem access errors in the memoverride.cpp file :(
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help with getting mouse control ingame.

Postby Sandern on Fri Jul 08, 2011 12:51 pm

Alien swarm overrides the mouse resetting function and then draws a custom cursor in CASWHudCrosshair. See asw_in_mouse.cpp (ResetMouse function in particular) and asw_hud_crosshair.cpp.

If you want to make the windows like mouse cursor visible you will need to use the MakePopup() function. You can just call it directly in your custom derived viewport class. In the template sdk this would be SDKViewport.
Sandern
Regular
Regular
 
Joined: Thu Jun 30, 2005 1:08 pm
Location: Netherlands

Re: Need help with getting mouse control ingame.

Postby NZNobody on Fri Jul 08, 2011 8:33 pm

Thanks Sander88, i shall give this a try when my internet cap resets (yay capped internet in NZ :( ) and i can DL the alienswarm SDK. Question about the popped up panel method: Does the 'popped' panel have to be in front? the 'active panel'? Because I managed to derive a panel from Source Towers, and included it under the CreateDefaultPanels function but literally nothing changed at all :( (But no errors either).[EDIT:] In the constructer of this new panel i have BaseClass::MakePopeup(false,false); which changed nothing, still no mouse in a game, only in the menu and when chatting. [EDIT ENDS] Thanks for your help I’ll try all that after work today and see how it goes, it’s so frustrating because making 'spells' i thought would be harder but I’m managing that ok, this is just murder though.
Also i managed to 'lock' the users pitch to 0 degrees (straight ahead) because as it’s a top down game ofc i don't want them to be able to look up and down, BUT if you move the mouse REALLY fast you can still look up or down a bit before it snaps back to horizontal, which makes me think the SetPitch function in in_main.cpp is not the only function controlling this and elsewhere there is one with a faster frequency. Any Ideas?
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Return to Programming

Who is online

Users browsing this forum: No registered users

cron