Posted By

ZonjaCapalini on 07/21/09


Tagged

generator 10 for Klein V bottle Zonja Opensim


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


Klein bottle generator


Published in: Other 






URL: http://zonjacapalini.wordpress.com/2009/07/20/2889-working-with-very-large-linksets-in-opensim/

Expand | Embed | Plain Text
  1. // Time to sleep between rezzes -- avoids compile errors
  2. float sleep = 1;
  3. // Number of "slices"
  4. integer m = 120;
  5. // Number of "stripes"
  6. integer n = 8;
  7. // Name of the rezzed object (must exist in inv)
  8. string edgeprimname = "Cylinder";
  9.  
  10. // Rezz a segment between 2 given points, assign its color color
  11. // Mod of a routine found here:
  12. // http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBezierCurveDemo
  13. // Original credits follow:
  14. // Bezier Curve Demo 1.0.1
  15. // Catherine Omega Heavy Industries
  16. // Modified by Lionel Forager 29-12-2006:
  17. // Added segment drawing between points. Corrected minor bugs.
  18. drawLineSegment(vector base, vector p1,vector p2, integer order)
  19. {
  20. // Calc the position of the center of the segment
  21. vector center = (p1+p2)/2.;
  22. vector localZ = p2 - p1;
  23. // Get distance between points
  24. float distance= llVecMag(localZ);
  25. // Normalize the vector
  26. localZ = localZ / distance;
  27.  
  28. vector xAxis;
  29. // Let's choose as x local axis the direction of a vector normal
  30. // to localZ and contained in the plain given by localZ and global X
  31. // or global Y, the one that is less parallel to localZ
  32. if ( localZ.x < localZ.y ) xAxis= <1.,0.,0.>;
  33. else xAxis= <0.,1.,0.>;
  34.  
  35. // localX is the one contain in the plane given by localZ and xAxis
  36. // that is normal to localZ. That is, localX = xAxis - localZ*xaxis*localZ.
  37. // We should normalize the vector to get a unitary one.
  38. vector localX= xAxis - (localZ * xAxis) * localZ;
  39. localX= llVecNorm(localX);
  40.  
  41. // Now get the rotation to put axis Z oriented pointing
  42. // to the direction between the two given points.
  43. rotation rot = llAxes2Rot(localX,localZ % localX, localZ);
  44.  
  45. // Rezz the cylinder!
  46. llRezObject(edgeprimname,base + center,ZERO_VECTOR,rot,(integer) (distance*1000)*100+order);
  47.  
  48. // Avoid clogging the queue and subsequent compile problems
  49. llSleep(sleep);
  50. }
  51.  
  52.  
  53. default
  54. {
  55.  
  56. touch_start(integer total_number)
  57. {
  58.  
  59. llSay(0, "Generating Klein bottle...");
  60.  
  61. integer i;
  62. integer j;
  63. float a = 2;
  64. float b = 7;
  65. float c = 2;
  66. float r;
  67. float u;
  68. float v;
  69. float x;
  70. float y;
  71. float z;
  72. list oldcoor = [];
  73. list firstcoor = [];
  74. list coor = [];
  75. vector prevpos;
  76. rotation rot;
  77.  
  78. for (i = 0; i <= m; i++) {
  79. // llSay(0,"Looping I="+(string)i+" of "+(string)m);
  80.  
  81. for (j = 0; j < n; j++) {
  82. // llSay(0," Looping J="+(string)j+" of "+(string)n);
  83.  
  84. u = 2 * PI * i / m;
  85. v = 2 * PI * j / n;
  86.  
  87. if (n % 2 == 1) v += PI / n * i/m;
  88.  
  89. r = c * (1 - llCos(u) / 2);
  90.  
  91. // See PlanetMath,
  92. // http://planetmath.org/?op=getobj&from=objects&id=4249
  93.  
  94. if (u < PI) {
  95. x = a * llCos(u) * (1 + llSin(u)) + r * llCos(u) * llCos(v);
  96. y = b * llSin(u) + r * llSin(u) * llCos(v);
  97. } else {
  98. x = a * llCos(u) * (1 + llSin(u)) + r * llCos(v + PI);
  99. y = b * llSin(u);
  100. };
  101.  
  102. z = r * llSin(v);
  103.  
  104.  
  105. // draw "horizontal" lines
  106. if (j > 0) {
  107. prevpos = llList2Vector(coor,j-1);
  108. drawLineSegment(llGetPos(),prevpos,<x,y,z>,j);
  109. };
  110.  
  111. if (j == n-1) {
  112. prevpos = llList2Vector(coor,0);
  113. drawLineSegment(llGetPos(),prevpos,<x,y,z>,0);
  114. };
  115.  
  116.  
  117. // draw "vertical" and diagonal lines
  118. if (i > 0) {
  119.  
  120. prevpos = llList2Vector(oldcoor,j);
  121. drawLineSegment(llGetPos(),prevpos,<x,y,z>,j);
  122.  
  123. if (j > 0) prevpos = llList2Vector(oldcoor,j-1);
  124. else prevpos = llList2Vector(oldcoor,n-1);
  125. drawLineSegment(llGetPos(),prevpos,<x,y,z>,j);
  126.  
  127. };
  128.  
  129.  
  130. // if (i < m) llRezObject("Vertex", llGetPos() + <x,y,z>,
  131. // <0.0,0.0,0.0>, <0.0,0.0,0.0,1.0>, 0);
  132.  
  133. coor = coor + [<x,y,z>];
  134.  
  135. };
  136.  
  137. if (i == 0) firstcoor = coor;
  138. oldcoor = coor;
  139. coor = [];
  140.  
  141. };
  142. llSay(0, "Done!");
  143. }
  144. }

Report this snippet 

You need to login to post a comment.