Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with orthographic camera #48

Closed
Temechon opened this issue Sep 8, 2013 · 6 comments
Closed

Problem with orthographic camera #48

Temechon opened this issue Sep 8, 2013 · 6 comments
Labels

Comments

@Temechon
Copy link
Contributor

Temechon commented Sep 8, 2013

Hi !

I wanted to create an orthographic camera (for a 2d view of a 3d scene) with a Camera, but I detected a little issue in Camera.getProjectionMatrix line 61 : I think this._projectionMatrix is missing as last parameter.

Moreover, I cannot have a correct orthographic camera on Y axis looking on (0,0,0). On Z axis, it works great, but the display is weird on axis X or Y. I thought the problem was in the function Matrix.OrthoOffCenterLHToRef, but I can't find it...
Can you help me ?

@deltakosh
Copy link
Contributor

You're ABSOLUTELY right :) I'll fixed it right now^^
The code for Matrix.OrthoOffCenterLHToRef is in babylon.math.js. Here is the code:

BABYLON.Matrix.OrthoOffCenterLHToRef = function (left, right, bottom, top, znear, zfar, result) {
    result.m[0] = 2.0 / (right - left);
    result.m[1] = result.m[2] = result.m[3] = 0;
    result.m[5] = 2.0 / (top - bottom);
    result.m[4] = result.m[6] = result.m[7] = 0;
    result.m[10] = -1.0 / (znear - zfar);
    result.m[8] = result.m[9] = result.m[11] = 0;
    result.m[12] = (left + right) / (left - right);
    result.m[13] = (top + bottom) / (bottom - top);
    result.m[14] = znear / (znear - zfar);
    result.m[15] = 1.0;
};

@Temechon
Copy link
Contributor Author

Temechon commented Sep 8, 2013

Thank you David :)
Maybe I was not clear in my second sentence, I found the code of this function, but couldn't find the issue in it.

Anyway, do you know why I can't have an orthographic camera on X or Y axis looking at my scene ?

@deltakosh
Copy link
Contributor

Strange...could you share you code so I can try to find the issue?

@Temechon
Copy link
Contributor Author

Temechon commented Sep 9, 2013

Nothing fancy here. Here is my code :

var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);

// Camera on Y axis looking at (0,0,0)
var camera = new BABYLON.FreeCamera("Cam", new BABYLON.Vector3(0,-10,0), scene);
camera.setTarget(new BABYLON.Vector3.Zero());

var box = BABYLON.Mesh.CreateBox("box", 1, scene);
box.position = new BABYLON.Vector3(1, 0, 0);

var renderFunction = function () {
          scene.render();
};
engine.runRenderLoop(renderFunction);
camera.attachControl(canvas);

When I execute this code, nothing is displayed. I have to attach a control to the camera and rotate the view to see my scene.

@deltakosh
Copy link
Contributor

Ohh I know this bug :) This is related to maths^^
just move the box a little bit just to ensure the box is not perpendicular to its target:

camera.setTarget(new BABYLON.Vector3(0, 0, 0.001));

@Temechon
Copy link
Contributor Author

Temechon commented Sep 9, 2013

Perfect, it's working great :)

Thank you !!

@Temechon Temechon closed this as completed Sep 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants