Jump to content

Recommended Posts

Posted

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.

 

 

Posted

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

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...