18.09.2020
+ Textures ~ Changed 2D coordnate system to lower right as XY+
This commit is contained in:
parent
589d131246
commit
a603ecc417
26 changed files with 267 additions and 16 deletions
43
SMCode/SM2D/Drawing/DrawTexture.cs
Normal file
43
SMCode/SM2D/Drawing/DrawTexture.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Drawing;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Textures;
|
||||
using SM2D.Types;
|
||||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
public class DrawTexture : DrawingBasis<Transformation>
|
||||
{
|
||||
public Texture Texture
|
||||
{
|
||||
get => (Texture) _material.Texture;
|
||||
set => _material.Texture = value;
|
||||
}
|
||||
|
||||
public Color4 Tint
|
||||
{
|
||||
get => _material.Tint;
|
||||
set => _material.Tint = value;
|
||||
}
|
||||
|
||||
public DrawTexture(Bitmap map) : this(map, Color4.White)
|
||||
{ }
|
||||
|
||||
public DrawTexture(Bitmap map, Color4 tint)
|
||||
{
|
||||
_material.Texture = new Texture(map);
|
||||
_material.Tint = tint;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
ApplyContext(ref context);
|
||||
|
||||
context.ModelMatrix = Transform.GetMatrix();
|
||||
|
||||
_material.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
|
@ -45,10 +46,12 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Drawing\DrawEmpty.cs" />
|
||||
<Compile Include="Drawing\DrawTexture.cs" />
|
||||
<Compile Include="GLWindow2D.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scene\Camera.cs" />
|
||||
<Compile Include="Scene\Scene.cs" />
|
||||
<Compile Include="Types\Transformation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SM.Base\SM.Base.csproj">
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace SM2D.Scene
|
|||
|
||||
public override void RecalculateWorld(float width, float height)
|
||||
{
|
||||
OrthographicWorld = Matrix4.CreateOrthographic(width, height, 0.1f, 100);
|
||||
OrthographicWorld = Matrix4.CreateOrthographicOffCenter(-width / 2, width / 2, height / 2, -height / 2, 0.1f, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
SMCode/SM2D/Types/Transformation.cs
Normal file
19
SMCode/SM2D/Types/Transformation.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using OpenTK;
|
||||
using SM.Base.Scene;
|
||||
|
||||
namespace SM2D.Types
|
||||
{
|
||||
public class Transformation : GenericTransformation
|
||||
{
|
||||
public Vector2 Position;
|
||||
public Vector2 Size = new Vector2(50);
|
||||
public float Rotation;
|
||||
|
||||
public override Matrix4 GetMatrix()
|
||||
{
|
||||
return Matrix4.CreateScale(Size.X, Size.Y, 1) *
|
||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
|
||||
Matrix4.CreateTranslation(Position.X, Position.Y, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue