-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
se crea HUD, se lo ajusta a pantalla y se hace que funcione en full s…
…creen
- Loading branch information
1 parent
2f8b603
commit d9b18d4
Showing
8 changed files
with
386 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Microsoft.DirectX.Direct3D; | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace TGC.Examples.Engine2D.Spaceship.Core | ||
{ | ||
public class CustomBitmap : IDisposable | ||
{ | ||
public CustomBitmap(string filePath, Device d3dDevice) | ||
{ | ||
try | ||
{ | ||
D3dTexture = TextureLoader.FromFile(d3dDevice, filePath, 0, 0, 0, Usage.RenderTarget, Format.A8R8G8B8, | ||
Pool.Default, Filter.Linear, Filter.Linear, Color.Magenta.ToArgb(), ref imageInformation); | ||
} | ||
catch | ||
{ | ||
throw new Exception(string.Format("Error at loading texture: {0}", filePath)); | ||
} | ||
} | ||
|
||
#region Miembros de IDisposable | ||
|
||
public void Dispose() | ||
{ | ||
if (D3dTexture != null) | ||
{ | ||
D3dTexture.Dispose(); | ||
} | ||
} | ||
|
||
#endregion Miembros de IDisposable | ||
|
||
#region Public members | ||
|
||
/// <summary> | ||
/// returns the underlying texture. | ||
/// </summary> | ||
public Texture D3dTexture { get; } | ||
|
||
/// <summary> | ||
/// Ancho de la textura | ||
/// </summary> | ||
public int Width | ||
{ | ||
get { return D3dTexture.GetLevelDescription(0).Width; } | ||
} | ||
|
||
/// <summary> | ||
/// Alto de la textura | ||
/// </summary> | ||
public int Height | ||
{ | ||
get { return D3dTexture.GetLevelDescription(0).Height; } | ||
} | ||
|
||
/// <summary> | ||
/// Dimensiones de la textura | ||
/// </summary> | ||
public Size Size | ||
{ | ||
get { return new Size(Width, Height); } | ||
} | ||
|
||
private ImageInformation imageInformation; | ||
|
||
/// <summary> | ||
/// Returns the image information of the bitmap. | ||
/// </summary> | ||
public ImageInformation ImageInformation | ||
{ | ||
get { return imageInformation; } | ||
set { imageInformation = value; } | ||
} | ||
|
||
#endregion Public members | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using Microsoft.DirectX; | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace TGC.Examples.Engine2D.Spaceship.Core | ||
{ | ||
public class CustomSprite : IDisposable | ||
{ | ||
public CustomSprite() | ||
{ | ||
initialize(); | ||
} | ||
|
||
#region Miembros de IDisposable | ||
|
||
public void Dispose() | ||
{ | ||
if (Bitmap != null) | ||
{ | ||
Bitmap.Dispose(); | ||
} | ||
} | ||
|
||
#endregion Miembros de IDisposable | ||
|
||
private void initialize() | ||
{ | ||
//Set the identity matrix. | ||
TransformationMatrix = Matrix.Identity; | ||
|
||
//Set an empty rectangle to indicate the entire bitmap. | ||
SrcRect = Rectangle.Empty; | ||
|
||
//Initialize transformation properties. | ||
position = new Vector2(0, 0); | ||
scaling = new Vector2(1, 1); | ||
scalingCenter = new Vector2(0, 0); | ||
rotation = 0; | ||
rotationCenter = new Vector2(0, 0); | ||
|
||
Color = Color.White; | ||
} | ||
|
||
private void UpdateTransformationMatrix() | ||
{ | ||
TransformationMatrix = Matrix.Transformation2D(scalingCenter, 0, scaling, rotationCenter, rotation, position); | ||
} | ||
|
||
#region Public members | ||
|
||
/// <summary> | ||
/// The transformation matrix. | ||
/// </summary> | ||
public Matrix TransformationMatrix { get; set; } | ||
|
||
/// <summary> | ||
/// The source rectangle to be drawn from the bitmap. | ||
/// </summary> | ||
public Rectangle SrcRect { get; set; } | ||
|
||
/// <summary> | ||
/// The linked bitmap for the sprite. | ||
/// </summary> | ||
public CustomBitmap Bitmap { get; set; } | ||
|
||
/// <summary> | ||
/// The color of the sprite. | ||
/// </summary> | ||
public Color Color { get; set; } | ||
|
||
private Vector2 position; | ||
|
||
/// <summary> | ||
/// The sprite position in the 2D plane. | ||
/// </summary> | ||
public Vector2 Position | ||
{ | ||
get { return position; } | ||
set | ||
{ | ||
position = value; | ||
UpdateTransformationMatrix(); | ||
} | ||
} | ||
|
||
private float rotation; | ||
|
||
/// <summary> | ||
/// The angle of rotation in radians. | ||
/// </summary> | ||
public float Rotation | ||
{ | ||
get { return rotation; } | ||
set | ||
{ | ||
rotation = value; | ||
UpdateTransformationMatrix(); | ||
} | ||
} | ||
|
||
private Vector2 rotationCenter; | ||
|
||
/// <summary> | ||
/// The position of the centre of rotation | ||
/// </summary> | ||
public Vector2 RotationCenter | ||
{ | ||
get { return rotationCenter; } | ||
set | ||
{ | ||
rotationCenter = value; | ||
UpdateTransformationMatrix(); | ||
} | ||
} | ||
|
||
private Vector2 scalingCenter; | ||
|
||
/// <summary> | ||
/// The position of the centre of scaling | ||
/// </summary> | ||
public Vector2 ScalingCenter | ||
{ | ||
get { return scalingCenter; } | ||
set | ||
{ | ||
scalingCenter = value; | ||
UpdateTransformationMatrix(); | ||
} | ||
} | ||
|
||
private Vector2 scaling; | ||
|
||
/// <summary> | ||
/// The scaling factors in the x and y axes. | ||
/// </summary> | ||
public Vector2 Scaling | ||
{ | ||
get { return scaling; } | ||
set | ||
{ | ||
scaling = value; | ||
UpdateTransformationMatrix(); | ||
} | ||
} | ||
|
||
#endregion Public members | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Microsoft.DirectX; | ||
using Microsoft.DirectX.Direct3D; | ||
using System.Drawing; | ||
using TGC.Core.Direct3D; | ||
|
||
namespace TGC.Examples.Engine2D.Spaceship.Core | ||
{ | ||
/// <summary> | ||
/// Draws sprites and primitives. | ||
/// </summary> | ||
public class Drawer2D | ||
{ | ||
private readonly Sprite DxSprite; | ||
private readonly Line line; | ||
|
||
private readonly CustomVertex.PositionColoredTextured[] LineVertexData = | ||
new CustomVertex.PositionColoredTextured[2]; | ||
|
||
public Drawer2D() | ||
{ | ||
DxSprite = new Sprite(D3DDevice.Instance.Device); | ||
line = new Line(D3DDevice.Instance.Device); | ||
} | ||
|
||
/// <summary> | ||
/// Call this method before drawing. | ||
/// </summary> | ||
public void BeginDrawSprite() | ||
{ | ||
DxSprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortDepthFrontToBack); | ||
} | ||
|
||
/// <summary> | ||
/// Call this method after drawing. | ||
/// </summary> | ||
public void EndDrawSprite() | ||
{ | ||
DxSprite.End(); | ||
} | ||
|
||
/// <summary> | ||
/// Draws a sprite on the screen. | ||
/// </summary> | ||
/// <param name="sprite">The sprite.</param> | ||
public void DrawSprite(CustomSprite sprite) | ||
{ | ||
DxSprite.Transform = sprite.TransformationMatrix; | ||
DxSprite.Draw(sprite.Bitmap.D3dTexture, sprite.SrcRect, Vector3.Empty, Vector3.Empty, sprite.Color); | ||
} | ||
|
||
/// <summary> | ||
/// Draws a colored point. | ||
/// </summary> | ||
/// <param name="position">The location.</param> | ||
/// <param name="color">The color.</param> | ||
public void DrawPoint(Vector2 position, Color color) | ||
{ | ||
LineVertexData[0].X = position.X; | ||
LineVertexData[0].Y = position.Y; | ||
LineVertexData[0].Color = color.ToArgb(); | ||
|
||
D3DDevice.Instance.Device.VertexFormat = CustomVertex.PositionColoredTextured.Format; | ||
|
||
D3DDevice.Instance.Device.DrawUserPrimitives(PrimitiveType.PointList, 1, LineVertexData); | ||
} | ||
|
||
/// <summary> | ||
/// Draws a line segment between two points. | ||
/// </summary> | ||
/// <param name="position1">The first point.</param> | ||
/// <param name="position2">The second point.</param> | ||
/// <param name="color">The color.</param> | ||
/// <param name="width">The width</param> | ||
/// <param name="antiAlias">Anti-alias enabled.</param> | ||
public void DrawLine(Vector2 position1, Vector2 position2, Color color, int width, bool antiAlias) | ||
{ | ||
var positionList = new Vector2[2] { position1, position2 }; | ||
DrawPolyline(positionList, color, width, antiAlias); | ||
} | ||
|
||
/// <summary> | ||
/// Draws a polyline. | ||
/// </summary> | ||
/// <param name="positionList">The list of lines.</param> | ||
/// <param name="color">The color</param> | ||
/// <param name="width">The width</param> | ||
/// <param name="antiAlias">Anti-alias enabled.</param> | ||
public void DrawPolyline(Vector2[] positionList, Color color, int width, bool antiAlias) | ||
{ | ||
line.Antialias = antiAlias; | ||
line.Width = width; | ||
line.Draw(positionList, color); | ||
} | ||
} | ||
} |
Oops, something went wrong.