<?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 camera() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=camera%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:57:33 +0000</pubDate>
         <description>Tagged with camera() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedcamera%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Shapes 3D library camera doesn´t focus whole composition</title>
      <link>https://forum.processing.org/two/discussion/8039/shapes-3d-library-camera-doesn-t-focus-whole-composition</link>
      <pubDate>Mon, 10 Nov 2014 00:37:06 +0000</pubDate>
      <dc:creator>Marc21758</dc:creator>
      <guid isPermaLink="false">8039@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys, well i´ve been using the Shapes3D library, y downloaded a sketch for a tunnel and used the examples from the library, this example had 2 java codes added, it showed me the tunnel full at the display but didn´t let me add images, use the displayWidth and displayHeight commands or use present ir at full screen, so i took out the java codes added, now it works perfectly, but doesn´t get the whole tunel just the center of it, like if the camera had smaller vision o was far from the composition. I´ve tried everything, closing up the camera, scaling, making bigger the tunnel, nothing works.</p>

<pre><code> /* OpenProcessing Tweak of *@*<a href="http://www.openprocessing.org/sketch/25597*@*" target="_blank" rel="nofollow">http://www.openprocessing.org/sketch/25597*@*</a> */
        /* !do not delete the line above, required for linking your tweak if you upload again */
        import shapes3d.utils.*;
        import shapes3d.animation.*;
        import shapes3d.*;

        int enviar=0;

        // Path dependent variables
        I_PathGen[] path;
        int nbrPaths = 1;
        int currPath = 0;
        float[] speedFactor;

        // The tubes
        PathTube atube, wtube;
        int tubeType = 0;
        int nbrTubeTypes = 2;
        final int SLICES = 300, SEGMENTS = 8;

        // The shuttle
        //Toroid train;
        Box[] bcar;
        final int nbrBoxCars = 0;

        // Used for train/car orientation to the tube
        final PVector FORWARD_AXIS = new PVector(0, 1, 0);
        final PVector LEFT_AXIS = new PVector(-1, 0, 0);
        final PVector RIGHT_AXIS = new PVector(0, 0, -1);
        PVector normal, tangent, position;
        PVector camPos, camLookAt, camUp;
        Rot rot;
        float[] ang;

        // SHUTTLE SPEED CONTROL VARIABLES
        float speed = 0.06, pathFactor = 1, elapsed;
        float paraT = 0.5;  // starting position on curve
        float camParaT;
        long st, ct;      // keep track of running time


        void setup() {

          size(1280, 690, P3D);
          // Create the path generator
          //  path = new Tube (this,4,6);
          path = new I_PathGen[nbrPaths];

          // hacer una clase para definir el parámetro 
            path[0] = new Lissajous(1, 1, 1);
          speedFactor = new float[nbrPaths];

          // Create the tube
          atube = new PathTube(this, path[currPath], 40, SLICES, 35, false); 
          atube.drawMode(Shape3D.SOLID);
          atube.visible(false, Shape3D.BOTH_CAP);


          // Create path cage
          wtube = new PathTube(this, path[currPath], 38, (SLICES/2), 8, true);
          wtube.stroke(color(120, 120, 255));
          wtube.strokeWeight(1);
          wtube.drawMode(Shape3D.WIRE); // estructura alámbrica 
          wtube.visible(false, Shape3D.BOTH_CAP);


          // Initialise spacing and speed factors
          float l = atube.length(400); 
          speedFactor[currPath] = 800 / l;

          // Create the box cars
          bcar = new Box[nbrBoxCars];
          for (int i = 0; i &lt; nbrBoxCars; i++) {
            bcar[i] = new Box(this, 0);
          }
          // Initialise times
          st = ct = millis();
        }

        void draw() {
         // scale(10,10,10);
          background(16);
          lights();
          // Used to get frame-rate independent speed
          ct = millis();
          //image(img, 0, 0);
          elapsed = (ct - st)/1000.0;
          st = ct;
          paraT += elapsed * speed * speedFactor[currPath];
          paraT = (paraT &gt; 1) ? paraT-1 : paraT;
          normal = atube.getNormal(paraT);
          tangent = atube.getTangent(paraT);
          position = atube.getPoint(paraT); 

          // Calculate camera position to move with the shuttle
          normal.normalize();
          camUp = PVector.mult(normal, -1);
        println (camLookAt);
          camParaT = paraT - 0.0;
          camParaT = (camParaT &gt; 1) ? camParaT: camParaT;
          camPos = atube.getPoint(camParaT);
          camPos.add(camUp);


          camLookAt = PVector.mult(tangent, 90); 
          camLookAt.add(camPos);

          camera(camPos.x, camPos.y, camPos.z, 
          camLookAt.x, camLookAt.y, camLookAt.z, 
          camUp.x, camUp.y, camUp.z);

          float bparaT = paraT;
          for (int i = 0; i &lt; nbrBoxCars; i++) { 
            bparaT = (bparaT &lt; 0) ? bparaT + 1 : bparaT;
            normal = atube.getNormal(bparaT);
            position = atube.getPoint(bparaT);
            rot = new Rot(FORWARD_AXIS, RIGHT_AXIS, tangent, normal);
            ang = rot.getAngles(RotOrder.XYZ);
            bcar[i].moveTo(position);
            bcar[i].rotateTo(ang);
            bcar[i].draw();
          }
          wtube.draw();
          atube.draw();
        }

        void keyReleased() {
          // Adjust speed
          if (key &gt;= '0' &amp;&amp; key &lt;= '9') {
            speed = (key - 48) / 50.0;
          }
        }
</code></pre>

