I am working on a project that uses scale/translate/rotate. I know that I need to rotate first (bottom of list of transformations) I am currently pushing before every objects draw and popping matrix afterwards. This is done in the draw() method I created. I have tested removing drawing of objects systematically and not using transformations other than rotate on the object in question.
This is my problem. When I rotate the object at 0/360 degrees it is a perfect square, as it rotates it stretches longer along the x-axis (still maintaining properties of a rectangle if you follow me) at 270 degrees (straight down x-axis) the stretch reaches its highest point... It will stretch directly coordinating to the angle in which it is facing. I am setting point of origin to 0,0 before I re-rotate.
I am wondering if this problem is a case of a common newbie mistake, working as intended and I need to compensate, or my code has a flaw that I couldn't find in a few hours of research and digging. I will post code if requested but I think that because of the nature and the checking I have already done it may take quite a bit of space.
Any input would be greatly appreciated.
Thanks in advance!
I changed the image so that I could see more of what was happening. It doesn't appear to be rotating the way I intended so that might be the cause of all this.
After fixing the angle I have noticed that the slope is where it's being drawn from/to is off. I am assuming that I have a problem with my points.
Related
I am using OpenGLES20 with android and I would like to know how to do the following:
I think it's easier to explain with a picture...
How can I rectify this stretching. Note: I am working in 2D.
I've heard this problem is solved using something called a projection matrix. I have also read a StackOverflow question saying that the android documentation for setting up a projection matrix is not good. I have tried it personally and couldn't get it to work.
This question is extremely poorly put. On the left image you have rectangular view with coordinate system [0,1]x[0,1] and a correctly drawn triangle while on the right you have the same view with view coordinate system and stretched triangle... Taking this 2 things into consideration your triangle coordinates are already stretched to begin with (or there is an extra model view matrix). If they weren't stretched the triangle would be drawn correctly on the right image.
It is a very common issue your scene is stretched when dealing with different view ratios. In general to solve this you are looking for something like glOrtho which can define your coordinate system. The input parameters for this method are left, right, top and bottom and it is easiest to simply use screen coordinates (like presented on the right image). Another approach is to normalise this input to either [0,1]x[0,height/width] or [0,width/height]x[0,1]. These two methods represent "fit" and "fill" and which is which depends on width of view being smaller or larger then height (portrait, landscape).
When using a correct orthographical matrix your square will always be a square without using any additional matrices or multiplying the vertex arrays... In your case it seems you already multiplied your vertices so I suggest you remove that, all of it. If you can not and those vertices will continue to be scaled incorrectly I suggest you use model view matrix to rescale them.
I know this question has been asked to death, but I'm somewhat confused about the answers I've been seeing. So I want to resize a bitmap I am displaying on the screen in my android app. I need to be able to resize it efficiently, in real time. It is expected for the user to be constantly resizing / panning around the image, so I want to do this as efficiently as possible.
So far, I've only seen Bitmap.createScaledBitmap(...) which seems like its completely rebuilding the bitmap. It gets a bit of lag when the user is performing pinch and zoom (many resizes in a row).
Whats weird is that when I tried using canvas.scale(...), there was no lag in zooming the image. The only problem with this is that it resizes the coordinates as well, making it impossible to use in this application. Is there something similar to canvas.scale() for Bitmaps, that just scale the image without reloading it, similar to canvas.scale()?
You can find all the Canvas methods here.
What you are after is probably a combination of Canvas.scale(...) and the Canvas.save()/Canvas.restore() methods to reset the coordinates after drawing.
If this is not what you are looking for, another solution might be to get the current transformation matrix and apply to your coordinates to get the 'currently active' coordinates.
We use Camera to do 3D transformations in canvas.We usually rotate camera and get it's Matrix then translate it.But Camera also has translate method.The results of using methods are different.
My question is : What is difference between Camera.translate and Matrix.preTranslate or Matrix.postTranslate?
The reason there are both, is because matrix multiplication must be done in a certain order to achieve the proper result (as you may already know).
The sequence of translations/rotations/scales are done in reverse order as you type them.
So if you do something like this:
Camera.rotate(15, 0, 0);
Camera.scale(.5f, .5f, .5f);
Camera.translate(70, 70, 70);
You're first translating 70,70,70 then scaling by 50% in all directions, then rotating 15 degrees about the X axis.
So Matrix has a pre and post translate (well, pre and post everything), because maybe you want to actually rotate it first by 15 degrees and then translate it, and then finally scale it.
So that answers the pre and post translates. Now the reason Camera has a straight rotate and translate is for people that know how this works already (like me!), so I never use Matrix or Camera for that matter, because I can simply do my rotations and translations directly on the Canvas. You can too as long as you know that translations, scales, and rotates are done in reverse order.
Also, if you know what I have told you, it gives you more power. You can do a sequence of 10 matrices without surrounding them in multiple Matrix objects for each one (for example you want to do a swing motion that swings outward AND rotates about the center to simulate centrifugal force). This would need to be done with multiple rotates and translations (surrounded by multiple Matrix objects being passed into one another), but if you know how each translate works, you can simply do a series of .translate(), .rotate(), and .scale().
This information is especially useful if you ever do 3D graphics, because that's when these matrices give people headaches.
I hope this helps!
The result would be visually the same if you i.e. do not touch the canvas but rotate the camera 90 degs or keep camera still but rotate the canvas it looks at by -90 degs.
I am trying to make a 3D-looking scrollable list, with elements stacking in a row moving forward and backwards, and all that needs to be 3D-looking (back elements faded out and scaled down, etc). Problem is that the front element, when moving out of the view (more to the front, that is) needs to rotate on X-axis and sort of "fall down", as if it was falling from an end of a conveyor belt.
I have searched far and wide for an elegant solution that does not involve developing a real 3D environment or applying whole code libraries, but could not find anything of the sort. I am really a noob at developing for Android, so I guess I might have overlooked something.
The only solution that came close to it was using a 0-duration animation that applied rotation transformation via Camera class onto View's canvas, but that wasn't a good enough 'cause the View's boundaries were clipping the rotated content, and let's face it - that's a crooked way to apply something as trivial as rotation.
Is there really no simple way to rotate Views? I mean, iOS has it, Flash has it - even CSS3 gives a way to do it without breaking a sweat.
My target is API 10 (2.3.3) and up.
I need to draw a growing 3d line using open gl on an Android device.
The problem is I need to draw lines that scale with a "laser" type effect on them.
Originally I just thought of drawing simple gl lines or line loops but they wont scale if the camera is moved closer to them - like a fly through.
My next thought was to generate a cylinder mesh and extrude it as I would do a line in real time, accounting for 90 degree turns by adding a 45degree rotation after extruding from the end point a new cylinder, turning the end 45degrees again and extruding another cylinder to create the new line extension and so on and so-forth...
Problem with cylinders is the near clipping plane will clip through them.
Anyone have a better thought or idea they can throw at me for this?
Problem with cylinders is the near clipping plane will clip through them.
This will be the case with any kind of geometry. You can however use depth clamping to avoid some of the effects of clipping. See here for details http://arcsynthesis.org/gltut/Positioning/Tut05%20Depth%20Clamping.html