From 490d793cec95aa492a76a51c02e821bb44c3d991 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 14 Mar 2016 08:41:22 +0300 Subject: [PATCH] scene3d fixes --- examples/d3d/src/d3d.d | 51 ++++++++-------------------- src/dlangui/graphics/gldrawbuf.d | 2 ++ src/dlangui/graphics/scene/camera.d | 2 +- src/dlangui/graphics/scene/scene3d.d | 4 +-- 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/examples/d3d/src/d3d.d b/examples/d3d/src/d3d.d index 5ab4e78f..cf216325 100644 --- a/examples/d3d/src/d3d.d +++ b/examples/d3d/src/d3d.d @@ -150,50 +150,27 @@ class UiWidget : VerticalLayout { Log.e("Invalid texture"); return; } - _cam.setPerspective(4.0f, 3.0f, 45.0f, 1.1f, 100.0f); - mat4 projectionViewModelMatrix; - if (true) { - // ======== Projection Matrix ================== - mat4 projectionMatrix; - float aspectRatio = cast(float)rc.width / cast(float)rc.height; - projectionMatrix.setPerspective( - 45.0f, //angle - aspectRatio, // aspect - 1.1f, // near - 1000.0f // far - ); + _cam.setPerspective(rc.width, rc.height, 45.0f, 0.1f, 100.0f); + _cam.setIdentity(); + _cam.translate(vec3(0, 0, -1.1)); // - angle/1000 + _cam.rotateZ(30.0f + angle * 0.3456778); + mat4 projectionViewMatrix = _cam.projectionViewMatrix; - // ======== View Matrix ================== - mat4 viewMatrix; - //viewMatrix.translate(0, 0, -1 + angle / 100); // + angle - //viewMatrix.translate(0, 0, -4); // + angle - //viewMatrix.rotatez(-15.0f + angle); - //viewMatrix.rotatez(angle); - //viewMatrix.lookAt(vec3(0, 0, -1 + angle / 100), vec3(0, 0, 0), vec3(0, 1, 0));//translation(0.0f, 0.0f, 4.0f).rotatez(angle); - //viewMatrix.lookAt(vec3(0, angle / 1000, -2 - angle / 100), vec3(0, 0, 0), vec3(0, 1, 0));//translation(0.0f, 0.0f, 4.0f).rotatez(angle); - viewMatrix.lookAt(vec3(0, 1, -3), vec3(0, 0, 0), vec3(0, 1, 0));//translation(0.0f, 0.0f, 4.0f).rotatez(angle); + // ======== Model Matrix ================== + mat4 modelMatrix; + //modelMatrix.scale(0.1f); + modelMatrix.rotatez(30.0f + angle * 0.3456778); + //modelMatrix.rotatey(25); + //modelMatrix.rotatex(15); + modelMatrix.rotatey(angle); + modelMatrix.rotatex(angle * 1.98765f); - // ======== Model Matrix ================== - mat4 modelMatrix; - //modelMatrix.scale(0.1f); - modelMatrix.rotatez(30.0f + angle * 0.3456778); - //modelMatrix.rotatey(25); - //modelMatrix.rotatex(15); - modelMatrix.rotatey(angle); - modelMatrix.rotatex(angle * 1.98765f); + mat4 projectionViewModelMatrix = projectionViewMatrix * modelMatrix; - // ======= PMV matrix ===================== - projectionViewModelMatrix = projectionMatrix * viewMatrix * modelMatrix; - } else { - projectionViewModelMatrix = _scene.viewProjectionMatrix; - } //projectionViewModelMatrix.setIdentity(); //Log.d("matrix uniform: ", projectionViewModelMatrix.m); - glEnable(GL_BLEND); - checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); checkgl!glEnable(GL_CULL_FACE); - //checkgl!glDisable(GL_CULL_FACE); checkgl!glEnable(GL_DEPTH_TEST); checkgl!glCullFace(GL_BACK); diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 4ad38b92..3f49a22d 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -771,6 +771,8 @@ public: if (_handler) { glSupport.setOrthoProjection(_windowRect, _rc); glSupport.clearDepthBuffer(); + //glEnable(GL_BLEND); + //checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); _handler(_windowRect, _rc); glSupport.setOrthoProjection(_windowRect, _windowRect); } diff --git a/src/dlangui/graphics/scene/camera.d b/src/dlangui/graphics/scene/camera.d index 41a9b1da..289876cd 100644 --- a/src/dlangui/graphics/scene/camera.d +++ b/src/dlangui/graphics/scene/camera.d @@ -40,7 +40,7 @@ class Camera : Node3d { } /// get projection*view matrix - @property ref const(mat4) viewProjectionMatrix() { + @property ref const(mat4) projectionViewMatrix() { if (_dirtyTransform || _dirtyViewProjection) { _viewProjectionMatrix = _projectionMatrix * matrix; _dirtyViewProjection = false; diff --git a/src/dlangui/graphics/scene/scene3d.d b/src/dlangui/graphics/scene/scene3d.d index 44ea8dfa..c9dc0dbd 100644 --- a/src/dlangui/graphics/scene/scene3d.d +++ b/src/dlangui/graphics/scene/scene3d.d @@ -41,9 +41,9 @@ class Scene3d : Node3d { } /// get projection*view matrix - @property ref const(mat4) viewProjectionMatrix() { + @property ref const(mat4) projectionViewMatrix() { if (_activeCamera) - return _activeCamera.viewProjectionMatrix; + return _activeCamera.projectionViewMatrix; static mat4 dummyIdentityMatrix; return dummyIdentityMatrix; }