/* * * rootApostolos * P5js example * IMU 3D * * * * */ var data = {}; // Global object to hold results from the loadJSON call var data1 // Global object to hold results from the loadJSON call var bubbles = []; // Global array to hold all bubble objects let aX = 0; let aY = 0; let aZ = 0; var rot = 0; var anglesX =0; var anglesY =0; var anglesZ =0; var x1 = 500 var y1 = 500 var x2 = 800 var y2 = 800 // g greece var G = 9.82 // miliseconds se second read in sketch var dt = 0.1 // motion scene to show var motion = 1 var train; var AX, AY, BX, BY, CX, CY; var i = 0 AX = 120; AY = 900; // Put any asynchronous data loading in preload to complete before "setup" is run function preload() { data = loadJSON('./data/b.json'); let file = "./data/test2.txt" data1 = loadJSON(file); train = loadModel('data/train-corrected.obj'); } // Convert saved Bubble data into Bubble Objects function loadData() { var bubbleData = data['bubbles']; for (var vv = 0; vv < bubbleData.length; vv++) { // Get each object in the array var bubble = bubbleData[vv]; // Get a position object var position = bubble['position']; // Get x,y from position var x = position['x']; var y = position['y']; // Get diameter and label var diameter = bubble['diameter']; var label = bubble['label']; // Put object in array bubbles.push(new Bubble(x, y, diameter, label)); } } // Create a new Bubble each time the mouse is clicked. function mousePressed() { keyPressed() } function keyPressed() { // Add diameter and label to bubble var diameter = random(10, 20); var label = 'New Label'; console.log(" ---> object " + i/3) aX = data1[i].X * G; aY = data1[i].Y * G; aZ = data1[i].Z * G; sensor = data1[i].sensor; console.log(" source aX " + aX); console.log(" source aY " + aY); console.log(" source aZ " + aZ); AX=AX+aX*dt; AY=AY+aY*dt; console.log(" metavoli aX " + AX); console.log(" metavoli aY " + AY); var ii=i+1 gX = data1[ii].X; gX = gX * dt; gY = data1[ii].Y; //gY = gY/8.999; gY = gY * dt; gZ = data1[ii].Z; gZ = gZ * dt; console.log(" gX " + gX); console.log(" gY " + gY); console.log(" gZ " + gZ); var iii=i+2 mX = data1[iii].X; mY = data1[iii].Y; mZ = data1[iii].Z; sensor = data1[iii].sensor; console.log(sensor); console.log(" mX " + mX); console.log(" mY " + mY); console.log(" mZ " + mZ); anglesZ = Math.acos((-gY)/(Math.pow(1-Math.pow(gZ,2),0.5))); console.log("anglesZ:"+anglesZ); //peristrofi ston x axona mikos anglesX=acos(gZ); var anglesXX = anglesX * 180 / Math.PI; console.log("anglesXX:"+anglesXX); console.log("anglesX:"+anglesX); //peristrofi ston y axona anglesY=acos(gX/(Math.pow(1-pow(gZ,2),0.5))); console.log("anglesY:"+anglesY); BX=BX+aX*3; BY=BY+aY*3; CX=CX+aX*3; CY=CY+aY*3; bubbles.push(new Bubble(AX, AY, diameter, label)); console.log( " X " + AX + " Y " + AY + " D " + diameter + " L " + label); // Prune Bubble Count if there are too many if (bubbles.length > motion) { bubbles.shift(); // remove first item from array } i=i+3 } function setup() { createCanvas(1850, 1750, WEBGL); } function draw() { //background(250); background(150); //background(100, 100, 100); // Display all bubbles for (var v = 0; v < bubbles.length; v++) { bubbles[v].display(); } } // Bubble class function Bubble(x, y, diameter, name) { this.x = x; this.y = y; this.diameter = diameter; this.radius = diameter / 2; this.name = name; this.display = function() { //angleMode(DEGREES); angleMode(RADIANS); //translate(this.x,this.y); var camX = map(mouseX, 0 , width, -500 , 0); camera(0,0,(height/2)/tan(PI/6),camX,0,0,1,0,1); rotateZ(anglesZ ); rotateX(anglesX ); rotateY(anglesY ); model(train); normalMaterial(); //noStroke(); ambientLight(255); }; }