scene3d fixes

This commit is contained in:
Vadim Lopatin 2016-03-14 08:41:22 +03:00
parent d8f10f01bf
commit 490d793cec
4 changed files with 19 additions and 40 deletions

View File

@ -150,28 +150,11 @@ class UiWidget : VerticalLayout {
Log.e("Invalid texture"); Log.e("Invalid texture");
return; return;
} }
_cam.setPerspective(4.0f, 3.0f, 45.0f, 1.1f, 100.0f); _cam.setPerspective(rc.width, rc.height, 45.0f, 0.1f, 100.0f);
mat4 projectionViewModelMatrix; _cam.setIdentity();
if (true) { _cam.translate(vec3(0, 0, -1.1)); // - angle/1000
// ======== Projection Matrix ================== _cam.rotateZ(30.0f + angle * 0.3456778);
mat4 projectionMatrix; mat4 projectionViewMatrix = _cam.projectionViewMatrix;
float aspectRatio = cast(float)rc.width / cast(float)rc.height;
projectionMatrix.setPerspective(
45.0f, //angle
aspectRatio, // aspect
1.1f, // near
1000.0f // far
);
// ======== 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 ================== // ======== Model Matrix ==================
mat4 modelMatrix; mat4 modelMatrix;
@ -182,18 +165,12 @@ class UiWidget : VerticalLayout {
modelMatrix.rotatey(angle); modelMatrix.rotatey(angle);
modelMatrix.rotatex(angle * 1.98765f); modelMatrix.rotatex(angle * 1.98765f);
// ======= PMV matrix ===================== mat4 projectionViewModelMatrix = projectionViewMatrix * modelMatrix;
projectionViewModelMatrix = projectionMatrix * viewMatrix * modelMatrix;
} else {
projectionViewModelMatrix = _scene.viewProjectionMatrix;
}
//projectionViewModelMatrix.setIdentity(); //projectionViewModelMatrix.setIdentity();
//Log.d("matrix uniform: ", projectionViewModelMatrix.m); //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!glEnable(GL_CULL_FACE);
//checkgl!glDisable(GL_CULL_FACE);
checkgl!glEnable(GL_DEPTH_TEST); checkgl!glEnable(GL_DEPTH_TEST);
checkgl!glCullFace(GL_BACK); checkgl!glCullFace(GL_BACK);

View File

@ -771,6 +771,8 @@ public:
if (_handler) { if (_handler) {
glSupport.setOrthoProjection(_windowRect, _rc); glSupport.setOrthoProjection(_windowRect, _rc);
glSupport.clearDepthBuffer(); glSupport.clearDepthBuffer();
//glEnable(GL_BLEND);
//checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_handler(_windowRect, _rc); _handler(_windowRect, _rc);
glSupport.setOrthoProjection(_windowRect, _windowRect); glSupport.setOrthoProjection(_windowRect, _windowRect);
} }

View File

@ -40,7 +40,7 @@ class Camera : Node3d {
} }
/// get projection*view matrix /// get projection*view matrix
@property ref const(mat4) viewProjectionMatrix() { @property ref const(mat4) projectionViewMatrix() {
if (_dirtyTransform || _dirtyViewProjection) { if (_dirtyTransform || _dirtyViewProjection) {
_viewProjectionMatrix = _projectionMatrix * matrix; _viewProjectionMatrix = _projectionMatrix * matrix;
_dirtyViewProjection = false; _dirtyViewProjection = false;

View File

@ -41,9 +41,9 @@ class Scene3d : Node3d {
} }
/// get projection*view matrix /// get projection*view matrix
@property ref const(mat4) viewProjectionMatrix() { @property ref const(mat4) projectionViewMatrix() {
if (_activeCamera) if (_activeCamera)
return _activeCamera.viewProjectionMatrix; return _activeCamera.projectionViewMatrix;
static mat4 dummyIdentityMatrix; static mat4 dummyIdentityMatrix;
return dummyIdentityMatrix; return dummyIdentityMatrix;
} }