SHARE
TWEET

Untitled

a guest Dec 18th, 2011 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This is what's on the server side of things, as although you can view the source from most browsers, you can't exactly see the stuff that is changed by the PHP server.
  2.  
  3. The following is to be saved as a php file. You must have PHP and MySQL if you're going to be running this from your own server.
  4.  
  5. You also will need the libraries you see at the beginning of the first document if you're going to be using them yourself. They're freely available; google should be able to help.
  6.  
  7.  
  8.  
  9.  
  10. <html>
  11. <head>
  12.         <title>WebGL Test</title>
  13. </head>
  14. <body bgcolor=#000000>
  15. <?php echo 'Why hello there~'; ?>
  16.  
  17. <div id="container"></div>
  18.  
  19. <script type="text/javascript" src="Three.js"></script>
  20. <script type="text/javascript" src="RequestAnimationFrame.js"></script>
  21. <script type="text/javascript" src="Stats.js"></script>
  22. <script type="text/javascript" src="prototype.js"></script>
  23.  
  24. <div id="main-code">
  25.  
  26. <script type="text/javascript">
  27.  
  28. var container, stats;
  29. var camera, scene, renderer, controls, clock;
  30. var particles, material = [], group, i;
  31. var mouse = { x: 0, y: 0 };
  32. var keypress = 0;
  33. var keyhold = 0;
  34. var mousemove = 0;
  35. var currentlyPressedKeys = {};
  36. var me;
  37.  
  38. init();
  39. animate();
  40.  
  41. function init() {
  42.  
  43.         clock = new THREE.Clock()
  44.  
  45.         container = document.getElementById( 'container' );
  46.  
  47.         scene = new THREE.Scene();
  48.         scene.fog = new THREE.FogExp2( 0xffffff, 0.002 );
  49.  
  50.         camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 500 );
  51.         camera.position.z = 200;
  52.  
  53.         controls = new THREE.FirstPersonControls( camera );
  54.  
  55.         controls.movementSpeed = 70;
  56.         controls.lookSpeed = 0.05;
  57.         controls.noFly = false;
  58.         controls.lookVertical = true;
  59.  
  60.         me = Math.random();
  61.  
  62.         i = 0;
  63.        
  64.         var numMemories = 0;
  65.  
  66.         var memA = [], memB = [], memC = [], memInt = [];
  67.         // DO PHP HERE
  68.  
  69.  
  70.         <?php
  71.  
  72.                 $con = mysql_connect("localhost","root","mspl@l5ltOK");
  73.                 if (!$con) { die('Error Of Sadness'); }
  74.  
  75.                 mysql_select_db("memories", $con);
  76.  
  77.                 //echo 'numMemories = ';
  78.  
  79.                 //$sqlStuff = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM data;"));
  80.  
  81.                 //echo $sqlStuff[0];
  82.  
  83.                 $random_rows = mysql_query("SELECT * FROM data ORDER BY rand() LIMIT 20;");
  84.  
  85.                 $count = 0;
  86.  
  87.  
  88.                 while($row = mysql_fetch_array($random_rows)) {
  89.                         echo "memA[".$count."] = " . $row['mm'] . " % 30;\n" .
  90.                                 "memB[".$count."] = " . $row['mm'] . " % 100;\n" .
  91.                                 "memC[".$count."] = (" . $row['mm'] . " % 3000) / 1000.0;\n" .
  92.                                 "memInt[".$count."] = " . $row['mm'] . " % 100000;\n";
  93.  
  94.                         $count = $count + 1;
  95.                 }
  96.  
  97.                 echo "numMemories = " . $count . ";\n\n";
  98.                
  99.                 mysql_close($con);
  100.         ?>
  101.  
  102.  
  103.         var myCounter = 0;
  104.         while(numMemories > 0) {
  105.  
  106.  
  107.                 // MOVE THINGS
  108.  
  109.                 // ALSO MORE PHP
  110.                 var x = 0.1, y = 0.1, z = 0.1;
  111.                 var a = memA[myCounter];
  112.                 var b = memB[myCounter];
  113.                 var c = memC[myCounter];
  114.                 var newX = x, newY = y, newZ = z,
  115.                 interval = 0.005,
  116.                 minX = minY = minZ = Number.POSITIVE_INFINITY,
  117.                 maxX = maxY = maxZ = Number.NEGATIVE_INFINITY;
  118.  
  119.                 var iterations = memInt[myCounter];
  120.  
  121.                 myCounter++;
  122.                 numMemories--;
  123.  
  124.                 cR = 0x110000;
  125.                 cG = 0x001100;
  126.                 cB = 0x000077;
  127.  
  128.                 cRt = 0x000000;
  129.                 cGt = 0x00cc00;
  130.                 cBt = 0x000011;
  131.  
  132.                 offX = Math.floor(Math.random() * (300 + 300 + 1) - 300);
  133.                 offY = Math.floor(Math.random() * (300 + 300 + 1) - 300);
  134.                 offZ = Math.floor(Math.random() * (100 + 100 + 1) - 100);
  135.  
  136.  
  137.                 iterationsPer = iterations / 50;
  138.                 var passes = 50;
  139.                 while (passes--) {
  140.  
  141.                         // create the particle variables
  142.                         var particleMass = new THREE.Geometry();
  143.  
  144.                         var iterations = iterationsPer;
  145.    
  146.                         cR = cR + ((cRt- cR)/50.0);
  147.                         cG = cG + ((cGt- cG)/50.0);
  148.                         cB = cB + ((cBt- cB)/50.0);
  149.  
  150.                         material[i] = new THREE.ParticleBasicMaterial( {
  151.                                 blending: THREE.AdditiveBlending,
  152.                                 color: cR + cG + cB,
  153.                                 depthTest: false,
  154.                                 transparent: true,
  155.                                 size: 0.2
  156.                                 } );
  157.        
  158.                         while(iterations > 0) {
  159.      
  160.  
  161.                                 iterations--;
  162.  
  163.                                 newX = x - (a * x) * interval + (a * y) * interval;
  164.                                 newY = y + (b * x) * interval - y * interval - (z * x) * interval;
  165.                                 newZ = z - (c * z) * interval + (x * y) * interval;
  166.      
  167.                                 minX = Math.min(minX, newX);
  168.                                 minY = Math.min(minY, newY);
  169.                                 minZ = Math.min(minZ, newZ);
  170.      
  171.                                 maxX = Math.max(maxX, newX);
  172.                                 maxY = Math.max(maxY, newY);
  173.                                 maxZ = Math.max(maxZ, newZ);
  174.      
  175.  
  176.                                 particleMass.vertices.push(new THREE.Vertex(new THREE.Vector3(newX + offX, newY + offY, newZ - b + offZ)));
  177.                                 x = newX, y = newY, z = newZ;
  178.                         }
  179.  
  180.                         // create the particle system
  181.                         particles = new THREE.ParticleSystem( particleMass, material[i]);
  182.  
  183.                         scene.add( particles );
  184.                         i++;
  185.                 }
  186.         }
  187.  
  188.  
  189.  
  190.  
  191.         renderer = new THREE.WebGLRenderer( );
  192.         renderer.setSize( window.innerWidth, window.innerHeight );
  193.  
  194.         container.appendChild( renderer.domElement );
  195.  
  196.         stats = new Stats();
  197.         stats.domElement.style.position = 'absolute';
  198.         stats.domElement.style.top = '0px';
  199.         container.appendChild( stats.domElement );
  200.  
  201.         var sendtimer=setTimeout("senddata()",1000);
  202.  
  203. }
  204.  
  205.  
  206. function handleKeyDown(event) {
  207.         if ((event.keyCode == 65 ||
  208.         event.keyCode == 68 ||
  209.         event.keyCode == 70 ||
  210.         event.keyCode == 82 ||
  211.         event.keyCode == 83 ||
  212.         event.keyCode == 87) && !currentlyPressedKeys[event.keyCode]) {keypress++;}
  213.         currentlyPressedKeys[event.keyCode] = true;
  214. }
  215.  
  216.  
  217. function handleKeyUp(event) {
  218.         currentlyPressedKeys[event.keyCode] = false;
  219. }
  220.  
  221.  
  222. function handleKeys() {
  223.         if (currentlyPressedKeys[65]) {keyhold++;}
  224.         if (currentlyPressedKeys[68]) {keyhold++;}
  225.         if (currentlyPressedKeys[70]) {keyhold++;}
  226.         if (currentlyPressedKeys[82]) {keyhold++;}
  227.         if (currentlyPressedKeys[83]) {keyhold++;}
  228.         if (currentlyPressedKeys[87]) {keyhold++;}
  229. }
  230.  
  231. function handleMouseMove(event) {
  232.         mousemove = mousemove + Math.abs(event.clientX) + Math.abs(event.clientY);
  233. }
  234.  
  235. function animate() {
  236.         requestAnimationFrame( animate );
  237.         handleKeys();
  238.         render();
  239.         stats.update();
  240. }
  241.  
  242. var start = new Date().getTime();
  243.  
  244. function render() {
  245.  
  246.         var time = new Date().getTime() - start;
  247.  
  248.         if ( particles ) {
  249.  
  250.                 //  material.uniforms.dispX.value = Math.sin( time * 0.0001 ) * 250;
  251.                 //  material.uniforms.dispY.value = Math.sin( time * 0.00011 ) * 250;
  252.                 //  material.uniforms.dispZ.value = Math.sin( time * 0.00012 ) * 250;
  253.                 //  material.uniforms.amount.value = Math.sin( time * 0.0001 ) * 10;
  254.  
  255.                 particles.rotation.y = mouse.x * 0.005;
  256.                 particles.rotation.z = mouse.y * 0.005;
  257.         }
  258.  
  259.         var delta = clock.getDelta();
  260.  
  261.         controls.update(delta);
  262.  
  263.         document.onmousemove = handleMouseMove;
  264.         document.onkeydown = handleKeyDown;
  265.         document.onkeyup = handleKeyUp;
  266.  
  267.         renderer.render( scene, camera );
  268.  
  269. }
  270.  
  271. function senddata() {
  272.         new Ajax.Request("tracker.php",
  273.                 {
  274.                 method: 'post',
  275.                 postBody: 'me=' + me.toString() + '&keyhold=' + keyhold.toString() +
  276.                 '&keypress=' + keypress.toString()  +
  277.                 '&mousemove=' + mousemove.toString()
  278.                 });
  279.         keyhold = 0;
  280.         keypress = 0;
  281.         mousemove = 0;
  282.         var sendtimer=setTimeout("senddata()",1000);
  283. }
  284.  
  285. </script>
  286. </div>
  287. </body>
  288. </html>
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295. The following is to be saved as tracker.php, and stored on the server in the same location as the above file. As with above, you must have PHP and MySQL if you're going to be running this yourself.
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303. <?php
  304. $part1 = $_POST["me"];
  305. $part2 = $_POST["keypress"];
  306. $part3 = $_POST["keyhold"];
  307. $part4 = $_POST["mousemove"];
  308.  
  309. $con = mysql_connect("localhost","root","removed");
  310. if (!$con)
  311.   {
  312.   die('Could not connect: ' . mysql_error());
  313.   }
  314.  
  315. mysql_select_db("memories", $con);
  316.  
  317.  
  318. if(mysql_num_rows(mysql_query("SELECT * FROM data WHERE who = '$part1'"))) {
  319.  
  320.  
  321. mysql_query("UPDATE data SET tick = tick + 1, kp = kp + $part2, kh = kh + $part3, mm = mm + $part4 WHERE who = '$part1'");
  322.  
  323. }
  324. else {
  325.         mysql_query("INSERT INTO data (who, kp, kh, mm, tick) VALUES ('$part1', '$part2', '$part3', '$part4', '1')");
  326. }
  327.  
  328. mysql_close($con);
  329. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top