Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera movement improvements with proper up and down movement. #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions BanjoKazooieLevelEditor/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class Form1 : Form
private bool zoomOut;
private bool left;
private bool right;
private bool moveUp;
private bool moveDown;
private GLCamera BBCamera = new GLCamera();
private int newMouseX;
private int newMouseY;
Expand Down Expand Up @@ -756,9 +758,9 @@ private void locateEORFiles()
private void camera()
{
bool flag = false;
if (this.zoomIn | this.zoomOut | this.left | this.right)
if (zoomIn | zoomOut | left | right | moveUp | moveDown)
{
this.BBCamera.PanUpdate(this.zoomIn, this.zoomOut, this.left, this.right);
BBCamera.PanUpdate(zoomIn, zoomOut, left, right, moveUp, moveDown);
flag = true;
}
Point mousePosition1 = Control.MousePosition;
Expand Down Expand Up @@ -2295,6 +2297,8 @@ private void openSetupFile()
this.BBCamera.Reset();
this.zoomIn = false;
this.zoomOut = false;
moveUp = false;
moveDown = false;
this.left = false;
this.right = false;
this.newMouseX = 0;
Expand Down Expand Up @@ -3141,25 +3145,25 @@ private void LevelViewer_KeyDown(object sender, KeyEventArgs e)
{
case Keys.ShiftKey:
case Keys.Shift:
this.multiselect = true;
multiselect = true;
break;
case Keys.A:
this.right = true;
right = true;
break;
case Keys.D:
this.left = true;
left = true;
break;
case Keys.E:
this.zoomOut = true;
moveUp = true;
break;
case Keys.Q:
this.zoomIn = true;
moveDown = true;
break;
case Keys.S:
this.zoomOut = true;
zoomOut = true;
break;
case Keys.W:
this.zoomIn = true;
zoomIn = true;
break;
}
}
Expand All @@ -3170,25 +3174,25 @@ private void LevelViewer_KeyUp(object sender, KeyEventArgs e)
{
case Keys.ShiftKey:
case Keys.Shift:
this.multiselect = false;
multiselect = false;
break;
case Keys.A:
this.right = false;
right = false;
break;
case Keys.D:
this.left = false;
left = false;
break;
case Keys.E:
this.zoomOut = false;
moveUp = false;
break;
case Keys.Q:
this.zoomIn = false;
moveDown = false;
break;
case Keys.S:
this.zoomOut = false;
zoomOut = false;
break;
case Keys.W:
this.zoomIn = false;
zoomIn = false;
break;
}
}
Expand Down
271 changes: 138 additions & 133 deletions BanjoKazooieLevelEditor/GLCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,140 +4,145 @@
// MVID: 9E4E8A9F-6E2F-4B24-B56C-5C2BF24BF813
// Assembly location: F:\BanjosBackpack\BB.exe

using System;

namespace BanjoKazooieLevelEditor
{
public class GLCamera
{
private Vector3 position = new Vector3(0.0f, 0.0f, -2161f);
private Vector3 rotation = new Vector3(0.0f, 0.0f, 0.0f);
private Vector3 up = new Vector3(0.0f, 1f, 0.0f);
private Matrix4 ryMatrix = Matrix4.I;
private Matrix4 rxMatrix = Matrix4.I;
private float movementSpeed = 10f;

public float MovementSpeed
{
set => this.movementSpeed = value;
}

public float X
{
set => this.position.x = value;
get => this.position.x;
}

public float Y
{
set => this.position.y = value;
get => this.position.y;
}

public float Z
public class GLCamera
{
set => this.position.z = value;
get => this.position.z;
private Vector3 position = new Vector3(0.0f, 0.0f, -2161f);
private Vector3 rotation = new Vector3(0.0f, 0.0f, 0.0f);
private Matrix4 ryMatrix = Matrix4.I;
private Matrix4 rxMatrix = Matrix4.I;
private float movementSpeed = 10f;

public float MovementSpeed
{
set => movementSpeed = value;
}

public float X
{
set => position.x = value;
get => position.x;
}

public float Y
{
set => position.y = value;
get => position.y;
}

public float Z
{
set => position.z = value;
get => position.z;
}

public float Yaw
{
set
{
rotation.y = value;
ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians(rotation.y));
}
get => rotation.y;
}

public float Pitch
{
set
{
rotation.x = value;
if (rotation.x < -180.0f)
rotation.x = 360f + rotation.x;
if (rotation.x > 180.0f)
rotation.x = 360f - rotation.x;
rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians(rotation.x));
}
get => rotation.x;
}

public float Roll
{
set => rotation.z = value;
get => rotation.z;
}

public float GetXRotation() => rotation.x;

public float GetYRotation() => rotation.y;

public float GetZRotation() => rotation.z;

public void Reset()
{
position = new Vector3(0.0f, 0.0f, -2161f);
rotation = new Vector3(0.0f, 0.0f, 0.0f);
}

public void LookAt(Vector3 target)
{
rotation.x = 0.0f;
rotation.y = 0.0f;
rotation.z = 0.0f;
position.x = target.x * -1f;
position.y = target.y * -1.0f - 50.0f;
position.z = target.z * -1.0f - 500.0f;
ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians(rotation.y));
rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians(rotation.x));
}

