is there a way to offset a scene center pointer without having to make my canvas bigger? I have a canvas at 100% of the width but I got some floating legend content that takes up about 25% of the width and I want my focus object center to be at 37.5% instead of 50%. The only way I can do it is by making my width 125% and position my canvas to the left by -25%. Thanks,
jk
Related
I'm trying to rotate a sprite around its center with following code:
Vector2 origin = new Vector2(position.Width / 2, position.Height / 2);
s.Draw(position, origin, angle, Color.White);
spriteBatch.Draw(texture, position, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0);
Note: Since I'm drawing from a sprite sheet, the source rectangle is being calculated.
The original size of my sprite is 15x32. If I use this size, the rotation looks nearly correct but it's still a little bit shifted:
However, when I resize the width and height to 75x128 the sprite is completely displaced:
Is there a way to always place the sprite correct, when resizing it? And why is the sprite even displaced when drawing it in the original size?
By the way, the green box is the origin point with the size of the sprite.
Thank you very much!
Ok I figured it out myself!
When creating the origin point, I used the new Width and Height (75, 128) but one has to use the width and height of the original sprite. In this case (15, 32).
In the right side I have the Viewport object that renders the OriginalImage.
Then in the left side I have a Sprite whose texture is the output of the Viewport object.
When running the Scene, I only get one quarter of the image, no matter how I place or offset Viewport, Camera, Sprites, etc.
For more information, please check the repo and of course pull requests are welcome:
https://github.com/Drean64/godot-viewport
Offset'd the Camera to the center of the viewport, because it was otherwise centered at the viewport's origin.
https://github.com/Drean64/godot-viewport/commit/ccfd095eb4bc23e2c5f385a35921280b878ee3d7
Tried this:
-filter watermark:"welcome.jpg" in=0 out=320 composite.progressive=1 producer.align=centre composite.valign=middle composite.halign=center crop_to_fill=1 composite.geometry="0=0,0:80%x80%:0%;60=0,0:100%x100%:100%;260=0,0:120%x120%:100%;320=0,0:120%x120%:0%"
But it doesn't increase size of watermark, it just moves it to right bottom side...
I don't know of a way to animate a center zoom only using the watermark filter. But it is possible to animate a center zoom using the affine transition. You would need to use two tracks: one with the background video and another with the text to be animated. Here is an example:
melt color:blue in=0 out=320 -track welcome.jpg in=0 out=320 -transition affine valign=middle halign=center scale=1 fill=1 geometry="0=10%,10%:80%x80%:0%;60=0,0:100%x100%:100%;260=-10%,-10%:120%x120%:100%;320=-10%,-10%:120%x120%:0%"
The key is that the position of the watermark is relative to the left corner. So, in addition to animating the size, you also need to animate the x and y position as shown in the example.
Also note that the animation will interpolate the size and position for each frame - but the position is rounded to the nearest pixel. So the motion may not be smooth. That is a known limitation to the animation capabilities in MLT.
I have a view in which I placed a scrollView that fits the entire view. Inside the scrollView I have a textView, below a imageView, below a textView and so on. The textViews are filled with content from the ViewController with localized text, so its height will change depending on language. I gave the textViews the constraints for top, bottom, left and right with 10 each. The ImageViews i gave the constraints top and bottom with 10 each, width 200 and centered in container horizontal. The height of the images is different for each image and no constraint for the height is given.
The first result was, the scrollView got a width of the longest text of the localized text. I changed for the
scrollView
Content Hugging Priority Horizontal to 995 and Vertical to 250.
textViews
Content Hugging Priority Horizontal of 400 and 200 Vertical,
Content Compression Resistance Priority Horizontal is 200 and Vertical 750.
Perfect result in portrait mode. When changing to landscape the width of the scrollView stays at 320 and is aligned to the left.
How can I fix the problem to let the scrollView take 100% width of the screen without giving the textViews the chance to force to enlarge themselves to 100% width?
Found solution:
The scrollView has constraints: top/bottom 8 and left/right 0 each to superview.
The textViews have constraints to top, left, bottom and right.
The images have constraints top, bottom and width, centered to X in container.
This results that the textViews take one line and grow to giant width.
Then I centered the textViews to X in Container and selected all textViews and images and centered them too.
Now the scrollView takes 100% width of screen, height as needed no matter if portrait or landscape.
So for all who have maybe the same issue: scrollView looks a bit smaller than the view, its constraints when adding are 0 to left and right and a top/bottom >0. When drag and drop scrollView in the view it takes 100% of the view size. That was the problem, the constraints were -16. Setting the scrollView to x = 16 and width = 288 results in fitting properly to the view! Next giving the textViews constraints top/left/bottom/right and center it to container (even if offset to real center, right to the item is 0 predefined - change it to use current canvas value).
I have a scene with a sphere in the middle and a camera spinning around it. Now I was wondering if it is possible with Three.JS to make a crop of this viewport so that the sphere for example would appear on the left or right.
I'm not looking to moving the camera or looking at a point besides the sphere, since that would distort the perspective, but a clip or crop of the rendering.
Is this possible?
One potential solution is to position a second canvas over your Three.js canvas, then re-draw the three.js scene onto your second canvas by blitting:
overlayCanvas.getContext('2d').drawImage(threeCanvas, 40, 40, 960, 960, 0, 0, 1200, 1200);
You can read more about the parameters to drawImage() in the documentation, but what this does is crop a certain area of the three.js canvas and stretch it over a larger area of your second canvas. It should be much faster than rendering the scene a second time, and it will display at the size you want it (albeit with some stretching).
You can alleviate the stretching by drawing the original (three.js) scene at a larger size than it would normally be displayed such that the area you want to crop into view is the same size as your secondary canvas.