Faced the problem of disabling the zoom with a small number of points. How can I disable further zooming if the number of points to fit on the canvas is less than 10, for example?
Related
I have a square. Then I have a known number of rectangles, varying in widths and heights (tendency to be near square, but not always). I need to pack the rectangles into the square such that a minimum amount of area is wasted in the square. So far, basic.
But additionally, the rectangles can be scaled, as well as rotated. Their relative sizes to one another should change by as little as possible.
With so many degrees of freedom the problem becomes rather fuzzy. Does anyone have links to further reading, or a suggestion on how to approach this problem?
I need to move surfaces around the screen based on certain horizontal and vertical velocities. I need those velocities to be completely random. My idea was to generate random float numbers (in which I succeeded) and use them as the velocities. This way I could have many different velocities, never being too fast or too slow. The problem is: SDL_BlitSurface will only accept a SDL_Rect as the parameter to determine the new rect with which the surface will be drawn, and SDL_Rect is a struct made of 4 ints: two for coordinates and two for dimensions;
Resuming: How to work with precision when blitting surfaces on SDL?
There is a solution to actually display a surface with a half-pixel precision. There is a performance cost but it renders quite nicely. This is basically how old-school anti-aliasing works: rendering at a higher resolution then downscaling.
win = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); //create a new rendering window
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); //create a new renderer
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother.
SDL_RenderSetLogicalSize(renderer, width*2, height*2); //tell the renderer to work internally with this size, it will be scaled back when displayed on your screen
You can find some explanation about the functions here or on the API page here and here.
Now you can use your window as if it was twice bigger but it still outputs at the same size. When you're doing your output, you put the same SDL_Rect in the blitting functions except everything is doubled. That way you can keep half pixel precision. You can get even cleaner output if your sprites have also the increased precision.
You could also do it with quarter pixel precision but the performance cost will be even bigger so it might not be possible in your application. There is also a memory cost because the surfaces are bigger (times four for half pixel precision, sixteen for quarter pixel).
SDL_BlitSurface is working with pixels, and unfortunately you cannot have "half pixels". You should still represent your objects' coordinates as float, but convert them to int when passing them to your SDL_Rect. Since your SDL_Surfaces will always land perfectly on screen pixels, your graphics should always remain crisp.
That being said, to have more precision, I guess you could switch to rendering quads in OpenGL. The hardware will be responsible for calculating the pixel color of your textures when they are not properly aligned with screen pixels, resulting in "fuzzy" textures, but at least you will have total control of their position.
It does not make sense to deal with sub-pixel precision when rendering, as pixels by definition are the smallest addressable element in raster graphics.
You could instead round the position to the nearest integer when rendering, e.g. (Sint16)(x+0.5). The rest of your application can still use coordinates with higher precision if you need it.
Similar to calibrating a single camera 2D image with a chessboard, I wish to determine the width/height of the chessboard (or of a single square) in pixels.
I have a camera aimed vertically at the ground, ensured to be perfectly level with the surface below. I am using the camera to determine the translation between consequtive frames (successfully achieved using fourier phase correlation), at the moment my result returns the translation in pixels, however I would like to use techniques similar to calibration, where I move the camera over the chessboard which is flat on the ground, to automatically determine the size of the chessboard in pixels, relative to my image height and width.
Knowing the size of the chessboard in millimetres, I can then convert a pixel unit to a real-world-unit in millimetres, ie, 1 pixel will represent a distance proportional to the height of the camera above the ground. This will allow me to convert a translation in pixels to a translation in millimetres, recalibrating every time I change the height of the camera.
What would be the recommended way of achieving this? Surely it must be simpler than single camera 2D calibration.
OpenCV can give you the position of the chessboard's corners with cv::findChessboardCorners().
I'm not sure if the perspective distortion will affect your calculations, but if the chessboard is perfectly aligned beneath the camera, it should work.
This is just an idea so don't hit me.. but maybe using the natural contrast of the chessboard?
"At some point it will switch from bright to dark pixels and that should happen (can't remember number of columns on chessboard) times." should be a doable algorithm.
I have a button which Max and Min height X width are 1024X1360 and 72X95 pixels. I am resizing this button by handling DragDelta events of Thumbs present in button's Template. The problem is the updation of height and width at lower levels, i.e upto 210X280, gives out a smooth operation which is not the case with greater sizes. Anybody out here has faced the issue? Any suggestion to improve the user experience in this situation.
The easiest fix here is to make the contents of your button less complex. In general, the more stuff there is to draw inside of it (i.e. larger size) the longer it is going to take to draw it. This can become even more problematic when you consider that hardware will play an (unpredictable) role in the performance as well.
So a couple of easy options: Mix and match for best results.
1. Make your button less complex.
2. Limit its maximum size. (To something smaller)
3. Accept the choppiness.
In my Silverlight application I display texts (textblock on canvas) as well as rectangles and lines (again shapes drawn on the canvas) over deep zoom images. I handle zoom in / out, pan and tilts. What is not realy cool in my opinion, is the way my vector objects look at different zoom factors. Of cause they become bigger or smaller.
Would you have any suggestions how to keep some of the objects dimentions look the same at any zoom? let's say, a line with StrokeThickness will always be of 10 screen pixels. or text block width, height 100 screen pix by 300 screen pix.
Thanks,
Val
It depends on how/where your objects are defined that you want to remain at 1:1 scale.
The 2 options I can think of are:
Render those objects in a canvas above the deep zoom (this means you need to work out the positions again yourself).
Apply reciprocal scaling to those objects (which means you work out what scale the item is going to display at and apply a 1/x scaling factor to them. That way the deep zoom shrinks an object that is scaled up to compensate and the 2 cancel out).
Hope this helps.