Results 1 to 7 of 7
  1. #1
    MSgt. Shooter Person
    Join Date
    Jul 2008
    Posts
    94

    Default Free Floating Crosshair?

    Hello again, Community. I've asked many questions in the past (I feel like I have anyway) and I thank those who answered.

    I do Have another question however. How can I create a free floating Crosshair? I know it's mainly done Through hud, adressed from playercontroller, and I've seen alot of good tutorials and reference codes, but I want it so that it only applies to the vehicles that I am planning for them to be used in. Here's what I know:

    • Need to get mouse Coordinates
    • Display A Crosshair at that position
    • Relate that position to the world


    Help would be greatly appreciated, as it always is!
    Last edited by 1Lt Coagulator; 08-02-2012 at 08:25 PM.

  2. #2
    MSgt. Shooter Person
    Join Date
    Jul 2008
    Posts
    94

    Default

    Was Able to get mouse coordinates, and log them, but unable to get the cursor (simple crosshair) to follow it; it's still locked on the screen.

    Custom Input Class
    Code:
    class AceMouseInput extends PlayerInput;
    Var IntPoint MousePosition;
    
    Event PlayerInput(float DeltaTime)
    {
    //Handle the mouse and make sure I have a HUD
    	//if (myHUD != None)
    	//	{
    		//Get For the aMouseX used in udk, use the PlayerInput.aTurn instead.
    		MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX);
    		//Get For the aMouseY used in udk, use the PlayerInput.aLookup instead.
    		MousePosition.Y = Clamp(MousePosition.Y + aMouseY, 0, myHUD.SizeY);
    		//}
    	Super.PlayerInput(DeltaTime);
    		`Log("MOUSE X is" @MousePosition.X);
    		`Log("MOUSE Y is" @MousePosition.Y);
    }
    
    
    defaultproperties
    {
    	MouseCursorMaterial=Material'PDUI_Gameplay.PDUI_Gameplay.CursorNormal'
    	CursorSize=64
    }
    Custom HUD Class
    Code:
    class AceHUD extends HUD;
    var() Material MouseCursorMaterial;
    var() float CursorSize;
    
    var const Texture2D CursorTexture; 
    // The color of the cursor
    var const Color CursorColor;
    /*
    function UpdateMousePosition()
    {
    	local int x, y;
    
    	class'UIRoot'.static.GetCursorPosition(x, y);
    
    	PlayerOwner.PlayerInput.aturn = MouseX;
    	PlayerOwner.PlayerInput.aLookup =MouseY;
    
    	//`Log("PDHud::UpdateMouseition" @ Mouse.X @ Mouse.Y);
    }
    */
    /*
    function RenderMouseCursor()
    {
    
    	// Center the cursor on our cursor position
    	Canvas.SetPos(MouseX - (CursorSize/2), MouseY - (CursorSize/2));
    	Canvas.DrawColor = Whitecolor;
    	Canvas.DrawMaterialTile(MouseCursorMaterial,CursorSize,CursorSize,0,0,1,1);
    }
    */
    
    event PostRender()
    {
    
    Local AceMouseInput MouseInput;
    
    	//UpdateMousePosition();
    	//RenderMouseCursor();
    //Make sure that there is a player controller
    If (PlayerOwner != None)
    	{
    	`Log("PlayerOwner is" @PlayerOwner);
    		MouseInput = AceMouseInput(PlayerOwner.PlayerInput);
    		
    		If (MouseInput != None)
    		{
    		
    			Canvas.Setpos(MouseInput.MousePosition.X, MouseInput.MousePosition.Y);
    			Canvas.DrawColor = Whitecolor;
    			Canvas.DrawMaterialTile(MouseCursorMaterial,CursorSize,CursorSize,0,0,1,1);
    		}
    	super.PostRender();
    	
    }
    }
    
    function Vector GetMouseWorldLocation()
    {
      local AceMouseInput MouseInterfacePlayerInput;
      local Vector MousePosition;
      local Vector MouseWorldOrigin, MouseWorldDirection, HitLocation, HitNormal;
    
      // Ensure that we have a valid canvas and player owner
      if (Canvas == None || PlayerOwner == None)
      {
        return Vect(0, 0, 0);
      }
    
      // Type cast to get the new player input
      MouseInterfacePlayerInput = AceMouseInput(PlayerOwner.PlayerInput);
    
      // Ensure that the player input is valid
      if (MouseInterfacePlayerInput == None)
      {
        return Vect(0, 0, 0);
      }
    
      // We stored the mouse position as an IntPoint, but it's needed as a Vector2D
      MousePosition.X = MouseInterfacePlayerInput.MousePosition.X;
      MousePosition.Y = MouseInterfacePlayerInput.MousePosition.Y;
      // Deproject the mouse position and store it in the cached vectors
      Canvas.DeProject(MousePosition);
    
      // Perform a trace to get the actual mouse world location.
      Trace(HitLocation, HitNormal, MouseWorldOrigin + MouseWorldDirection * 65536.f, MouseWorldOrigin , true,,, TRACEFLAG_Bullet);
      return HitLocation;
    }
    
    
    
    defaultproperties
    {
    	MouseCursorMaterial=Material'PDUI_Gameplay.PDUI_Gameplay.CursorNormal'
    	CursorSize=64
    }
    PlayerController
    Code:
    class AcePlayerController extends UTPlayerController;
    
    
    
    
    defaultproperties
    {
    
    	InputClass=class'Ace_Vehicles.AceMouseInput'
    	
    }
    I think everything is referenced, and the only link that is missing is the one that connects the mouse cursor to the crosshair.
    As always, advice is appreciated!

  3. #3
    MSgt. Shooter Person
    Join Date
    Jul 2008
    Posts
    94

    Default

    Edit: Able to Get a mouse cursor on screen. Will try replicating screen-to-world actions soon.

  4. #4
    MSgt. Shooter Person
    Join Date
    Jun 2009
    Posts
    429

    Default

    Did you check the UDK development gem
    Creating a mouse interface?

    General approach: Deprojet 2D mouse coordinates to 3D coordinates and do a trace check in that direction the controller is looking (Rotation >> MyWorldLoc (vect(1,0,0) * 65536)). You're able to retrieve the hit actor (or hit component).

  5. #5
    MSgt. Shooter Person
    Join Date
    Jul 2008
    Posts
    94

    Default

    Quote Originally Posted by RattleSN4K3 View Post
    Did you check the UDK development gem
    Creating a mouse interface?

    General approach: Deprojet 2D mouse coordinates to 3D coordinates and do a trace check in that direction the controller is looking (Rotation >> MyWorldLoc (vect(1,0,0) * 65536)). You're able to retrieve the hit actor (or hit component).
    I did, over and over. I tried replicating that for ut3, but kept failing. I'm going to give it another shot though, as It is one of the better (and more documented) methods of achieving what I am trying to accomplish.

    I was able to get the cursor on the screen, but I changed the Custom hud I made to extend UTHUD instead of just HUD, as well as the custom playercontroller to extend 'UTPlayerController' Instead of just 'PlayerController' (that way it works with gametypes), and now I get this in the log file:
    Code:
    ScriptWarning: AcePlayerController VCTF-RocketForst.TheWorld:PersistentLevel.AcePlayerController_0 (Function UTGame.UTPlayerController:LoadSettingsFromProfile:08BA) Accessed None 'PlayerInput'
    The cursor doesnt move, and I'm unsure why. I checked the player controller that I use, and I believe it is correct.

    Code:
    class AcePlayerController Extends UTPlayerController;
    
    defaultproperties
    {   
      // Set the input class to the mouse interface player input
      InputClass=class'AceMouseInput'
    }
    I am not sure what's up with this, I'll keep looking, but suggestions are welcome. It may just be a simple thing I am missing too..
    Last edited by 1Lt Coagulator; 09-04-2012 at 02:14 PM.

  6. #6
    MSgt. Shooter Person
    Join Date
    Jun 2009
    Posts
    429

    Default

    Are you creating a pure standalone mod/gametype/TC?
    I'm asking because of the compatiblity problems you can run into.

    InputClass is the last thing i would touch as it may uses default keybindings and may overwrite some custom settings/bindings for a player.
    There are several other solutions.

    One solution would be by creating/spawning/opening a scene. A scene has a native function to retrieve the cursorsettings. If you set the value of SceneInputMode to INPUTMODE_None the scene should not block any user input (like the UTUIScene_Hud does).
    Code:
    defaultproperties
    {
        bPauseGameWhileActive=false
        SceneInputMode=INPUTMODE_None
        bRenderParentScenes=true
        bCloseOnLevelChange=true
        bExemptFromAutoClose=true
    }
    You can change the input method with the following function.
    Code:
    /**
     * The types of split-screen input modes that are supported for UI scenes.  These control what a UIScene does when it
     * receives input from multiple gamepads at once.
     *
     * @note: the order of the values in this enum should not be changed.
     */
    enum EScreenInputMode
    {
        /**
         * This scene doesn't process input at all.  Useful for optimizing input processing for scenes which don't process any input,
         * such as HUD scenes.
         */
        INPUTMODE_None,
    
        /**
         * Simultaneous inputs are not supported in this scene.  Only input from the gamepad that is associated with
         * this scene will be processed.  Input from other gamepads will be ignored and swallowed.
         * This is the most common input mode.
         */
        INPUTMODE_Locked,        // MIM_Bound
    
        /**
         * Similar to INPUTMODE_Locked, except that input from gamepads not associated with this scene is passed to the
         * next scene in the stack.
         * Used for e.g. profile selection scenes where each player can open their own profile selection menu.
         */
        INPUTMODE_MatchingOnly,    // MIM_NonBlocking
    
        /**
         * Similar to INPUTMODE_Free, except that input is only accepted from active gamepads which are associated with a
         * player.
         * All input and focus is treated as though it came from the same gamepad, regardless of where it came from.
         * Allows any active player to interact with this screen.
         */
        INPUTMODE_ActiveOnly,    // MIM_Cooperative
    
        /**
         * Any active gamepad can interact with this menu, even if it isn't associated with a player.
         * Used for menus which allow additional players to become active, such as the character selection menu.
         */
        INPUTMODE_Free,            // MIM_Unbound
    
        /**
         * Input from any active gamepad will be processed by this scene.  The scene contains a unique set of controls
         * for each active gamepad, and those controls only respond to input from the gamepad they're associated with.
         * Used for scenes where all players should be able to interact with the same controls in the scene (such as a
         * character selection menu in most fighting games)
         */
        INPUTMODE_Simultaneous,    // MIM_Simultaneous
    };
    
    /**
     * Changes the screen input mode for this scene.
     */
    native final function SetSceneInputMode( EScreenInputMode NewInputMode );
    Another approch is to use the static native function of UIRoot

    Code:
    /**
     * Returns the current position of the mouse or joystick cursor.
     *
     * @param    CursorX        receives the X position of the cursor
     * @param    CursorY        receives the Y position of the cursor
     * @param    Scene        if specified, provides access to an FViewport through the scene's SceneClient that can be used
     *                        for retrieving the mouse position when not in the game.
     *
     * @return    TRUE if the cursor position was retrieved correctly.
     */
    native static final noexport function bool GetCursorPosition( out int CursorX, out int CursorY, const optional UIScene Scene );
    
    /**
     * Returns the current position of the mouse or joystick cursor.
     *
     * @param    CursorXL    receives the width of the cursor
     * @param    CursorYL    receives the height of the cursor
     *
     * @return    TRUE if the cursor size was retrieved correctly.
     */
    native static final noexport function bool GetCursorSize( out float CursorXL, out float CursorYL );
    If you do some research, you'll get a fully working code snippet.

  7. #7
    MSgt. Shooter Person
    Join Date
    Jul 2008
    Posts
    94

    Default

    For now, I'm trying to make a Gametype, although in the future It'll be a TC hopefully. I don't want to move to udk because of framerate drops and lack of game modes, but What I have is this:

    Code:
    class AceHud Extends UTHud;
    // The texture which represents the cursor on the screen
    var const Texture2D CursorTexture; 
    // The color of the cursor
    var const Color CursorColor;
    Var AcePlayerController PC;
    
    event PostRender()
    {
      local AceMouseInput AMI;
    	PC = AcePlayerController(UTPlayerController(Owner));
    	
      // Ensure that we have a valid PlayerOwner and CursorTexture
      if (PC != None && CursorTexture != None) 
      {
        // Cast to get the AceMouseInput
        AMI = AceMouseInput(PC.PlayerInput); 
    
        if (AMI != None)
        {
          // Set the canvas position to the mouse position
          Canvas.SetPos(AMI.MousePosition.X, AMI.MousePosition.Y); 
          // Set the cursor color
          Canvas.DrawColor = CursorColor;
          // Draw the texture on the screen
          Canvas.DrawTile(CursorTexture, CursorTexture.SizeX, CursorTexture.SizeY, 0.f, 0.f, CursorTexture.SizeX, CursorTexture.SizeY);
    	//  Worldinfo.game.BroadCast(PC, "INPUT IS" @PC.PlayerInput);
        }
      }
       if (PC == None || CursorTexture == None || PC == None && CursorTexture == None) 
    	{
    		`log("Is there a PC?" @ PC);
    		`log("is there a Cursor Texture" @CursorTexture);
    	}
    	`Log("PlayerOwner Is:" @PlayerOwner);
    	`Log("Owner of hud is:" @self.owner);
    	`Log("PlayerController is" @PC);
      Super.PostRender();
    }
    
    defaultproperties
    {
      CursorColor=(R=255,G=255,B=255,A=255)
      CursorTexture=Texture2D'UI_HUD.HUD.UI_HUD_Redeemer'
    }
    and the input file:
    Code:
    class AceMouseInput extends PlayerInput; 
    
    // Stored mouse position. Set to private write as we don't want other classes to modify it, but still allow other classes to access it.
    var IntPoint MousePosition; 
    
    event PlayerInput(float DeltaTime)
    {
      // Handle mouse 
      // Ensure we have a valid HUD
      if (myHUD != None) 
      {
        // Add the aMouseX to the mouse position and clamp it within the viewport width
        MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX); 
        // Add the aMouseY to the mouse position and clamp it within the viewport height
        MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, myHUD.SizeY); 
      }
    
      Super.PlayerInput(DeltaTime);
    }
    
    defaultproperties
    {
    }
    It's dirty in my opinion, but I actually used this (I believe from the UDN website), and obviously something's wrong. I think it's because the UDN Gem that this is from is specifically for a TC (I think) or a custom game mode. Thanks for the info, I will surely look into this. Results will be posted.

    Edit:
    Awesome, Thank you. With your insight I was able to (quite easily actually) use the get cursor position function successfully, and it appeared the way I wanted it to. I am now going to try and work on the deproject function to get a 3d coordinate where the weapon fires at the location, then try to limit the free-floating cursor to a specific range away from the center using clamps. Results/errors will be posted.
    Last edited by 1Lt Coagulator; 09-05-2012 at 04:33 PM.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.