Search Results

Search found 15 results on 1 pages for 'catransform3d'.

Page 1/1 | 1 

  • Are CMAttitude and CATransform3D related by rotational matrices?

    - by Alex Stone
    I'm looking at the core motion class CMAttitude, it can express the device's orientation as a 3x3 rotational matrix. At the same time I've taken a look at the CATransform3D, which encapsulates the view's attitude, as well as scaling. The CATransform3D is a 4x4 matrix. I've seen that the OpenGL rotational matrix is 4x4 and is simply 0001 padded in the 4th row and column. I'm wandering if the CMAttitude's rotational matrix is related to CATransform's matrix? Can I use the device's rotation in space obtained via a rotational matrix to transform a UIView using CATransform3D? My intention is to let the user move the phone and apply the same transform to a UIView on the screen. Bonus question: if they are related, how do I transform a CMAttitude's rotational matrix to CATransform3D?

    Read the article

  • New CATransform3DMakeRotation deletes old transformation?!

    - by david
    I added a CATransform3DMakeRotation to a layer. When I add another one it deletes the old one? The first one: [UIView beginAnimations:@"rotaty" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14); kuvert.transform = CGAffineTransformRotate(transform, DegreesToRadians(134)); kuvert.center = CGPointMake(kuvert.center.x-70, kuvert.center.y+100); [UIView commitAnimations]; and the second one: CABasicAnimation *topAnim = [CABasicAnimation animationWithKeyPath:@"transform"]; topAnim.duration=1; topAnim.repeatCount=0; topAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0, 0, 0)]; float f = DegreesToRadians(180); // -M_PI/1; topAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(f, 0,1, 0)]; topAnim.delegate = self; topAnim.removedOnCompletion = NO; topAnim.fillMode = kCAFillModeBoth; [topAnim setValue:@"flippy" forKey:@"AnimationName"]; [[KuvertLasche layer] addAnimation:topAnim forKey:@"flippy"]; The second one resets the view and applies itself after that. How do I fix this??

    Read the article

  • Maintaining last stage when rotating through CATransform3DIdentity

    - by Mikhail Naimy
    Hi. i am rotating imageview through following code.it rotates fine..but when i rotate again , Imageview goes to previous angle( which is in initial stage) and then it rotates...any one can help in this?rotationTransform has been declared as CABasicAnimation* rotationAnimation in .h file.... - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *touch = [touches anyObject]; startTouchPosition = [touch locationInView:self.view]; } - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *touch = [[event allTouches] anyObject]; location = [touch locationInView:self.view]; currentLocationRadians = atan2f(location.y - self.view.frame.size.height/2, location.x - self.view.frame.size.width/2); lastLocationRadians = atan2f(startTouchPosition.y - self.view.frame.size.height/2, startTouchPosition.x - self.view.frame.size.width/2); rotationTransform = CATransform3DIdentity; rotationTransform = CATransform3DRotate(rotationTransform, currentLocationRadians-lastLocationRadians + rad, 0.0, 0.0, 1.0); _imgview.layer.transform = rotationTransform; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { rotationTransform = _imgview.layer.transform; }

    Read the article

  • CATransaction: Layer Changes But Does Not Animate

    - by macinjosh
    I'm trying to animate part of UI in an iPad app when the user taps a button. I have this code in my action method. It works in the sense that the UI changes how I expect but it does not animate the changes. It simply immediately changes. I must be missing something: - (IBAction)someAction:(id)sender { UIViewController *aViewController = <# Get an existing UIViewController #>; UIView *viewToAnimate = aViewController.view; CALayer *layerToAnimate = viewToAnimate.layer; [CATransaction begin]; [CATransaction setAnimationDuration:1.0f]; CATransform3D rotateTransform = CATransform3DMakeRotation(0.3, 0, 0, 1); CATransform3D scaleTransform = CATransform3DMakeScale(0.10, 0.10, 0.10); CATransform3D positionTransform = CATransform3DMakeTranslation(24, 423, 0); CATransform3D combinedTransform = CATransform3DConcat(rotateTransform, scaleTransform); combinedTransform = CATransform3DConcat(combinedTransform, positionTransform); layerToAnimate.transform = combinedTransform; [CATransaction commit]; // rest of method... } I've tried simplifying the animation to just change the opacity (for example) and it still will not animate. The opacity just changes instantly. That leads me to believe something is not setup properly. Any clues would be helpful!

    Read the article

  • How to cast C struct just another struct type if their memory size are equal?

    - by Eonil
    I have 2 matrix structs means equal data but have different form like these: // Matrix type 1. typedef float Scalar; typedef struct { Scalar e[4]; } Vector; typedef struct { Vector e[4]; } Matrix; // Matrix type 2 (you may know this if you're iPhone developer) struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; typedef struct CATransform3D CATransform3D; Their memory size are equal. So I believe there is a way to convert these types without any pointer operations or copy like this: // Implemented from external lib. CATransform3D CATransform3DMakeScale (CGFloat sx, CGFloat sy, CGFloat sz); Matrix m = (Matrix)CATransform3DMakeScale ( 1, 2, 3 ); Is this possible? Currently compiler prints an "error: conversion to non-scalar type requested" message.

    Read the article

  • iphone - why is this flip animation using layers not working?

    - by Digital Robot
    I would like to make an animation that goes like this: imagine a picture sitting on a shelve. It drops from the shelve and as it falls it rotates along the horizontal axis and translates along the vertical axis. I would like to do this with perspective and the back side should be the image reversed, like the picture is a kind of slide. I have done this: CALayer* layer = myImageView.layer; layer.doubleSided = YES; CAKeyframeAnimation* animationTransform = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; CATransform3D startTransform = CATransform3DIdentity; CATransform3D endTransform = CATransform3DTranslate (layer.transform, 0.0f, 200.0f, 0.0f); endTransform = CATransform3DRotate (endTransform, degreesToRadian(350.0f), 1.0f, 0.0f, 0.0f); endTransform.m34 = 1.0 / -500; NSArray *values = [NSArray arrayWithObjects: [NSValue valueWithCATransform3D:startTransform], [NSValue valueWithCATransform3D:endTransform], nil]; [animationTransform setValues:values]; NSArray *tempos = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.7f], nil]; [animationTransform setKeyTimes:tempos]; NSArray *timing = [NSArray arrayWithObjects: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], nil]; [animationTransform setTimingFunctions:timing]; animationTransform.fillMode = kCAFillModeRemoved; animationTransform.removedOnCompletion = YES; animationTransform.repeatCount = 1; animationTransform.duration = 3.7f; animationTransform.cumulative = YES; the result of this has nothing to do with anything. The result is: the image translates down an inch on the screen and then up half inch. Then it disappears and appears at its starting position again. What am I missing? thanks

    Read the article

  • UIView animation problem

    - by FoJjen
    I try to make a UIImageView open like a hatch, and under the "hatchView" its anoter imageView but when I start the animation its like the view under gets over and cover the animation, When the animation gets over the imageView the its getting visibel. its works fine if a remove the imageView thats under. Here is the code for animation view. - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *) event { if (!isHatchOpen) { if (hatchView.layer.anchorPoint.x != 0.0f) { hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f); hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y); } UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:hatchView]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationBeginsFromCurrentState:YES]; float pct = location.x / 320.0f; float rad = acosf(pct); CATransform3D transform = CATransform3DMakeRotation(-rad+5, 0.0f, -1.0f, 0.0f); transform.m14 = (1.0 / -2000) * acosf(pct); hatchView.layer.transform = transform; [UIView commitAnimations]; isHatchOpen = YES; } else { if (hatchView.layer.anchorPoint.x != 0.0f) { hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f); hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y); } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationBeginsFromCurrentState:YES]; CATransform3D transform = CATransform3DMakeRotation(0, 0.0f, -1.0f, 0.0f); transform.m14 = 0; hatchView.layer.transform = transform; // Commit the changes [UIView commitAnimations]; isHatchOpen = NO; } } And here a add the Views hatchView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, frame.size.width-1, frame.size.height-2)]; [self addSubview:hatchView]; imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, frame.size.width-2, frame.size.height-2)]; imageView.contentMode = UIViewContentModeScaleAspectFit; [self insertSubview:imageView belowSubview:hatchView];

    Read the article

  • Rotate rectangle around center

    - by ESoft
    I am playing with Brad Larsen's adaption of the trackball app. I have two views at a 60 degree angle to each other and was wondering how I get the rotation to be in the center of this (non-closed) rectangle? In the images below I would have liked the rotation to take place all within the blue lines. Code (modified to only rotate around x axis): #import "MyView.h" //===================================================== // Defines //===================================================== #define DEGREES_TO_RADIANS(degrees) \ (degrees * (M_PI / 180.0f)) //===================================================== // Public Interface //===================================================== @implementation MyView - (void)awakeFromNib { transformed = [CALayer layer]; transformed.anchorPoint = CGPointMake(0.5f, 0.5f); transformed.frame = self.bounds; [self.layer addSublayer:transformed]; CALayer *imageLayer = [CALayer layer]; imageLayer.frame = CGRectMake(10.0f, 4.0f, self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f); imageLayer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(60.0f), 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)[[UIImage imageNamed:@"IMG_0051.png"] CGImage]; imageLayer.borderColor = [UIColor yellowColor].CGColor; imageLayer.borderWidth = 2.0f; [transformed addSublayer:imageLayer]; imageLayer = [CALayer layer]; imageLayer.frame = CGRectMake(10.0f, 120.0f, self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f); imageLayer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(-60.0f), 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)[[UIImage imageNamed:@"IMG_0089.png"] CGImage]; imageLayer.borderColor = [UIColor greenColor].CGColor; imageLayer.borderWidth = 2.0f; transformed.borderColor = [UIColor whiteColor].CGColor; transformed.borderWidth = 2.0f; [transformed addSublayer:imageLayer]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height / 2.0f, self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor redColor]]; [self addSubview:line]; line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height * (1.0f / 4.0f), self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor blueColor]]; [self addSubview:line]; line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height * (3.0f / 4.0f), self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor blueColor]]; [self addSubview:line]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { previousLocation = [[touches anyObject] locationInView:self]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint location = [[touches anyObject] locationInView:self]; //location = CGPointMake(previousLocation.x, location.y); CATransform3D currentTransform = transformed.sublayerTransform; //CGFloat displacementInX = location.x - previousLocation.x; CGFloat displacementInX = previousLocation.x - location.x; CGFloat displacementInY = previousLocation.y - location.y; CGFloat totalRotation = sqrt((displacementInX * displacementInX) + (displacementInY * displacementInY)); CGFloat angle = DEGREES_TO_RADIANS(totalRotation); CGFloat x = ((displacementInX / totalRotation) * currentTransform.m12 + (displacementInY/totalRotation) * currentTransform.m11); CATransform3D rotationalTransform = CATransform3DRotate(currentTransform, angle, x, 0, 0); previousLocation = location; transformed.sublayerTransform = rotationalTransform; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Missing z-axis rotation for transforming between two vectors

    - by Steve Baughman
    I'm trying to rotate a cube so that it's facing up, but am getting hung up on the final implementation details. It now reliably will rotate the x,y axis to the correct side, but the z-axis is never rotating (See photos of before and after rotation). When I'm using the code below I always get '0' for my rotationVector.z. What am I missing here? // Define lookAt vector lookAtVector = GLKVector3Make(0,0,1); // Define axes vectors axes[0] = GLKVector3Make(0,0,1); axes[1] = GLKVector3Make(-1,0,0); axes[2] = GLKVector3Make(0,1,0); axes[3] = GLKVector3Make(1,0,0); axes[4] = GLKVector3Make(0,-1,0); axes[5] = GLKVector3Make(0,0,-1); CGFloat highest_dot = -1.0; GLKVector3 closest_axis; for(int i = 0; i < 6; i++) { // multiply cube's axes by existing matrix GLKVector3 axis = GLKMatrix4MultiplyVector3(matrix, axes[i]); CGFloat dot = GLKVector3DotProduct(axis, lookAtVector); if(dot > highest_dot) { closest_axis = axis; highest_dot = dot; } } GLKVector3 rotationVector = GLKVector3CrossProduct(closest_axis, lookAtVector); // Get angle between vectors CGFloat angle = atan2(GLKVector3Length(rotationVector), GLKVector3DotProduct(closest_axis, lookAtVector)); // normalize the rotation vector rotationVector = GLKVector3Normalize(rotationVector); // Create transform CATransform3D rotationTransform = CATransform3DMakeRotation(angle, rotationVector.x, rotationVector.y, rotationVector.z); // add rotation transform to existing transformation baseTransform = CATransform3DConcat(baseTransform, rotationTransform); return baseTransform; Before 3d Rotation After 3d Rotation Implementation based on this post

    Read the article

  • rotating circle with swipe question

    - by Joe
    Okay so I'm making something that basically works as a knob, but only half on the screen -- so I just need horizontal swipes to cause it to rotate. I have it nearly all sorted with one exception: if you change direction of your swipe in mid-swipe, the rotation doesn't change direction. I even can see the problem, but not sure what to do about a solution. So in my touchesMoved, I get the swipe into radians in the predictable way: CGFloat radians = atan2f(location.y - centerY, location.x - centerX); I then store radians, add/subtract it to previous rotation and then give the result to the CATransform3D. So the prob is that even though the swipe changes direction, there is a "balance" which doesn't allow an immediate change of direction. Does this make any sense?

    Read the article

  • CALayer Sublayers Flipping

    - by user128647
    Hello All, How to Flip CALayer Sublayer. i have tried : CGFloat timeOffset = 0; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; CATransform3D transform = CATransform3DMakeRotation(M_PI/2, 0, 1, 0); animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; animation.toValue = [NSValue valueWithCATransform3D:transform]; animation.duration = 0.2; animation.beginTime = CACurrentMediaTime() + timeOffset; animation.fillMode = kCAFillModeBoth; animation.removedOnCompletion = NO; [selectedLayer addAnimation:animation forKey:nil]; timeOffset += 0.1; in this code selected layer is not flipping properly, Give me some suggestions. Thank you

    Read the article

  • MonoTouch- 'curated' bindings?

    - by Glinkot
    I'm just converting a video player sample to MT and came to this part: self.view.layer.sublayerTransform = CATransform3DMakePerspective(1000); In Monotouch, I've started with: this.View.Layer.SublayerTransform(CATransform3D.... But no perspective option is available. There is a 'scale' and 'rotate' one - does this mean this functionality is unavailable in MT? Or that I need to start creating my own bindings even though this one has been processed by the binding creation tool Xamarin uses? If anyone could advise how I would apply that transform I'd appreciate it. Cheers

    Read the article

  • iPhone - is it IMPOSSIBLE to grab the contents of a CALayers composition?

    - by Mike
    I have a CALayer transformed in 3D on a offscreen UIView (much larger than 320x480). How do I dump what is seen on this UIView to a UIImage? NOTE: I Have edited the question to include this code... This is how I create the layer... CGRect area = CGRectMake (0,0,400,600]; vista3D = [[UIView alloc] initWithFrame:area ]; [self.view addSubview:vista3D]; [vista3D release]; transformed = [CALayer layer]; transformed.frame = area; [vista3D.layer addSublayer:transformed]; CALayer *imageLayer = [CALayer layer]; imageLayer.doubleSided = YES; imageLayer.frame = area; imageLayer.transform = CATransform3DMakeRotation(40 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)myRawImage.CGImage; [transformed addSublayer:imageLayer]; // Add a perspective effect CATransform3D initialTransform = transformed.sublayerTransform; initialTransform.m34 = 1.0 / -500; transformed.sublayerTransform = initialTransform; // now the layer is in perspective // my next step is to "flatten" the composition into a UIImage UIImage *thisIsTheResult = some magic command thanks for any help! EDIT 1: I have tried jessecurry solution but it gives me a flat layer without any perspective. EDIT 2: I discovered a partial solution for this that works, but this solution gives me an image the size of the screen and I was looking for obtaining a higher resolution version, rendering off screen.

    Read the article

  • How do I stack images to simulate depth using Core Animation?

    - by Jeffrey Berthiaume
    I have a series of UIImages with which I need to simulate depth. I can't use scaling because I need to be able to rotate the parent view, and the images should look like they're stacked visibly in front of each other, not on the same plane. I made a new ViewController-based project and put this in the viewDidLoad (as well as attached three 120x120 pixel images named 1.png, 2.png, and 3.png): - (void)viewDidLoad { // display image 3 UIImageView *three = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3.png"]]; three.center = CGPointMake(160 + 60, 240 - 60); [self.view addSubview:three]; // rotate image 3 around the z axis // THIS IS INCORRECT CATransform3D theTransform = three.layer.transform; theTransform.m34 = 1.0 / -1000; three.layer.transform = theTransform; // display image 2 UIImageView *two = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]]; two.center = CGPointMake(160, 240); [self.view addSubview:two]; // display image 1 UIImageView *one = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]]; one.center = CGPointMake(160 - 60, 240 + 60); [self.view addSubview:one]; // rotate image 3 around the z axis // THIS IS INCORRECT theTransform = one.layer.transform; theTransform.m34 = 1.0 / 1000; one.layer.transform = theTransform; // release the images [one release]; [two release]; [three release]; // rotate the parent view around the y axis theTransform = self.view.layer.transform; theTransform.m14 = 1.0 / -500; self.view.layer.transform = theTransform; [super viewDidLoad]; } I have very specific reasons why I'm not using an EAGLView and why I'm not loading the images as CALayers (i.e. why I'm using UIImageViews for each one). This is just a quick demo that I can use to work out exactly what I need in my parent application. Is there some matrix way to translate these 2d images along the z-axis so they will look like what I'm trying to represent? I've gone through the other StackOverflow articles as well as the Wikipedia references, and have not found what I'm looking for -- although I might not necessarily be using the right terms for what I'm trying to do.

    Read the article

1