Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL flip or mirror the drawing object

Tags:

opengl

How can i flip, ot mirror up/left of the image OBJECT, not the screen in the onDraw method?

I tried scale(1, -1, 1) that not worked

my code:

 opengl.selectVertex(vertexname)
                                .translate(x-1, y, -9);

                                if (opengl.getPathModifier(vertexname).getAngle()>-180 && 
                                    opengl.getPathModifier(vertexname).getAngle()<0 ) {
                                    opengl.selectVertex(vertexname).scale(-scale,scale,1);  
                                } else {
                                    opengl.selectVertex(vertexname).scale(scale,scale,1);
                                }

opengl.rotate(opengl.getPathModifier(vertexname).getAngle()+90, 0, 0, 1);
like image 716
lacas Avatar asked Feb 03 '11 13:02

lacas


2 Answers

Not 100% sure what you're asking here, but I think what you want to do is transform the projection matrix. If you want to flip so that things on the left appear on the right then you need to Scale the projection matrix by (-1, 1, 1). If you want things at the top to appear at the bottom you need to scale by (1,-1, 1) and if you want both you can scale (-1, -1, 1).

Edit based on extra information: If all you want to do is display the object exactly the same, but with texture flipped, you need to change the texture coordinates of the vertices in the objects - flip the texture coordinates by replacing the old u texture coordinate with 1-u.

like image 123
Jackson Pope Avatar answered Sep 21 '22 13:09

Jackson Pope


If you are using glFrustum(l,r,b,t,n,f) then change it yo glFrustum(l,r,t,b,n,f), in case you want a vertical flip. This apply also to glOrtho function.

like image 36
tibur Avatar answered Sep 21 '22 13:09

tibur