<p><img src="http://forum.processing.org/two/uploads/imageupload/174/JTXZRT7208JN.JPG" alt="actual_view" title="actual_view" />
<img src="http://forum.processing.org/two/uploads/imageupload/905/EN2CSKZRF32M.JPG" alt="view_needed" title="view_needed" /></p>
]]></description>
   </item>
   <item>
      <title>Can't get camera() to work the way I want it to.</title>
      <link>https://forum.processing.org/two/discussion/27815/can-t-get-camera-to-work-the-way-i-want-it-to</link>
      <pubDate>Sat, 21 Apr 2018 11:15:47 +0000</pubDate>
      <dc:creator>GameMaker123</dc:creator>
      <guid isPermaLink="false">27815@/two/discussions</guid>
      <description><![CDATA[<p>I want to use camera() in a way that allows me to rotate the camera properly. I want you to make 2 functions; 1 that converts pitch, yaw, and roll into x, y, and z for the eye variables, and another that takes the same variables and produces x, y, and z, for the up variables. Use PVector for the return types.</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>Rotate a camera around Z axis</title>
      <link>https://forum.processing.org/two/discussion/27716/rotate-a-camera-around-z-axis</link>
      <pubDate>Sat, 07 Apr 2018 14:48:48 +0000</pubDate>
      <dc:creator>Paganoni</dc:creator>
      <guid isPermaLink="false">27716@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody !</p>

<p>I'm having big problems to understand the maths behind camera rotation for short animations of terrain or planet flight by (like a kind of spatial vessel)</p>

<p>Following Daniel Shifman's lessons about vector I use vectors for position, velocity, acceleration and lookAt (and later implement applyForce to velocity to create some nice camera movements)
I use the Processing camera() method</p>

<p>It's very basic but it works, except concerning rotations. I want my camera to rotate on Z axis and I really don't know how to do. It's not as simple as calling rotateZ(rad_angle)</p>

<p>I don't rotate on X or Y axis because I presume I should be able to achieve rotations by computing a new lookAt vector correctly.</p>

<p>Is the solution to play_with/compute/tweak the up vector ? And how ? I'm totally at loss...</p>

<p>Note : I've digged into quesycam, peasycam, OCD but that not helped me that much - and frankly I really want to code my own Camera class from a learning point of view.</p>

<p>Note 2 : sorry if this post is not very clear, that's very hard to formulate questions about a confusing subject ;-)</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>First person camera problem</title>
      <link>https://forum.processing.org/two/discussion/26671/first-person-camera-problem</link>
      <pubDate>Tue, 06 Mar 2018 13:14:04 +0000</pubDate>
      <dc:creator>mothersmilkk</dc:creator>
      <guid isPermaLink="false">26671@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys, i'm trying to implement a first person camera for a little program i'm writing. I actually did implement the camera (it works with differentials and spherical coordinates) and it's doing quite well except for a problem. As i look around the scene (move my mouse), the cursor will eventually fall off the screen and of course stop working. How can i fix that? Here is my code:</p>

<pre><code>void updateCamera(){

    this.horizontalAngle += (mouseX - pmouseX)/100f;
    this.verticalAngle -= (mouseY - pmouseY)/100f;

    if(this.verticalAngle &lt; -PI+0.1)
      this.verticalAngle = -PI+0.1;
    if(this.verticalAngle &gt; 0)
      this.verticalAngle = 0;

    centerX = this.pos.x + cos(horizontalAngle) * sin(verticalAngle);
    centerY = this.pos.y + sin(horizontalAngle) * sin(verticalAngle);
    centerZ = this.pos.z + cos(verticalAngle);

    camera(this.pos.x, this.pos.y, this.pos.z, this.centerX, this.centerY, this.centerZ, 0, 0, -1);

}
</code></pre>

<p>I tried the robot class with <code>robot.mouseMove();</code> to set the mouse to center every time i move it, but in this way my camera gets locked. Suggestions? Thank you!</p>
]]></description>
   </item>
   <item>
      <title>virtual reality</title>
      <link>https://forum.processing.org/two/discussion/26758/virtual-reality</link>
      <pubDate>Sat, 10 Mar 2018 19:58:42 +0000</pubDate>
      <dc:creator>_igo_r_</dc:creator>
      <guid isPermaLink="false">26758@/two/discussions</guid>
      <description><![CDATA[<p>How to create a simple program with virtual reality object using camera, which allows you to look at it from different angles?
I just can't find the solution</p>
]]></description>
   </item>
   <item>
      <title>Why is my "If" not working?</title>
      <link>https://forum.processing.org/two/discussion/26689/why-is-my-if-not-working</link>
      <pubDate>Wed, 07 Mar 2018 12:01:58 +0000</pubDate>
      <dc:creator>iWiKKiD</dc:creator>
      <guid isPermaLink="false">26689@/two/discussions</guid>
      <description><![CDATA[<p>Hey there,</p>

<p>Im pretty new to software coding (even tho i come from PLC programming) i ran into a problem using a simple if function.
This code creates a mesh out of boxes and you can move through it with your keys W and S. I wanted to loop the cameraposition somewhere around camZ=9000 using a the If in line 29 but it just wont work and i dont know why. It is supposed to substract one box size, once the camZ value goes over the bounce value. Can someone explain why it doesnt work?</p>

<p>Here is my code:</p>

<pre><code>void setup() {

  fullScreen(P3D);

  translate(width/2, height/1, 0);
  stroke(255);
  noFill();
}

int size = 14;
int boxes = 1000;
float camX = boxes*size/2;
float camY = boxes*size/2*-1;
float camZ = boxes*size/30*-1;
float camM = 0;
float loopval = 9000.0;

void draw() {

  int size = 14;
  int boxes = 1000;
  float camP = camM+camZ;
  println(camP);
  println(frameRate);
  background(120);

  if (camZ &gt; loopval) {
    camZ = loopval - boxes*3;
  } else {
  }

  if (keyPressed) {
    if (key == 'w' || key == 'W') {
      camM = camM-50;
    }
  } 

  if (keyPressed) {
    if (key == 's' || key == 'S') {
      camM = camM+50;
    }
  }

  camera(camX, camY, camZ+camM, // eyeX, eyeY, eyeZ
    camX, camY, 0.0, // centerX, centerY, centerZ
    0.0, 1.0, 0.0); // upX, upY, upZ

  for (int i3 = 0; i3 &lt; size; i3 = i3+1) 
  {
    for (int i2 = 0; i2 &lt; size; i2 = i2+1) //Y row
    {
      for (int i = 0; i &lt; size; i=i+1) //X row
      {
        box(boxes);
        translate(boxes, 0, 0); //X
      }
      translate(boxes*size*-1, 0, boxes); //Y
    }
    translate(0, boxes*-1, boxes*size*-1); //Z
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>3D First Person Camera - Walking around</title>
      <link>https://forum.processing.org/two/discussion/22233/3d-first-person-camera-walking-around</link>
      <pubDate>Wed, 26 Apr 2017 20:17:34 +0000</pubDate>
      <dc:creator>MaxR18</dc:creator>
      <guid isPermaLink="false">22233@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>Iv'e been trying to get a first person camera up and running. Walk with WASD and click and hold mouse to steer direction. 
Ive setup a "room" with some paintings. When you first start to walk its seems okay. But try walk close to a painting and the stand still and rotate the camera. What should happen: You turn around and can see the other paintings further away. What happens: The "room" rotates instead of the camera turning. It's easier to understand if you walk backwards, out of the "room" and rotate with the mouse. Youll then see how the room rotates like a carousel, instead of the camera turning away from the room. 
Run it here: <a rel="nofollow" href="https://maximilian-r.github.io/first-person-camera/">https://maximilian-r.github.io/first-person-camera/</a> . The goal is to create an interactive 3D-presentation for my final essay in school. The paintings will be switched to powerpoint-slide images later on.</p>

<p>Sketch and camera script available here: <a rel="nofollow" href="https://github.com/Maximilian-R/first-person-camera">https://github.com/Maximilian-R/first-person-camera</a></p>

<p>Ive spent tens of hours trying to solve this. I did try another alternativte to skip the p5 camera function, and instead translate all the paintings I draw according to how I "walk". It worked better, as you turned the camera you turned around and saw the other paintings further away. However, it felt like the camera position was too far ahead and you didnt walk in the direction you was looking with forward "W".</p>

<p>Any ideas?</p>
]]></description>
   </item>
   <item>
      <title>Clipping planes in ortho()</title>
      <link>https://forum.processing.org/two/discussion/23744/clipping-planes-in-ortho</link>
      <pubDate>Tue, 08 Aug 2017 08:04:03 +0000</pubDate>
      <dc:creator>Tim</dc:creator>
      <guid isPermaLink="false">23744@/two/discussions</guid>
      <description><![CDATA[<p>If you rotate the cube at the link to vertical, then it gets clipped out of the scene - can anyone help me understand why? I can't seem to find much in the help documentation.</p>

<p><a href="https://www.openprocessing.org/sketch/442987" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/442987</a></p>

<p>I am thinking perhaps I need to update the clipping planes when the camera moves?</p>

<pre><code>camera(eye.x,eye.y,eye.z,focus.x,focus.y,focus.z,0,0,-1);
scale(zoom);
</code></pre>

<p>Thank you :)</p>
]]></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>Copy a 3D PGraphics? (Processing.js)</title>
      <link>https://forum.processing.org/two/discussion/21131/copy-a-3d-pgraphics-processing-js</link>
      <pubDate>Fri, 03 Mar 2017 16:17:55 +0000</pubDate>
      <dc:creator>cems</dc:creator>
      <guid isPermaLink="false">21131@/two/discussions</guid>
      <description><![CDATA[<p>Rationale:  The problem I'm trying to solve is I want to rotate a camera around to show different viewpoints on a complex 3D surface that is very time expensive to redraw.  But it's not changing it's shape.  Thus I'd like to draw it once then rotate the camera (or it) and then just generate images to show on the screen.</p>

<pre><code>pattern:
t = createGraphics(size and stuff)
&lt;fill it with a TRIANGLE_STRIP surface&gt;
draw() {
  camera( changing parameters go here )
  image( t,  more_parameters)
}
</code></pre>

<p><strong>What I expected</strong> was the image to show a rotating object as the camera is changed.</p>

<p><strong>What happens:</strong> I just the very first image perpetually, then nothing changes.</p>

<p>If instead I put the creation and triangle_strip drawing into the draw loop so it is redrawn every time then I get what I expect to see but of course I'm having to recreate the 3D object every time.</p>

<p>Regression:  My wild guess here is that calling Image is forcing some delayed lazy rendering of the graphics, and then subsequent calls do not re-render the image even if the graphics was  rotated.  Somehow this would seem like a lousy behaviour so I'm sort of doubting this theory.  But I can't think of another one</p>

<p>I've tried using the following two commands to see based on the guess that I might be able to reset some lazy image creation flag to it wold recreate the image but these did not work-- get errors:</p>

<pre><code>//t.Image.setLoaded(false);
//t.updatePixels() ;
</code></pre>

<p>So Maybe that guess is incorrect.</p>

<p>But if this sticky on-time rendering hypothesis. correct then maybe a solution would be to copy the graphics object before I display it so I can keep an unrendered copy.</p>

<p>if so then the problem becomes:</p>

<p>**Problem: ** how to duplicate a 3D PGraphics Object.</p>

<p>Note: <strong>this is 3D not 2D</strong>, so it's not the same as simply copying the pixels from one image to another.</p>
]]></description>
   </item>
   <item>
      <title>Plot camera course and make it glide from one point to the other</title>
      <link>https://forum.processing.org/two/discussion/19993/plot-camera-course-and-make-it-glide-from-one-point-to-the-other</link>
      <pubDate>Fri, 30 Dec 2016 11:09:00 +0000</pubDate>
      <dc:creator>abulgako</dc:creator>
      <guid isPermaLink="false">19993@/two/discussions</guid>
      <description><![CDATA[<p>As the title says I am trying to plot a certain course for a camera to move around a 3D space. In a way that after a certain amount of time it would glide from the first plotted XYZ to another one.</p>

<p>I've looked up moveEye examples and believe it is not what I am looking for. I was just wondering if anyone could direct me towards a resource, a library or generously throw some code at me.</p>

<p>Much appreciated.</p>
]]></description>
   </item>
   <item>
      <title>How to align an axis with a vector?</title>
      <link>https://forum.processing.org/two/discussion/19036/how-to-align-an-axis-with-a-vector</link>
      <pubDate>Mon, 14 Nov 2016 17:26:59 +0000</pubDate>
      <dc:creator>Hersherlock</dc:creator>
      <guid isPermaLink="false">19036@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone!
I'm stuck on a problem, and I don't think there's a simple answer (or any answer at all) so that's why I'm asking you.</p>

<p>Here's the problem: I've got a 3D vector. I'd simply like to rotate the system to align an axis (the z axis for instance) with my vector.
I've tried to do it with <code>rotateX()</code> and <code>rotateY()</code> but it didn't work.
That would be pretty easy if, like with the <code>camera()</code> function, you'd be able to just set the direction to face.
I was looking for a function that would do the job, but I didn't find anything (did I miss it?).</p>

<p>Thank you for your help!</p>
]]></description>
   </item>
   <item>
      <title>How to find or change Processing3+ camera angle of view and focal length?</title>
      <link>https://forum.processing.org/two/discussion/18695/how-to-find-or-change-processing3-camera-angle-of-view-and-focal-length</link>
      <pubDate>Mon, 24 Oct 2016 22:39:30 +0000</pubDate>
      <dc:creator>ricardoscholz</dc:creator>
      <guid isPermaLink="false">18695@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>I'm working with a P3D render and having trouble to compute the actual width which will fit in my monitor on a given plane (the monitor/screen plane) perpendicular to the camera axis, when I get closer or further away from that plane, moving the camera through the perpendicular axis.</p>

