forked from mirror/DotRecast
remove new float[16]
This commit is contained in:
parent
5dd6f5f910
commit
01d7740e81
|
@ -636,7 +636,7 @@ public class DebugDraw
|
||||||
return _projectionMatrix;
|
return _projectionMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[] ViewMatrix(RcVec3f cameraPos, float[] cameraEulers)
|
public RcMatrix4x4f ViewMatrix(RcVec3f cameraPos, float[] cameraEulers)
|
||||||
{
|
{
|
||||||
var rx = RcMatrix4x4f.CreateFromRotate(cameraEulers[0], 1, 0, 0);
|
var rx = RcMatrix4x4f.CreateFromRotate(cameraEulers[0], 1, 0, 0);
|
||||||
var ry = RcMatrix4x4f.CreateFromRotate(cameraEulers[1], 0, 1, 0);
|
var ry = RcMatrix4x4f.CreateFromRotate(cameraEulers[1], 0, 1, 0);
|
||||||
|
@ -648,10 +648,9 @@ public class DebugDraw
|
||||||
t.M42 = -cameraPos.y;
|
t.M42 = -cameraPos.y;
|
||||||
t.M43 = -cameraPos.z;
|
t.M43 = -cameraPos.z;
|
||||||
var mul = RcMatrix4x4f.Mul(r, t);
|
var mul = RcMatrix4x4f.Mul(r, t);
|
||||||
mul.CopyTo(_viewMatrix);
|
GetOpenGlDraw().ViewMatrix(ref mul);
|
||||||
GetOpenGlDraw().ViewMatrix(_viewMatrix);
|
|
||||||
UpdateFrustum();
|
UpdateFrustum();
|
||||||
return _viewMatrix;
|
return mul;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public interface IOpenGLDraw
|
||||||
|
|
||||||
void ProjectionMatrix(float[] projectionMatrix);
|
void ProjectionMatrix(float[] projectionMatrix);
|
||||||
|
|
||||||
void ViewMatrix(float[] viewMatrix);
|
void ViewMatrix(ref RcMatrix4x4f viewMatrix);
|
||||||
|
|
||||||
void Fog(float start, float end);
|
void Fog(float start, float end);
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ public class ModernOpenGLDraw : IOpenGLDraw
|
||||||
private readonly ArrayBuffer<OpenGLVertex> vertices = new();
|
private readonly ArrayBuffer<OpenGLVertex> vertices = new();
|
||||||
private readonly ArrayBuffer<int> elements = new();
|
private readonly ArrayBuffer<int> elements = new();
|
||||||
private GLCheckerTexture _texture;
|
private GLCheckerTexture _texture;
|
||||||
private float[] _viewMatrix;
|
private float[] _viewMatrix = new float[16];
|
||||||
private float[] _projectionMatrix;
|
private float[] _projectionMatrix;
|
||||||
private int uniformUseTexture;
|
private int uniformUseTexture;
|
||||||
private int uniformFog;
|
private int uniformFog;
|
||||||
|
@ -320,9 +320,9 @@ public class ModernOpenGLDraw : IOpenGLDraw
|
||||||
_projectionMatrix = projectionMatrix;
|
_projectionMatrix = projectionMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ViewMatrix(float[] viewMatrix)
|
public void ViewMatrix(ref RcMatrix4x4f viewMatrix)
|
||||||
{
|
{
|
||||||
_viewMatrix = viewMatrix;
|
viewMatrix.CopyTo(_viewMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fog(float start, float end)
|
public void Fog(float start, float end)
|
||||||
|
|
|
@ -147,10 +147,10 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float[] modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
var modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
||||||
cameraPos.x += scrollZoom * 2.0f * modelviewMatrix[2];
|
cameraPos.x += scrollZoom * 2.0f * modelviewMatrix.M13;
|
||||||
cameraPos.y += scrollZoom * 2.0f * modelviewMatrix[6];
|
cameraPos.y += scrollZoom * 2.0f * modelviewMatrix.M23;
|
||||||
cameraPos.z += scrollZoom * 2.0f * modelviewMatrix[10];
|
cameraPos.z += scrollZoom * 2.0f * modelviewMatrix.M33;
|
||||||
scrollZoom = 0;
|
scrollZoom = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,16 +172,16 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
if (pan)
|
if (pan)
|
||||||
{
|
{
|
||||||
float[] modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
var modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
||||||
cameraPos = origCameraPos;
|
cameraPos = origCameraPos;
|
||||||
|
|
||||||
cameraPos.x -= 0.1f * dx * modelviewMatrix[0];
|
cameraPos.x -= 0.1f * dx * modelviewMatrix.M11;
|
||||||
cameraPos.y -= 0.1f * dx * modelviewMatrix[4];
|
cameraPos.y -= 0.1f * dx * modelviewMatrix.M21;
|
||||||
cameraPos.z -= 0.1f * dx * modelviewMatrix[8];
|
cameraPos.z -= 0.1f * dx * modelviewMatrix.M31;
|
||||||
|
|
||||||
cameraPos.x += 0.1f * dy * modelviewMatrix[1];
|
cameraPos.x += 0.1f * dy * modelviewMatrix.M12;
|
||||||
cameraPos.y += 0.1f * dy * modelviewMatrix[5];
|
cameraPos.y += 0.1f * dy * modelviewMatrix.M22;
|
||||||
cameraPos.z += 0.1f * dy * modelviewMatrix[9];
|
cameraPos.z += 0.1f * dy * modelviewMatrix.M32;
|
||||||
if (dx * dx + dy * dy > 3 * 3)
|
if (dx * dx + dy * dy > 3 * 3)
|
||||||
{
|
{
|
||||||
movedDuringPan = true;
|
movedDuringPan = true;
|
||||||
|
@ -574,9 +574,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
RcVec3f bmin = bminN;
|
RcVec3f bmin = bminN;
|
||||||
RcVec3f bmax = bmaxN;
|
RcVec3f bmax = bmaxN;
|
||||||
|
|
||||||
camr = (float)(Math.Sqrt(
|
camr = (float)(Math.Sqrt(Sqr(bmax.x - bmin.x) + Sqr(bmax.y - bmin.y) + Sqr(bmax.z - bmin.z)) / 2);
|
||||||
Sqr(bmax.x - bmin.x) + Sqr(bmax.y - bmin.y) + Sqr(bmax.z - bmin.z))
|
|
||||||
/ 2);
|
|
||||||
cameraPos.x = (bmax.x + bmin.x) / 2 + camr;
|
cameraPos.x = (bmax.x + bmin.x) / 2 + camr;
|
||||||
cameraPos.y = (bmax.y + bmin.y) / 2 + camr;
|
cameraPos.y = (bmax.y + bmin.y) / 2 + camr;
|
||||||
cameraPos.z = (bmax.z + bmin.z) / 2 + camr;
|
cameraPos.z = (bmax.z + bmin.z) / 2 + camr;
|
||||||
|
@ -610,7 +608,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
dd.Clear();
|
dd.Clear();
|
||||||
projectionMatrix = dd.ProjectionMatrix(50f, (float)width / (float)height, 1.0f, camr);
|
projectionMatrix = dd.ProjectionMatrix(50f, (float)width / (float)height, 1.0f, camr);
|
||||||
modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
dd.ViewMatrix(cameraPos, cameraEulers).CopyTo(modelviewMatrix);
|
||||||
|
|
||||||
dd.Fog(camr * 0.1f, camr * 1.25f);
|
dd.Fog(camr * 0.1f, camr * 1.25f);
|
||||||
renderer.Render(_sample, settingsView.GetDrawMode());
|
renderer.Render(_sample, settingsView.GetDrawMode());
|
||||||
|
|
Loading…
Reference in New Issue