Thirsty Panther Posted October 10, 2015 Share Posted October 10, 2015 I'm working on a version of Operation Wolf www.arcade-museum.com/game_detail.php?game_id=8927 for the Halloween Games tournament. In this the players character stays still and moves the mouse to target enemies. For this I need to change the default mouse pointer to a crosshair. My current idea is to hide the default mouse pointer with window:hideMouse and to draw a crosshair image in its place. My problem is to getting the mouse co-ordinates and applying them to the crosshair image. Window:GetMousePosition gives a vec3 but I'm clueless on how to apply these to the crosshair image. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 10, 2015 Share Posted October 10, 2015 Window:GetMousePosition() This function gets the mouse position. The X and Y components of the returned values are the screen coordinates, and the Z component is the mouse wheel position. example: window = Window:Create("crosshair",0,0,800,600,window.Titlebar+window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:Move(0,0,-3) light = DirectionalLight:Create() light:SetRotation(35,35,0) model = Model:Box() model:SetColor(1,.5,0,1) crosshair = Texture:Load("Materials/Crosshair/crosshair.tex") ch_width = crosshair:GetWidth() ch_height = crosshair:GetHeight() --window:HideMouse() while window:KeyDown(Key.Escape)==false do model:Turn(0,Time:GetSpeed(),0) Time:Update() world:Update() world:Render() m_pos = window:GetMousePosition() context:SetBlendMode(Blend.Alpha) context:DrawImage(crosshair, m_pos.x - (ch_width/2), m_pos.y - (ch_height/2)) context:DrawText("Mouse position: "..m_pos.x..", "..m_pos.y, 2, 2) context:SetBlendMode(Blend.Solid) context:Sync() end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Slastraf Posted October 10, 2015 Share Posted October 10, 2015 Hide the real mouse and make the mouse icon always the same position as the real mouse in an updating function should work. didnt go trough the code above 1 Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted October 10, 2015 Author Share Posted October 10, 2015 Thank you both. The step I was missing was loading the GetMousePosition into a variable so that I could then get the X and Y co-ordinates from. Thanks also for the factoring in the size of the crosshair. I probably would not have realized until much later that I had forgotten this as well. Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.