I'm creating a Quicktime movie file using AVAssetWriter. Currently the output video is "upside down". In theory I can correct this by rotating the video 180 degrees about the horizontal axis (essentially "flipping" the video). What's the best way to do this?
Currently I'm trying to assign a CGAffineTransform to myAVAssetWriterInput.transform. Perhaps CGAffineTransformMake(a, b, c, d, tx, ty) will allow me to specify the correct affine transformation matrix?
Neither the Apple docs nor wikipedia gives a clear explanation on how an affine transformation matrix works. And there might be a better way all together.
myAVAssetWriterInput.transform = CGAffineTransformMakeRotation(M_PI);
if you want to rotate the video 180 degrees around z-axis, or
myAVAssetWriterInput.transform = CGAffineTransformMakeScale(1, -1);
if you want to reflect in x-axis
[AVAssetTrack preferredTransform] will return the right CGAffineTransform.
You can assign this CGAffineTransform to writeInput.
Related
I have a simple UIImageView in my view, but I can't seem to find any feature in Apple's documentation to change the UV Coordinates of this UIImageView, to convey my idea to you, this GIF file should preview how changing 4 vertices coordinates can change how the image gets viewed on the final UIImageView.
I tried to find a solution online too (other than documentation) and found none.
I use Swift.
You can achieve that very animation using UIView.transform or CALayer.transform. You'll need basic geometry to convert UV coordinates to a CGAffineTransform or CATransform3D.
I made an assumption that affine transform would suffice because in your animation the transform is affine (parallel lines stay parallel). In that case, 3 vertices are free -- the 4th one is constrained by the other 3.
If you have 3 vertices, you can compute the affine transform matrix using: Affine transformation algorithm
To achieve the infinite repeat, use UIImageResizingMode.Tile.
There are:
1.
CGAffineTransform layerTransform = CGAffineTransformMakeRotation(M_PI_2);
layerTransform = CGAffineTransformTranslate(layerTransform, 1080, 0);
2.
CGAffineTransform layerTransform = CGAffineTransformMakeTranslation(1080, 0);
layerTransform = CGAffineTransformRotate(layerTransform, M_PI_2);
What's the different between them ?
Rotate before or after translate, is there any different?
CGAffineTransformTranslate is basically create a new affine transform by translating (moving) existing affine transform with specified method. We have to use CGAffineTransform CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx, CGFloat ty ) method for it. Here tx and ty has the values by which new affine transform have to move in X and Y direction respectively.
CGAffineTransformRotate is basically create a new affine transform by rotating existing transform with specified method. We have to use CGAffineTransform CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle ) method for it. Here angle has the rotation angle for new affine transform.
I hope, you can get that first one is used to get a shift from one position to another one, and second one is used to get a roation.
The thing you need to know is that translation means move the location.
Rotation is self explanatory.
The order does matter depending on the origin point and the effect you want to achieve.
I'm Core Graphics this is lower left on a OS X and upper left on iOS.
In Core Animation objects can be transformed more easily by their center points.
CG works with rects though.
The most common hurtful thing is trying to rotate something about its center in CG.
If you just rotate transform the thing will appear to rotate around its origin like the hand of a clock.
So if you move the origin then rotate, you you can compensate for this.
The math is not easy unless you know trig and radians.
The trick is that you need to apply both transformations before drawing again or the thing will jump about.
I am using 3ds max for a long time and I know xyz axis. what I see in xcode in rotation the scnnode what made my mind blowed up is w component of scnvector4.
Can someone explain in detail how to use this method because I searched a lot of time but I can't make my object spin as I desire. anyone can help to make him spin to his back in 180 degree but I will appreciate if someone explain more for further rotations, Knowing that I saw this link but I didn't understand something.
http://www.cprogramming.com/tutorial/3d/rotationMatrices.html
I believe that your are trying to rotate nodes (rotation property).
From the documentation :
The four-component rotation vector specifies the direction of the rotation axis in the first three components and the angle of rotation (in radians) in the fourth.
You might find it easier to use eulerAngles :
The node’s orientation, expressed as pitch, yaw, and roll angles, each in radians
Use .transform to rotate a node
node.transform = SCNMatrix4Mult(node.transform, SCNMatrix4MakeRotation(angle, x, y, z))
if you want to rotate your node 180 degree by x axis
node.transform = SCNMatrix4Mult(node.transform, SCNMatrix4MakeRotation(Float(M_PI), 1, 0, 0))
I have a single cloud texture that I want to displace arbitrarily along the Y ("vertical") axis of a SCNNode spherical geometry, to give the illusion there are many different textures of clouds.
I read the docs about SCNMaterialProperty, CATransform3D rotation, but I'm completely lost. In a 3D program, you can set your texture "origin" along the X, Y and Z axis -- what is the equivalent in Scene Kit / Core Animation ?
Thanks for your help!
SCNMaterialProperty has a contentsTransform property that allows you to animate texture coordinates. You can also use shader modifiers if you want more control and depending on th effect you want to achieve.
In the Bananas sample code from WWDC 2014 this technique is used to animate the smoke emitted by the volcano in the background.
I finally ended up with this:
self.cloudNode.rotation = SCNVector4Make(0.0,
1.0,
0.0,
arc4random_uniform(360)*M_PI/180.0);
I'm not a maths genius anyway.
I want to create the same transforming effect on XNA 4 as Photoshop does:
Transform tool is used to scale, rotate, skew, and just distort the perspective of any graphic you’re working with in general
This is what all the things i want to do in XNA with any textures http://www.tutorial9.net/tutorials/photoshop-tutorials/using-transform-in-photoshop/
Skew: Skew transformations slant objects either vertically or horizontally.
Distort: Distort transformations allow you to stretch an image in ANY direction freely.
Perspective: The Perspective transformation allows you to add perspective to an object.
Warping an Object(Im interesting the most).
Hope you can help me with some tutorial or somwthing already made :D, iam think vertex has the solution but maybe.
Thanks.
Probably the easiest way to do this in XNA is to pass a Matrix to SpriteBatch.Begin. This is the overload you want to use: MSDN (the transformMatrix argument).
You can also do this with raw vertices, with an effect like BasicEffect by setting its World matrix. Or by setting vertex positions manually, perhaps transforming them with Vector3.Transform().
Most of the transformation matrices you want are provided by the Matrix.Create*() methods (MSDN). For example, CreateScale and CreateRotationZ.
There is no provided method for creating a skew matrix. It should be something like this:
Matrix skew = Matrix.Identity;
skew.M12 = (float)Math.Tan(MathHelper.ToRadians(36.87f));
(That is to skew by 36.87f degrees, which I pulled off this old answer of mine. You should be able to find the full maths for a skew matrix via Google.)
Remember that transformations happen around the origin of world space (0,0). If you want to, for example, scale around the centre of your sprite, you need to translate that sprite's centre to the origin, apply a scale, and then translate it back again. You can combine matrix transforms by multiplying them. This example (untested) will scale a 200x200 image around its centre:
Matrix myMatrix = Matrix.CreateTranslation(-100, -100, 0)
* Matrix.CreateScale(2f, 0.5f, 1f)
* Matrix.CreateTranslation(100, 100, 0);
Note: avoid scaling the Z axis to 0, even in 2D.
For perspective there is CreatePerspective. This creates a projection matrix, which is a specific kind of matrix for projecting a 3D scene onto a 2D display, so it is better used with vertices when setting (for example) BasicEffect.Projection. In this case you're best off doing proper 3D rendering.
For distort, just use vertices and place them manually wherever you need them.