class MobileBarNode extends MobileAbstractNode { float m_width = 0; float m_radius = 0; int m_curtex = -1; MobileThreadNode m_parent; MobileBarNode(MobileAbstractNode parent) { println("Made bar node"); m_parent = (MobileThreadNode)parent; m_width = 40; m_radius = 10; m_kind = barNode; println("m_kind = " + m_kind); m_curtex = -1; } int SaveMyself(String [] buffer, int curIndex) { //m_width buffer[curIndex++] = str(m_width); //m_radius buffer[curIndex++] = str(m_radius); //m_curtex buffer[curIndex++] = str(m_curtex); return curIndex; } int LoadMyself(String [] buffer, int curIndex) { //m_width m_width=float(buffer[curIndex++]); //m_radius m_radius=float(buffer[curIndex++]); //m_curtex m_curtex=int(buffer[curIndex++]); return curIndex; } void DrawMyself() { pushMatrix(); noStroke(); if ( m_selected == true) { //strokeWeight(3); //stroke(red); fill(red); } else { //strokeWeight(1); //stroke(black); fill(grey); } int children = m_childrenNode.size(); if ( children > 1 ) { translate(0, m_radius, 0); sphere(m_radius); float angle = (2*PI/children); for ( int i = 0; i < children; i++ ) { float angleBranch = angle*i; pushMatrix(); rotateY(angleBranch); translate(m_radius+m_width/2, 0, 0); box(m_width, m_radius*2, m_radius*2); popMatrix(); } } else { translate(0, m_radius, 0); pt c = new pt(0, 0, 0); //c.y = c.y + m_width/2; CreateSphere( c, m_radius, 16); } popMatrix(); } boolean IsMouseIn(float thisX, float thisY, float thisZ) { if ( thisX-m_width-m_radius < ptMouse3D.x && ptMouse3D.x < thisX+m_width+m_radius && thisY < ptMouse3D.y&& ptMouse3D.y< thisY+m_radius*2 && thisZ-m_width-m_radius < ptMouse3D.z && ptMouse3D.z < thisZ+m_width+m_radius ) { //println("OK in"); return true; } else { return false; } } void ShowMenuMyself() { fill(black); text("Press 'a' to add child",0,0); noFill(); translate(0, 20); fill(black); text("Press 'r' to remove child",0,0); noFill(); translate(0, 20); fill(black); text("Press 'w' to shorthen width.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'W' to lengthen width.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'h' to decrease radius.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'H' to increase radius.",0,0); noFill(); translate(0, 20); fill(black); text("Press '+' to speed up in CCW.",0,0); noFill(); translate(0, 20); fill(black); text("Press '-' to speed up in CW.",0,0); noFill(); translate(0, 20); fill(black); text("Press 's' to stop.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'l' to load a mesh.",0,0); noFill(); translate(0, 20); fill(black); text("Press 't' to load a texture.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'u' to unload a texture.",0,0); noFill(); translate(0, 20); } void PressKeyMyself() { if(key == 'a') { AddChild(); RearrangeX(); RearrangeY(); } else if(key == 'r') { RemoveChild(); RearrangeX(); } else if(key == 'w') { m_width = m_width - 2; if ( m_width < 2 ) m_width = 2; RearrangeX(); } else if(key == 'W') { m_width = m_width + 2; RearrangeX(); } else if(key == 'h') { m_radius = m_radius - 2; if ( m_radius < 2 ) m_radius = 2; RearrangeX(); RearrangeY(); } else if(key == 'H') { m_radius = m_radius + 2; RearrangeX(); RearrangeY(); } else if(key == '+' || key =='=') { m_deltaAngle += 2; } else if (key == '-' || key =='_') { m_deltaAngle -= 2; } else if (key == 's') { m_deltaAngle = 0; m_prevAngle = 0; } else if (key == 'l') { if ( m_childrenNode.size() == 0 ) { m_parent.ReplaceChild(true); } } else if ( key == 't') { m_curtex++; } else if ( key == 'u') { m_curtex = -1; } } void AddChild() { MobileAbstractNode child = new MobileThreadNode(); m_childrenNode.add(child); } void RemoveChild() { int size = m_childrenNode.size(); if ( size > 0 ) { m_childrenNode.remove(size-1); } } void RearrangeX() { int size = m_childrenNode.size(); if ( size < 1 ) return; if ( size == 1 ) { MobileAbstractNode childNode = (MobileAbstractNode)m_childrenNode.get(0); childNode.SetPosX(0); } else { float radius = m_radius+m_width-2; float angle = (2*PI/size); for ( int i = 0; i < size; i++ ) { float angleBranch = angle*i; float x = radius * cos(angleBranch); float z = radius * sin(angleBranch); MobileAbstractNode childNode = (MobileAbstractNode)m_childrenNode.get(i); childNode.SetPosX(x); childNode.SetPosZ(z); } } } void RearrangeY() { for ( int i = 0; i < m_childrenNode.size(); i++ ) { MobileAbstractNode childNode = (MobileAbstractNode)m_childrenNode.get(i); childNode.SetPosY(2*m_radius); } } void DraggedChild(float dxChild, float dyChild) {}; // from http://local.wasp.uwa.edu.au/~pbourke/texture_colour/spheremap/ /* Create a sphere centered at c, with radius r, and precision n Draw a point for zero radius spheres */ void CreateSphere(pt c, float r, int n) { int i,j; float theta1,theta2,theta3; pt e = new pt(); pt p = new pt(); if (r < 0) r = -r; if (n < 0) n = -n; if (n < 4 || r <= 0) { beginShape(POINTS); vertex(c.x,c.y,c.z); endShape(); return; } noStroke(); beginShape(QUAD_STRIP); if ( m_curtex > -1 ) { texture(tex[m_curtex%texnum]); for (j=0;j