Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy16823 committed Jul 18, 2024
1 parent 691c738 commit 62bd620
Show file tree
Hide file tree
Showing 231 changed files with 1,540 additions and 3,152 deletions.
14 changes: 14 additions & 0 deletions Source/Genesis/Core/GameElements/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ public void PlayAnimation(String name)
}
}

/// <summary>
/// Stops the currently playing animation.
/// </summary>
/// <remarks>
/// This method sets the animator's play state to false, effectively pausing the animation.
/// </remarks>
public void StopAnimation()
{
if(this.Animator.Play != false)
{
this.Animator.Play = false;
}
}

/// <summary>
/// Finds an animation with the specified name.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion Source/Genesis/Genesis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
<Compile Include="Graphics\IRenderDevice.cs" />
<Compile Include="Graphics\Material.cs" />
<Compile Include="Graphics\PerspectiveCamera.cs" />
<Compile Include="Graphics\RenderDevice\BetaRenderer.cs" />
<Compile Include="Graphics\RenderDevice\GLRenderer.cs" />
<Compile Include="Graphics\RenderSettings.cs" />
<Compile Include="Graphics\Shaders\OpenGL\AnimatedModelShader.cs" />
Expand Down
31 changes: 19 additions & 12 deletions Source/Genesis/Graphics/RenderDevice/GLRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class GLRenderer : IRenderDevice

public Framebuffer sceneBuffer;
private Framebuffer uiBuffer;

private Viewport m_viewport;

public GLRenderer(IntPtr hwnd, RenderSettings settings)
Expand Down Expand Up @@ -860,7 +861,7 @@ public void DrawSprite(Sprite sprite)
gl.Disable(OpenGL.DepthTest);
//Create the modelview matrix
mat4 mt_mat = mat4.Translate(sprite.Location.X, sprite.Location.Y, sprite.Location.Z);
mat4 mr_mat = mat4.RotateZ(sprite.Rotation.Z);
mat4 mr_mat = mat4.RotateZ(Utils.ToRadians(sprite.Rotation.Z));
mat4 ms_mat = mat4.Scale(sprite.Size.X, sprite.Size.Y, sprite.Size.Z);
mat4 m_mat = mt_mat * mr_mat * ms_mat;

Expand Down Expand Up @@ -1172,7 +1173,7 @@ public void SetViewport(Viewport viewport)
UpdateFramebufferSize(this.sceneBuffer, (int)viewport.Width, (int)viewport.Height);
UpdateFramebufferSize(this.uiBuffer, (int)viewport.Width, (int)viewport.Height);

if (m_viewport == null || m_viewport != viewport)
if(m_viewport == null || m_viewport != viewport)
{
m_viewport = viewport;
}
Expand All @@ -1184,22 +1185,28 @@ public void SetViewport(Viewport viewport)
/// <param name="camera"></param>
public void SetCamera(Viewport viewport, Camera camera)
{
if(camera.Type == CameraType.Ortho)
float correction = camera.CalculateScreenCorrection(viewport);

if (camera.Type == CameraType.Ortho)
{
float x = camera.Location.X - (camera.Size.X / 2);
float y = camera.Location.Y - (camera.Size.Y / 2);
float top = y + camera.Size.Y;
float right = x + camera.Size.X;
float halfWidth = (viewport.Width / 2) / correction;
float halfHeight = (viewport.Height / 2) / correction;

float left = camera.Location.X - halfWidth;
float right = camera.Location.X + halfWidth;
float bottom = camera.Location.Y - halfHeight;
float top = camera.Location.Y + halfHeight;

p_mat = mat4.Ortho(x, right, y, top, 0.0f, 100.0f);
p_mat = mat4.Ortho(left, right, bottom, top, 0.1f, 100.0f);
v_mat = mat4.LookAt(new vec3(0f, 0f, 1f), new vec3(0f, 0f, 0f), new vec3(0f, 1f, 0f));
}
else
{
float aspectRatio = (viewport.Width * correction) / (viewport.Height * correction);
vec3 cameraPosition = camera.Location.ToGlmVec3();
Vec3 cameraFront = Utils.CalculateCameraFront2(camera);

p_mat = mat4.Perspective(Utils.ToRadians(45.0f), camera.Size.X / camera.Size.Y, camera.Near, camera.Far);
p_mat = mat4.Perspective(Utils.ToRadians(45.0f), aspectRatio, camera.Near, camera.Far);
v_mat = mat4.LookAt(cameraPosition, cameraPosition + cameraFront.ToGlmVec3(), new vec3(0.0f, 1.0f, 0.0f));
}

Expand All @@ -1216,8 +1223,8 @@ private void SetUIMatrices()
{
float x = 0;
float y = 0;
float top = y + camera.Size.Y;
float right = x + camera.Size.X;
float top = y + m_viewport.Height;
float right = x + m_viewport.Width;

p_mat = mat4.Ortho(x, right, y, top, 0.0f, 100.0f);
v_mat = mat4.LookAt(new vec3(0f, 0f, 1f), new vec3(0f, 0f, 0f), new vec3(0f, 1f, 0f));
Expand Down Expand Up @@ -1811,7 +1818,7 @@ public void FinishSceneRendering(Scene scene)
public void PrepareLightmap2D(Scene scene, Framebuffer framebuffer)
{
Scene2D scene2D = (Scene2D)scene;
this.UpdateFramebufferSize(framebuffer, (int)camera.Size.X, (int)camera.Size.Y);
this.UpdateFramebufferSize(framebuffer, (int)m_viewport.Width, (int)m_viewport.Height);
gl.BindFramebuffer(OpenGL.FrameBuffer, framebuffer.FramebufferID);
gl.Enable(OpenGL.DepthTest);
gl.Enable(OpenGL.Blend);
Expand Down
Loading

0 comments on commit 62bd620

Please sign in to comment.