<p>(<a href="https://forum.processing.org/two/uploads/imageupload/507/2HZHUOVM4KRL.png" target="_blank" rel="nofollow">https://forum.processing.org/two/uploads/imageupload/507/2HZHUOVM4KRL.png</a> "Problem Description")</p>

<p>Considering the code I created below to illustrate my problem (Java class), I would like to print the rectangle always coinciding with the border of the screen, but on the z=0 plane, no matter what my "eye" variable value is (as far as it is positive).</p>

<pre><code>import processing.core.PApplet;
import processing.core.PConstants;

public class CameraTest extends PApplet {

    private static final int CAMERA_EYE = 900;

    //camera distance from the x,y plane, over z axis
    private float eye = CAMERA_EYE; 

    public void setup() {
        super.frameRate(30);
        super.background(0xFFFFFFFF);
    }

    public void settings() {
        super.fullScreen(PConstants.P3D);
    }

    public void draw() {
        super.background(0xFFFFFFFF);
        //adjusting camera
        super.beginCamera();
        super.camera(
                super.displayWidth/2, super.displayHeight/2, this.eye, //eye in middle of the screen, custom distance
                super.displayWidth/2, super.displayHeight/2, 0, //scene center at middle of the screen, in xy plane (z = 0)
                0, 1, 0); //camera up side on y axis
        super.endCamera();

        //drawing the monitor borders, using 3D lines (z = 0)
        super.stroke(0xFFFF0000);
        super.strokeWeight(4);
        //upper line
        super.line(0, 0, 0, super.displayWidth, 0, 0);
        //botton line
        super.line(0, super.displayHeight, 0, super.displayWidth, super.displayHeight, 0);
        //left line
        super.line(0, 0, 0, 0, super.displayHeight, 0);
        //right line
        super.line(super.displayWidth, 0, 0, super.displayWidth, super.displayHeight, 0);

        //printing eye value in the middle of screen
        super.fill(0xFF000000);
        super.textMode(PApplet.CENTER);
        super.text("Distance: " + this.eye, super.displayWidth/2, super.displayHeight/2, 
                this.eye - 660); //keeping distance from camera always the same.

    }

    public void keyPressed() {
        if (super.key == PApplet.CODED) {
            switch (super.keyCode) {
            case PApplet.UP:
                //move camera closer to the display plane
                this.eye -= 10;
                if (this.eye &lt; 10) {
                    this.eye = 10;
                }
                break;
            case PApplet.DOWN:
                //move camera away from the display plane
                this.eye += 10;
                break;
            }
        } else if (super.key == 'r') {
            //reset camera position
            this.eye = CAMERA_EYE;
        }
    }

    public static void main(String[] args) {
        PApplet.main(CameraTest.class.getName()); 
    }

}
</code></pre>

<p>I imagine that I would need to find out the camera angle of view and/or focal length to do that. Am I right? Any hints on how can I do it? Couldn't find these information yet googling...</p>

<p>Usage:
Arrow Up: get closer to the z=0 axis;
Arrow Down: get further from the z=0 axis;
r: resets the camera's position.</p>

<p>Crossed fingers! Thank you!</p>
]]></description>
   </item>
   <item>
      <title>camera() in processing vs camera postion in After Effects</title>
      <link>https://forum.processing.org/two/discussion/17776/camera-in-processing-vs-camera-postion-in-after-effects</link>
      <pubDate>Sun, 07 Aug 2016 04:14:19 +0000</pubDate>
      <dc:creator>TSH</dc:creator>
      <guid isPermaLink="false">17776@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>Would any of you know how comparable the camera() function in processing matches to the one in After effects position wise?</p>
]]></description>
   </item>
   <item>
      <title>How to increase our camera in processing?</title>
      <link>https://forum.processing.org/two/discussion/17061/how-to-increase-our-camera-in-processing</link>
      <pubDate>Thu, 09 Jun 2016 09:54:53 +0000</pubDate>
      <dc:creator>susabgp</dc:creator>
      <guid isPermaLink="false">17061@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to keep the balls in the screen but they they keep disapearinvg in the z axis. I dont know if i'm doing anything wrong with the forces, or if there's any way i could manipulate the camera caracters, to make it bigger. The Z axis seems to be very "short".</p>

