<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with box() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=box%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:57:39 +0000</pubDate>
         <description>Tagged with box() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbox%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to combine a z-buffer with a blur fragment shader</title>
      <link>https://forum.processing.org/two/discussion/27807/how-to-combine-a-z-buffer-with-a-blur-fragment-shader</link>
      <pubDate>Fri, 20 Apr 2018 15:27:54 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">27807@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I'm trying to fake a Depth of Field effect in a 3D scene. More specifically, I would like to use a z-buffer (depth buffering) to adjust the level of blur of a an object based on its distance from the camera. While searching the forum I found the following vertex and fragment shaders provided by <a href="/two/profile/Poersch">@Poersch</a> (from <a rel="nofollow" href="https://forum.processing.org/two/discussion/2153#Item_3">this topic</a> ).</p>

<p><strong>vert.glsl</strong></p>

<pre><code>uniform mat4 transform;

attribute vec4 vertex;
attribute vec4 color;

varying vec4 vertColor;

void main() {
    gl_Position = transform * vertex;
    vertColor = color;
}
</code></pre>

<p><strong>frag.glsl</strong></p>

<pre><code>#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform vec4 nearColor = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 farColor = vec4(0.0, 0.0, 0.0, 1.0);
uniform float near = 0.0;
uniform float far = 100.0;

varying vec4 vertColor;

void main() {
    gl_FragColor = mix(nearColor, farColor, smoothstep(near, far, gl_FragCoord.z / gl_FragCoord.w));
}
</code></pre>

<p>You can see the shaders in action with this sketch example:</p>

<p><strong>sketch.pde</strong></p>

<pre><code>PShader depthShader;
float angle = 0.0;


void setup(){

    // Set screen size and renderer
    size(600, 480, P3D);
    noStroke();

    // Load shader
    depthShader = loadShader("frag.glsl", "vert.glsl");
    //depthShader.set("near", 40.0); // Standard: 0.0
    //depthShader.set("far", 60.0); // Standard: 100.0
    //depthShader.set("nearColor", 1.0, 0.0, 0.0, 1.0); // Standard: white
    //depthShader.set("farColor", 0.0, 0.0, 1.0, 1.0); // Standard: black

}


