《Unity虚拟现实技术及其应用》 课件 vector3-matrix-quaternion_第1页
《Unity虚拟现实技术及其应用》 课件 vector3-matrix-quaternion_第2页
《Unity虚拟现实技术及其应用》 课件 vector3-matrix-quaternion_第3页
《Unity虚拟现实技术及其应用》 课件 vector3-matrix-quaternion_第4页
《Unity虚拟现实技术及其应用》 课件 vector3-matrix-quaternion_第5页
已阅读5页,还剩42页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Unity的坐标系Unity采用左手坐标系Vector3Vector3类描述三维矢量和三维空间点,是三维运算中最基本的数学操作.Vector3v=newVector3(1.0f,1.0f,1.0f);print(v);Vector3的静态性质PropertiesVector3back=Vector3.back;//(0,0,-1)Vector3down=Vector3.down;//(0,-1,0)Vector3forward=Vector3.forward;//(0,0,1)Vector3left=Vector3.left;//(-1,0,0)Vector3one=Vector3.one;//(1,1,1)Vector3right=Vector3.right;//(1,0,0)Vector3up=Vector3.up;//(0,1,0)Vector3zero=Vector3.zero;//(0,0,0)Vector3的一般性质Properties获取矢量v的三个坐标分量:获取矢量v的长度:获取矢量v的单位矢量:Vector3的静态方法publicstaticfloatAngle(Vector3from,Vector3to);获取小于180度的夹角。publicstaticfloatSignedAngle(Vector3f,Vector3t,Vector3axis);获取夹角,该夹角可以大于180度。publicstaticVector3Cross(Vector3lhs,Vector3rhs);publicstaticfloatDot(Vector3lhs,Vector3rhs);Vector3a=newVector3(2,0,0);Vector3b=newVector3(0,2,0);floatx=Vector3.Dot(a,b);Vector3MoveTowards(Vector3current,Vector3target,floatmaxDistanceDelta);voidOrthoNormalize(refVector3normal,refVector3tangent);将矢量normal和tangent归一,同时将tangent方向垂直于normal。voidOrthoNormalize(refVector3normal,refVector3tangent,refVector3binormal);

Vector3

Project(Vector3

vector,

Vector3

onNormal);Projects

vector

ontovectoronNormal.Vector3ProjectOnPlane(Vector3vector,Vector3planeNormal);Projectsavectorontoaplanedefinedbyanormalorthogonaltotheplane.planeNormalVector3

Reflect(Vector3

inDirection,

Vector3

inNormal)Reflectsavectorofftheplanedefinedbyanormal.Vector3RotateTowards(Vector3current,Vector3

target,floatmaxRadiansDelta,floatmaxMagnitudeDelta);Rotatesavectorcurrenttowardstarget.staticVector3Scale(Vector3a,Vector3b);publicvoidScale(Vector3scale);Result=(a.x*b.x,a.y*b.y,a.z*b.z);

staticfloatSignedAngle(Vector3from,Vector3to,Vector3axis);Returnsthesignedangleindegreesbetweenfromandto.staticVector3Slerp(Vector3a,Vector3b,floatt);Sphericallyinterpolatesbetweentwovectors.Interpolatesbetweenaandbbyamountt.Vector3v1=newVector3(2.0f,1.0f,0.0f);Vector3v2=newVector3(-2.0f,1.0f,0.0f);for(inti=1;i<10;++i){Vector3v=Vector3.Slerp(v1,v2,0.1f*i);Debug.DrawLine(Vector3.zero,v,Color.yellow);}