<p>Here's what i've got so far:</p>

<pre><code>Ball[] balls;
int numBalls = 0;
Ball b;
boolean isPressed = false;

void setup() {
  size (800, 800, P3D);
  smooth();
  //camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);
  background (0);
  balls = new Ball[300];
}

void draw (){
  noStroke();
  fill (0);
  rect(0, 0, width, height);
  if (mousePressed){

    //println(isPressed, numBalls);
    if(isPressed == false &amp;&amp; numBalls &lt; 300){
      println("cria bola");
      b = new Ball(mouseX, mouseY, 200.0);
      balls[numBalls] = b;
      numBalls++;
      isPressed = true;
    }

  }else{
   isPressed = false; 
  }
  println("NUMBALLS:", numBalls);
  for( int i = 0; i&lt;numBalls; i++){
    //println("&gt;", i,  balls[i]);
     balls[i].update();
  }

 for( int i = 0; i&lt;numBalls; i++){
     balls[i].draw();
  }


}


public class Ball {

  PVector location;
  PVector velocity;
  PVector acceleration;
  PVector gravity;
  PVector lance;
  float friction ;
  int depth;


  Ball(float x, float y, float z) {

    location = new PVector (x, y, z);
    lance = new PVector (0, -20, -15);
    velocity = new PVector(0, 0, 0);
    //println("created:", location.x, location.y);
  }
  void update(){
    //println(location.x,location.y,location.z, this);
    velocity.add(lance);
    lance = new PVector(0, 0, 0);

    if ((location.z &lt; 10)) {
    friction = 0.76;
    gravity = new PVector(0, 0, 0);
    } else {
    friction = 1.0;
    gravity = new PVector(0, 0.98, 0);
    }


    depth = 800;
    smooth();
    //gravity = new PVector(0, 0.98, 0);
    //location = new PVector(width/2, height/2, -3000);
    //velocity = new PVector(0, 10, -20);
    //lance = new PVector(0, 0, 0);
    //friction = 1.0; //0.98;  

    velocity.add(gravity);
    velocity.mult(friction);
    location.add(velocity);

  }
  void draw(){
    pushMatrix();
    //println("draw", this);
    noStroke();
    fill(255);
    lights();
    translate(location.x, location.y, location.z);
    sphere(35);
    popMatrix();
  }
}
</code></pre>