void draw(){

    // Fill background and set camera
    background(#000000);
    camera(0.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    // Bind shader
    shader(depthShader);

    // Calculate angle
    angle += 0.01;

    // Render "sky"-cube
    pushMatrix();
    rotate(angle, 0.0, 1.0, 0.0);
    box(100.0);
    popMatrix();

    // Render cubes
    pushMatrix();
    translate(-30.0, 20.0, -50.0);
    rotate(angle, 1.0, 1.0, 1.0);
    box(25.0);
    popMatrix();
    pushMatrix();
    translate(30.0, -20.0, -50.0);
    rotate(angle, 1.0, 1.0, 1.0);
    box(25.0);
    popMatrix();

    // Render spheres
    pushMatrix();
    translate(-30.0, -20.0, -50.0);
    rotate(angle, 1.0, 1.0, 1.0);
    sphere(20.0);
    popMatrix();
    pushMatrix();
    translate(30.0, 20.0, -50.0);
    rotate(angle, 1.0, 1.0, 1.0);
    sphere(20.0);
    popMatrix();

}
</code></pre>

<p>Here, the z-buffer is used to change the <strong>color</strong> of an object: the closer the lighter, the farther, the darker.
<img src="https://i.imgur.com/LNMfKI4.png" alt="" /></p>

<p><strong>QUESTION</strong></p>

<ul>
<li>How can I use the same z-buffer to change the blur level of an object ?</li>
</ul>

<p>Ideally I would like to use the Gaussian blur shader from the PostFX library:</p>

<pre><code>#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif


#define PROCESSING_TEXTURE_SHADER

uniform sampler2D texture;

// The inverse of the texture dimensions along X and Y
uniform vec2 texOffset;

varying vec4 vertColor;
varying vec4 vertTexCoord;


uniform int blurSize;       
uniform int horizontalPass; // 0 or 1 to indicate vertical or horizontal pass
uniform float sigma;        // The sigma value for the gaussian function: higher value means more blur
                            // A good value for 9x9 is around 3 to 5
                            // A good value for 7x7 is around 2.5 to 4
                            // A good value for 5x5 is around 2 to 3.5
                            // ... play around with this based on what you need &lt;span class="Emoticon Emoticon1"&gt;&lt;span&gt;:)&lt;/span&gt;&lt;/span&gt;

const float pi = 3.14159265;

void main() {  
  float numBlurPixelsPerSide = float(blurSize / 2); 

  vec2 blurMultiplyVec = 0 &lt; horizontalPass ? vec2(1.0, 0.0) : vec2(0.0, 1.0);

  // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
  vec3 incrementalGaussian;
  incrementalGaussian.x = 1.0 / (sqrt(2.0 * pi) * sigma);
  incrementalGaussian.y = exp(-0.5 / (sigma * sigma));
  incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;

  vec4 avgValue = vec4(0.0, 0.0, 0.0, 0.0);
  float coefficientSum = 0.0;

  // Take the central sample first...
  avgValue += texture2D(texture, vertTexCoord.st) * incrementalGaussian.x;
  coefficientSum += incrementalGaussian.x;
  incrementalGaussian.xy *= incrementalGaussian.yz;

  // Go through the remaining 8 vertical samples (4 on each side of the center)
  for (float i = 1.0; i &lt;= numBlurPixelsPerSide; i++) { 
    avgValue += texture2D(texture, vertTexCoord.st - i * texOffset * 
                          blurMultiplyVec) * incrementalGaussian.x;         
    avgValue += texture2D(texture, vertTexCoord.st + i * texOffset * 
                          blurMultiplyVec) * incrementalGaussian.x;         
    coefficientSum += 2.0 * incrementalGaussian.x;
    incrementalGaussian.xy *= incrementalGaussian.yz;
  }

  gl_FragColor = (avgValue / coefficientSum);
}
</code></pre>

<p>Unfortunately I can't figure out how to make the two (z-buffer and blur fragment shader) work together. 
Any hint would be greatly appreciated !</p>
]]></description>
   </item>
   <item>
      <title>Remove left-click requirement to move camera in PeasyCam</title>
      <link>https://forum.processing.org/two/discussion/27811/remove-left-click-requirement-to-move-camera-in-peasycam</link>
      <pubDate>Fri, 20 Apr 2018 22:00:59 +0000</pubDate>
      <dc:creator>GameMaker123</dc:creator>
      <guid isPermaLink="false">27811@/two/discussions</guid>
      <description><![CDATA[<p>I am working on a Minecraft clone developed using Processing and PeasyCam. I will code the rest myself, with help from this forum. I need to know how to track mouse movement without having to left-click. That will be used for a first-person look-around feature. Here is the code right now:</p>

<pre><code>import peasy.PeasyCam;

PeasyCam cam;

final float gravity = 1; //Inaccurate gravity simulation (impulse rather than force)

// ArrayLists for the class
//ArrayList&lt;Box3D&gt; boxes = new ArrayList(); 
//Box3D box;

// this is a very important size: size boxes
float sizeBox = 70.0;
float sizeLimit = 180;

float rotationX;
float rotationY;
float rotationZ;

float translatex=-sizeBox;
float translatey=-sizeBox;
float translatez=0;

float z = 1.0;

int objectNumber = 0;

// folded triangle 
PShape s; 

float offsetZ=400;

color colCurrent=color(0, 0, 255);

boolean showHelpText=true; 

void setup() {

  size(500, 500, P3D);
  background(0);
  sphereDetail(32);

  cam = new PeasyCam(this, 400); // new
  //box = new Box3D(0, 0, 0, 0, 0, color(255));

  s = createShape();
  s.beginShape();
  s.fill(255, 0, 0);
  s.stroke(177);
  s.vertex(100, 0, -100);
  s.vertex(-60, 0, 200);
  s.vertex(-50, 60, -30);
  s.vertex(110, 160, 40);
  s.scale(0.4);
  s.endShape(CLOSE);
}

void draw() {
  background(0);
  lights();

  //for (Box3D b : boxes ) {
   // box.display();
  //}

  noFill();
  box(sizeLimit*2+sizeBox); // ?

  showObject();

  cam.beginHUD(); 
  /**if (showHelpText) {
    fill(255); // white 
    text ("Use PeasyCam. Use wasd and pl; r/g/b for colors, space bar to toggle object, RETURN to enter object to list.\n\n"
      +"Use x to switch this text on and off. \n"
      +"Use Mousewheel to zoom, double click to reset view. The box you move has a white outline. An item that has been added to the list is marked with a gray box.\n"
      +"On adding to the list the placing box moves two units left. \n"
      +"Current: "
      +translatex
      +", "
      +translatey
      +", "
      +translatez, 
      19, 19);
  }*/ //HUD disabled

  if (keyPressed)
    keyPressed_ForContinuusKeyinput();

  cam.endHUD();
}

// -----------------------------------------------------------

void showObject() {

  // show object 

  pushMatrix();

  translatey+=gravity;

  translatex=constrain(translatex,-sizeLimit,sizeLimit);
  translatey=constrain(translatey,-sizeLimit,sizeLimit);
  translatez=constrain(translatez,-sizeLimit,sizeLimit);

  fill(colCurrent); // color
  //translate(width/3, height/2, 0);
  translate(translatex, translatey, translatez);
  //rotateZ(rotationZ);
  //rotateY(rotationY);
  //rotateX(rotationX);

  stroke(255); 

  if (objectNumber==0) {
    //stroke(111);
    box(sizeBox);
  } else if (objectNumber==1) {
    s.setFill(colCurrent);
    shape(s, 0, 0);
  } else if (objectNumber==2) {
    //noStroke();
    sphere(sizeBox);
  }//else 

  popMatrix();
}

// -----------------------------------------------------------

void keyPressed_ForContinuusKeyinput() {
  // keyPressed for registering a key throughout  

  float speed = 3.9; 

  //speed += gravity; //More accurate gravity simulation, may be removed

  switch(key) {

  case 'a':
    translatex-=speed;
    break; 

  case 'd':
    translatex+=speed;
    break;

  case 'w':
  case ' ':
    translatey-=speed; //Conflicting keypress info: change object
    break;

  case SHIFT:
  case 's':
    translatey+=speed;
    break;

    // --

  case 'p':
    translatez-=speed;
    break; //Unnecessary in 2D version, but useful

  case 'l':
    translatez+=speed;
    break; //Unnecessary in 2D version, but useful

    // -----

    //
  }//switch
  //
}//func

// ----------------------------

void keyPressed() {

  // keyPressed for registering a single key only 

  switch(key) {
    /**
  case ' ':
    objectNumber++;
    if (objectNumber&gt;2)
      objectNumber=0;
    key=0;
    break;
    */ //Object switch disabled in favor of jumping

 /**
  case RETURN:
  case ENTER:
    Box3D newBox = new Box3D (
      translatex, 
      translatey, 
      translatez, 
      rotationY, 
      objectNumber, 
      colCurrent
      ); 
    boxes.add(newBox); 
    translatex-=sizeBox*2;
    break;
    */ //New object function disabled

    // ---
    //colors

  case 'r':
    colCurrent=color(255, 0, 0);
    break;

  case 'b':
    colCurrent=color(0, 0, 255);
    break;

  case 'g':
    colCurrent=color(0, 255, 0);
    break;

    // --

  case 'x':
    showHelpText = !showHelpText; 
    break;
  }//switch
  //
} //func

//=============================================================

class Box3D {

  float x=mouseX, y=410, z=mouseY;

  float offsetX=0; 
  float offsetZ2=0; 

  float rotateY=0;
  color colBox = color(255, 0, 0);

  // type
  final int boxTypeUndefined = -1;
  final int boxType0   = 0;
  final int boxType1   = 1; 
  final int boxType2   = 2; 
  // more needed !!!!! ???? 
  int type = boxTypeUndefined; 

  // constr - full
  Box3D(float x_, 
    float y_, 
    float z_, 
    float rotateY_, 
    int type_, 
    color col1_) {
    //

    x=x_;
    y=y_;
    z=z_;

    rotateY= rotateY_;
    type=type_;

    colBox=col1_;
  } // constr 2 

  void display() {
    pushMatrix();

    translate(x, y, z);
    //  rotateY(radians(rotateY)); 

    fill(colBox);
    noStroke(); 

    // depending on the current buttons tag 
    // 
    switch (type) {

    case boxTypeUndefined:
      // undefined 
      break; 

    case boxType0: 
      stroke(111);
      box(sizeBox);
      break; 

    case boxType1: 
      s.setFill(colBox);
      shape(s, 0, 0);
      break;

    case boxType2: 
      noStroke();
      sphere(sizeBox);
      break;

    default:
      // error 
      break;
    }//switch 

    if (showHelpText) {
      translate(sizeBox/2, -sizeBox/2, sizeBox/2);

      fill(111);
      stroke(0);
      box(sizeBox/6);
    }

    popMatrix();
  } // method 

  String toString() {
    return
      str(x) +","+ 
      str(y) +","+ 
      str(z) +","+ 
      str(rotateY) +","+ 
      str(type) +","+ 
      str(red(colBox)) +","+ 
      str(green(colBox)) +","+ 
      str(blue(colBox)) ;
  }
  //
} // class 
//
</code></pre>

<p>I understand there is a redundant class "Box3D", but I will handle that before implementing whatever solution you give me.</p>
]]></description>
   </item>
   <item>
      <title>How to approximate an object?</title>
      <link>https://forum.processing.org/two/discussion/27613/how-to-approximate-an-object</link>
      <pubDate>Sun, 01 Apr 2018 08:50:04 +0000</pubDate>
      <dc:creator>_igo_r_</dc:creator>
      <guid isPermaLink="false">27613@/two/discussions</guid>
      <description><![CDATA[<p>How to approximate an object using acceleration function and formulas from physics? Here is my program now. For some reasons it doesn't approximate my box correctly like in the real life.</p>

<pre><code>camX = map(m, 0, width,-200,200);
camY = map(k, 0, width,-200,200);
camZ = map(n, 0, width,-200,200);   
camera(-camY+300,0,-camY+200,-camZ,camX,0,0,-1,0)
fill (0,0,255);
box(150);

t1 =  0.7
aZ = accelerationZ;
S1 = Vox*t1 + (aZ*t1*t1)/2;
if (aZ&gt;-0.2 &amp;&amp; aZ&lt;0.2) {Vox = 0}
else {Vox = Vox + aZ*t1;}
k = k + S1;
S1 = 0;
</code></pre>

<p>I need to do it more realistic. Could you help me?</p>
]]></description>
   </item>
   <item>
      <title>How to figure out what is happening with an approximation?</title>
      <link>https://forum.processing.org/two/discussion/27714/how-to-figure-out-what-is-happening-with-an-approximation</link>
      <pubDate>Sat, 07 Apr 2018 10:19:22 +0000</pubDate>
      <dc:creator>_igo_r_</dc:creator>
      <guid isPermaLink="false">27714@/two/discussions</guid>
      <description><![CDATA[<pre><code>camX = map(m, 0, width,-200,200);
camY = map(k, 0, width,-200,200);
camZ = map(n, 0, width,-200,200);   
camera(-camY+300,0,-camY+200,-camZ,camX,0,0,-1,0);
fill (0,0,255);
box(150);
t = 0.7
if (aZ&gt;-0.5 &amp;&amp; aZ&lt;0.5){Voz = 0}
else {Voz = Voz + aZ*t1;}   
S1 = 0; 
aZ = accelerationZ;
if (aZ&gt;-0.1 &amp;&amp; aZ&lt;0.1){aZ = 0}
S1 = Voz*t1 + (aZ*t1*t1)/2;
if (aZ&lt;-0.5 &amp;&amp; aZ&lt;0.5){S1 = 0}
k = k + S1;
</code></pre>

<p>This program should allow the user move to the cube and away from it. But when I, for example, move to the cube at first it approximation and then it becomes small like it was in the beginning. I though that it was so because of the acceleration, but I can not find the solution</p>

<p>the final program should imitate the movement. that is why  I use formulas</p>
]]></description>
   </item>
   <item>
      <title>How to rotate text around box?</title>
      <link>https://forum.processing.org/two/discussion/26284/how-to-rotate-text-around-box</link>
      <pubDate>Thu, 08 Feb 2018 17:13:23 +0000</pubDate>
      <dc:creator>mellon_collie</dc:creator>
      <guid isPermaLink="false">26284@/two/discussions</guid>
      <description><![CDATA[<p>Hi! First of all, I want to apologize for my bad English. I have the assingment in which I have to:</p>

<ul>
<li>play music from mp3 file</li>
<li>create a box and make it rotating, changing sizes and colors</li>
<li>create a circle by clicking on a screen and make the circle moving down outside of the screen</li>
<li>import txt file and make lines of text from this file rotating around the box</li>
</ul>

<p>I managed to do 3 tasks (although not very good, I think), but I have no idea how to cope with the fourth one. Any suggestions? This is my code, maybe someone may have some suggestions on how to improve other tasks.</p>

<p>Thank you very much.</p>

<pre><code>import ddf.minim.*;
Minim minim;
AudioPlayer player;

void setup(){
  size(500,500,P3D);
  background(#F0AB16);
  smooth();

  minim=new Minim(this);
  player=minim.loadFile("music.mp3",512);
  player.play(); 
}

void draw(){
  background(#F0AB16);

  if (mouseButton==LEFT){
     fill(#CE2A92);
     ellipse(mouseX,mouseY,100,100);
      mouseY++;
  if (mouseY &gt; height) {
    ;
  }
  }

  translate(width/2,height/2);
  rotateX(millis()/1000.0f);
  rotateY(millis()/1000.0f);
  fill(255.0*sin(millis()/650.0),255.0*sin(millis()/800.0),255.0*sin(millis()/1000.0));
  box(250*abs(sin(millis()/1000.0))); 

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Continuous Eased Flip/Rotation</title>
      <link>https://forum.processing.org/two/discussion/25941/continuous-eased-flip-rotation</link>
      <pubDate>Sat, 13 Jan 2018 20:14:08 +0000</pubDate>
      <dc:creator>PJMcPrettypants</dc:creator>
      <guid isPermaLink="false">25941@/two/discussions</guid>
      <description><![CDATA[<p>I want to move a shape around in 3D continuously, but I want it to spend most of the time close to perpendicular to the camera.</p>

<p>I'm looking for a motion something like this:
<img src="https://forum.processing.org/two/uploads/imageupload/786/T2TGQJZ1F7U3.jpg" alt="EasedContinuousFlip" title="EasedContinuousFlip" /></p>

<p>I have the following code, which does what I want it do for now:</p>

<pre><code>int flipTime;
float rotation;

void setup() {
  size(400, 400, P3D);
  rotation = 0.0;
  flipTime = 100;
}

void draw() {

  background(128);
  translate(200, 200, 20);

  if ( (frameCount % flipTime) &lt; (flipTime/2) ) {
    rotation = HALF_PI * ( 1+ sin( ( (frameCount % (flipTime/2)) * PI / (flipTime/2) ) -HALF_PI) );
  } else {
    rotation = PI + (HALF_PI * ( 1+ sin( ( (frameCount % (flipTime/2)) * PI / (flipTime/2) ) -HALF_PI) ));
  }

  rotateY(rotation);

  fill(255);
  box(200, 200, 20);
  fill(0);
  translate(0, 0, -20);
  box(200, 200, 20);
}
</code></pre>

<p>However, the if/else structure seems like it's going to make things complicated further down the line. I'd like to stack many such rotations and translations on different axes and apply them to the same object, all out of phase with each other, and be able to tweak the variables, maybe using sin(x)^3, sin(x)^5 etc. for more eased motion.</p>

<p>Is there a more elegant way to do this?</p>

<p>Also, is there a page somewhere that gives examples on how to manipulate sine functions for these kinds of purposes? Something like the <a rel="nofollow" href="https://processing.org/tutorials/trig/">Trigonometry Primer</a>, but part 2?</p>
]]></description>
   </item>
   <item>
      <title>Keep the object top</title>
      <link>https://forum.processing.org/two/discussion/25163/keep-the-object-top</link>
      <pubDate>Thu, 23 Nov 2017 11:45:35 +0000</pubDate>
      <dc:creator>rickyfbrianto</dc:creator>
      <guid isPermaLink="false">25163@/two/discussions</guid>
      <description><![CDATA[<p>Hi i just learned processing and i just made a 3D sketch and there is a beam on it.
what puzzles me is when the cursor I pointed down the block disappears, what I want is to keep the beam always above the grid. Any suggestion would be greatly appreciated.</p>

<pre><code>int baris, kolom;
int kotak = 40;
int w = 2200;
int h = 800;

void setup() {
  fullScreen(P3D); // 1366 x 768
  baris = h / kotak;
  kolom = w / kotak;
}

void draw() {
  background(255);
  axisPlot();
  objek();
}

void axisPlot() {
  pushMatrix();
  stroke(255);
  fill(#D6D6D6);
  translate(width/2, height/2);
  rotateX(PI/3);
  translate(-w/2, -height/2);
  for (int y = 0; y &lt; baris; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x &lt; kolom; x++) {
      vertex(x * kotak, y * kotak);
      vertex(x * kotak, (y+1) * kotak);
    }
    endShape();
  }
  popMatrix();
}

void objek() {
  pushMatrix();
  lights();
  noStroke();
  fill(246, 225, 65);
  translate(mouseX, mouseY);
  rotateX(-PI/6);
  box(100, 50, 150);
  popMatrix();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is it possible for a 3D box to "grow" on one side only?</title>
      <link>https://forum.processing.org/two/discussion/23271/is-it-possible-for-a-3d-box-to-grow-on-one-side-only</link>
      <pubDate>Fri, 30 Jun 2017 18:35:11 +0000</pubDate>
      <dc:creator>Rheibe</dc:creator>
      <guid isPermaLink="false">23271@/two/discussions</guid>
      <description><![CDATA[<p>Hello fellow programmers,</p>

<p>I am currently working on a side project and I was playing with the box() object.</p>

<p><img src="https://my.mixtape.moe/bauxgm.png" alt="" /></p>

<p>When I tweak the z parameter, both ends are affected.</p>

<p><img src="https://my.mixtape.moe/yusebu.png" alt="" /></p>

<p>Can I make it that only the top end is affected by the z parameter?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Stroke not visible through png</title>
      <link>https://forum.processing.org/two/discussion/23212/stroke-not-visible-through-png</link>
      <pubDate>Mon, 26 Jun 2017 11:56:48 +0000</pubDate>
      <dc:creator>frankbass</dc:creator>
      <guid isPermaLink="false">23212@/two/discussions</guid>
      <description><![CDATA[<p>I can't see the stroke of the box() when the png image is in front.
What am I doing wrong?</p>

<pre><code>PImage body1;
int w = 400;    
int h = 200;

void setup() {    
  size(1000, 700, P3D);   
  body1 = loadImage("Basketball.png");    
}

void draw() {    
  background(200);   
  translate(width/2, height/2);   
  float x = map(mouseX, 0, width, -PI/2, PI/2);   
  rotateY(x);

  noFill();   
  box(w, h, w);

  pushMatrix();
  translate(-100, 15);
  scale(.25);    
  image(body1, 0, 0);    
  popMatrix();    
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Simple isometric stuff</title>
      <link>https://forum.processing.org/two/discussion/5037/simple-isometric-stuff</link>
      <pubDate>Sat, 10 May 2014 17:56:51 +0000</pubDate>
      <dc:creator>redraw</dc:creator>
      <guid isPermaLink="false">5037@/two/discussions</guid>
      <description><![CDATA[<p>I've been using ortho() function for isometric projection. It's great. Now I wonder what's the best approach for a simple game.</p>

<p>I have this example,</p>

<pre><code>void setup() {
  size(400, 400, P3D);
  ortho(0, width, 0, height); // same as ortho()
  stroke(255);
  noFill();
}

void draw() {
  //lights();
  background(0);
  translate(width/2, height/2, 0);
  rotateX(-PI/6);
  rotateY(map(mouseX, 0, width, 0, 2*PI));  
  box(width/3);
}
</code></pre>

<p>However, I am rotating the whole canvas. Should I rotate the camera instead? Is there any little advice on how to make an isometric room, considering walls in a future?</p>

<p>You know, when making a 2d grid, you start from the top left generally, so you're attached to that point when rotating for example. would it be convenient to make everything relative to the center of the grid?</p>
]]></description>
   </item>
   <item>
      <title>How to Rotate a 3D "Line" like a 2D "Line"</title>
      <link>https://forum.processing.org/two/discussion/21400/how-to-rotate-a-3d-line-like-a-2d-line</link>
      <pubDate>Tue, 14 Mar 2017 22:22:40 +0000</pubDate>
      <dc:creator>nelsitorocks</dc:creator>
      <guid isPermaLink="false">21400@/two/discussions</guid>
      <description><![CDATA[<p>Hello I am trying to get a 3D "Line" (the "line" is really a box() but you get the idea) I am drawing to rotate around one end the same way a 2D line does. In the example below you can see that the red line which is your standard line() object rotates around one of its points. I would like to get my box() object which is in green to rotate the same way as the red line. 
Any advice would be greatly appreciated.</p>

<pre><code>void setup()
{
  size(640,360,P3D);

}
float n=0;
void draw(){
background(255);
//GREEN LINE
pushMatrix();
stroke(0,255,0);
translate(width/2, height/2);
rotate(n);
box(90,1,1);
popMatrix();

//RED LINE
pushMatrix();
stroke(255,0,0);
translate(width/2, height/2);
rotate(n);
line(0,0,-95,100);
popMatrix();
n=n+0.01;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Rotation cube problem</title>
      <link>https://forum.processing.org/two/discussion/19837/rotation-cube-problem</link>
      <pubDate>Tue, 20 Dec 2016 05:24:08 +0000</pubDate>
      <dc:creator>Spicy</dc:creator>
      <guid isPermaLink="false">19837@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I'm new at processing code and I'm doing a little code for the mouvement of a finger (the index).
I'm doing it with the rotation of phalanges, remplaced by cube.</p>

<p>But I have a big problem,  the third box 's rotation isn't what I want, I don't know how to explain it but here is my code.
How to fix this and have a good  mouvement of index ?
Thanks for the help.</p>

<pre><code>int a = 80;
int z = 0;
int e =50;
int r = 60;
float rot1;//rotation of cube_1
float rot2;//rotation of cube_2
float rot3;//rotation of cube_3




void setup() {
  size(400, 400, P3D);
  smooth();
}

void  draw() {
  background(20, 50, 80);

  //base
  translate(width/4, height/4);
  box(80, 50, 50);
  pushMatrix();
  // 1/2/3
  translate(a, z);//1
  rotateZ(rot1);
  box(r, e, e);
  translate(a, z);//2
  rotateZ(rot2);
  box(r, e, e);

  translate(a, z);//3
  rotateZ(rot3);
  box(r, e, e);
  popMatrix();

  if  (keyPressed == true)
  {
    if (key =='a') {  //Rot1
      rot1 = rot1 + 0.01;
    } else if (key == 'z') {
      rot1 = rot1 - 0.01;
    }

    if (key =='a') { //rot2
      rot2 = rot2 + 0.01;
    } else if (key == 'z') {
      rot2 = rot2 - 0.01;
    }

    if (key =='a') { //rot3
      rot3 = rot3 + 0.01;
    } else if (key == 'z') {
      rot3 = rot3 - 0.01;
    }
  }

  if (rot1 &gt; 1.5) {
    rot1 = 1.5;
  } else if (rot1 &lt; -0.5) {
    rot1 = -0.5;
  }
  if (rot2 &gt; 1.0) {
    rot2 =60;
  } else if (rot2 &lt; 0.0) {
    rot2 = 0.0;
  }
  if (rot3 &gt; 1.5) {
    rot3 = 1.5;
  } else 
  if (rot3 &lt; 0) {
    rot3 = 0;
  }
  println(rot3);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Marker not getting detected to display my digital box</title>
      <link>https://forum.processing.org/two/discussion/15918/marker-not-getting-detected-to-display-my-digital-box</link>
      <pubDate>Fri, 08 Apr 2016 11:55:00 +0000</pubDate>
      <dc:creator>processsingdeven</dc:creator>
      <guid isPermaLink="false">15918@/two/discussions</guid>
      <description><![CDATA[<p>hello everyone.
i m new to processing. i need help with below code.</p>

<h2>what i m trying is that when my camera starts running it should show box as soon as the marker is shown by me for detection. But it does not detect any marker or show any cube.  But camera does start.</h2>

<pre><code>    import jp.nyatla.nyar4psg.*; // NyAR2 library from cpbotha.net for multi markers

    import processing.opengl.*;
    import processing.video.*;

    Capture vid; 
    NyARMultiBoard nya;

    void setup(){
      size(640,480,P3D);

      vid= new Capture(this, 640,480, 30);
      String[] patts= {"patt.kanji"};
      double[] widths= {80};
      nya= new NyARMultiBoard(this, width, height, "camera_para.dat", patts, widths);

      vid.start();
    }


    void draw(){
      background(200);
      vid.read();
      image(vid,0,0);
           if(nya.detect(vid)) // marker detection code starts here
         {
          nya.markers[0].beginTransform();
          box(40);
          nya.markers[0].endTransform();

         }
    } 
</code></pre>
]]></description>
   </item>
   <item>
      <title>would like to program 3d graphic in p5.js/ a simple cube with all the rotations and translations</title>
      <link>https://forum.processing.org/two/discussion/18202/would-like-to-program-3d-graphic-in-p5-js-a-simple-cube-with-all-the-rotations-and-translations</link>
      <pubDate>Sun, 18 Sep 2016 11:23:01 +0000</pubDate>
      <dc:creator>martinpla</dc:creator>
      <guid isPermaLink="false">18202@/two/discussions</guid>
      <description><![CDATA[<p>without any 3d libraries. only code.</p>
]]></description>
   </item>
   <item>
      <title>issues Applying Camera Matrix</title>
      <link>https://forum.processing.org/two/discussion/17977/issues-applying-camera-matrix</link>
      <pubDate>Fri, 26 Aug 2016 04:21:01 +0000</pubDate>
      <dc:creator>bontempos</dc:creator>
      <guid isPermaLink="false">17977@/two/discussions</guid>
      <description><![CDATA[<p>I have a camera matrix extracted from another application.
Currently, if I multiply a 3D point to this matrix, I get the 2D coords correspondent to where that point exists in camera projection plane.</p>

<p>I was trying to use "applyMatrix()" directly. BUT this is flattening everything, meaning object back faces and occluded faces becomes visible. Lights have no effect. stroke and fill get mixed.</p>

<pre><code>PMatrix3D p; 

void setup() {
  size(600, 400, P3D);
}

void draw() {

  float x = map(mouseX, 0, width, -10, 10);
  float z = map(mouseY, 0, height, -10, 10);

 p = new PMatrix3D(
 5.400566, 0.519709, -4.3888016, 193.58757, 
 5.284709, -9.016302, 3.312224, 266.927, 
 0.012042404, 7.253584E-5, 0.0084899925, 1.0, 
 0, 0, 0, 1);

  applyMatrix(p);
  background(20);
  translate(x,0,z);
  fill(100);
  box(10);

}
</code></pre>

<p>second attempt was to apply transformation on PGraphicsOpenGL, but I still couldn't figure out how to do it properly.</p>

<pre><code>PMatrix3D p; 

void setup() {
  size(600, 400, P3D);

  p = new PMatrix3D(
    5.400566, 0.519709, -4.3888016, 193.58757, 
    5.284709, -9.016302, 3.312224, 266.927, 
    0.012042404, 7.253584E-5, 0.0084899925, 1.0, 
    0, 0, 0, 1);

  p.invert();
}

void draw() {

  float x = map(mouseX, 0, width, -200, 200);
  float z = map(mouseY, 0, height, -150, 150);

  //((PGraphicsOpenGL) g).modelview.set(p);
  ((PGraphicsOpenGL) g).camera.set(p);
  //((PGraphicsOpenGL) g).projection.set(p);
  //((PGraphicsOpenGL) g).projmodelview.set(p);

  background(20);
  lights();
  translate(width/2, height/2);
  translate(x, 0, z);
  box(100);
}
</code></pre>

<p>from here: //<a href="https://github.com/processing/processing/issues/2904" target="_blank" rel="nofollow">https://github.com/processing/processing/issues/2904</a>
I got the idea of making a shader but I have never done this before, so I am clueless so far...</p>
]]></description>
   </item>
   <item>
      <title>Smooth Rotation</title>
      <link>https://forum.processing.org/two/discussion/17655/smooth-rotation</link>
      <pubDate>Tue, 26 Jul 2016 18:22:05 +0000</pubDate>
      <dc:creator>johnnyUtah05</dc:creator>
      <guid isPermaLink="false">17655@/two/discussions</guid>
      <description><![CDATA[<p>Hello, 
I am trying to get the boxes in this sketch to rotate smoothly. The goal is to have them rotate smoothly in randomly different directions. I am using millis() for this, but it is maybe not the best solution. 
Thanks.</p>

<pre><code>Cube[] cubes = new Cube[5];

void setup() {
  size(500, 800, P3D);
  frameRate(5); //this is part of the problem
  for (int i = 0; i &lt;cubes.length; i++) {
    cubes[i] = new Cube();
  }
}

void draw() {
  translate(0, 75);
  for (int i = 0; i &lt; cubes.length; i++) {
    background(255);
    cubes[i].display();
  }
}

class Cube {
  float rot;

  public Cube() {
    this.rot = random(PI);
  }

  void display() {
    for (int i = 0; i &lt; 5; i++) {
      int yoff = height/5;
      pushMatrix();
      translate(width/2, i*yoff);
      rotateY(rot*random(-1, 1)*millis()*.01); //not very elegant
      fill(100, 50);
      box(100);
      popMatrix();
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why doesn't P3D work for me ?</title>
      <link>https://forum.processing.org/two/discussion/16098/why-doesn-t-p3d-work-for-me</link>
      <pubDate>Tue, 19 Apr 2016 13:22:03 +0000</pubDate>
      <dc:creator>TheSpectron3</dc:creator>
      <guid isPermaLink="false">16098@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I recently tried to work with P3D and OpenGL on Processing, but for some reason it doesn't let me put the P3D argument in the size function, and says "Declaration must include a precision qualifier or the default precision must have been previously declared", any idea of what's going on ?</p>

<p>this is my (very simple) code that i'm trying to run :</p>

<pre><code>void setup(){
  size(400, 400, P3D);
  background(0);
}

void draw(){
  stroke(255);
  noFill();
  translate(-100, 20, 30);
  box(50);
}
</code></pre>

<p>Thanks !</p>
]]></description>
   </item>
   <item>
      <title>Perspective correction</title>
      <link>https://forum.processing.org/two/discussion/15290/perspective-correction</link>
      <pubDate>Sat, 05 Mar 2016 04:52:18 +0000</pubDate>
      <dc:creator>complic</dc:creator>
      <guid isPermaLink="false">15290@/two/discussions</guid>
      <description><![CDATA[<p>Hi..I am trying to build a mouse coupled perspective with the following sketch.It is doing well in X axis but for nearly the same settings it is totally wrong with Y axis.What is the wrong with it?</p>

<pre><code>int sketch_width=600;
int sketch_height=400;

void setup() {
  size(sketch_width, sketch_height, P3D);
}

void draw() {
  background(100);
  lights();

  float near = 0.1;
  float far = 1000.0;
  float fov = tan( 120 *(PI / 360));
  float ratio = sketch_width / sketch_height;
  float mouse_X;
  float mouse_Y;
  float dis = -200;

mouse_X = ((mouseX/2) / 950.0 * 2.0) - 1.0;
  mouse_Y = ((500.0 - (mouseY/2)) / 500.0 * 2.0) - 1.0;
  mouse_X *= 0.5;
  mouse_Y *= 0.25;

  frustum(near*(-fov * ratio + mouse_X),
               near*(fov * ratio + mouse_X),
               near*(-fov + mouse_Y),
               near*(fov + mouse_Y),
               near, far);



camera( mouse_X * dis, mouse_Y * dis, 0, mouse_X * dis, mouse_Y * dis, -1, 0, 1, 0);
   translate( 0.0, 0.0, dis);

  println(mouseX);


  translate(0,0,0);
  box(50);

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Interactive rotating cube. 3D graph paper (with rules)</title>
      <link>https://forum.processing.org/two/discussion/12955/interactive-rotating-cube-3d-graph-paper-with-rules</link>
      <pubDate>Mon, 12 Oct 2015 04:55:25 +0000</pubDate>
      <dc:creator>Kemware</dc:creator>
      <guid isPermaLink="false">12955@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone. I am a beginner to processing. I would like to:</p>

<ol>
<li>Display a grid of dots. Grid points only. No lines (ex. 90x90)</li>
<li>Allow the user to switch between a 2d and "3D View"</li>
<li>Allow the user to spin, pivot, tilt, rotate the cube using the mouse. (Ex. <a href="http://visjs.org/graph3d_examples.html" target="_blank" rel="nofollow">http://visjs.org/graph3d_examples.html</a>) </li>
<li>Allow the user to zoom in/out using the mouse scroll button. (Ex. <a href="http://visjs.org/graph3d_examples.html" target="_blank" rel="nofollow">http://visjs.org/graph3d_examples.html</a>)</li>
<li>Allow the user to select a dot within in the cube.</li>
<li>Allow the user to left-click on a dot highlighting it (the dot becomes bigger/bold) </li>
<li><p>Allow the user to select a second dot in the same plane connecting a straight line between them. 
Allow the user to go on creating lines in a plane until:</p></li>
<li><p>The user right-clicks a dot in the selected plane and chooses (perhaps from a pop-up/drop-down menu) "degrees of arc" (45, 90, 135).</p></li>
<li><p>Once chosen a straight "arc line" is created between the "arc point" and a landing point in the adjacent plane determined by the angle chosen (i.e 90 degree arc creates a line running along the z axis (perpendicular to the plane) connecting the "arc dot" to the corresponding dot in the above plane (closer to the user). If 45, or 135 degrees the "arc line" will end at one of two points in-between visible grid dots in the above plane.)</p></li>
<li><p>The new plane is automatically selected and any further points (left) clicked will create a line similar to step 7 above (snapping to the nearest grid point (45, 90, 135).</p></li>
</ol>

<p>Optional:</p>

<p>A control panel may be displayed (perhaps at the bottom of the screen) Where:
The user can view/edit the number/color of the highlighted plane. 
The user can highlight the 45/135 grid points within the cube (smaller than initial 90 degree grid dots) 
The user can "take back" previous line creation/dot selections.</p>

<p>I have copied code from two examples I found in the forums here and managed the stitch them together to sort of do the job.</p>

<p>Ive managed to get LINES (not dots) drawn and rotate the shape in 3d however it seems like the grid is made up of separate</p>

<p>boxes all being rotated individually. See code below:</p>

<pre><code>// Below - (Added from rotating cube script) 
float rotx = PI/4;
float roty = PI/4;
float rotz = PI/4;
// Above - (Added from rotating cube script) 

void setup() {
  size(500, 500, P3D);
  strokeWeight(.5);
  stroke(0, 0, 0);
}
void draw() {

  background(152);


  for (int x = 0; x &lt;= height/2; x += 50) {
    for (int y = 0; y &lt;= height/2; y += 50) {
      for (int z = 0; z &lt;= height/2; z += 50) {
        pushMatrix();
        translate(height/4 + x, height/4 + y, -125);

        // Below - (Added from rotating cube script) 
        rotateX(rotx);
        rotateY(roty);
        //scale(90);
        // Above - (Added from rotating cube script) 

        fill(255);
        box(150, 150, 150);
        popMatrix();
      }
    }
  }
}
// Below - (Added from rotating cube script) 
void mouseDragged() {
  float rate = 0.01;
  rotx += (pmouseY-mouseY) * rate;
  roty += (mouseX-pmouseX) * rate;
}
// Above - (Added from rotating cube script) 
</code></pre>

<p>Any help would be appreciated.</p>
]]></description>
   </item>
   <item>
      <title>Why won't it let me use Box(); I am using p3d</title>
      <link>https://forum.processing.org/two/discussion/14851/why-won-t-it-let-me-use-box-i-am-using-p3d</link>
      <pubDate>Thu, 11 Feb 2016 00:57:12 +0000</pubDate>
      <dc:creator>NoraFaithrainbow</dc:creator>
      <guid isPermaLink="false">14851@/two/discussions</guid>
      <description><![CDATA[<p>void Setup(){</p>

<p>size(700,700,P3D);
}</p>

<p>void draw(){
  background(0);</p>

<p>if(mousePressed){// This if statement should allow the user to click and make a box appear 
    pushMatrix();
    translate(mouseX<em>0.01,mouseY</em>0.01);
    rotateX(mouseX);
    rotateY(mouseY);
    box(150);
    popMatrix();
  }
}</p>
]]></description>
   </item>
   <item>
      <title>3D array</title>
      <link>https://forum.processing.org/two/discussion/14691/3d-array</link>
      <pubDate>Sat, 30 Jan 2016 18:09:16 +0000</pubDate>
      <dc:creator>micky</dc:creator>
      <guid isPermaLink="false">14691@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
Anyone has an idea how can we create 3D rectangle array in processing in 3D scene?</p>

<p>Thanks for your help</p>
]]></description>
   </item>
   <item>
      <title>NyARToolkit Activate the same marker twice</title>
      <link>https://forum.processing.org/two/discussion/14718/nyartoolkit-activate-the-same-marker-twice</link>
      <pubDate>Mon, 01 Feb 2016 22:39:21 +0000</pubDate>
      <dc:creator>zanza71</dc:creator>
      <guid isPermaLink="false">14718@/two/discussions</guid>
      <description><![CDATA[<p>hi everybody, someone know how to activate the same marker in a sketch of processing.
I'm trying to make active more than single one marker in the same scene, because I need to create content on the same phisical object taken by the camera.</p>

<p>below the script that I'm trying to modify.</p>

<pre lang="javascript">
import processing.video.*;
import jp.nyatla.nyar4psg.*;

Capture cam;
MultiMarker nya;

void setup() {
  size(640,480,P3D);
  colorMode(RGB, 100);
  println(MultiMarker.VERSION);  
  cam=new Capture(this,640,480);
  nya=new MultiMarker(this,width,height,"camera_para.dat",NyAR4PsgConfig.CONFIG_PSG);
  nya.addARMarker("patt.hiro",80);//id=0
  nya.addARMarker("patt.kanji",80);//id=1
  cam.start();
}

void draw()
{
  if (cam.available() !=true) {
      return;
  }
  cam.read();
  nya.detect(cam);
  background(0);
  nya.drawBackground(cam);
  for(int i=0;i</pre>
]]></description>
   </item>
   <item>
      <title>3D box repeating, how do I get it to not repeat?</title>
      <link>https://forum.processing.org/two/discussion/14260/3d-box-repeating-how-do-i-get-it-to-not-repeat</link>
      <pubDate>Mon, 04 Jan 2016 19:03:28 +0000</pubDate>
      <dc:creator>Hooga</dc:creator>
      <guid isPermaLink="false">14260@/two/discussions</guid>
      <description><![CDATA[<pre><code>PImage myImage;
float x,y,z;
int rotatex, ry, rz = 0;
float newt;

void setup() {  // this is run once.   

  // set the background color
  background(255, 255, 255);

  // canvas size (Integers only, please.)
  size(800, 600, P3D); 

  // smooth edges
  smooth();

  // limit the number of frames per second
  frameRate(50);

  // set the width of the line. 
  strokeWeight(1);
  x = width/2;
  y = height/2;
  z = 0;
} 

void draw() {  // this is run repeatedly. 

translate(x, y, z);
rotateZ(rz);
rotateY(ry);
rotateX(newt);
fill(0, 0, 255);
box(50, 100, 50);
}
</code></pre>

<p>This code right here makes a 3D box that I can edit but it keep making the same box over and over again, how can i make one box and keep it there without it making another box? I tried putting it on setup but it didnt work.</p>
]]></description>
   </item>
   <item>
      <title>How to rotate a box with changing angular velocity</title>
      <link>https://forum.processing.org/two/discussion/14109/how-to-rotate-a-box-with-changing-angular-velocity</link>
      <pubDate>Tue, 22 Dec 2015 03:20:00 +0000</pubDate>
      <dc:creator>KYama</dc:creator>
      <guid isPermaLink="false">14109@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am trying to rotate a box with the angular velocity set in array. The data is</p>

<pre lang="text">
(Time)   (X-axis)         (Y-axis)      (Z-axis)
0        -0.00478796     -0.017262705  -0.002968556
1.7      -0.006942641    -0.020502579  -0.004041603
...
</pre>

<p>Now, the box is rotating with the data in the first row, but I want to add each data like this.</p>

<pre lang="text">
step1 X += -0.00478796
step2 X += -0.006942641
...
</pre>

<p>Could you give me an advice? And thank you!</p>

<pre lang="processing">
int tsvWidth = 0;
int LENGTH;
String [][] tsv;
float t, rotX, rotY, rotZ, X, Y, Z;

void setup() {
  size(800, 800, P3D);
  frameRate(20);
  smooth();

  String lines [] = loadStrings("Satelite_time_Axis_1_Axis_2_Axis_3.txt");

  //calculate max width of tsv file
  for (int i=0; i &lt; lines.length; i++) {
    String [] chars  =  split(lines[i], TAB); //split by TAB, not comma
    if (chars.length &gt; tsvWidth) {
      tsvWidth = chars.length;
    }
  }

  //create tsv array based on # of rows and columns in csv file
  tsv    = new String [lines.length][tsvWidth];
  LENGTH = lines.length; 
  println(LENGTH);
  //parse values into 2d array
  for (int i = 0; i &lt; lines.length; i++) {
    String [] temp = new String [lines.length];
    temp = split(lines[i], TAB);
    for (int j = 0; j &lt; temp.length; j++) {
      tsv[i][j] = temp[j];
    }
  }
}


void draw() {
  background(0);
  println(X, Y, Z);
  renderBox();
  X += Float.parseFloat(tsv[0][1]);
  Y += Float.parseFloat(tsv[0][2]);
  Z += Float.parseFloat(tsv[0][3]);
}

void renderBox() {
  pushMatrix();
  translate(width/2, height/2, 0.0);
  rotateX(X); 
  rotateY(Y); 
  rotateZ(Z);
  fill(128);
  box(400);
  popMatrix();
}
</pre>
]]></description>
   </item>
   <item>
      <title>Matrix Transformation Question</title>
      <link>https://forum.processing.org/two/discussion/13723/matrix-transformation-question</link>
      <pubDate>Tue, 01 Dec 2015 11:55:11 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">13723@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I'm trying to complete this exercise which involves controlling an avatar through a forest using matrix transformation.
However when I press the Space button to move the view back to the camera (as opposed to FPV) I can't get it to follow the avatar.</p>

<p>Could someone please point me in the right direction?</p>

<p>Many thanks,
Charles</p>

<pre><code>//Avatar eye height
int viewHeight = 100;

//matrix to capture position and orientation of match
PMatrix3D eye = new PMatrix3D();

Boolean record = false;
Boolean view = true;

int treeCount = 400;
float[] treeX = new float[treeCount];
float[] treeY = new float[treeCount];
float [] treeH = new float[treeCount];

void setup()
{
  //3D rendering
  size(700, 500, P3D);
  //white fill
  fill(255);
  strokeWeight(0.5);

  //translate eye matrix
  eye.translate(100, 100, viewHeight);
  eye.rotate(PI/6);

  //initialize tree position and height
  for (int i = 0; i &lt; treeCount; i++) {
    treeX[i] = random(width*-5, width*5);
    treeY[i] = random(width*-5, width*5);
    treeH[i] = random(200, 1000);
  }
}

void draw()
{  
  background(255);
  camera(500, 0, 200, 0, 0, 125, 0, 0, -1);

  /*
        Create a new matrix to transform the ****whole scene****
   except the match, which we're not drawing
   because we're in the head of the match!
   */
  PMatrix3D camera = new PMatrix3D();

  //(when we apply this, it will) drag the origin up to the camera
  camera.translate(500, 0, 200);

  /*
        Invert the match transformation; or, move the whole scene
   so the origin is at the avatar and it's
   */
  PMatrix3D inv =  new PMatrix3D(eye);
  inv.invert();
  camera.apply(inv);

  if (view) { // FPV state
    applyMatrix(camera);
    for (int i = 0; i &lt; treeCount; i++) {
      drawTree(treeX[i], treeY[i], treeH[i]);
    }
    drawGrid();
  } else { // camera state
    for (int i = 0; i &lt; treeCount; i++) {
      drawTree(treeX[i], treeY[i], treeH[i]);
    }

    drawGrid();
    applyMatrix(eye);
    avatar();
  }

  recordFrames();
  movements();
}

void drawGrid() {
  //how far should the lines go?
  int horizon = width*5;
  //line separation
  int sep = 100;

  stroke(100);
  for (int i=-horizon; i&lt;horizon; i += sep)
  {
    //lines in x-direction
    line(horizon, i, -horizon, i);
    //lines in y-direction
    line(i, -horizon, i, horizon);
  }
}

//create a simple avatar
void avatar() {

  noStroke();
  fill(200);
  pushMatrix();
  sphere(20);
  //start at the top - translate down half the height of the match
  translate(0, 0, -viewHeight/2);
  //draw the stick
  fill(150);
  box(20, 20, viewHeight);
  popMatrix();
}

void keyPressed() {

  if (key=='f') saveFrame("images/image.png");
  if (key=='r') record = !record;
  if (key==' ') view = !view;
}

void movements() {
  if (keyPressed &amp;&amp; keyCode==LEFT) eye.rotateZ(-0.05);
  if (keyPressed &amp;&amp; keyCode==RIGHT) eye.rotateZ(0.05);
  if (keyPressed &amp;&amp; keyCode==UP) eye.translate(-10, 0, 0);
  if (keyPressed &amp;&amp; keyCode==DOWN) eye.translate(10, 0, 0);
}

void recordFrames() {
  if (record) saveFrame("frame_#####.png");
}

void drawTree(float x, float y, float h) {

  noStroke();
  fill(#715448);
  pushMatrix();
  translate(x, y, h/2);
  box(h*0.06, h*0.03, h);
  popMatrix();
  pushMatrix();
  translate(x, y, h);
  fill(#7EFF8C);
  sphere(h*0.3);
  popMatrix();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to draw a box (just a frame ) the frame bulit by boxes in 3D processing?</title>
      <link>https://forum.processing.org/two/discussion/11675/how-to-draw-a-box-just-a-frame-the-frame-bulit-by-boxes-in-3d-processing</link>
      <pubDate>Mon, 13 Jul 2015 21:41:35 +0000</pubDate>
      <dc:creator>irish</dc:creator>
      <guid isPermaLink="false">11675@/two/discussions</guid>
      <description><![CDATA[<p>how to draw a box (just a frame ) in 3D processing? the box is (20,20,20)</p>
]]></description>
   </item>
   <item>
      <title>Cross section of 3d shape</title>
      <link>https://forum.processing.org/two/discussion/11544/cross-section-of-3d-shape</link>
      <pubDate>Thu, 02 Jul 2015 12:06:33 +0000</pubDate>
      <dc:creator>Fridolin</dc:creator>
      <guid isPermaLink="false">11544@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to get a cross section of a 3d shape from any given Z position.
My current sketch only shows the top and bottom plane.</p>

<pre><code>void setup() {
  size(400, 400, P3D);
  ortho();
}

void draw() {
  background(0);
  translate(200, 200, 145);
  box(200);
  ortho(0, width, 0, height, mouseY, mouseY + 1);
}
</code></pre>

<p>What would be the correct way to do this?</p>
]]></description>
   </item>
   <item>
      <title>Why is this Python code not working?</title>
      <link>https://forum.processing.org/two/discussion/10604/why-is-this-python-code-not-working</link>
      <pubDate>Fri, 01 May 2015 01:26:52 +0000</pubDate>
      <dc:creator>JamesWlf</dc:creator>
      <guid isPermaLink="false">10604@/two/discussions</guid>
      <description><![CDATA[<p>This is from the excellent book "Algorithms for Visual Design Using Processing". It's a simple code to draw a cube on the screen and then paint it red when clicking on it. There is no error, but the cube doesn't change color. What am I doing wrong?</p>

<pre><code>add_library('peasycam')

class MyObject(object):
    dim = 40
    x =0
    y=0
    z = 0
    picked = False
    c_face = color(255)


    def pick (self, xp, yp):
        if (dist(xp,yp,screenX(x,y,z), screenY(x,y,z))&lt;dim):
            MyObject.picked = True
        else:
            MyObject.picked = False

    def draw3(self):
        if (MyObject.picked == True):
            fill(255,0,0)
        else:
            fill(MyObject.c_face)
        box(MyObject.dim)

b =  MyObject()

def setup():

    size(200,200,P3D)
    #PeasyCam(this,100)
    camera(-100,100,-100,0,0,0,0,0,1)

def draw():

    b.draw3()

    def mousePressed():
        b.pick(mouseX,mouseY)
</code></pre>
]]></description>
   </item>
   <item>
      <title>Rotation function not working correctly</title>
      <link>https://forum.processing.org/two/discussion/8914/rotation-function-not-working-correctly</link>
      <pubDate>Tue, 06 Jan 2015 17:13:27 +0000</pubDate>
      <dc:creator>lukeP</dc:creator>
      <guid isPermaLink="false">8914@/two/discussions</guid>
      <description><![CDATA[<p>So I have this rotation function, <code>rotate2D(horizontal, vertical)</code> that you can see and play with in the below sketch.</p>

<p>I am using it to try to correctly simulate simultaneous rotation of a cube in multiple dimensions at once. (processing's standard rotation functions make this tricky)</p>

<p>It works okay, but it is a little bit off, which causes it to be glitchy sometimes. For example, if you do <code>rotate2D(90,90);</code> I want it to look just like it does if you do <code>rotate2D(0,0);</code>(disregarding the position of the axes) but it seems like X and Y don't quite get rotated enough. For example if youare doing a 90 90 rotation and you change the test condition on line 51 to <code>i&lt;=abs(rotations[0])+37</code> you get what you expect.</p>

<p>please feel free to ask me to clarify further. Can anyone help me out?</p>

<pre><code>float y=0;
float x=0;
float box_size=50.0;
float rotation_scale=(90.0/50.0);
void setup()
{
  size(1000,1000,P3D);
}    

void draw()
{

   background(255);
   translate(500,500);
   translate(x*rotation_scale,-y*rotation_scale);
   rotate2D(x,y);
   x++;
   y++;      
  draw_axes();
  box(box_size);
}

void draw_axes()
{
    stroke(255,0,0);
    line(0,-250,0,250);
    stroke(0,250,0);
    line(-250,0,250,0);
    stroke(0,0,255);
    line(0,0,-250,0,0,250);
    stroke(0);
}

void rotate2D(float horizontal, float vertical)
{  
  float[] rotations ={horizontal, vertical};
  if(rotations[0]&gt;rotations[1])
  {
    float tmp = rotations[1];
    rotations[1]=rotations[0];
    rotations[0]=tmp;
  } 

  if(rotations[1]==vertical) rotateX(radians(rotations[1]-rotations[0]));
  else rotateY(radians(rotations[1]-rotations[0]));

  float hIncr= (horizontal&lt;0) ? -0.1 : 0.1;
  float vIncr= (vertical&lt;0) ? -0.1 : 0.1;
  for(float i=0; i&lt;=abs(rotations[0]);i+=0.1)
  {    
    rotateY(radians(hIncr));
    rotateX(radians(vIncr));
  }   
}
</code></pre>

<h2>Edit for clarity</h2>

<p>The point of this function is to try to create semi-realistic, visually appealing rotation of a box given movement in a particular direction. Although, in this case, I am deciding the rotations first and then translating accordingly, just for simplicity.</p>

<p><strong>Explanation of <code>horizonal</code> and<code>vertical</code> parameters and their meaning:</strong></p>

<p>To get an idea of the exact significance of these parameters and their meanings, try calling the function with one of the values set to zero.</p>

<p>calling <code>rotate2D(45,0)</code> causes the box to rotate to the right but not upwards.</p>

<p>calling <code>rotate2D(0,45)</code> causes the box to rotate upwards but not to the right.</p>

<p>These results can be achieved by simply calling <code>rotateY(45)</code> and <code>rotateX(45)</code> respectively, however, if you want to rotate in 2 directions simultaneously, simply calling these  functions will likely not yield a desirable result because once you rotate about the Y axis, the X axis itself has been rotated. I am trying to simulate the rotation about a fixed set of axis, by slowly rotating in each direction until the bounds are reached. And it <strong>does</strong> yield a desirable rotation but It seems like the box is just not rotating enough given each parameter. I'm looking for a way to correct this while still yielding the same general rotational pattern.</p>

<p>In response to quark: I am aware that the box just rolls off of the screen, I was just providing a template for people to play around with the increments to see the way the rotation was affected.</p>

<p>The reason I have it at x++; y++; is because, (because of the problem I am trying to solve here) this increment pattern gives the best results currently, but even this is not perfect as you can see it glitch sometimes.</p>
]]></description>
   </item>
   <item>
      <title>Picking 3D without lib - but peasyCam and lights() - wth?</title>
      <link>https://forum.processing.org/two/discussion/5924/picking-3d-without-lib-but-peasycam-and-lights-wth</link>
      <pubDate>Sat, 21 Jun 2014 06:21:18 +0000</pubDate>
      <dc:creator>Chrisir</dc:creator>
      <guid isPermaLink="false">5924@/two/discussions</guid>
      <description><![CDATA[<p>hello all,</p>

<p>simple question, but I couldn't find anything about it.</p>

<p>I want to do a Picking with 3D boxes.</p>

<p>I don't want to use the shapes lib.</p>

<p>All boxes have different colors, So I just wanted to take the color via get(mouseX, mouseY), bu I realized that doesn't work since I use lights().</p>

<p>Then I decided to draw everything in a second PGraphics and do the get(mouseX, mouseY) there - but since I use peasyCam, the boxes on the screen and in PGraphics don't match. So it doesn't work.</p>

<p>So my question here is: How can I do a picking without lib but with lights() and peasyCam in use?</p>

<p>Or in other words: How can I impose peasyCam on my PGraphics?</p>

<p>(or can I use modelX etc. and use it to paint my boxes in my PGraphics?)</p>

<p>Thank you all!</p>

<p>Greetings, Chrisir  ;-)</p>

<ul>
<li><p>part of my class:</p>

<p>void display() {</p>

<pre><code>noStroke();
stroke(0);
fill(boxFillColor);

if (selected) {  // only outline
  noFill();
  strokeWeight(2);
  stroke(boxFillColor);
}

if (allNoFill) { // only outline
  noFill();
  strokeWeight(2);
  stroke(boxFillColor);
}

//pg.beginDraw();
pg.pushMatrix();
pg.fill(boxFillColor);
pg.noStroke();
pg.translate (Position.x, Position.y, Position.z);
pg.box ( boxSize.x );
pg.popMatrix();
// pg.endDraw();

// the box
pushMatrix(); 
translate (Position.x, Position.y, Position.z);
    box ( boxSize.x ); 

    popMatrix();

}
</code></pre></li>
</ul>
]]></description>
   </item>
   </channel>
</rss>