Create a ball

Source: Internet
Author: 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 F Or 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 (vertex t 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/>; // end for seg <B R/>}// 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); <br/>}< br/>}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.