I am try to create a bivariate map but I adjusted my projection incorrectly and can't figure out how to set it back. I used:
geo2xy _Y _X, proj(Mercator) replace
and now the map is zoomed out beyond where it should be. What is the best way to set it back to normal?
Related
I am working on a project in which I need to use high accuracy input coordinates for further calculation.
I call GetTouchInputInfo function in WM_TOUCH message handler to acquire PTOUCHINPUT variables, but the coordinates provided in this struct are indicated in hundredths of a pixel of physical screen coordinates. So basically the last 2 digits are always 0, and after divided by 100, these coordinates are just integer screen coordinates. I don't know why did they make it in hundredth.
Besides, does the touchscreen sensor gives continuous signal instead of discreet signal? As I know, there is a thing called touch prediction in Window, it creates a small touch input lag as it holds a few latest input points and do some prediction algorithm to fix these fresh inputs smooth and pretty. Even if the touchscreen can only sense discreet signal, the input should be float anyway after the prediction algorithm right?
I really couldn't find out how to obtain float touch input. Is there any way or any function to achieve this?
Thank you!
And sorry about my English.
To convert the scaled long coordinates to float do:
PTOUCHINPUT pt;
float xf = pt->x / 100.0;
float yf = pt->y / 100.0;
I am trying to implement this SAO algorithm.
I am getting the following result :
I can't figure out why I have the nose on top of the walls, it seems to be a z-buffer issue.
Here are my input values :
const float projScale = 100.0;
const float radius = 0.9;
const float bias = 0.0005;
const float intensityDivR6 = pow(radius, 6);
I am using the original shader without modifications, except that I disable the usage of mipmaps of the depth buffer.
My depth buffer (on different scene, sorry) :
It should be an issue with the zbuffer linearization or it's not between -1 and 1.
Thank you Bruno, I finally figure out what were the issues.
The first was that I didn't transform my Z correctly, they use a specific pre-pass to make the Z linear and put it between -1 and 1. I was using an incompatible method to do it.
I also had to negate my near and far planes values directly in the projection matrix to compute correctly some uniforms.
Result :
I had a similar problem, having visual wrong occlusion, linked to the near/far, so I decided to give you what I've done to fix it.
The problem I had is discribed in a previous comment. I was getting self occlusion, when the camera was close to an object or when the radius was really too big.
If you take a closer look at the conversion from depth buffer value to camera-space value (the reconstructCSZ function from the g3d engine), you will see that replacing the depth by 0 will give you the near plane if you work with positive near/far. So, what it means is that every time you will get a tap outside the model, you will get a z component equals to near, which will give you wrong occlusion for fragments having a z close to 0.
You basically have to discard each taps that are located on the near plane, to avoid them being taken into account when comptuing the full contribution.
I want to draw a triangle and text using C++ and Cairo like this:
|\
| \
|PP\
|___\
If I add the triangle and the text using Cairo I get:
___
| /
|PP/
| /
|/
So the y-axis is from top to bottom, but I want it from bottom to top. So I tried to changed the viewpoint matrix (cairo_transform(p, &mat);) or scale the data (cairo_scale(p, 1.0, -1.0);). I get:
|\
| \
|bb\
|___\
Now the triangle is the way I want it BUT the TEXT is MIRRORED, which I do not want to be mirrored.
Any idea how to handle this problem?
I was in a similar situation as the OP that required me to change a variety of coordinates in the cartesian coordinate system with the origin at the bottom left. (I had to port an old video game that was developed with a coordinate system different from Cairo's, and because of time constraints/possible calculation mistakes/port precision I decided it was better to not rewrite the whole bunch) Luckily, I found an okay approach to change Cairo's coordinate system. The approach is based around Cairo's internal transformation matrix, that transforms Cairo's input to the user device. The solution was to change this matrix to a reflection matrix, a matrix that mirrors it's input through the x-axis, like so:
cairo_t *cr;
cairo_matrix_t x_reflection_matrix;
cairo_matrix_init_identity(&x_reflection_matrix); // could not find a oneliner
/* reflection through the x axis equals the identity matrix with the bottom
left value negated */
x_reflection_matrix.yy = -1.0;
cairo_set_matrix(cr, &x_reflection_matrix);
// This would result in your drawing being done on top of the destination
// surface, so we translate the surface down the full height
cairo_translate(cr, 0, SURFACE_HEIGHT); // replace SURFACE_HEIGHT
// ... do your drawing
There is one catch however: text will also get mirrored. To solve this, one could alter the font transformation matrix. The required code for this would be:
cairo_matrix_t font_reflection_matrix;
// We first set the size, and then change it to a reflection matrix
cairo_set_font_size(cr, YOUR_SIZE);
cairo_get_font_matrix(cr, &font_reflection_matrix);
// reverse mirror the font drawing matrix
font_reflection_matrix.yy = font_reflection_matrix.yy * -1;
cairo_set_font_matrix(cr, &font_reflection_matrix);
Answer:
Rethink your coordinates and pass them correctly to cairo. If your coordinates source has an inverted axis, preprocess them to flip the geometry. That would be called glue code, and it is ofter neccessary.
Stuff:
It is a very common thing with 2D computer graphics to have the origin (0,0) in the top left corner and the y-axis heading downwards (see gimp/photoshop, positioning in html, webgl canvas). As allways there are other examples too (PDFs).
I'm not sure what the reason is, but I would assume the reading direction on paper (from top to bottom) and/or the process of rendering/drawing an image on a screen.
To me, it seems to be the easiest way to procedurally draw an image at some position from the first to the last pixel (you don't need to precalculate it's size).
I don't think that you are alone with your oppinion. But I don't think that there is a standard math coordinate system. Even the very common carthesian coordinate system is incomplete when the arrows that indicate axis direction are missing.
Summary: From the discussion I assume that there is only one coordinate system used by Cairo: x-axis to the right, y-axis down. If one needs a standard math coordinate system (x-axis to the right, y-axis up) one has to preprocess the data.
I'm developping an editor that must use SVG shapes to create diagrams.
To open and display SVGs I use librsvg which is actually pretty good but only useful to render SVGs not to edit them.
I would like to access to shape's property and change their values (i.e. width, size ).
I use Cairo to draw them to the screen but I don't want to use the cairo's scale feature, cause it's not the same as changing the size of the shapes.
I use C++ builder XE3 on Win32.
Is anyone knows a good C/C++ library I could use to do so ?
Thanks for your help.
Cairo's scale function scales the entire coordinate system, but you can use it on an individual shape if you translate first to the shape's origin; and if you bracket these changes with a save/restore pair it will only affect drawing done within this span. Resetting the matrix before stroking allows you to resize a drawing without changing the stroke-width (alternately, you can adjust the stroke_width by 1/scaling-factor).
cairo_matrix_t m;
cairo_get_matrix(cr, &m);
cairo_save(cr);
cairo_translate(shape_x, shape_y);
cairo_scale(shape_w, shape_h);
//cairo_move_to(cr, x, y); //perform the actual drawing
//cairo_line_to(cr, x, y);
//cairo_closepath(cr);
cairo_set_matrix(cr, &m);
cairo_stroke(cr);
cairo_restore(cr);
And if resetting the matrix explicitly like this, you don't actually need the save/restore anymore (translate and scale don't affect anything but the matrix, and stroke resets the path).
I am using QT and try to plot a graph with QGraphicsView and QGraphicsScene..i dont want any additional dependencies, thats why i dont use QWT. When i plot my data, at the moment i use
scene->drawLine(x1,y1,x2,y2,pen);
then this draws a line between the 2 points in the QGraphicScene. But this uses a top left x=0 y=0 system... i would like to use my own system like in the picture below. Another problem is that i have double values from -3 to +3..has anyone some experience with QGraphicScene and QGraphicsView and can tell me how i can accomplish this?
Try looking into QGraphicsView::setTransform. This matrix defines how "scene coordinates" are translated to "view coordinates", it's a common concept in graphics programming.
There are also convenience functions scale(), rotate(), translate() and shear() which modify the view's current transformation matrix.
So you could do something like this:
scale(1.0, -1.0); // invert Y axis
// translate to account for fact that Y coordinates start at -3
translate(0.0, 3.0);
// scale Y coordinates to height of widget
scale(1.0, (qreal)viewport()->size().height()/6.0);
And since this is dependent on the size of the widget, you'd also want to catch any resize events and reset the transformation matrix again there. Assuming you want "3" to represent the top of the viewport and "-3" the bottom.