https://dl.dropboxusercontent.com/u/55657765/cursor.wad
You're absolutely free to use this in your mods, just give me credit.

The reason I made this was I've noticed that in so many mods, their on-screen mouse scripts feel awkward to use.
It's just because it deviates from what I'm used to in my operating system. So I felt a need to put an end to that!
It's impossible for mouse look being turned off to be accounted for though. You need mouse look on!
Edit: Added support for keyboard binds to control cursor.
I forget if I've shown anybody anything like this before.
If I've come late to the making of this, this has already been done, etc. etc. I apologize.

I can't really seem to find anything like this on the forums though.
Math involved:

Δx is the offset of our cursor's x position, Δy is the offset of our cursor's y position.
θ₁ is our player's yaw input, θ₂ is our player's pitch input.
Δ₁ is our player's mouse turning speed (m_yaw), Δ₂ is our player's mouselook speed (m_pitch).
s is our player's overall mouse sensitivity.
ACS source taken directly from the level:
Code: Select all
#include "ZCommon.acs"
// This is an on-screen mouse script written by wtg62.
// I've written it so that it tries to match your operating system mouse sensitivity.
// So mess with your mouse settings as you like!
// No matter what you do, you won't experience awkward cursor movement in game!
// Mouse's coordinates
// Starting values don't matter that much, but I prefer it to start in the center of the screen.
int mx = 0.5;
int my = 0.5;
// Pixels to move every tic when using keyboard to move cursor.
int kbSpeed = 10.0;
// Cursor graphic
str cursorGraphic = "cursor";
// Hud size. The numbers are big because I want a small cursor graphic.
int HUDX = 960;
int HUDY = 600;
// This function will take any value from 0.0 to 1.0.
// It will then convert it to a number between 0 and the "scale" variable.
// It will return a fixed number.
function int fixedToPixel(int x, int scale)
{
// Here, I multiply 'x' by our scale to get the appropriate number.
// However, I must round down (basically truncate digits).
// The best way to do this is to shift our bits to the right, and back to the left.
// This effectively rounds down for us.
return (FixedMul(x,scale<<16)>>16)<<16;
}
Script 1 Enter
{
// Level set up, not an important part of the script at all.
SetMusic("");
SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
ChangeCamera(1,0,0);
// Set up
SetHudSize(HUDX,HUDY,0); // I just use these numbers for a small cursor graphic.
SetFont(cursorGraphic); // Optional, but looks better than using a character such as "+" or "."
while(true)
{
// We need to support keybinds for keyboard look.
// So let's check if we're using the keyboard or mouse, and then respond appropriately.
if(GetPlayerInput(0,INPUT_BUTTONS) & (BT_LEFT|BT_RIGHT|BT_LOOKUP|BT_LOOKDOWN))
{
// Keyboard controlled cursor
// Should be slow enough for user to be able to precisely hover over stuff.
// 'kbSpeed' pixels per tic.
// I use our previously set hud size to make movement speed on both axes look the same.
if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LEFT) mx -= kbSpeed/HUDX;
if(GetPlayerInput(0,INPUT_BUTTONS) & BT_RIGHT) mx += kbSpeed/HUDX;
if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LOOKUP) my -= kbSpeed/HUDY;
if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LOOKDOWN) my += kbSpeed/HUDY;
}
else
{
// So here's our mouse controlled cursor.
// Basically, these 2 variables below will take our player's yaw and pitch input and scale it.
// Input is scaled so that our in-game "cursor" movement accurately matches operating system mouse movement.
// 'pitchscale' is also basically multiplied by 2.
// Why? Because pitch input is 2x slower than yaw input.
int yawScale = FixedDiv(2.5,FixedMul(GetCVar("m_yaw"),GetCVar("mouse_sensitivity")));
int pitchScale = FixedDiv(5.0,FixedMul(GetCVar("m_pitch"),GetCVar("mouse_sensitivity")));
// Now we get our delta x and delta y. 'Delta' means 'change in'. So 'change in x', and 'change in y'.
// We'll use these to offset our current mouse position.
int dmx = -FixedMul(GetPlayerInput(0,INPUT_YAW),yawScale);
int dmy = -FixedMul(GetPlayerInput(0,INPUT_PITCH),pitchScale);
// Apply our offsets.
mx += dmx;
my += dmy;
}
// Clamp our mouse position, so our mouse doesn't go offscreen and into the abyss forever.
if(mx < 0) mx = 0;
if(my < 0) my = 0;
if(mx > 0.999) mx = 0.999;
if(my > 0.999) my = 0.999;
// Time to display our cursor!
// I have to remember that we used the SetHudSize function.
// I can't use a value from 0.0 to 1.0 for our display coordinates.
// I have to use a value from 0.0 to 960.0 for x, and 0.0 to 600.0 for y.
// So that's why I have my fixedToPixel function defined above!
// I also have to add 0.1 to each of our coordinates.
// This signals to ZDoom I want the upper left corner of my image to be at the integer part of the coordinates.
HudMessage(s:"a"; HUDMSG_PLAIN, 1, CR_UNTRANSLATED, fixedToPixel(mx,HUDX)+0.1, fixedToPixel(my,HUDY)+0.1, 0);
Delay(1);
}
}