Scenekit do a spin on the Earth effect

Source: Internet
Author: User

Scenekit can use a few electrician you to complete a lot of OpenGL complex 3D Setup code, below this cat will take you to complete a rotating 3D earth scene.

First you need a picture of the Earth's surface and import it into Xcode:

We use the Scenekit built-in geometry sphere class to create an instance of the ball and apply the image of the Earth's surface to the surface of the ball:

let globe = scnsphere (radius: 15.0 ) Let Globenode = Scnnode (geometry:globe) globenode.position  = SCNVector3 (x : 20 , y : 40 , z :-50 ) globenode< Span class= "Hljs-preprocessor" >.geometry ? .firstmaterial ? .diffuse  .contents  = UIImage (named:  "earthdiffuse.jpg" ) Globenode.geometry ? .firstmaterial ? .diffuse  .mipfilter  =  

We then use the animation provided by coreanimation to rotate the sphere around its Y axis:

Let rotation = cabasicanimation (keypath:"Rotation") rotation. Fromvalue= Nsvalue (Scnvector4:scnvector4 (x:0,y:0,Z:0W:0)) rotation. Tovalue= Nsvalue (Scnvector4:scnvector4 (x:0,y:1,Z:0, W:float (m_pi*2.0)) rotation. Duration=TenRotation. RepeatCount=. InfinityGlobenode. Addanimation(Rotation, Forkey:"Rotation")

To add some funny, we move the ball up and down at the same time as it rotates, and it keeps getting bigger and smaller, which can be done using Coreanimation's Scnaction class:

Let Moveglobeup = Scnaction. Movebyx(0.0,y:10.0,Z:0.0, Duration:1.0) Let Moveglobedown = Scnaction. Movebyx(0.0,y: -10.0,Z:0.0, Duration:1.0) Let seq = scnaction. Sequence([Moveglobeup,moveglobedown]) Let Repeatseq = Scnaction. Repeatactionforever(seq) Globenode. Runaction(REPEATSEQ) Let scaleup = Scnaction. Scaleto(5.0, Duration:5.0) Let Scaledown = Scnaction. Scaleto(0.5, Duration:5.0) Let REPEATSEQ2 = Scnaction. Repeatactionforever(scnaction. Sequence([Scaledown,scaleup])) Globenode. Runaction(REPEATSEQ2)

This can be seen, cocoa about the animation of things are interlinked, in View,layer learning animation effect, it is easy to get 3D to use, very convenient, so that the cost of re-learning is very low.

Run the app, the effect is as follows (the dynamic diagram is a bit large, load please wait a moment):

You can see in the game scene not only completed the animation of the node, but also increased the effect of the ambient and transmitted light, the original need to use complex OpenGL to complete things, and now basically effortless;]

Scenekit do a spin on the Earth effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.