I'm looking to Animate a UIView and give it some 3D Effects.
I've experimented with CATransform3DMakeRotation() but can't seem to get the correct effect.
What I am trying to achieve is something like this:
Where the red view is moving from side to side with a 3d perspective.
Not the exact answer, but something to point you to right direction. Tumbljack has a nice tutorial, sample project and video on how to do 3D transformation on a view.
You can try with the following properties as mentioned in that.
layer.transform = CATransform3DMakeRotation(radian, x, y, z);
or
transform.m34 = 1.0 / -zDistance;
Try tweaking the sample code to get the desired output on your UIVIew. His tutorial is to have a complete 3D cube/sphere transformation and in your case you might need only the left and right movement from that.
Related
i have a 2d object, something like a square grid. I would like to add some depth to it so it looks like its going off into the distance so the top left and right points of the square should get closer together, something like looking down a long road. I currently have the square make on a 2d surface and it looks fine i was just wondering if theres a method in Cocos2d that will rotate the square and give that effect. I've tried using
CCFiniteTimeAction* action = [CCActionTween actionWithDuration:7 key:#"scaleY" from:.5 to:1.2];
[self runAction:action];
but that only seems to decrease the length and width of the square and not actually adds any depth to it. I found CCTransitionFlipY which seems like it would give a desired effect but it looks like that is only for Scenes. Any help into this would be awesome!
Found a nice solution here. I used CCOrbitCamera to get the desired effect!
It feels simple really. I have an UIImageView:
and I want to apply an affine transform to get this image:
However, the particular transform in question eludes me. Rotating by 180° gets me this:
transform = CGAffineTransformMakeRotation(M_PI);
// similarly, CGAffineTransformMakeScale(-1, -1);
which is oviously quite far off. Translation is also problematic:
transform = CGAffineTransformMakeTranslation(x, y);
Reflecting over the line y = x and then rotating 180° gets me this:
transform = CGAffineTransformMake(0, 1, 1, 0, 0, 0);
transform = CGAffineTransformRotate(M_PI);
which is closer, but still not there. Is there something obvious that I'm missing, or is this really complicated? Does anyone know what sort of transform I'm looking for here?
Edit:
Twitter feedback is suggesting that affine transforms aren't the way to go. At the end of the day, I simply want the resultant image, so any suggested routes to success are greatly appreciated!
You are trying to move a sprite, whether you realize it or not. No transformation can move the star and keep the background. Your options are to:
- make a large background and clip it at the end, so that translation works
- make a sprite image on top of a separate background image. If you're using iOS7, you may want to use the Sprite Kit.
Okay, this is driving me crazy. I've looked through tons of examples and can't seem to get quite what I need. I'm using XNA and I have a plane of vertices and my camera is up in the sky looking down on the vertices.
What I want is to rotate the camera around on the Y axis, basically get the same result as adjusting its YAW. However whenever I try to rotate around on the Y axis or adjust its YAW nothing actually happens. I can however get the effect I want by creating a Y rotation matrix on the world, but that doesn't feel like the "correct" way of doing it, I want the camera itself to spin and not the world. Here's a code snippet for what I have:
cameraPosition = Vector3.Transform(new Vector3(
cameraOffset.X - cameraOffset.X,
zoomAmount,
cameraOffset.Z - cameraOffset.Z),
Matrix.CreateRotationY(rotationAngle)) + cameraOffset;
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, new Vector3(0, 0, 1));
Thanks!
Since you have the camera looking straight down, it sounds like what you want is for the camera to roll in local space. To roll your camera, you must rotate the Up vector you are feeding to the CreateLookAt(). Like this:
Vector3 newUp = Vector3.Transform(Vector3.UnitZ, Matrix.CreateRotationY(rotationAngle));
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, newUp);
I'd like to build a random animation of a imageview on iPad. What i manage to build so far is this:
The arrow represents my imageview. it moves to the bounds of its parent view an changes it direction. Actually this is not what i want. Id like to move the view randomly in it's parent view, in curves. And also adjust its heading, like in this figure:
I've no clue how to solve this and in particular how to generate a nice smooth path. Maybe someone has a hint for me.
Brad Larson answers a question that will give you some insight here: How do I translate parabolically?
Choosing random points is pretty easy and when you add them using a keyframe animation and a path, you get the smoothing you're looking for. You would just need to add the points to the path reference.
You add the path to the keyframe animation according to the link above and then add the animation to the UIImagView's layer with:
[[imageView layer] addAnimation:pathAnimation forKey:#"pathAnimation"];
Best regards.
Try out with Bezier curves with following
Drawing bezier curves with my finger in iOS?
and
CGPathReference
You would actually get quite far by just configuring the calculation mode of the key frame animation to be cubic
positionAniamation.calculationMode = kCAAnimationCubic; // or kCAAnimationCubicPaced
That will cause it to construct cubic splines between the points specified in the values array.
I'm creating an ios drawing app and would like to understand how to rotate the texture I'm using for drawing to have the texture follow the direction of my stroke.
Sketchbook for iOS and brushes are two apps that Ive seen accomplish this.
Does anyone have any idea of how to achieve this?
Here's an example of the concept that I'm trying to capture: http://drawsketch.about.com/od/learntodraw/ss/pencilshading_5.htm
Attached is a screenshot from the sketchbook app of this in practice.
UPDATE:
I was able to figure this out (thanks to SO community for helping out!) and posted my answer here: https://stackoverflow.com/a/11298219/111856
You can just rotate the brush texture as you're drawing it. You can get the angle by taking the arctangent of the y delta divided by the x delta for each segment of the stroke:
atan2(newY - prevY, newX - prevX);
Then rotate your brush texture by that amount before blending it at each point along the line.