建立一個球

來源:互聯網
上載者:User

void createSphere1(String strName, float r, int nRings, int nSegments) {<br />IManualObject manual = mSceneMgr.createManualObject(strName);<br />manual.begin("BaseWhiteNoLighting", OperationType.OT_TRIANGLE_LIST);<br />float fDeltaRingAngle = (float) (Math.PI / nRings);<br />float fDeltaSegAngle = (float) (2 * Math.PI / nSegments);<br />short wVerticeIndex = 0;<br />// Generate the group of rings for the sphere<br />for (int ring = 0; ring <= nRings; ring++) {<br />float r0 = (float) (r * Math.sin(ring * fDeltaRingAngle));<br />float y0 = (float) (r * Math.cos(ring * fDeltaRingAngle));<br />// Generate the group of segments for the current ring<br />for (int seg = 0; seg <= nSegments; seg++) {<br />float x0 = (float) (r0 * Math.sin(seg * fDeltaSegAngle));<br />float z0 = (float) (r0 * Math.cos(seg * fDeltaSegAngle));<br />// Add one vertex to the strip which makes up the sphere<br />manual.position(x0, y0, z0);<br />Vector3 temp = new Vector3(x0, y0, z0);<br />Vector3 vNormal = new Vector3();<br />temp.normalisedCopy(vNormal);<br />manual.normal(vNormal);<br />manual.textureCoord((float) seg / (float) nSegments,<br />(float) ring / (float) nRings);<br />if (ring != nRings) {<br />// each vertex (except the last) has six indicies pointing<br />// to it<br />manual.index(wVerticeIndex + nSegments + 1);<br />manual.index(wVerticeIndex);<br />manual.index(wVerticeIndex + nSegments);<br />manual.index(wVerticeIndex + nSegments + 1);<br />manual.index(wVerticeIndex + 1);<br />manual.index(wVerticeIndex);<br />wVerticeIndex++;<br />}<br />}<br />; // end for seg<br />} // end for ring<br />manual.end();<br />MeshPtr mesh = new MeshPtr();<br />manual.convertToMesh(mesh, strName,<br />ResourceGroupManager.getDEFAULT_RESOURCE_GROUP_NAME());<br />mesh.get()._setBounds(<br />new AxisAlignedBox(new Vector3(-r, -r, -r),<br />new Vector3(r, r, r)), false);<br />mesh.get()._setBoundingSphereRadius(r);<br />short src = 0, dest = 0;<br />if (!mesh.get().suggestTangentVectorBuildParams(<br />VertexElementSemantic.VES_TANGENT, new IntegerPointer(src),<br />new IntegerPointer(dest))) {<br />mesh.get().buildTangentVectors(VertexElementSemantic.VES_TANGENT,<br />src, dest, false, false, false);<br />}<br />}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.