SceneKit自學之路(3)

第三個Demo,專門研究了SCNCamera

這個實例就是把SCNCamera的各個屬性列出來,通過值變化觀察實際作用。

Demo不細講了,主要紀錄一下測試結果。


SCNCamera

SCNKit的坐標系如下圖,X軸左負右正,Y軸下負上正,Z軸前負后正。


圖片來自:http://blog.csdn.net/pzhtpf/article/details/50313933

默認情況下,SCNCamera總是沿著節點的坐標系(0,0,0)像-z軸方向觀看。
所以說默認情況下,我們看不到物件,因為我們在物件的里面。

我們可以使用postioneulerAnglesscalerotationtransform等來調整觀看的角度和形狀。可以通過zFarzNear等來調整觀看的范圍。

Position
/*! 
 @property position
 @abstract Determines the receiver's position. Animatable.
 */
@property(nonatomic) SCNVector3 position;

決定了接收機的位置。


Position

SCNVector3 是一個三維坐標系,分為x,y,z。默認是在原點(0,0,0)。

當x<0時,表示相機在水平位置往左移了,看到飛船就會在右邊。是左側視角。
y<0時,相機往下移動,飛船出現在上面。是仰視視角。
z<0時,相機向前移動,飛船出現在后方面。是遠視視角。
所以,如果想讓飛船出現在視野中,只需要設置z>0即可。具體值需要根據飛船的大小和需要觀測的距離決定。z要大于物件,z軸方向z越大,就離得越遠,觀察到的就越小。

Euler Angles
/*!
 @property eulerAngles
 @abstract Determines the receiver's euler angles. Animatable.
 @dicussion The order of components in this vector matches the axes of rotation:
               1. Pitch (the x component) is the rotation about the node's x-axis (in radians)
               2. Yaw   (the y component) is the rotation about the node's y-axis (in radians)
               3. Roll  (the z component) is the rotation about the node's z-axis (in radians)
            SceneKit applies these rotations in the reverse order of the components:
               1. first roll
               2. then yaw
               3. then pitch
 */
@property(nonatomic) SCNVector3 eulerAngles API_AVAILABLE(macos(10.10));

歐拉角,注釋看得有點暈。看Demo

Euler Angles

也是一個三維坐標系,默認(0,0,0)。
繞三個軸的旋轉值pitch,yaw,roll,意思為俯仰角,偏航角,翻滾角,
當x<0時,飛船往上飛了。反之x>0,飛船往下。
當y<0時,飛船往左。同理y>0,飛船往右。
當z<0時,飛船逆時針翻滾。x>0,飛船順時針翻滾。
需要注意的是,這個只是觀察角度,實際上物件位置并沒有變化。

Scale
/*! 
 @property scale
 @abstract Determines the receiver's scale. Animatable.
 */
@property(nonatomic) SCNVector3 scale;

物件縮放比。


Scale

同樣是三維坐標系,默認(1,1,1)。
當x>0時,物件在x軸的長度會隨x增加而變小。當x==1時為原始大小。
當x<0時,物件在x軸的長度會隨x減小而變小。當x==-1時為原始大小。此時物件顯示為背面。這個為什么會顯示成背面我暫時沒有理解。所有的點都乘以一個負數,說明在負坐標系的空間。不過平常使用過程中應該也不會出現x<0的情況。

y軸和z軸同理對應,物件在y軸和z軸的變化。

Z Far
/*! 
 @property zFar
 @abstract Determines the receiver's far value. Animatable.
 @discussion The far value determines the maximal distance between the camera and a visible surface. If a surface is further from the camera than this maximal distance, then the surface is clipped. Defaults to 100.
 */
@property(nonatomic) double zFar;

決定相機和可見表面之間的最大距離。如果一個物體的表面比這個最大的距離更遠,那么它的表面就會被剪掉。默認為100。


zFar
Z Near
/*! 
 @property zNear
 @abstract Determines the receiver's near value. Animatable.
 @discussion The near value determines the minimal distance between the camera and a visible surface. If a surface is closer to the camera than this minimal distance, then the surface is clipped. The near value must be different than zero. Defaults to 1.
 */
@property(nonatomic) double zNear;

決定了相機和可見表面之間的最小距離。如果一個表面離攝像機比這個最小距離更近,那么表面就會被剪掉。接近的值必須與零不同。默認為1。


zNear
Rotation
/*! 
 @property rotation
 @abstract Determines the receiver's rotation. Animatable.
 @discussion The rotation is axis angle rotation. The three first components are the axis, the fourth one is the rotation (in radian).
 */
@property(nonatomic) SCNVector4 rotation;

軸角旋轉,和以上的幾個不同,它除了x、y、z軸的旋轉之外。多了一個弧度旋轉,w。默認值(0,0,0,0)

這個實在觀察不出來有什么用。以后再補充。


先記錄常用的幾個屬性。其他的以后用到再回來補充吧。


不再補充了,其實我們可以在SceneKit Scene File里可視化得更加直觀得觀察各個屬性。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容