public void PanUpdate(bool forward, bool back, bool left, bool right, bool moveUp, bool moveDown)
{
Matrix4 m = Matrix4.GetRotationMatrix(Core.ToRadians(rotation.x), Core.ToRadians(rotation.y), Core.ToRadians(rotation.z));

Vector3 vector3 = new Vector3();
if (forward)
{
vector3 += new Vector3(m.matrix[2, 0], m.matrix[2, 1], m.matrix[2, 2]);
}

if (back)
{
vector3 += new Vector3(-m.matrix[2, 0], -m.matrix[2, 1], -m.matrix[2, 2]);
}

if (left)
{
vector3 += new Vector3(-m.matrix[0, 0], -m.matrix[0, 1], -m.matrix[0, 2]);
}

if (right)
{
vector3 += new Vector3(m.matrix[0, 0], m.matrix[0, 1], m.matrix[0, 2]);
}

if (moveUp)
{
vector3 += new Vector3(0, -1, 0);
}

if (moveDown)
{
vector3 += new Vector3(0, 1, 0);
}

if (vector3 == Vector3.Zero) return;

position += vector3.Normalize() * movementSpeed;
}

public void MouseUpdate(int mouseDeltaX, int mouseDeltaY)
{
rotation.y += mouseDeltaX * 0.25f;
rotation.x += mouseDeltaY * 0.25f;
if (rotation.x <= -90.0f)
rotation.x = -90f;
if (rotation.x >= 90.0f)
rotation.x = 90f;
ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians(rotation.y));
rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians(rotation.x));
}

public float[] GetWorldToViewMatrix() => (rxMatrix * ryMatrix * Matrix4.GetTranslationMatrix(position.x, position.y, position.z)).ToGLMatrix();
}

public float Yaw
{
set
{
this.rotation.y = value;
this.ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians((double) this.rotation.y));
}
get => this.rotation.y;
}

public float Pitch
{
set
{
this.rotation.x = value;
if ((double) this.rotation.x < -180.0)
this.rotation.x = 360f + this.rotation.x;
if ((double) this.rotation.x > 180.0)
this.rotation.x = 360f - this.rotation.x;
this.rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians((double) this.rotation.x));
}
get => this.rotation.x;
}

public float Roll
{
set => this.rotation.z = value;
get => this.rotation.z;
}

public float GetXRotation() => this.rotation.x;

public float GetYRotation() => this.rotation.y;

public float GetZRotation() => this.rotation.z;

public void Reset()
{
this.position = new Vector3(0.0f, 0.0f, -2161f);
this.rotation = new Vector3(0.0f, 0.0f, 0.0f);
}

public void LookAt(Vector3 target)
{
this.rotation.x = 0.0f;
this.rotation.y = 0.0f;
this.rotation.z = 0.0f;
this.position.x = target.x * -1f;
this.position.y = (float) ((double) target.y * -1.0 - 50.0);
this.position.z = (float) ((double) target.z * -1.0 - 500.0);
this.ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians((double) this.rotation.y));
this.rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians((double) this.rotation.x));
}

public void PanUpdate(bool forward, bool back, bool left, bool right)
{
float movementSpeed = this.movementSpeed;
float num1 = (float) Math.Sin(Core.ToRadians((double) this.rotation.y)) * movementSpeed;
float num2 = (float) Math.Cos(Core.ToRadians((double) this.rotation.y)) * movementSpeed;
float num3 = (float) Math.Sin(Core.ToRadians((double) this.rotation.x)) * movementSpeed;
Vector3 vector3 = new Vector3();
if (forward)
{
vector3.x -= num1;
vector3.z += num2;
vector3.y += num3;
}
if (back)
{
vector3.x += num1;
vector3.z -= num2;
vector3.y -= num3;
}
if (left)
{
vector3.x -= num2;
vector3.z -= num1;
}
if (right)
{
vector3.x += num2;
vector3.z += num1;
}
this.position += vector3;
}

public void MouseUpdate(int mouseDeltaX, int mouseDeltaY)
{
this.rotation.y += (float) mouseDeltaX * 0.25f;
this.rotation.x += (float) mouseDeltaY * 0.25f;
if ((double) this.rotation.x <= -90.0)
this.rotation.x = -90f;
if ((double) this.rotation.x >= 90.0)
this.rotation.x = 90f;
this.ryMatrix = Matrix4.GetRotationMatrixY(Core.ToRadians((double) this.rotation.y));
this.rxMatrix = Matrix4.GetRotationMatrixX(Core.ToRadians((double) this.rotation.x));
}

public float[] GetWorldToViewMatrix() => (this.rxMatrix * this.ryMatrix * Matrix4.GetTranslationMatrix(this.position.x, this.position.y, this.position.z)).ToGLMatrix();
}
}
}
Loading