PDA

View Full Version : basic animation (moving an object)




liptonlover
Jul 1, 2008, 10:04 AM
I'm working on learning core animation right now, though it's hard since everything I find is complicated demonstrations and not tutorials. Anyways, I'm doing well enough, but I want to know how to move an object on all three axis. I can't figure out AT ALL how to move an object of any sort in any direction. Help? And while you're at it if you know of any core animation tutorials other than apple documentation that would be great. Thanks!



Cromulent
Jul 1, 2008, 10:22 AM
I'm working on learning core animation right now, though it's hard since everything I find is complicated demonstrations and not tutorials. Anyways, I'm doing well enough, but I want to know how to move an object on all three axis. I can't figure out AT ALL how to move an object of any sort in any direction. Help? And while you're at it if you know of any core animation tutorials other than apple documentation that would be great. Thanks!

Your probably looking in the wrong places. This is more of a maths question rather than a programming question. What have you tried?

Edit : Here you go:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html

All you need.

Edit 2 : And this is the specific page which deals with exactly what you are looking for.

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html#//apple_ref/doc/uid/TP40006082

liptonlover
Jul 1, 2008, 10:31 AM
thanks!
And what I had found was CGPoint, but I have no clue how to use it so I googled it, and I still couldn't find anything helpful. Thanks again!

Cromulent
Jul 1, 2008, 10:38 AM
thanks!
And what I had found was CGPoint, but I have no clue how to use it so I googled it, and I still couldn't find anything helpful. Thanks again!

A CGPoint is just a struct holding two CGFloats for the x and y axis coordinates.

Edit : http://developer.apple.com/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/doc/c_ref/CGPoint

It was the second thing on the list when I Googled CGPoint.

liptonlover
Jul 1, 2008, 11:51 AM
ok that brings me to hopefully my final question. How do I set up a new "instance" of a struct and use it? I don't have much experience with structs, all I did was read about how to use them. I know what they do and all that and I can use one in plain C but not in concert with cocoa/obj-c.
Thanks again for your help and all these links!

lucasgladding
Jul 1, 2008, 12:54 PM
CGPoint point;
point.x = 100;
point.y = 100;


Structs work like integers or floats. They don't work like classes. Your best bet is to look at some of the drawing examples that ship with Xcode.

BTW: I responded to your post yesterday and included the link to the new Pragmatic Programmers book about Core Animation.

Best of luck

liptonlover
Jul 1, 2008, 01:23 PM
ok so the code you just posted will create a CGPoint called point, with x and y values both equaling 100 right?
Now how do I use those points? I can't find a function like [[layer animator]location:point];
or anything like that.
Finally, what about zlocation? Is that just a third field in the struct? Can I just do point.z=[];?

Cromulent
Jul 1, 2008, 02:24 PM
ok so the code you just posted will create a CGPoint called point, with x and y values both equaling 100 right?
Now how do I use those points? I can't find a function like [[layer animator]location:point];
or anything like that.
Finally, what about zlocation? Is that just a third field in the struct? Can I just do point.z=[];?

No, read the reference for CGPoint. It is for 2D only.

I posted the reference material that explained what you need to do. It is maths you need to do, so you need to translate the objects using the functions in one of the links I posted above.

liptonlover
Jul 1, 2008, 02:31 PM
Sorry forgot about the links you gave me. I gotta go now but I'll read through them tomorrow.

I'm kind of curious though... why is math involved in translating that CGPoint into movement of an object? I don't get why you said that at all... :confused:

Cromulent
Jul 1, 2008, 03:16 PM
I'm kind of curious though... why is math involved in translating that CGPoint into movement of an object? I don't get why you said that at all... :confused:

Because anything to do with 3D in programming is just trigonometry, matrices and vectors basically.

Yes, maths does have some uses - wish I had paid more attention in my school maths lessons now when I was younger but there you go, hindsight and all that.

liptonlover
Jul 1, 2008, 05:02 PM
I know programming involves loads of math usually, but don't forget core data is 2.5D not 3D :P and it certainly isn't involved in what I want to do right now.

Cromulent
Jul 1, 2008, 05:09 PM
I know programming involves loads of math usually, but don't forget core data is 2.5D not 3D :P and it certainly isn't involved in what I want to do right now.

Yes it is.

You want to move an object in simulated 3D space. That is a transformation.

Transformation (http://en.wikipedia.org/wiki/Transformation_%28geometry%29) = maths.

liptonlover
Jul 1, 2008, 05:23 PM
you're just full of links aren't you :D
Well now that I can stick around I'm going to read the appl doc before asking another question..... maybe. Questions are just such a nicer and easier way to learn for me :rolleyes: