# 3D Coding on the Z-axis

**URL:** <https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359>\
**Category:** Coding Questions\
**Created:** [May 1, 2020, 6:03pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359 "2020-05-01T18:03:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilRandom](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PhilRandom](https://discourse.processing.org/u/PhilRandom)\
**Post date:** [May 1, 2020, 6:03pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/1 "2020-05-01T18:03:07Z")

</div>

Hi all!  
Phil here again, as you know this has been a very stressful year, so I thought coding would be a fantastic way to get back my mojo in self-isolation! For those of you who are unaware, I began to learn coding last year and I have loved every minute of it! I was inspired to code when my namesake, Punxsutawney Phil, the groundhog on groundhogs day said that we would have a long winter…brr… Anyway, it seems that I am in a bit of pickle as I have expanded my coding repertoire into the 3D world, an exciting new endeavor! I am having some trouble with coding 3D shapes that rotate on the Z axis and I would love any trips, tricks, or code that might be helpful.  
Thank you all  
Warmest regards,  
Phil Random

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 1, 2020, 6:07pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/2 "2020-05-01T18:07:08Z")

</div>

Hello,

Check out resources here:

[https://processing.org/](https://processing.org/)  
[https://processing.org/tutorials/p3d/](https://processing.org/tutorials/p3d/)

`:)`

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 1, 2020, 6:32pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/3 "2020-05-01T18:32:33Z")

</div>

See also [https://github.com/Kango/Processing-snippets/wiki/3D---P3D---OPENGL-BASICS](https://github.com/Kango/Processing-snippets/wiki/3D---P3D---OPENGL-BASICS)

see [https://github.com/Kango/3DSketches](https://github.com/Kango/3DSketches)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 1, 2020, 8:43pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/4 "2020-05-01T20:43:17Z")

</div>

here is an example

what is your specific question?

Chrisir

```auto

float angle1; 

void setup() {
  // init
  size(800, 600, P3D);
} // func 

void draw() {
  // runs on and on 
  background(0);
  lights();

  stroke(100); 
  // noFill();
  fill(255, 0, 0);

  pushMatrix();
  translate(100, 100, 0);
  rotateZ(angle1);
  angle1+=.04; 
  box(60);
  popMatrix();

  pushMatrix();
  translate(400, 100, 0); 
  rotateX(angle1);
  fill(0, 0, 255);
  box(60);
  popMatrix();

  pushMatrix();
  translate(700, 100, 0);
  rotateY(angle1);
  box(60);
  popMatrix();

  pushMatrix();
  translate(700, 300, -330);
  noStroke(); 
  sphere(50);
  popMatrix();
} // func 
//

```

---

<div class="post-metadata">

**Author:** ![PhilRandom](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PhilRandom](https://discourse.processing.org/u/PhilRandom)\
**Post date:** [May 8, 2020, 4:52pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/5 "2020-05-08T16:52:31Z")

</div>

Thank you all for the help! Immensely appreciated!  
-Phil 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 14, 2020, 6:02am UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/6 "2020-05-14T06:02:27Z")

</div>

> [@PhilRandom](#):
>
> I am having some trouble with coding 3D shapes that rotate on the Z axis

Also don’t forget the PeasyCam library, if you want to rotate something that is centered and look at it.

---

<div class="post-metadata">

**Author:** ![PhilRandom](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PhilRandom](https://discourse.processing.org/u/PhilRandom)\
**Post date:** [May 21, 2020, 9:33pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/7 "2020-05-21T21:33:30Z")

</div>

Thank you Jeremy! Much appreciated!  
Best wishes to you and I hope you are staying healthy!  
-Phil

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 21, 2020, 9:45pm UTC](https://discourse.processing.org/t/3d-coding-on-the-z-axis/20359/8 "2020-05-21T21:45:06Z")

</div>

To you also, Phil–be well.
