GetClipBounds in Direct2D - windows

Is there a way to get the clip bounds in Direct2D similar to GDI+?
https://learn.microsoft.com/en-us/windows/win32/api/gdiplusgraphics/nf-gdiplusgraphics-graphics-getclipbounds(rectf)
I have a D2D render target that has been transformed (translate, rotate and scale). How do I now calculate the clipped bounds? Any sample code or a function to calculate this?
Thanks

I 'd create a rectangle geometry on the target rectangle, then and calculate the bounds passing the transform. You don't even need a target, geometries are target-indepentent.

Related

Circular fisheye distort using opencv3 fisheye model

I use a OpenCV fisheye model function to perform fisheye calibration work. My image is a Circular fisheye (example), but I'm getting this result from the OpenCV fisheye model function.
I have the following problems:
I don't know why the result is an oval and not a perfect circle. Is this as expected?
Can OpenCV fisheye model be calibrated for a Circular fisheye image?
I don't understand why the image is not centered when using the cv::fisheye::calibrate function to get the Cx Cy parameter in K?
What tips (picture number, angle and position...) can be used on the checkboard to get the corrent camera matrix and Distortion factor?
Expected Result
My Result
First at all cv::fisheye uses a very simple idea. To remove radial distortion it will move points of fisheye circle in direction from circle center to circle edge.
Points near center will be moved a little. Points near edges will be moved on much larger distance.
In other words distance of point movement is not a constant. It's a function f(x)= 1+K1*x3+K2*x5+K3*x7=K4*x9. K1-K4 are coefficients of radial distortion of opencv fisheye undistortion model. In normal case undistorted image is always larger then initial image.
As you can see your undistorted image is smaller then initial fisheye image. I think the source of problem is bad calibration.
I don't know why the result is an oval and not a perfect circle. Is this as expected?
-> Tangential parameter of the calibration model can make it look like oval. It could be either your actual lens is tilted or calibration is incorrect. Just try to turn off tangential parameter option.
Can OpenCV fisheye model be calibrated for a Circular fisheye image?
-> No problem as far as I know. Try ocam as well.
I don't understand why the image is not centered when using the cv::fisheye::calibrate function to get the Cx Cy parameter in K?
-> It is normal that optical center does not align with the image center. It is a matter of degree, however. Cx, Cy represents the actual optical center. Low-quality fisheye camera manufactures does not control the quality of this parameter.
What tips (picture number, angle and position...) can be used on the checkboard to get the corrent camera matrix and Distortion factor?
-> clear images only, different distances, different angles, different positions. As many as possible.

Define rotational anchor point in the center of a quad shape in p5js

I know that there is rectMode(CENTER) of both rectangles and ellipses, but what about other shapes like triangles and quad shapes?
It's going to be hard to write a long reply because the answer is no, there isn't a rectMode() for triangles or shapes you create using the quad() or vertex() functions.
You could use the translate() function to translate to the center of the shape, and then draw all of the points relative to that. That would also solve the question that I think you're trying to ask about then calling the rotate() function.

Issue with Terrain Collision using Three.js

I have created a terrain via a heightmap in Three.js and am using mrdoob's misc_controls_pointerlock for collision and movement. However, when I do objects.push(terrainobj); the performance goes down to about 3fps (from around 60) and there is no collision with the terrain. The collision is achieved via rays. How can I get around this?
If it's just a heightmap you could avoid using ray and do the collision checking right in the bitmap (using canvas and imagedata).
You just need to convert your XZ world position to the XY pixel in the heightmap. Then, if your Y position in the world is lower than the color vaue of the pixel then you move up the object.

Limiting the drawing to a rectangle in OpenGLES

I need to limit the drawing of an object to a rectangle. I can't just change the viewport to match the rectangle becouse the ModelView matrix (that should change the rectangle, but not the content) may not be identity. A solution that would work is to draw to a FBO that match the rectangle, then draw the FBO to the screen, but it seems to slow. Is there any better option to do that?
If I understood you correctly, glScissor should be the function you are looking for. It crops the rendering to a selected sub-rectangle of the viewport. This does not modify the viewport. So the objects cover the same size on the screen, it just prevents you from drawing any pixels outside of the scissor region. If this is not what you want and you want the sub-rectangle to contain the whole scene and thus your objects to shrink, then changing the viewport is the solution of choice.
EDIT: If you want the rectangle to be transformable and especially rotatable (and therefore not a rectangle anymore on the screen), then rendering into an FBO and using this as texture on a quad is probably the best solution. Otherwise you could probably also just modify the vertex coordinates after projection, thus multiplying the transformation matrix of the target rectangle with the projection matrix and using this as new projection matrix, but I'm not completely sure about that (but at least something similar should do it.

How to get consistent gradient fill in GDI+ when using a rotated LinearGradientBrush?

I'm using GDI+ in my application, and I need to use a rotated LinearGradientBrush to paint several rects in the exact same way. However, although I'm calling the same code to fill each rect, the results aren't what I expect. Here's the code to create the gradient fill, where rcDraw is the rect containing the area to paint for each rect. These coordinates are in the parent window's coordinates, so they are not identical for the 2 rects.
g_hbrLinear = new LinearGradientBrush( Rect( 0, rcDraw.top, 0, rcDraw.bottom - rcDraw.top ),
clrStart, clrEnd, (REAL) 80, FALSE );
What I see on screen looks like this (http://www.nnanime.com/bugs/LinGradBrush-rotate10.png). You can see that it's as if the fill from the first rect continues into the second one. What I really want is to have the 2 rects look identical. I think I can do that if I paint each rect separately using its own client coordinates, but for the purposes of my app, I need to use the parent window's coordinates.
I guess what I'm asking is, how does GDI+ calculate the "origin" of a fill? Is it always based on 0,0 in the coordinate system you use? Is there a way to shift it? I tried TranslateTransform, but it doesn't seem to shift the fill in a way that I find predictable or understandable.
The rect passed to the linear gradient brush determines the where the left and right colors will sit, and the gradient will be painted within this rectangle.
So, I think you need to create a brush for each rectangle you are painting, where the rectangle you are painting is also passed to the constructor for the linear gradient brush.
My experience with the "transform" of linear gradient brushes matches yours; I haven't been able to understand what it's supposed to do.
You can think of a brush in GDI+ as a function mapping world co-ordinates to a color. What the brush looks like at a given point does not change based on the shape being filled.
It does change with the transform of the Graphics object you're drawing on. So, if you don't want to change the brush, you could temporarily change the transform of the Graphics object so that the rectangle you're drawing has a specific, known size and position in world coordinates. The BeginContainer and EndContainer methods should make this easy.
(There is also the RenderingOrigin property but it only affects hatch brushes, which oddly are unaffected by world transforms.)

Resources