simplify camera code a little bit

This commit is contained in:
UnknownShadow200 2018-05-18 11:02:22 +10:00
parent 3aecb338c1
commit b4b84fa442
4 changed files with 20 additions and 34 deletions

View File

@ -87,9 +87,6 @@ namespace ClassicalSharp {
protected static Point previous, delta;
void CentreMousePosition() {
if (!game.Focused) return;
Point current = game.DesktopCursorPos;
delta = new Point(current.X - previous.X, current.Y - previous.Y);
Point topLeft = game.PointToScreen(Point.Empty);
int cenX = topLeft.X + game.Width / 2;
int cenY = topLeft.Y + game.Height / 2;
@ -100,12 +97,8 @@ namespace ClassicalSharp {
public override void RegrabMouse() {
if (!game.Exists) return;
Point topLeft = game.PointToScreen(Point.Empty);
int cenX = topLeft.X + game.Width / 2;
int cenY = topLeft.Y + game.Height / 2;
game.DesktopCursorPos = new Point(cenX, cenY);
previous = new Point(cenX, cenY);
delta = Point.Empty;
CentreMousePosition();
}
static readonly float sensiFactor = 0.0002f / 3 * Utils.Rad2Deg;
@ -141,7 +134,9 @@ namespace ClassicalSharp {
public override void UpdateMouse() {
if (game.Gui.ActiveScreen.HandlesAllInput) {
delta = Point.Empty;
} else {
} else if (game.Focused) {
Point pos = game.DesktopCursorPos;
delta = new Point(pos.X - previous.X, pos.Y - previous.Y);
CentreMousePosition();
}
UpdateMouseRotation();

View File

@ -36,32 +36,21 @@ void PerspectiveCamera_GetPickedBlock(PickedPos* pos) {
Picking_CalculatePickedBlock(eyePos, dir, reach, pos);
}
Point2D previous, delta;
Point2D cam_prev, cam_delta;
void PerspectiveCamera_CentreMousePosition(void) {
if (!Window_GetFocused()) return;
Point2D current = Window_GetDesktopCursorPos();
delta = Point2D_Make(current.X - previous.X, current.Y - previous.Y);
Point2D topLeft = Window_PointToScreen(Point2D_Empty);
Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenY = topLeft.Y + Game_Height / 2;
Window_SetDesktopCursorPos(Point2D_Make(cenX, cenY));
/* Fixes issues with large DPI displays on Windows >= 8.0. */
previous = Window_GetDesktopCursorPos();
cam_prev = Window_GetDesktopCursorPos();
}
void PerspectiveCamera_RegrabMouse(void) {
if (!Window_GetExists()) return;
Point2D topLeft = Window_PointToScreen(Point2D_Empty);
Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenY = topLeft.Y + Game_Height / 2;
Point2D point = { cenX, cenY };
Window_SetDesktopCursorPos(point);
previous = point;
delta = Point2D_Empty;
cam_delta = Point2D_Empty;
PerspectiveCamera_CentreMousePosition();
}
#define CAMERA_SENSI_FACTOR (0.0002f / 3.0f * MATH_RAD2DEG)
@ -73,13 +62,13 @@ void PerspectiveCamera_UpdateMouseRotation(void) {
Real32 sensitivity = CAMERA_SENSI_FACTOR * Game_MouseSensitivity;
if (Game_SmoothCamera) {
speedX += delta.X * CAMERA_ADJUST;
speedX += cam_delta.X * CAMERA_ADJUST;
speedX *= CAMERA_SLIPPERY;
speedY += delta.Y * CAMERA_ADJUST;
speedY += cam_delta.Y * CAMERA_ADJUST;
speedY *= CAMERA_SLIPPERY;
} else {
speedX = (Real32)delta.X;
speedY = (Real32)delta.Y;
speedX = (Real32)cam_delta.X;
speedY = (Real32)cam_delta.Y;
}
LocalPlayer* player = &LocalPlayer_Instance;
@ -101,8 +90,10 @@ void PerspectiveCamera_UpdateMouseRotation(void) {
void PerspectiveCamera_UpdateMouse(void) {
Screen* screen = Gui_GetActiveScreen();
if (screen->HandlesAllInput) {
delta = Point2D_Empty;
} else {
cam_delta = Point2D_Empty;
} else if (Window_GetFocused()) {
Point2D pos = Window_GetDesktopCursorPos();
cam_delta = Point2D_Make(pos.X - cam_prev.X, pos.Y - cam_prev.Y);
PerspectiveCamera_CentreMousePosition();
}
PerspectiveCamera_UpdateMouseRotation();

View File

@ -19,8 +19,8 @@
bool input_buttonsDown[3];
Int32 input_pickingId = -1;
Int32 input_normViewDists[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
Int32 input_classicViewDists[] = { 8, 32, 128, 512 };
Int32 input_normViewDists[10] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
Int32 input_classicViewDists[4] = { 8, 32, 128, 512 };
Key input_lastKey;
DateTime input_lastClick;
Real32 input_fovIndex = -1.0f;

View File

@ -194,7 +194,7 @@ void ButtonWidget_SetText(ButtonWidget* widget, STRING_PURE String* text) {
widget->Height = max(widget->Texture.Height, widget->MinHeight);
Widget_Reposition(widget);
widget->Texture.X = widget->X + (widget->Width / 2 - widget->Texture.Width / 2);
widget->Texture.X = widget->X + (widget->Width / 2 - widget->Texture.Width / 2);
widget->Texture.Y = widget->Y + (widget->Height / 2 - widget->Texture.Height / 2);
}
}