staticVector3SlerpUnclamped(Vector3a,Vector3b,floatt);tcanbelessthanzeroorgreaterthanonestaticVector3SmoothDamp(Vector3current,Vector3target,refVector3currentVelocity,floatsmoothTime,floatmaxSpeed=Mathf.Infinity,floatdeltaTime=Time.deltaTime);Operatorsoperator-Subtractsonevectorfromanother.operator!=Returnstrueifvectorsdifferent.operator*Multipliesavectorbyanumber.operator/Dividesavectorbyanumber.operator+Addstwovectors.operator==Returnstrueiftwovectorsareapproximatelyequal.Vector2andVector4ScalingTransformsRotationTransformsHomogeneousCoordinatesA3DpointPisextendedtofourdimensionsbysettingitsfourthcoordinate,whichwecallthewcoordinate,equalto1.(x,y,z,w),w=1,Translationmatrix????Matrix4x4Atransformationmatrixcanperformarbitrarylinear3Dtransformations(i.e.translation,rotation,scale,shearetc.)andperspectivetransformationsusinghomogenouscoordinates.先平移,再旋Matrix4x4matrix=newMatrix4x4(newVector4(1,2,3,4),newVector4(5,6,7,8),newVector4(9,10,11,12),newVector4(13,14,15,16));Matrix4x4me=Matrix4x4.identity;Debug.Log(m0);Matrix4x4m0=Matrix4x4.zero;Debug.Log(m0);Matrix4x4matrix=newMatrix4x4(newVector4(1,2,3,4),newVector4(5,6,7,8),newVector4(9,10,11,12),newVector4(13,14,15,16));Matrix4x4mi=matrix.transpose;Debug.Log(matrix);Debug.Log(mi);Quaternionquat=matrix.rotation;Debug.Log(quat);Matrix4x4mt=matrix.inverse;Debug.Log(mt);PublicmethodsGetColumnGetacolumnofthematrix.GetRowReturnsarowofthematrix.MultiplyPointTransformsapositionbythismatrix(generic).MultiplyPoint3x4Transformsapositionbythismatrix(fast).MultiplyVectorTransformsadirectionbythismatrix.SetColumnSetsacolumnofthematrix.SetRowSetsarowofthematrix.SetTRSSetsthismatrixtoatranslation,rotationandscalingmatrix.ToStringReturnsanicelyformattedstringforthismatrix.TransformPlaneReturnsaplanethatistransformedinspace.ValidTRSChecksifthismatrixisavalidtransformmatrix.StaticMethodsFrustumThisfunctionreturnsaprojectionmatrixwithviewing.LookAtGivenasourcepoint,atargetpoint,andanupvector.OrthoCreatesanorthogonalprojectionmatrix.PerspectiveCreatesaperspectiveprojectionmatrix.RotateCreatesarotationmatrix.ScaleCreatesascalingmatrix.TranslateCreatesatranslationmatrix.TRSCreatesatranslation,rotationandscalingmatrix.StaticmethodsinMatrix4x4//旋转Matrix4x4mr=Matrix4x4.Rotate(newQuaternion(0.1f,0.2f,0.3f,1.0f));//缩放Matrix4x4ms=Matrix4x4.Scale(newVector3(0.1f,0.1f,0.1f));//平移Matrix4x4mt=Matrix4x4.Translate(newVector3(10f,0f,0f));Matrix4x4matrix=Matrix4x4.TRS(newVector3(1,0,0),Quaternion.identity,newVector3(1,1,1));Debug.Log(matrix);AttitudeandheadingNormalsituation,GimbalLockQuaternionsAquaternionisanalternativemathematicalentitythat3Dgraphicsprogrammersusetorepresentrotations.RotationswithQuaternionstheunitquaternionqcorrespondingtoarotationthroughtheangleθabouttheaxisAisgivenbyconvertaquaternionintotheequivalent3×3rotationmatrix:PropertieseulerAngles:Returnsorsetstheeulerangle.normalized:Returnsthisquaternionwithamagnitudeof1.this[int]:Accessthex,y,z,wcomponentsusing[0],[1],[2],[3].w: WcomponentoftheQuaternion.x: XcomponentoftheQuaternion.y: YcomponentoftheQuaternion.z: ZcomponentoftheQuaternion.publicVector3eulerAngles{get;set;}quaternion=newQuaternion(0.0f,0.0f,0.0f,1.0f);cube.transform.rotation=quaternion;Vector3angles=quaternion.eulerAngles;Quaternion的实例方法Set:Setx,y,zandwcomponentsofanexistingQuaternion.SetFromToRotation:CreatesarotationwhichrotatesfromfromDirectiontotoDirection.SetLookRotation:Createsarotationwiththespecifiedforwardandupwardsdirections.ToAngleAxis:Convertsarotationtoangle-axisrepresentation(anglesindegrees).ToString:ReturnsanicelyformattedstringoftheQuaternion.Quaternionq=Quaternion.identity;q.SetFromToRotation(v1,v2);transform.rotation=q;publicvoidSetLookRotation(Vector3view,Vector3up=Vector3.up);Quaternionquat=newQuaternion();quat.SetLookRotation(Vector3.down,Vector3.left);transform.rotation=quat;Angle:Returnstheangleindegreesbetweentworotationsaandb.AngleAxis:Createsarotationwhichrotatesangledegreesaroundaxis.Dot: Thedotproductbetweentworotations.Euler:Returnsarotationthatrotateszdegreesaroundthezaxis,xdegreesaroundthexaxis,andydegreesaroundtheyaxi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论