Help with the screen projection


#1

Hello there!
I would like to ask if there is a way to change the coordinate system of my screen. I am working on stage3D and because of the OpenGL(compiling for desktop), the viewport by default is at the bottom left corner. I created a camera, and an orthographic projection. I managed to reverse it, making it top left, but now the y value of each object must decrement to make it go down (unlike flash where it must increment). Is there a way to make the viewport exactly like flash.

I have achieved:
pic1

I need:
pic2


#2

Take a look at the projection I used here:

This sample won’t work until the next release (current OpenFL does not allow for GLSL in Stage3D) but that projection should still work if you use an AGAL shader, similar to the one from the Stage3DCamera or Stage3DMipmap samples


#3

Thanks for sharing some code with me singmajesty. I have modified my project so i use GLSL in stage3D as well. So i just copied your projection code into mine to test it. Unfortunetly, the y axis has not been changed (still, by increasing the y value on objects, makes them move up, not down). By putting negative values in the y of the matrix (-2.0 / stage.stageHeight) doesn’t change anything for me so i am still breaking my head with that. I append 3 matrices into the final matrix (modelMatrix, viewMatrix & projectionMatrix) just for the information. Any further help with my problem would be appriciated.


#4

Internally, OpenFL uses a function similar to this:

function createOrtho (x0:Float, x1:Float, y0:Float, y1:Float, zNear:Float, zFar:Float):Matrix3D {

    var sx = 1.0 / (x1 - x0);
    var sy = 1.0 / (y1 - y0);
    var sz = 1.0 / (zFar - zNear);
		
    return new Matrix3D (Vector.ofArray ([ 2.0 * sx, 0, 0, 0, 0, 2.0 * sy, 0, 0, 0, 0, -2.0 * sz, 0, -(x0 + x1) * sx, -(y0 + y1) * sy, -(zNear + zFar) * sz, 1 ]));
}

using these values:

__projection.createOrtho (__offsetX, __displayWidth + __offsetX, __offsetY, __displayHeight + __offsetY, -1000, 1000);
__projectionFlipped.createOrtho (__offsetX, __displayWidth + __offsetX, __displayHeight + __offsetY, __offsetY, -1000, 1000);

I tried to simplify it for the sample, but perhaps I got it a little bit wrong.


#5

Thanks for all your help singmajesty. I finally did it. The problem was that i used the same projection to render my world to a texture and to project every sprite in my world. Changing the projection code flipped both of them so nothing changed. By flipping only the projection for the sprites did the trick. How didnt i notice earlier, silly me. Thanks again for all your help.