180 lines
6.7 KiB
C#
180 lines
6.7 KiB
C#
using StgSharp.Control;
|
|
using StgSharp.Linear;
|
|
using StgSharp.Math;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Geometries
|
|
{
|
|
public class Rectangle : IPlainGeometry
|
|
{
|
|
internal Point _basePoint;
|
|
internal Point _center;
|
|
internal Point _vertex1;
|
|
internal Point _vertex2;
|
|
internal RenderMode _renderMode;
|
|
internal readonly uint bornTick;
|
|
|
|
public override sealed Point RefOrigin => _basePoint;
|
|
public override sealed Point RefPoint=>_center;
|
|
|
|
public override sealed Point RefVec01 => _vertex1;
|
|
|
|
public override sealed Point RefVec02 => _vertex2;
|
|
|
|
public override RenderMode renderMode => _renderMode;
|
|
|
|
public Rectangle(uint bornTime) : base(bornTime)
|
|
{
|
|
bornTick = bornTime;
|
|
}
|
|
|
|
public Rectangle(Counter<uint> tickCounter) : base(tickCounter)
|
|
{
|
|
bornTick = tickCounter._value;
|
|
}
|
|
|
|
internal override sealed void OnRender(uint tick)
|
|
{
|
|
tick-=bornTick;
|
|
CalcVec01(tick);
|
|
switch (renderMode)
|
|
{
|
|
case RenderMode.BasePoint:
|
|
CalcVec02(_basePoint._position,tick);
|
|
CalcVec03(_basePoint._position,tick);
|
|
break;
|
|
case RenderMode.RefPoint:
|
|
CalcVec02(_center._position, tick);
|
|
CalcVec03(_center._position, tick);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override sealed float SetArrayX()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override sealed float SetArrayY()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
internal override void CalcVec01(uint tick)
|
|
{
|
|
_center._position = _basePoint._position + MovCenter(tick);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算长方形第一条对角线的一半的矢量表示
|
|
/// </summary>
|
|
/// <param name="vec">作为参考的矢量,根据计算模式可以分为参考原点
|
|
/// 和参考中心点两种</param>
|
|
/// <param name="tick">当前游戏刻</param>
|
|
internal override void CalcVec02(vec3d vec, uint tick)
|
|
{
|
|
_vertex1._position = vec + UpdateCTC1(tick);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算长方形第二条对角线一半的矢量表示
|
|
/// </summary>
|
|
/// <param name="vec">作为参考的矢量,根据计算模式可以分为参考原点
|
|
/// 和参考中心点两种</param>
|
|
/// <param name="tick">当前游戏刻</param>
|
|
/// <exception cref="ArgumentException">计算出的第二条对角线长与第一条不相等</exception>
|
|
internal override void CalcVec03(vec3d vec, uint tick)
|
|
{
|
|
_vertex2._position = vec + UpdateCTC2(tick);
|
|
if (_vertex1._position.GetLength()
|
|
== _vertex2._position.GetLength())
|
|
{
|
|
throw new ArgumentException("Cannot form a triangle, " +
|
|
"two crossing lines are not equal!");
|
|
}
|
|
}
|
|
|
|
|
|
internal sealed override void CalcVec04(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec05(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec06(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec07(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec08(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec09(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec10(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec11(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec12(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec13(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec14(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec15(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
internal sealed override void CalcVec16(vec3d vec, uint tick) => throw new UnusedVertexException();
|
|
|
|
/// <summary>
|
|
/// 计算中心点相对于参考原点的位移
|
|
/// </summary>
|
|
/// <param name="tick">当前游戏刻</param>
|
|
/// <returns></returns>
|
|
public virtual vec3d MovCenter(uint tick)=>default(vec3d);
|
|
|
|
/// <summary>
|
|
/// 计算第一个顶点相对于参考点的位移,可以是中心点,也可以是参考原点
|
|
/// </summary>
|
|
/// <param name="tick"></param>
|
|
/// <returns></returns>
|
|
public virtual vec3d UpdateCTC1(uint tick) => default(vec3d);
|
|
|
|
public virtual vec3d UpdateCTC2(uint tick) => default(vec3d);
|
|
|
|
public override Line[] GetAllSides()
|
|
{
|
|
|
|
Line[] sides = new Line[4]
|
|
{
|
|
new Line(GameTimeLine.tickCounter),
|
|
new Line(GameTimeLine.tickCounter),
|
|
new Line(GameTimeLine.tickCounter),
|
|
new Line(GameTimeLine.tickCounter),
|
|
};
|
|
|
|
|
|
sides[0]._basePoint = this._vertex1;
|
|
sides[0]._beginPoint = this._vertex1;
|
|
sides[0]._endPoint = this._vertex2;
|
|
|
|
sides[1]._basePoint = this._vertex2;
|
|
sides[1]._beginPoint = this._vertex2;
|
|
sides[1]._endPoint = new Point() { _position = GetVertex3(GameTimeLine.tickCounter) };
|
|
sides[1].movEnd += this.GetVertex3;
|
|
|
|
sides[2]._basePoint = sides[1]._endPoint;
|
|
sides[2]._beginPoint = sides[2]._basePoint;
|
|
sides[2]._endPoint = new Point() { _position = this.GetVertex4(GameTimeLine.tickCounter) };
|
|
sides[2].movEnd += this.GetVertex4;
|
|
|
|
sides[3]._beginPoint = sides[2]._endPoint;
|
|
sides[3]._endPoint = this._vertex1;
|
|
|
|
return sides;
|
|
}
|
|
|
|
public override Plain GetPlain()
|
|
{
|
|
return new Plain(this._center, this._vertex1,this._vertex2);
|
|
}
|
|
|
|
protected vec3d GetVertex3(Counter<uint> tick)
|
|
{
|
|
return 2 * this._center._position - this._vertex1._position;
|
|
}
|
|
|
|
protected vec3d GetVertex4(Counter<uint> tick)
|
|
{
|
|
return 2 * this._center._position - this._vertex2._position;
|
|
}
|
|
}
|
|
}
|