<p>(I' want to make something like this picture, by making random forces in the lances. )</p>

<p>Thank you so much<img src="https://forum.processing.org/two/uploads/imageupload/770/0IES5UW8JHEB.png" alt="Captura de ecrã 2016-06-02, às 14.09.36" title="Captura de ecrã 2016-06-02, às 14.09.36" /></p>
]]></description>
   </item>
   <item>
      <title>Is there a way to rotate the camera in 3d space?</title>
      <link>https://forum.processing.org/two/discussion/17031/is-there-a-way-to-rotate-the-camera-in-3d-space</link>
      <pubDate>Tue, 07 Jun 2016 20:50:18 +0000</pubDate>
      <dc:creator>llamablaster</dc:creator>
      <guid isPermaLink="false">17031@/two/discussions</guid>
      <description><![CDATA[<p>In processing, the camera() function takes 9 arguments: 3 for positioning in 3d space, 3 for the direction the camera is facing, and 3 for the upward vector in relation to the camera. It looks like there are only 3 parameters in the p5.js version, and I haven't been able to figure out a way to rotate the camera. Am I missing something?</p>
]]></description>
   </item>
   <item>
      <title>Rotating ellipse around its own Y axis</title>
      <link>https://forum.processing.org/two/discussion/16918/rotating-ellipse-around-its-own-y-axis</link>
      <pubDate>Tue, 31 May 2016 17:52:13 +0000</pubDate>
      <dc:creator>Isackender</dc:creator>
      <guid isPermaLink="false">16918@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I'm trying to rotate a circle around its own Y axis, but the rotation is not symmetric. It's driving me crazy and AFAIK everything is well written.</p>

<p>Check it out:</p>

<pre><code>color myWhite = 250;
color myBlack = 13;
int centerX = 440;
int centerY = 220;

float angle=-90;

void setup(){
  size(880,440,P3D);
  background(myBlack);
  stroke(myWhite);
  strokeWeight(1);
  noFill();
}

void draw(){
  background(myBlack);
  pushMatrix();
  translate(centerX, centerY, 0); 
  rotateY(radians(angle));
  ellipse(0,0,200,200);
  popMatrix();

  angle+=2; // speed
  if (angle&gt;=360) {
    angle=0; // keep in degree
  }

  line(centerX, 0, centerX, 440);
  line(0, centerY, 880, centerY);
  line(centerX-100, 0, centerX-100, 880);
  line(centerX+100, 0, centerX+100, 880);
}
</code></pre>

<p>As you can see, the top and bottom part of the circle are not cut by the central guideline simmetrically.</p>

<p>What I'm doing wrong?</p>

<p>P.S. I've taken the rotation code from <a rel="nofollow" href="https://forum.processing.org/one/topic/3d-rotation-logic-problem#25080000001320475.html">here</a> (thanks <a href="/two/profile/Chrisir">@Chrisir</a>).</p>
]]></description>
   </item>
   <item>
      <title>How to calculate vertex-camera alignment?</title>
      <link>https://forum.processing.org/two/discussion/16489/how-to-calculate-vertex-camera-alignment</link>
      <pubDate>Sun, 08 May 2016 13:37:47 +0000</pubDate>
      <dc:creator>hamoid</dc:creator>
      <guid isPermaLink="false">16489@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I would like to colorize faces depending on how well aligned they are to the camera.
Something like this:</p>

<pre><code>intensity = max(0.0, dot(camNormal, vertNormal));
</code></pre>

<p>I should pass camNormal and vertNormal from the vertex shader to the fragment shader.
My problem is, I don't know how to calculate the "camNormal" (the direction in which the camera is pointing).</p>

<p>In <a href="/two/profile/codeanticode">@codeanticode</a>'s blog I see that both modelview and normalMatrix should include in some way the camera information, but I don't know how to get it out of those matrices. Does someone know?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>[SOLVED] Convert sketch from 2D to 3D</title>
      <link>https://forum.processing.org/two/discussion/15890/solved-convert-sketch-from-2d-to-3d</link>
      <pubDate>Wed, 06 Apr 2016 21:18:54 +0000</pubDate>
      <dc:creator>borgejor</dc:creator>
      <guid isPermaLink="false">15890@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to convert my root system sketch from 2D to 3D so I can rotate around it and be able to see it from different angles. My friend told me about using PVectors to implement the z-axis but I am not sure about how to do that. Any body help? Sorry I am new to using a forum so forgive me if I am not asking properly or giving enough information. My code is below:</p>

<pre><code>Snake[] snakes = new Snake[0];

void setup() {

  background(0);
  size(1200, 600,P3D);

  smooth();
      for (int k = 0; k &lt; 10; k++){
         snakes = (Snake[]) append(snakes, new Snake(width/2, height/2, 15, random(100), 1));
      }
}
void draw() {

  for(int i = 0; i &lt; snakes.length; i++) {
    if(!snakes[i].done()){
    snakes[i].go();
    stroke(random(255), 0, 0, 50);}
  }



}





class Snake {

  float X;
  float Y;
  float rot;
  float V;
  float tm;
  int fm;

  Snake(int tX, int tY, float tfm, float trot, float tV) {
    X = tX;
    Y = tY;
    rot = trot;
    tm = tfm;
    V = tV;
  }

