aerys / minko

3D framework for web, desktop and mobile devices.
http://minko.io
Other
905 stars 210 forks source link

Picking controller doesn't work with orthogonal cameras #144

Closed Tortenazor closed 10 years ago

Tortenazor commented 11 years ago

To reproduce, modify Pickingexample.as so it uses an orthogonal camera instead of the default one:

override protected function initializeScene() : void { super.initializeScene();

scene.removeChild(camera)

var c:OrthographicCamera = new OrthographicCamera();
c.zoom = 50
scene.addChild(c)

var _cameraController:ArcBallController = new ArcBallController();
_cameraController.minDistance = 1;
_cameraController.yaw = Math.PI * -.5;
_cameraController.pitch = Math.PI / 2;
_cameraController.distance = 5;
c.addController(_cameraController);

... ...

I think the issue should be somewhere in PickingController.as between lines 360 and 370 because the projection matrix is used there.

SBRK commented 10 years ago

PickingTechnique.RAYCASTING_BOX works with Orthographic Camera. Pixel Picking doesn't seem to be working, we'll look into it.

Tortenazor commented 10 years ago

Finally I found the time to fix it myself. Here it goes:

// update picking projection to get the picked pixel in (0, 0) var projection : Matrix4x4 = _sceneData.pickingProjection;

                projection.lock();
                scene.activeCamera.getProjection(projection);

                if(scene.activeCamera is OrthographicCamera) {

                    var o:OrthographicCamera = scene.activeCamera as OrthographicCamera
                    projection.prependTranslation(-_mouseX / o.zoom , _mouseY / o.zoom ,0)

                } else {

                    var rawData : Vector.<Number> = projection.getRawData();
                    rawData[8] = (-_mouseX / viewport.width) * 2.;
                    rawData[9] = (_mouseY / viewport.height) * 2.;
                    projection.setRawData(rawData);

                }

                projection.unlock();