# Human-Form 3D Mocap - Graphics Code

**URL:** <https://discourse.processing.org/t/human-form-3d-mocap-graphics-code/8392>\
**Category:** Coding Questions\
**Created:** [February 14, 2019, 10:46am UTC](https://discourse.processing.org/t/human-form-3d-mocap-graphics-code/8392 "2019-02-14T10:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![L11L](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@L11L](https://discourse.processing.org/u/L11L)\
**Post date:** [February 14, 2019, 10:46am UTC](https://discourse.processing.org/t/human-form-3d-mocap-graphics-code/8392/1 "2019-02-14T10:46:20Z")

</div>

I started using Processing three days ago. I am using Processing to capture the motion of a MPU6050-driven IMU sensor. I need a human form (or something that resembles human) to represent the data output of the IMU sensor.

Something like this: [https://www.youtube.com/watch?v=LlhV-6v6uEY](https://www.youtube.com/watch?v=LlhV-6v6uEY) is good enough!

Help is 100% appreciated !!!

The code I have is this:  
// draw main body in red  
fill(255, 0, 0, 200);  
box(50, 25, 130);

```
// draw sphere representing head in red
fill(255, 0, 0, 200);
pushMatrix();
translate(0, 0, -120);
rotateX(PI/2);
sphere(20);
popMatrix();

// draw wings and tail fin in green
fill(0, 255, 0, 200);
beginShape(TRIANGLES);
vertex(-100, 2, 30); vertex(0, 2, -80); vertex(100, 2, 30); // wing top layer
vertex(-100, -2, 30); vertex(0, -2, -80); vertex(100, -2, 30); // wing bottom layer
vertex(-2, 0, 98); vertex(-2, -30, 98); vertex(-2, 0, 70); // tail left layer
vertex( 2, 0, 98); vertex( 2, -30, 98); vertex( 2, 0, 70); // tail right layer
endShape();
beginShape(QUADS);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
vertex( 100, 2, 30); vertex( 100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex(100, -2, 30); vertex(100, 2, 30);
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, -30, 98); vertex(-2, -30, 98);
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
vertex(-2, -30, 98); vertex(2, -30, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
endShape();

popMatrix();

```

L11L

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 14, 2019, 1:40pm UTC](https://discourse.processing.org/t/human-form-3d-mocap-graphics-code/8392/2 "2019-02-14T13:40:11Z")

</div>

sorry, i need to see it first,  
so i play little bit ( using my PTZ )

```auto
// https://discourse.processing.org/t/human-form-3d-mocap-graphics-code/8392

void draw_object() {
  // draw sphere representing head in red
  fill(255, 0, 0);
  stroke(0,0,200); //noStroke(); // test visibility
  pushMatrix();
  translate(0, 0, -120);
  rotateX(PI/2);
  sphere(20);
  popMatrix();

  // draw wings and tail fin in green
  pushMatrix();
  fill(0, 255, 0, 200);
  beginShape(TRIANGLES);
  vertex(-100, 2, 30); 
  vertex(0, 2, -80); 
  vertex(100, 2, 30); // wing top layer
  vertex(-100, -2, 30); 
  vertex(0, -2, -80); 
  vertex(100, -2, 30); // wing bottom layer
  vertex(-2, 0, 98); 
  vertex(-2, -30, 98); 
  vertex(-2, 0, 70); // tail left layer
  vertex( 2, 0, 98); 
  vertex( 2, -30, 98); 
  vertex( 2, 0, 70); // tail right layer
  endShape();
  beginShape(QUADS);
  vertex(-100, 2, 30); 
  vertex(-100, -2, 30); 
  vertex( 0, -2, -80); 
  vertex( 0, 2, -80);
  vertex( 100, 2, 30); 
  vertex( 100, -2, 30); 
  vertex( 0, -2, -80); 
  vertex( 0, 2, -80);
  vertex(-100, 2, 30); 
  vertex(-100, -2, 30); 
  vertex(100, -2, 30); 
  vertex(100, 2, 30);
  vertex(-2, 0, 98); 
  vertex(2, 0, 98); 
  vertex(2, -30, 98); 
  vertex(-2, -30, 98);
  vertex(-2, 0, 98); 
  vertex(2, 0, 98); 
  vertex(2, 0, 70); 
  vertex(-2, 0, 70);
  vertex(-2, -30, 98); 
  vertex(2, -30, 98); 
  vertex(2, 0, 70); 
  vertex(-2, 0, 70);
  endShape();
  popMatrix();
}

void setup() {
  size(500, 500, P3D);
  info_print();
}

void draw() {
  background(200, 200, 0);
  PTZ();
}

// _____________________________________ PTZ tab
int mode = 0;
float Zmag = 5;
int Zaxis=-10;                                                       
float Xmag, Ymag = 0;
float newXmag, newYmag = 0; 
int newZmag = 0;
int zoomf = 3;
float newxpos, newypos = 0; // for PAN
float xposd, yposd = 0; // for PAN

// _________________________________________________________________ ROTATE / TILDE and MOVE / PAN
void mousePressed() {
  if (mouseButton == LEFT) { 
    mode=1;
  } // ORBIT
  else if (mouseButton == RIGHT) { 
    mode=2;
  } // PAN
  // else if (mouseButton == CENTER) { mode=3; } // zoom mouse wheel works same , presssed or not
}

// _________________________________________________________________ mouse PT end
void mouseReleased() { 
  mode = 0;
}

// _________________________________________________________________ mouseWheel ZOOM
void mouseWheel(MouseEvent event) {
  int newZmag = event.getCount(); // +- 1
  //if (Zmag > 10) { Zmag += newZmag * 5; } else { Zmag += newZmag; }// from 1 to 11 go in step 1 else in step 5 
  Zmag += newZmag*0.3;
  //println("Zmag: "+nf(Zmag, 1, 2));
}

void keyPressed() {
  if ( keyCode == UP ) Ymag -= 0.1 ;
  if ( keyCode == DOWN ) Ymag += 0.1 ;
  if ( keyCode == RIGHT) Xmag -= 0.1 ;
  if ( keyCode == LEFT ) Xmag += 0.1 ;
  if ( keyCode == 16 ) Zmag -= 0.5 ;
  if ( keyCode == 11 ) Zmag += 0.5 ;
  //println("key: "+key); println("keyCode: "+keyCode);
}
// _________________________________________________________________ Pan Tilde Zoom
void PTZ() {
  pushMatrix(); 
  translate(width/2, height/2, Zaxis);
  // get new mouse operation  
  if ( mode == 2 ) { // PAN ( right mouse button pressed)
    xposd = (mouseX-float(width/2));
    yposd = (mouseY-float(height/2));
  }  
  newxpos = xposd;// xposd=0;
  newypos = yposd;// yposd = 0; 
  translate(newxpos, newypos, 0); // move object
  if ( mode == 1 ) { // ORBIT ( left mouse button pressed)
    newXmag = mouseX/float(width) * TWO_PI;
    newYmag = mouseY/float(height) * TWO_PI;

    float diff = Xmag-newXmag;
    if (abs(diff) > 0.01) Xmag -= diff/4.0;
    diff = Ymag-newYmag;
    if (abs(diff) > 0.01) Ymag -= diff/4.0;
  }
  rotateX(-Ymag);   
  rotateY(-Xmag);   
  scale(Zmag);
  draw_object(); // THE OBJECT see main tab
  popMatrix();
}

// _______________________________________________ SETUP PRINT INFO
void info_print() {
  println("PTZ info:");
  println("key UP DOWN RIGHT LEFT -> rotate // key PAGE UP DOWN -> zoom");
  println("mouse LEFT press drag up down right left -> rotate // mouse RIGHT press -> move // mouse WHEEL turn -> zoom");
}

```

 ![snap_0034](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3796ad9b0ea18596183e9a9c713a64ea378945cf.jpeg)

* * *

looks good, now what was the question?  
need 2 arms? made by 2 or 3 3D elements?
