Skip to content

Commit

Permalink
Add rotation funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Jan 27, 2024
1 parent d4b9193 commit 0e1c33b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
35 changes: 33 additions & 2 deletions public/Jailbreak.Public/Mod/Draw/BeamedShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,38 @@ protected BeamedShape(BasePlugin plugin, Vector position, int resolution) : base
beams = new BeamLine[resolution];
}

// TODO: Add support for rotation across arbitrary axis
public static void Rotate(float[][] coords, int size, float angle, float[] axis)
{
float[][] fCoords = new float[size][];
for (int i = 0; i < size; i++)
{
fCoords[i] = new float[3];
Array.Copy(coords[i], fCoords[i], 3);
}

float cosTheta = (float)Math.Cos(angle);
float sinTheta = (float)Math.Sin(angle);

for (int i = 0; i < size; i++)
{
float x = fCoords[i][0];
float y = fCoords[i][1];
float z = fCoords[i][2];

float dotProduct = x * axis[0] + y * axis[1] + z * axis[2];

float xRotated = cosTheta * x + (1 - cosTheta) * dotProduct * axis[0] +
sinTheta * (axis[1] * z - axis[2] * y);
float yRotated = cosTheta * y + (1 - cosTheta) * dotProduct * axis[1] +
sinTheta * (axis[2] * x - axis[0] * z);
float zRotated = cosTheta * z + (1 - cosTheta) * dotProduct * axis[2] +
sinTheta * (axis[0] * y - axis[1] * x);

coords[i][0] = xRotated;
coords[i][1] = yRotated;
coords[i][2] = zRotated;
}
}

public Color GetColor()
{
Expand All @@ -32,7 +63,7 @@ public void SetColor(Color color)

public override void Remove()
{
for(int i = 0; i < beams.Length; i++)
for (int i = 0; i < beams.Length; i++)
{
beams[i]?.Remove();
beams[i] = null;
Expand Down
5 changes: 5 additions & 0 deletions public/Jailbreak.Public/Mod/Draw/DrawableShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public virtual void Move(Vector position)
}

public abstract void Remove();

public Vector GetPosition()
{
return position;
}
}

0 comments on commit 0e1c33b

Please sign in to comment.