日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

实现物体绕不同轴旋转,并可以外部调用的函数

發(fā)布時間:2024/9/21 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实现物体绕不同轴旋转,并可以外部调用的函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

第一個文件,聲明枚舉類型,分別為均勻變化和加速變化

1 2 3 4 5 6 7 8 using?UnityEngine; using?System.Collections; public?enum?CTRotationType { ????Uniform, ????AccelerateUniformly }

?

第二個文件:主函數(shù),實現(xiàn)圍繞軸變化的兩個函數(shù),分別為均勻變化和加速變化

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 using?UnityEngine; using?System.Collections; public?class?CTRotation : MonoBehaviour { ?// Use this for initialization ?void?Start () { ?? ?} ?? ?// Update is called once per frame ?void?Update () { ????????if?(isRotating) ????????{ ????????????executeRotate(); ????????} ????} ????bool?isRotating = false; ????Quaternion definedRotation = new?Quaternion(0, 0, 0,0); ?? ????Vector3 rotateVector = new?Vector3(1,0,0); ?? ????float?rotateVelocity = 0; ?? ?float?accelerateDuration = 0; ?float?leftDuration = 0; ?float?rotateDuration = 0; ?? ????int?rotateAxis = 0; ?float?angleRange = 0; ?float?deltaRotate = 0;//0; ?? ?? ?// acceleration when it is in the accelerating process. ????float?rotateAcceleration = 0; ????CTRotationType rotateType; ?? ?//int RotateType = 0; ????private?void?initRotateArgument( float?_initAngleRange, int?_initRotateAxis, float?_initRotateDuration) ????{ ??rotateAxis = _initRotateAxis; ????????rotateDuration = _initRotateDuration; ????????leftDuration = _initRotateDuration; ??angleRange = _initAngleRange; ??rotateType = CTRotationType.Uniform; ????} ????public?void?RotateTo(float?_angleRange, int?_axis, float?_duration) ????{ ??print("in the rotateto"); ????????isRotating = false; ????????rotateType = CTRotationType.Uniform; ??//RotateType = 0; ??? ??initRotateArgument(_angleRange, _axis, _duration); ??? ??switch(rotateAxis) ??{ ???case?0: //rotate around X axis ???{ ????rotateVector = Vector3.right; ????break; ???} ???case?1://rotate around Y axis ???{ ????rotateVector = Vector3.up; ????break; ???} ???case?2://rotate around Z axis ???{ ????rotateVector = Vector3.forward; ????break; ???} ???default: ????break; ??} ??? ??deltaRotate = angleRange/rotateDuration; ??? ????????isRotating = true; ????} ????public?void?RotateTo(float?_angleRange, int?_axis, float?_duration, float?_accelerateDuration) ????{ ????????isRotating = false; ????????rotateType = CTRotationType.AccelerateUniformly; ??//RotateType = 1; ??rotateAcceleration = 1/((rotateDuration - accelerateDuration)*accelerateDuration); ????????initRotateArgument(_angleRange, _axis, _duration); ??? ??switch(rotateAxis) ??{ ???case?0: //rotate around X axis ???{ ????rotateVector = Vector3.right; ????break; ???} ???case?1://rotate around Y axis ???{ ????rotateVector = Vector3.up; ????break; ???} ???case?2://rotate around Z axis ???{ ????rotateVector = Vector3.forward; ????break; ???} ???default: ????break; ??} ????????accelerateDuration = _accelerateDuration; ??? ?????//?? deltaRotate = angleRange/(_duration - _accelerateDuration*2); ????????isRotating = true; ????} ????void?executeRotate() ????{ ????????switch?(rotateType) ????????{ ????????????//case 0://CTMoveType.Uniform: ???case?CTRotationType.Uniform: ????????????????uniformRotate(); ????????????????break; ????????????//case 1://CTMoveType.AccelerateUniformly: ???case?CTRotationType.AccelerateUniformly: ????????????????accelerateRotate(); ????????????????break; ????????} ???????? ????????leftDuration -= Time.deltaTime; ???????/* if (leftDuration <= 0) ????????{ ????????????transform.position = targetPosition; ????????????isMoving = false; ????????}*/ ????} ????private?void?accelerateRotate() ????{ ??print(leftDuration); ????????if?(leftDuration > (rotateDuration - accelerateDuration)) ????????{ ???rotateVelocity = (float)((angleRange*(rotateDuration - leftDuration))*rotateAcceleration); ??????????//? transform.Rotate(rotateVelocity * Time.deltaTime*rotateVector, Space.World); ???transform.Rotate(rotateVelocity * rotateVector*Time.deltaTime, Space.World); ????????} ????????else?if?(leftDuration > accelerateDuration) ????????{ ???rotateVelocity = (float)((angleRange*accelerateDuration)*rotateAcceleration); ????????????transform.Rotate(rotateVelocity*rotateVector*Time.deltaTime, Space.World); ????????} ????????else?if?(leftDuration > 0) ????????{ ???rotateVelocity= (float)((angleRange*leftDuration)*rotateAcceleration); ???transform.Rotate(rotateVelocity*rotateVector*Time.deltaTime, Space.World); ????????} ??else ???isRotating = false; ????} ????private?void?uniformRotate() ????{ ??print(leftDuration); ??//if(leftDuration) ??if(leftDuration > 0) ??{ ???transform.Rotate(rotateVector*deltaRotate*Time.deltaTime, Space.World); ???//transform.Rotate(rotateVector * Time.deltaTime*deltaRotate, Space.World); ??} ??else ???isRotating = false; ????} }

?

第三個文件,測試腳本

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 using?UnityEngine; using?System.Collections; public?class?TestRotationScript : MonoBehaviour { ?// Use this for initialization ?void?Start () { ?? ?} ?? ?// Update is called once per frame ?void?Update () { ??????? ?} ?void?OnGUI () ????{ ??CTRotation ttscript; ??CTChangeAlpha colorScript; ??GameObject testObject = GameObject.Find("TestCube"); ????????//Component testObjectScript = testObject.GetComponent("CRotation"); ????????ttscript = (CTRotation)testObject.GetComponent("CTRotation"); ??colorScript = (CTChangeAlpha)testObject.GetComponent("CTChangeAlpha"); ??? ???if?(GUI.Button (new?Rect (20,40,80,20), "UniRotate")) { ???????ttscript.RotateTo(3600f, 2, 2f); ??} ??? ???if(GUI.Button(new?Rect(20,60,80,20),"AccRotate")){ ??ttscript.RotateTo(3600f, 2, 2f, 0.5f); ???} ??? ????if(GUI.Button(new?Rect(20,80,80,20),"Color")){ ?????colorScript.ColorTo(2,5.0f); ????} ????} }

其中:第一個和第二腳本賦給目標(biāo)物體;第三個腳本賦給任何一個物體作為測試物體使用

?

代碼目的是方便外部調(diào)用和函數(shù)重用;注意isRotating參數(shù)的使用

總結(jié)

以上是生活随笔為你收集整理的实现物体绕不同轴旋转,并可以外部调用的函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩欧美福利视频 | 久久久99精品国产一区二区三区 | 日本少妇高潮抽搐 | 奇米97 | av免费片 | 奇米综合 | 欧美一级录像 | 国产小视频在线观看 | 91中文字幕 | 久久久久国产精品夜夜夜夜夜 | 四虎影视网| av免费观看不卡 | 日本三区视频 | 特级西西人体wwwww | 日日cao| 97caop| a天堂亚洲| 亚洲图片自拍偷拍区 | 骑骑上司妻电影 | 一级久久久久久久 | 国产视频日本 | 久久国产这里只有精品 | 黄色免费看片 | 国产精品自拍第一页 | 亚洲国产一区二区在线 | 欧美韩一区 | 日韩色中色 | 97久久超碰| 偷拍亚洲另类 | 国产亚洲片| 日鲁鲁 | 亚洲一区美女 | av操操| 黄色不卡av | 日韩国产在线观看 | 韩国美女视频在线观看18 | 麻豆一区二区在线观看 | 国产乡下妇女三片 | 国产成a人亚洲精v品在线观看 | 国产精品一区免费 | 97人妻精品一区二区三区动漫 | 日本在线不卡一区 | 日本特黄一级 | 精产国品一二三产品蜜桃 | 久久天| 91插插插插插插插插 | 野花视频在线观看免费 | 三级国产视频 | 欧洲视频一区二区三区 | 琪琪色av | 久久久精品毛片 | 一区二区三区国产av | 激情久久久久 | 九七伦理电影 | 综合色吧| 欧美一区二区大片 | 中文字幕人妻一区二区三区在线视频 | 欧美丝袜视频 | 国产资源在线看 | 91中文字幕 | 欧美激情视频一区二区三区不卡 | 五月天av在线| 毛片视频免费播放 | 中文字幕第6页 | 亚洲第一综合网 | 91久久综合| 日本二三区 | 国产亚洲精品美女久久久 | 日韩喷潮 | 国产日韩精品久久 | 最近中文字幕一区二区 | 琪琪色在线视频 | 日本黄色免费看 | 日本黄色激情视频 | 免费av在线播放 | 中国 免费 av | 一本高清视频 | 99精品一区二区三区 | 你懂的网站在线 | 欧美成人免费观看 | 国产精品性 | 正在播放adn156松下纱荣子 | 日韩国产综合 | 秋霞国产午夜精品免费视频 | 九九热色 | 成人在线电影网站 | 久久久久九九九九 | 日韩欧美色图 | 一区二区三区视频免费在线观看 | 91视频久久久| 日韩毛片无码永久免费看 | 欧美日韩在线高清 | 国产熟女一区二区丰满 | 一区www| 围产精品久久久久久久 | 中文字幕在线免费观看 | www.蜜桃av.com | 天堂岛av | 欧美亚洲日本一区 |