This commit is contained in:
Nitload
2023-02-14 14:26:57 +08:00
parent b3e55ecfc7
commit 3762a2e5ce
19 changed files with 162 additions and 90 deletions
Binary file not shown.
Binary file not shown.
+5 -4
View File
@@ -1,4 +1,5 @@
using StgSharp;
using StgSharp.Vector;
using System;
using System.Collections.Generic;
using System.Text;
@@ -7,14 +8,14 @@ namespace StgSharp
{
public interface IEntity:INode
{
public IGeometry CollisionShape { get; set; }
public IGeometry CollisionBox { get; set; }
public Sensor CollisionSensor { get; set; }
public string Texture { get; set; }
public Point Location { get; set; }
public Vec2D Location { get; }
public void SetLocation(Point p);
}
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public class Launcher
{
}
}
@@ -0,0 +1,47 @@
using StgSharp.Vector;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public class Partical : IEntity
{
internal IGeometry _collisionBox;
internal Sensor _collisionSensor;
internal string _texture;
internal Vec2D _position;
IGeometry IEntity.CollisionBox
{
get { return _collisionBox; }
set { _collisionBox = value; }
}
Sensor IEntity.CollisionSensor
{
get { return _collisionSensor; }
set { _collisionSensor = value; }
}
string IEntity.Texture
{
get { return _texture; }
set { _texture = value; }
}
Vec2D IEntity.Location
{
get { return _position; }
}
ContainerNode<INode> INode.ID => throw new NotImplementedException();
void INode.setID<T>(ContainerNode<T> id)
{
throw new NotImplementedException();
}
void IEntity.SetLocation(StgSharp.Point p)
{
this._position = p._position;
}
}
}
@@ -0,0 +1,58 @@
using StgSharp.Vector;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public class Player : IEntity
{
internal IGeometry _collisionBox;
internal Sensor _collisionSensor;
internal string _texture;
internal Vec2D _position;
private ContainerNode<INode> _id;
IGeometry IEntity.CollisionBox
{
get { return this._collisionBox; }
set { this._collisionBox = value; }
}
Sensor IEntity.CollisionSensor
{
get { return this._collisionSensor; }
set { this._collisionSensor = value; }
}
string IEntity.Texture
{
get { return this._texture; }
set { this._texture = value; }
}
Vec2D IEntity.Location
{
get { return this._position; }
set { this._position = value; }
}
ContainerNode<INode> INode.ID
{
get { return _id; }
}
void INode.setID<T>(ContainerNode<T> id)
{
if (id == null)
{
_id = id as ContainerNode<INode>;
}
else
{
throw new ArgumentException("Cannot set id twice!");
}
}
}
}
+13 -12
View File
@@ -1,5 +1,6 @@
using GLFWDotNet;
using StgSharp;
using StgSharp.Vector;
using System;
using System.Collections.Generic;
using System.Drawing;
@@ -13,11 +14,10 @@ namespace StgSharp
{
internal StgSharp.ContainerNode<INode> _id;
internal float _x;
internal float _y;
internal Vec2D _position;
public GetLocationHandler getXHandler;
public GetLocationHandler getYHandler;
internal GetLocationHandler getXHandler;
internal GetLocationHandler getYHandler;
ContainerNode<INode> INode.ID
{
@@ -26,17 +26,12 @@ namespace StgSharp
public float X
{
get
{
return getXHandler(Control.TimeLine.tickCounter);
}
get { return this._position.X; }
}
public float Y
{
get
{
return getYHandler(Control.TimeLine.tickCounter);
}
get { return this._position.Y; }
}
void INode.setID<T>(ContainerNode<T> id)
@@ -50,5 +45,11 @@ namespace StgSharp
throw new ArgumentException("Cannot set id twice!");
}
}
public void OnRender()
{
this.getXHandler.Invoke(Control.TimeLine.tickCounter);
this.getYHandler.Invoke(Control.TimeLine.tickCounter);
}
}
}
+26 -6
View File
@@ -1,22 +1,24 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;
namespace StgSharp.Vector
{
public struct Vec2D:IEquatable<Vec2D>
{
float X;
float Y;
float Direction;
float Length;
public float X;
public float Y;
public float Direction;
public float Length;
public Vec2D(float x,float y)
{
X = x;
Y = y;
Direction = 0;
Direction = Calc.ATan(X,Y);
Length = Calc.Sqrt(X * X + Y * Y);
}
public bool Equals(Vec2D other)
@@ -77,6 +79,24 @@ namespace StgSharp.Vector
return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y);
}
public static
public static float operator *(Vec2D vec1, Vec2D vec2)
{
return vec1.X * vec2.X + vec1.Y*vec2.Y;
}
public static Vec2D operator *(Vec2D vec, float x)
{
return new Vec2D(vec.X * x, vec.Y * x);
}
public static Vec2D operator /(Vec2D vec, float x)
{
return new Vec2D(vec.X/x, vec.Y/x);
}
public float x(Vec2D others)
{
return this.X * others.Y - this.Y * others.X;
}
}
}
+2 -68
View File
@@ -1,4 +1,5 @@
using StgSharp;
using StgSharp.Vector;
using System;
using System.Diagnostics;
@@ -6,74 +7,7 @@ internal class Program
{
private unsafe static void Main(string[] args)
{
/*
int cc = 3;
Console.WriteLine(cc/2);
/**/
/*
float test = StgSharp.Math.Calc.ATan(-1f,-1f);
Console.WriteLine(test);
/**/
/*
// 测速
for (int cycle = 0; cycle < 100; cycle++)
{
float time = 1000000;
float a = 114514;
System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // 开始监视代码运行时间
for (float i = 2; i < time; i++)
{
a = StgSharp.Math.ATan(i);
}
stopwatch.Stop(); // 停止监视
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
double milliseconds = timespan.TotalMilliseconds; // 总毫秒数
Console.WriteLine($"{milliseconds},{a}");
System.Diagnostics.Stopwatch stopwatch1 = new Stopwatch();
double b = 114514;
double time2 = time;
stopwatch1.Start();
for (float i = 2; i < time2; i++)
{
b = System.MathF.Atan(i);
}
stopwatch1.Stop();
timespan = stopwatch1.Elapsed;
double milliseconds2 = timespan.TotalMilliseconds;
Console.WriteLine($"{milliseconds2},{b}");
Console.WriteLine("");
}
/**/
/*
//精度测试
double accuracy = 0;
for (float i = -200f; i < 200f; i += 0.01f)
{
double r1 = StgSharp.Math.ATan(i);
double r2 = 180*System.Math.Atan(i)/3.1415926;
double ac = ( System.Math.Max(r1,r2)- System.Math.Min(r1, r2) ) / r2;
if (ac>accuracy)
{
accuracy = ac;
Console.WriteLine(i);
Console.WriteLine(ac);
Console.WriteLine(r1);
Console.WriteLine(r2);
Console.WriteLine("");
}
}
Console.WriteLine(accuracy);
/**/
}
}