NVisionXR_iOS教程七 —— 情境中物體運動

來源:互聯網
上載者:User

標籤:NVisionXR   iOS   Android   Vuforia   ARKit   

本章節教大家如何讓立方體按照自己想要的軌跡運動。 
添加標頭檔#import''NVAnimationEffect.h'',在onCreate方法中執行個體該動畫類,代碼如: 
1、立方體移動 
 
代碼: 
 

   /**      * 構建一個NVAnimationEffect對象      * name 可以隨便取,但是要唯一      * context 傳入情境即可      * widget 作用的NVWidget對象,本例傳入的是立方體      * duration 運動的總時間長度      */     NVAnimationEffect *move = [[NVAnimationEffect alloc] initWithAnimation:@"moveAni" Context:self Widget:cube Duration:4.0];          // 設定主要畫面格     // 在4秒內從(0,0,0)的位置線形的移動到(0,10,0)的位置     [move createKeyFrameWithTimePos:0 Pos:NVPosition(0.0, 0.0, 0.0) Type:TRANSLATE];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(0.0, 10.0, 0.0) Type:TRANSLATE];         // 是否迴圈播放動畫     [move setLoop:YES];        // 將動畫對象添加到情境中     [self addAnimEffect:move];       // 開始執行運動     [move start];



2、立方體邊移動邊縮放 
 
代碼: 
  

 // 設定主要畫面格     // 在4秒內從(0,0,0)的位置線形的移動到(0,10,0)的位置     [move createKeyFrameWithTimePos:0 Pos:NVPosition(0.0, 0.0, 0.0) Type:TRANSLATE];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(0.0, 10.0, 0.0) Type:TRANSLATE];          // 新開一個運動軌道,在4秒內從1倍放大到5倍     [move createKeyFrameWithTimePos:0 Pos:NVPosition(1.0, 1.0, 1.0) Type:SCALE];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(5.0, 5.0, 5.0) Type:SCALE];



3、立方體邊移動邊縮放邊自旋轉 
 
代碼: 
    

// 設定主要畫面格     // 在4秒內從(0,0,0)的位置線形的移動到(0,10,0)的位置     [move createKeyFrameWithTimePos:0 Pos:NVPosition(0.0, 0.0, 0.0) Type:TRANSLATE];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(0.0, 10.0, 0.0) Type:TRANSLATE];          // 新開一個運動軌道,在4秒內從1倍放大到5倍     [move createKeyFrameWithTimePos:0 Pos:NVPosition(1.0, 1.0, 1.0) Type:SCALE];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(5.0, 5.0, 5.0) Type:SCALE];          // 新開一個運動軌道,在4秒內繞z軸旋轉360度     [move createKeyFrameWithTimePos:0 Pos:NVPosition(0.0, 0.0, 0.0) Type:ROTATION];     [move createKeyFrameWithTimePos:4 Pos:NVPosition(0.0, 0.0, 360.0) Type:ROTATION];


   
4、貝茲路徑 
添加標頭檔#import''NVBezierPath.h'', 在onCreate方法中執行個體該軌跡類,代碼 
 
代碼: 
 

 /**      * startPoint 軌跡的起始點      * controlPoint1 控制點1      * controlPoint2 控制點2      * startPoint 軌跡的結束點      **/     NVVector3f startPoint = NVPosition(10.0, 0, 5.5);     NVVector3f controlPoint1 = NVPosition(6.0, 0, 3.5);     NVVector3f controlPoint2 = NVPosition(8.0, 0, 4.5);     NVVector3f endPoint = NVPosition(10.0, 0, 0.0);     // 執行個體話貝茲路徑對象     mMainPath = [[NVBezierPath alloc] initWithBezier:mContext Name:@"BezierPath"];     // 設定曲線的精細程度     [mMainPath setSubdivision:mSubdivision];     // 設定貝塞爾軌跡起始點     [mMainPath setPoints:startPoint EndPoint:endPoint];     // 設定控制點     [mMainPath setControlPoints:controlPoint1 Point2:controlPoint2];     // 描邊繪製     [mMainPath stroke];    // 執行個體話動畫對象     NVAnimationEffect *move = [[NVAnimationEffect alloc] initWithAnimation:@"moveAni" Context:self Widget:cube Duration:4.0];     // 將貝茲路徑設定到動畫中     [move selectPath:mMainPath Type:TRANSLATE];     // 是否迴圈播放動畫     [move setLoop:YES];          // 將動畫對象添加到情境中     [self addAnimEffect:move];          // 開始執行運動     [move start];



運行項目,可以看到立方體按照自己設定的軌跡運動起來了。 

歡迎聯絡:

  • 連絡方式: +86 18801341080

  • 電子郵箱: [email protected]

  • 網址:http://www.nvisionxr.com/

  • QQ群:416802300


NVisionXR_iOS教程七 —— 情境中物體運動

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.