  void go() {
    V += random(-0.01, 0.01);
    tm /= 1.01;
    strokeWeight(tm);
    rot += random(-0.2, 0.2);
    line( X,Y, X + V*sin(rot), Y + V*cos(rot));
    line(X, Y, X + V*sin(rot), Y + V*cos(rot));
    X += V*sin(rot);
    Y += V*cos(rot);

    fm++;
    if(random(400) &gt; 398.5-(fm/20)) {
      snakes = (Snake[]) append(snakes, new Snake(int(X), int(Y), tm, rot + random(-0.2, 0.2), V));

    }
  }
  boolean done() {
    if(tm &lt; 0.01) {
      return true;
    }else{
      return false;
    }
  }
}
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/089/UYU2H1O2ROTP.PNG" alt="example4" title="example4" /></p>
]]></description>
   </item>
   <item>
      <title>Translating/Rotating/Camera in P3D</title>
      <link>https://forum.processing.org/two/discussion/15708/translating-rotating-camera-in-p3d</link>
      <pubDate>Sun, 27 Mar 2016 14:55:33 +0000</pubDate>
      <dc:creator>LDB477</dc:creator>
      <guid isPermaLink="false">15708@/two/discussions</guid>
      <description><![CDATA[<p>Good morning world,</p>

<p>I'm getting foiled by P3D and translating/rotating and how they work with camera(), but I'm learning a bit about how they work.  So far I've learned that calling camera() with the specified values AFTER using translate/rotate earlier in the program causes undesirable results, I'm guessing because once compiled it is run first as actual translate/rotate.  This can get messy when trying to take snapshots of a 3D scene.  I've since started looking into beginCamera() and endCamera(), and boy are those interesting.  One thing that I've learned about the camera using beginCamera() and endCamera() is that changes to the camera (matrix?) are ADDED instead of set.  This is fine, but I'm still finding that the changes to the camera aren't happening when the changes are called.  I've created this little sketch to try and showcase my headache, comment in and out each box(150) to see different results:</p>

<pre><code>void setup(){
  size(500,500,P3D);
}
void draw(){
  background(0);
  stroke(150);
  noFill();

  sphere(60);
  line(0,0,0,0,-100,0);

  //box(150);          //Enable/disable these one by one

  beginCamera();
  camera();
  translate(width/2,height/2);
  endCamera();

  box(150);          //Enable/disable these one by one

  beginCamera();
  rotateX(radians(mouseX));
  rotateY(radians(45));
  endCamera();

  //box(150);          //Enable/disable these one by one
  box(20);
  line(0,0,0,0,-100,0);
}
</code></pre>

<p>I'm wondering if anyone has a better explanation (through code examples preferably) regarding rotating and translating within a 3D space, and how the camera function alters the prior translates and rotates.  I have some experience with using push/popMatrix() and translate/rotate in 2D land, but I'm not sure how push/popMatrix() affect the camera matrix, and finally how this all plays with the main window pixels.</p>

<p>Finally, I will talk briefly about what I'm actually trying to do.  I'm using processing to create a 3D robot simulation environment (for line following algorithm testing) and I would like this sketch to output a 2D image of the robot's perspective.  The problem I am running into is when I call translate/rotate to move about the scene and place the robot/floor etc, I still have to call camera() with the appropriate values given to me by the position of the robot to look at the world from the perspective of the robot.  I was having lots of trouble doing it this way when I realized that camera() stuff must be done first before moving about and drawing.  The way that I was trying to grab the 2D image was by reorienting the camera to the desired position, grabbing the window pixels and giving them to a PImage, then reorienting the camera to a top-down perspective.  The problem with this was the the Image only showed the final position of the camera, not any of the intermediary steps.  Here's the actual sketch that I'm working on, comment in/out the image at the end of main to see what the current image output would be (use arrow keys to drive around)(I attached TestCourseLine.png I think):</p>

<pre><code>//  Simulation environment for testing line following

int windowWidth = 1000;
int windowHeight = 700;

PImage course;
PImage robotCam;
PImage roomCam;
int robotCamWidth = 600;
int robotCamHeight = 400;
int window[][];
int robotCamArray[][];

//Camera (independent of translations)
float cameraX = 500;
float cameraY = 350;
float cameraZ = 606;
float cameraCenterX = 500;
float cameraCenterY = 350;
float cameraCenterZ = 0;
float targetDistance = 0;

int robotStep = 5;
float robotTurn = .1;

//Robot Position/orientation relative to center origin
float robotX = -170;
float robotY = 290;
float robotZ = 25;
float robotRotZ = 4.7;

//RobotCam position/orientation relative to robot
int robotCamX = 20;
int robotCamY = 0;
int robotCamZ = 30;
float robotCamRotX = 0;
float robotCamRotZ = 0;
float robotCamRotY = 0.4;

boolean adjustRobotCam = false;
boolean moveRobot = true;
boolean adjustWindowCam = false;

boolean chaseCam = false;

void setup(){

  size(windowWidth,windowHeight,P3D);

  frameRate(10);

  window = new int[windowWidth][windowHeight];
  robotCamArray = new int[robotCamWidth][robotCamHeight];

  course = loadImage("TestCourseLine.png");

  robotCam = createImage(robotCamWidth,robotCamHeight, RGB);

}
void draw(){

  pushMatrix();
 //Move the window camera to the robot's camera (Must be done before other translations/rotates)
  cameraX = cos(robotCamRotZ+robotRotZ)*0+(robotX+width/2);
  cameraY = sin(robotCamRotZ+robotRotZ)*0+(robotY+height/2);
  cameraZ = robotCamZ+robotZ;
  targetDistance = (robotZ+robotCamZ)/sin(robotCamRotY);
  cameraCenterX = cos(robotCamRotZ+robotRotZ)*targetDistance+(robotX+width/2);
  cameraCenterY = sin(robotCamRotZ+robotRotZ)*targetDistance+(robotY+height/2);
  camera(cameraX, cameraY, cameraZ, cameraCenterX, cameraCenterY, cameraCenterZ, 0,0,-1);



  background(0);

  fill(100);
  stroke(200);
  noFill();

  pushMatrix();
  //Center origin to scene
  translate(width/2,height/2);

  box(500);

  //Create Floor
  beginShape();
  texture(course);
  vertex(-250,-250,0,0,0);
  vertex(250,-250,0,500,0);
  vertex(250,250,0,500,500);
  vertex(-250,250,0,0,500);
  endShape(CLOSE);

  //Draw Robot and camera
  pushMatrix();
  translate(robotX, robotY, robotZ);
  rotateZ(robotRotZ);
  box(50);
  //line(0,0,0,100,0,0);
  translate(robotCamX,robotCamY,robotCamZ);
  rotateX(robotCamRotX);
  rotateZ(robotCamRotZ);
  rotateY(robotCamRotY);
  fill(100);
  box(20);
  line(0,0,0,30,0,0);
  popMatrix();

  //Load the pixels of the last camera perspective and the new image
  loadPixels();
  robotCam.loadPixels();

  //Load the window pixels into an array for easy access
  for (int i = 0; i &lt; pixels.length; i++){
    window[i-((i/windowWidth)*windowWidth)][i/windowWidth] = int(brightness(pixels[i]));
  }

  //Give the new image the pixel data from the last camera perspective
  for (int y = 0; y &lt; robotCamHeight; y++){
    for (int x = 0; x &lt; robotCamWidth; x++){
      robotCamArray[x][y] = window[x+(windowWidth-robotCamWidth)/2][y+(windowHeight-robotCamHeight)];
    }
  }

  //Load the robotCamArray data into robotCam pixels
  for (int i = 0; i &lt; robotCam.pixels.length; i++){
    robotCam.pixels[i] = color(robotCamArray[i-((i/robotCamWidth)*robotCamWidth)][i/robotCamWidth]);
  }
  updatePixels();
  robotCam.updatePixels();
  popMatrix();
  //popMatrix();



  popMatrix();

  //background(0);

  translate(width/2,height/2,100);

  //image(robotCam,-robotCamWidth/2,-robotCamHeight/2,robotCamWidth,robotCamHeight);


}

void keyPressed(){

  if (key == 'm'){
    moveRobot = true;
    adjustRobotCam = false;
    adjustWindowCam = false;
  } else if (key == 'c'){
    moveRobot = false;
    adjustRobotCam = true;
    adjustWindowCam = false;
  } else if (key == 'w'){
    adjustWindowCam = true;
    moveRobot = false;
    adjustRobotCam = false;
  }

  if (moveRobot == true){
    if (key == CODED){
      switch(keyCode){
        case UP:
          robotX += cos(robotRotZ)*robotStep;
          robotY += sin(robotRotZ)*robotStep;
          break;
        case DOWN:
          robotX += cos(robotRotZ)*-robotStep;
          robotY += sin(robotRotZ)*-robotStep;
          break;
        case LEFT:
          robotRotZ -= robotTurn;
          break;
        case RIGHT:
          robotRotZ += robotTurn;
          break;
      }
    }
  } else if (adjustRobotCam == true){
    if (key == CODED){
      switch(keyCode){
        case UP:
          robotCamRotY -= robotTurn;
          break;
        case DOWN:
          robotCamRotY += robotTurn;
          break;
        case LEFT:
          robotCamRotZ -= robotTurn;
          break;
        case RIGHT:
          robotCamRotZ += robotTurn;
          break;
      }
    }
  } else if (adjustWindowCam == true){
    if (key == CODED){
      switch(keyCode){
        case UP:
          //camera -= robotTurn;
          break;
        case DOWN:
          robotCamRotY += robotTurn;
          break;
        case LEFT:
          robotCamRotZ -= robotTurn;
          break;
        case RIGHT:
          robotCamRotZ += robotTurn;
          break;
      }
    }
  }
}
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/702/VJHMUVBG48YU.png" alt="TestCourseLine" title="TestCourseLine" /></p>
]]></description>
   </item>
   <item>
      <title>Spherical Coordinated Camera</title>
      <link>https://forum.processing.org/two/discussion/15464/spherical-coordinated-camera</link>
      <pubDate>Sat, 12 Mar 2016 20:09:52 +0000</pubDate>
      <dc:creator>noamnav</dc:creator>
      <guid isPermaLink="false">15464@/two/discussions</guid>
      <description><![CDATA[<p>hello there,</p>

<p>trying to create my own class for spherical movement of camera (based on mouse movement), i am experiencing a problem setting the up vector for the camera:
when scrolling the camera on the up and down the matrix (x and y) seem to flip.</p>

<p>don't seem to have this problem with the horizontal scroll.</p>

<p>help anyone?</p>

<p>thanks</p>

<pre><code>float camX, camY, camZ;
float camRad = width*20;
float camTheta, camPhi;
float camDragX, camDragY;
float newCamX = 50;
float newCamY = 600;
boolean moveCam = false;
PVector up;

void cam() {                                                                                            //camera
  camPhi   = map(newCamX, 0, width, PI, -PI);                              //phi is the horizontal angle 0-2PI    
  camTheta = map(newCamY, 0, height, HALF_PI, -HALF_PI);        //theta is the vertical angle 0-PI
  up    = new PVector (sin(camPhi), cos(camPhi));


  camX = camRad*sin(camTheta)*sin(camPhi);
  camY = camRad*sin(camTheta)*cos(camPhi);  
  camZ = camRad*cos(camTheta);

  camera(camX, camY, camZ, 0, 0, 0, up.x, up.y, up.z);
}

void mousePressed() {
  if (mouseButton == RIGHT) {
    camDragX = mouseX - newCamX;
    camDragY = mouseY - newCamY;
    moveCam = true;
  }
}

void mouseDragged() {
  if (mouseButton == RIGHT) {
    if (moveCam) {
      newCamX = mouseX - camDragX;
      newCamY = mouseY - camDragY;
    }
  }
}

void mouseReleased() {
  moveCam = false;
}

void mouseWheel(MouseEvent event) {
  float zoom = event.getCount();
  zoom = zoom*50;
  camRad += zoom;
}

void setup () {
  size (500, 500, P3D);
  colorMode(HSB, 360, 1, 1, 1);  
}


void draw() {
  background (0, 0, 1);  
  drawAxis();
  cam();
  fill(1,0,0);
  ellipse (width/2, height/2, 250, 250);
}

void drawAxis() {
  stroke (0, 1, 1);
  line (0, 0, 0, 1000, 0, 0);
  stroke (90, 1, 1);
  line (0, 0, 0, 0, 1000, 0);
  stroke (210, 1, 1);
  line (0, 0, 0, 0, 0, 1000);
  noStroke();
}
</code></pre>
]]></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>Stop Recursion When Out of Boundary</title>
      <link>https://forum.processing.org/two/discussion/14671/stop-recursion-when-out-of-boundary</link>
      <pubDate>Fri, 29 Jan 2016 18:43:30 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">14671@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I created a simple recursive tree using a proto-L-System and I'd like for the recursion to stop if it goes out of the box I've drawn.
