add a pre-kP evaluation function in c
This commit is contained in:
+24
-24
@@ -36,26 +36,26 @@ namespace StgSharp.Mathematics.Graphics
|
||||
{
|
||||
|
||||
private bool _isLookAtAvailable;
|
||||
internal Matrix44 _lookAt;
|
||||
internal Matrix44 _projection;
|
||||
internal Matrix44 cameraAtt;
|
||||
internal Matrix44 rotation;
|
||||
internal Matrix44 rotationAtt;
|
||||
internal GraphicsMatrix _lookAt;
|
||||
internal GraphicsMatrix _projection;
|
||||
internal GraphicsMatrix cameraAtt;
|
||||
internal GraphicsMatrix rotation;
|
||||
internal GraphicsMatrix rotationAtt;
|
||||
internal Radius _pitch;
|
||||
internal Radius _row;
|
||||
internal Radius _yaw;
|
||||
internal Uniform<Matrix44> convertedUniform;
|
||||
internal Uniform<GraphicsMatrix> convertedUniform;
|
||||
internal Vec3 _target, up;
|
||||
|
||||
public Camera()
|
||||
{
|
||||
cameraAtt = Matrix44.Unit;
|
||||
cameraAtt = GraphicsMatrix.Unit;
|
||||
_target = Vec3.Zero;
|
||||
up = Vec3.Zero;
|
||||
_isLookAtAvailable = false;
|
||||
_lookAt = Matrix44.Unit;
|
||||
rotationAtt = Matrix44.Unit;
|
||||
_projection = new Matrix44();
|
||||
_lookAt = GraphicsMatrix.Unit;
|
||||
rotationAtt = GraphicsMatrix.Unit;
|
||||
_projection = new GraphicsMatrix();
|
||||
}
|
||||
|
||||
public Camera(
|
||||
@@ -65,24 +65,24 @@ namespace StgSharp.Mathematics.Graphics
|
||||
)
|
||||
: this()
|
||||
{
|
||||
rotationAtt = Matrix44.Unit;
|
||||
cameraAtt = new Matrix44();
|
||||
rotationAtt = GraphicsMatrix.Unit;
|
||||
cameraAtt = new GraphicsMatrix();
|
||||
SetViewDirection(position, target, up);
|
||||
_pitch = Radius.Zero;
|
||||
_row = Radius.Zero;
|
||||
_yaw = Radius.Zero;
|
||||
}
|
||||
|
||||
public Matrix44 Projection => _projection;
|
||||
public GraphicsMatrix Projection => _projection;
|
||||
|
||||
public Matrix44 View
|
||||
public GraphicsMatrix View
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_isLookAtAvailable) {
|
||||
return _lookAt;
|
||||
}
|
||||
Matrix44 move = Matrix44.Unit;
|
||||
GraphicsMatrix move = GraphicsMatrix.Unit;
|
||||
move.column[3].vec -= cameraAtt.column[3].vec;
|
||||
_lookAt = rotationAtt.Transpose * move;
|
||||
_isLookAtAvailable = true;
|
||||
@@ -90,7 +90,7 @@ namespace StgSharp.Mathematics.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix44 CameraMatrix()
|
||||
public GraphicsMatrix CameraMatrix()
|
||||
{
|
||||
return Projection * View;
|
||||
}
|
||||
@@ -118,11 +118,11 @@ namespace StgSharp.Mathematics.Graphics
|
||||
params string[] uniformName
|
||||
)
|
||||
{
|
||||
if (uniformName is null || uniformName.Length != 1) {
|
||||
if ((uniformName is null) || (uniformName.Length != 1)) {
|
||||
throw new ArgumentException(
|
||||
"Camera needs exactly one uniform.", nameof(uniformName));
|
||||
}
|
||||
convertedUniform = source.GetUniform<Matrix44>(uniformName[0]);
|
||||
convertedUniform = source.GetUniform<GraphicsMatrix>(uniformName[0]);
|
||||
}
|
||||
|
||||
public void MoveNear(
|
||||
@@ -208,15 +208,15 @@ namespace StgSharp.Mathematics.Graphics
|
||||
offsetX = offset.X,
|
||||
offsetY = offset.Y,
|
||||
width = MathF.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||
height = width * size.Y / size.X;
|
||||
height = (width * size.Y) / size.X;
|
||||
|
||||
_projection.column[0].X = 2 * near / width;
|
||||
_projection.column[1].Y = 2 * near / height;
|
||||
_projection.column[2].X = 2 * offsetX / width;
|
||||
_projection.column[2].Y = 2 * offsetY / height;
|
||||
_projection.column[0].X = (2 * near) / width;
|
||||
_projection.column[1].Y = (2 * near) / height;
|
||||
_projection.column[2].X = (2 * offsetX) / width;
|
||||
_projection.column[2].Y = (2 * offsetY) / height;
|
||||
_projection.column[2].Z = (far + near) / (near - far);
|
||||
_projection.column[2].W = -1;
|
||||
_projection.column[3].Z = 2 * near * far / (near - far);
|
||||
_projection.column[3].Z = (2 * near * far) / (near - far);
|
||||
}
|
||||
|
||||
public void Test(
|
||||
|
||||
@@ -145,8 +145,8 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<Matrix44> uniform,
|
||||
Matrix44 mat
|
||||
[NotNull] Uniform<GraphicsMatrix> uniform,
|
||||
GraphicsMatrix mat
|
||||
)
|
||||
{
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
CustomizeDeinit();
|
||||
}
|
||||
|
||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(
|
||||
protected sealed override Uniform<GraphicsMatrix> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name
|
||||
)
|
||||
|
||||
@@ -50,24 +50,13 @@ namespace StgSharp.Graphics
|
||||
private protected ViewPort primeArgs;
|
||||
internal TimeSpanProvider _timeProvider;
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (Width, Height);
|
||||
}
|
||||
public (int width, int height) Size => (Width, Height);
|
||||
|
||||
public abstract bool IsContextSharable { get; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.Height;
|
||||
}
|
||||
public int Height => primeArgs.Height;
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => primeArgs.Width;
|
||||
}
|
||||
public int Width => primeArgs.Width;
|
||||
|
||||
public IntPtr Monitor
|
||||
{
|
||||
@@ -75,10 +64,7 @@ namespace StgSharp.Graphics
|
||||
internal set => primeArgs.Monitor = value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
}
|
||||
public string Name => primeArgs.Name;
|
||||
|
||||
public ViewPort BindedViewPortContext
|
||||
{
|
||||
@@ -86,11 +72,7 @@ namespace StgSharp.Graphics
|
||||
internal set => primeArgs = value;
|
||||
}
|
||||
|
||||
internal IntPtr CanvasHandle
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.ViewPortHandle;
|
||||
}
|
||||
internal IntPtr CanvasHandle => primeArgs.ViewPortHandle;
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
@@ -104,29 +86,13 @@ namespace StgSharp.Graphics
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected float FramePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
protected float FramePassed => _timeProvider.CurrentSpan;
|
||||
|
||||
protected int PassedFrames
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
protected int PassedFrames => _timeProvider.CurrentSpan;
|
||||
|
||||
protected float TimePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (float)_timeProvider.CurrentSecond;
|
||||
}
|
||||
protected float TimePassed => (float)_timeProvider.CurrentSecond;
|
||||
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider;
|
||||
}
|
||||
protected TimeSpanProvider TimeProvider => _timeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Set the Size limit of current form
|
||||
@@ -188,9 +154,9 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) uniform from a shader.
|
||||
/// This uniform will be used as projection matrix of this camera. Additionally, for
|
||||
/// multi- shader rendering, each shader requires a uniform, so do not ignore return
|
||||
/// Get <see cref="Uniform{T}" />(TView is <see cref="GraphicsMatrix" />) uniform from a
|
||||
/// shader. This uniform will be used as projection matrix of this camera. Additionally,
|
||||
/// for multi- shader rendering, each shader requires a uniform, so do not ignore return
|
||||
/// value of this method.
|
||||
/// </summary>
|
||||
/// <param _label="source">
|
||||
@@ -200,12 +166,12 @@ namespace StgSharp.Graphics
|
||||
/// ContextName of projection camera named in shader
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) representing projection
|
||||
/// matrix in shader program.
|
||||
/// <see cref="Uniform{T}" />(TView is <see cref="GraphicsMatrix" />) representing
|
||||
/// projection matrix in shader program.
|
||||
/// </returns>
|
||||
protected abstract Uniform<Matrix44> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name
|
||||
protected abstract Uniform<GraphicsMatrix> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user