However, because of all the translations, I'm confused as to how this can be achieved.</p>

<p>I'd be very grateful if someone can point me in the right direction.</p>

<p>Many Thanks,
Charles</p>

<pre><code>// A simple recursive tree using a proto-L-System

import processing.opengl.*;
Branch axiom;
PVector cameraPos = new PVector(600, -100, 600);

void setup()
{
  size(800, 800, OPENGL);
  axiom = new Branch();
}
void draw()
{

  background(0);
  stroke(192);
  fill(255);
  translate(width/2, height);
  rotateY(frameCount*0.01);
  axiom.draw();
  if (frameCount % 50 == 0) {
    axiom.replace(0);
  }
  translate(0, height*-0.5);
  noFill();
  box(400, 600, 400);

  camera(cameraPos.x, cameraPos.y, cameraPos.z, width/2, height*0.5, 0, 0, 1, 0);
}
void mousePressed()
{
  axiom = new Branch();
}

class Branch
{
  PMatrix3D joint;
  Branch child_a;
  Branch child_b;
  Branch()
  {
    joint = new PMatrix3D();
    child_a = null;
    child_b = null;
  }
  void replace(int depth)
  {
    // still need to prevent infinite recursion:
    if (depth &gt; 16) {
      return;
    }
    // note: grow children before yourself
    if (child_a != null) {
      child_a.replace(depth+1);
    }
    if (child_b != null) {
      child_b.replace(depth+1);
    }
    // now I grow myself
    rule();
  }
  void rule()
  {
    // rule: grow offshoot branches
    // B -&gt; B (+B) (-B)
    if (child_a == null) {
      // main stem -- almost straight
      child_a = new Branch();
      child_a.joint.rotateY(random(0, PI));
      child_a.joint.rotateX(random(-PI/16, PI/16));
    }
    if (child_b == null) {
      // branching off
      child_b = new Branch();
      child_b.joint.rotateY(random(0, PI));
      child_b.joint.rotateX(random(-PI/4, PI/4));
    }
  }
  void draw()
  {
    applyMatrix(joint);
    pushMatrix();
    {
      translate(0, -height/8, 0);
      box(10, height/4, 10);
    }
    popMatrix();
    pushMatrix();
    {
      translate(0, -height/4, 0);
      scale(0.7);
      if (child_a != null) {
        child_a.draw();
      }
    }
    popMatrix();
    pushMatrix();
    {
      translate(0, -height/4, 0);
      scale(0.7);
      if (child_b != null) {
        child_b.draw();
      }
    }
    popMatrix();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I get error "IndexOutOfBoundsExeption..." and cannot load object. Help me to solve it, please.</title>
      <link>https://forum.processing.org/two/discussion/14293/i-get-error-indexoutofboundsexeption-and-cannot-load-object-help-me-to-solve-it-please</link>
      <pubDate>Wed, 06 Jan 2016 12:22:33 +0000</pubDate>
      <dc:creator>Whiskas</dc:creator>
      <guid isPermaLink="false">14293@/two/discussions</guid>
      <description><![CDATA[<pre><code>PShape build;

void setup(){
  fullScreen (P3D); 
  build = loadShape("city.obj");
}

void draw(){
  camera (0,-55,55, 0,0,0, 0,1,0);

  background (39,39,39); 
  shape (build);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to use my own defined camera_like() function instead of camera()?</title>
      <link>https://forum.processing.org/two/discussion/12922/how-to-use-my-own-defined-camera-like-function-instead-of-camera</link>
      <pubDate>Sat, 10 Oct 2015 05:17:15 +0000</pubDate>
      <dc:creator>alwayzmile</dc:creator>
      <guid isPermaLink="false">12922@/two/discussions</guid>
      <description><![CDATA[<p>I've got a programming assignment to simulate how 3d viewing works from scratch. I want to use my own defined function for projection instead of using camera() function. Is it possible? If possible, how to do that?</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>camera() not working</title>
      <link>https://forum.processing.org/two/discussion/12843/camera-not-working</link>
      <pubDate>Mon, 05 Oct 2015 21:47:22 +0000</pubDate>
      <dc:creator>diyoyo</dc:creator>
      <guid isPermaLink="false">12843@/two/discussions</guid>
      <description><![CDATA[<p>Hi, 
I would like to test the simple example of "camera()" on p5js.org, but it doesn't even work.
I have the following error:
    6: Uncaught ReferenceError: camera is not defined</p>

<p>how come?</p>
]]></description>
   </item>
   <item>
      <title>Problems with Heads Up display (HUD) and perspective</title>
      <link>https://forum.processing.org/two/discussion/12535/problems-with-heads-up-display-hud-and-perspective</link>
      <pubDate>Wed, 16 Sep 2015 03:47:13 +0000</pubDate>
      <dc:creator>cems</dc:creator>
      <guid isPermaLink="false">12535@/two/discussions</guid>
      <description><![CDATA[<p>I am able to create a Heads Up Display (2D) overlay on my 3D image but I find my code fails when I set the perspective() to be different than the default perspective.</p>

<p>Below is the code.</p>

<p>If I comment out the perspective statement it works as expected drawing the overlay 2D rectangle in the upper left corner.
If I leave in the perspective statement the rectangle is drawn inset from the corner by quite a bit.
I have tried putting the originalMatrix assignment either before or after the perspective statement to no effect.</p>

<pre><code>// comment
float fov =  (float) PI/2.5f; // lens focal length or something like that

PMatrix originalMatrix; 

public void setup() {
    size(900,600, P3D);
    originalMatrix = (PMatrix) getMatrix();
    float cameraZ= (height/2.0f) / tan(fov/2.0f); // sets clipping plane
    perspective(fov, width*1.0f/height, 
    cameraZ/1000.0f, cameraZ*10.0f);  // near clipping plane smaller than normal

    //originalMatrix = (PMatrix) getMatrix();  // optional 
}

public void display() {

camera(   // set some camera angle-- doesn't seem to matter to the issue
    0f, -800f, 0f,
    2 + 0.05f * ts.x, ts.y, 2 + 0.05f * ts.z,// 2f,-100f,2f,
    0f, 1f, 0f);

    //  ****  (omitted)  DRAW SOME 3D stuff here ******

    // here I add the HUD which in this case is just a square drawn in the upper left corner.
    hint(DISABLE_DEPTH_TEST);
    pushMatrix();
    resetMatrix();
    applyMatrix(originalMatrix);

    fill(100,0,0,100);
    rect(0,0,100,100);
    popMatrix();
    hint(ENABLE_DEPTH_TEST);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>P3D Behaving Strangely Since Upgrading to Processing 3</title>
      <link>https://forum.processing.org/two/discussion/12102/p3d-behaving-strangely-since-upgrading-to-processing-3</link>
      <pubDate>Sun, 16 Aug 2015 03:05:06 +0000</pubDate>
      <dc:creator>DavidB</dc:creator>
      <guid isPermaLink="false">12102@/two/discussions</guid>
      <description><![CDATA[<p>Since upgrading from Processing 2 to 3, a sketch that I have been working on for Android that uses P3D has been loading in the third quadrant of the screen only, cutting most of the app out of view. Since my explanation is somewhat hard to understand, here's a visualization to help out.</p>

<p>Let's say that the following is my phone's screen with a coordinate plane drawn on it with the origin being in the center.</p>

<p><img src="http://forum.processing.org/two/uploads/imageupload/308/DKG5ZDZQDI8E.png" alt="Untitled" title="Phone Screen with Coordinate Plane" /></p>

<p>In the past, the contents of the app would load properly, but now, the contents of the first quadrant are being pushed in to the third quadrant and the contents of the other three quadrants are not visible, so the app now looks like this.</p>

<p><img src="http://forum.processing.org/two/uploads/imageupload/440/A7OOFKPFLZRM.png" alt="Untitled2" title="Phone Screen the way the App Appears" /></p>

<p>Here is the code from the draw() function that I believe may be the culprit, but do not know how to modify to resolve the issue:</p>

<pre><code> background(0);
 ortho(0, width, 0, height, -100, 100);
 camera(width / 2, height / 2, 10, width / 2, height / 2, 0, 0, 0.1, 0);
</code></pre>

<p>The code for setting the sketch size in the setup() function is nothing more than 'fullScreen(P3D)'.</p>
]]></description>
   </item>
   </channel>
</rss>