# How to translate an object in Z - but keep its screen X and Y pos?

**URL:** <https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171>\
**Category:** Coding Questions\
**Created:** [July 31, 2022, 11:45am UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171 "2022-07-31T11:45:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 11:45am UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/1 "2022-07-31T11:45:46Z")

</div>

How would I move a 3d point away / toward the camera - but have its position locked on a particular screen x y coordinate?

---

<div class="post-metadata">

**Author:** ![StasPovaliaevUkraine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/staspovaliaevukraine/32/16599_2.png) [@StasPovaliaevUkraine](https://discourse.processing.org/u/StasPovaliaevUkraine)\
**Post date:** [July 31, 2022, 12:34pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/2 "2022-07-31T12:34:27Z")

</div>

make Z as a variable, Z increases - the object decreases (moves away) and vice versa.

---

<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:** [July 31, 2022, 12:57pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/3 "2022-07-31T12:57:29Z")

</div>

To preserve visible x,y on screen

See [Reference / Processing.org](https://processing.org/reference/ortho_.html)

Or similar perspective or so

---

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 2:28pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/7 "2022-07-31T14:28:28Z")

</div>

i need to slide points along z to create an illusion of a 3d point cloud… this is based on a greyscale image input - where the brighter the pixel, the closer it is to the camera…  
once i move the points in z though - the camera fov changes their x y positions as you look head on - i need to fix this - these images show it better

Uploading: Screenshot 2022-07-31 at 15.00.28.jpg…  
Uploading: Screenshot 2022-07-31 at 15.00.00.jpg…

---

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 2:29pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/8 "2022-07-31T14:29:12Z")

</div>

> [@How to translate an object in Z - but keep its screen X and Y pos?](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/7):
>
> i need to slide points along z to create an illusion of a 3d point cloud… this is based on a greyscale image input - where the brighter the pixel, the closer it is to the camera… once i move the points in z though - the camera fov changes their x y positions as you look head on - i need to fix this - these images show it better Uploading: Screenshot 2022-07-31 at 15.00.28.jpg…Uploading: Screenshot 2022-07-31 at 15.00.00.jpg…

---

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 2:29pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/9 "2022-07-31T14:29:39Z")

</div>

………

> [@How to translate an object in Z - but keep its screen X and Y pos?](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/7):
>
> i need to slide points along z to create an illusion of a 3d point cloud… this is based on a greyscale image input - where the brighter the pixel, the closer it is to the camera… once i move the points in z though - the camera fov changes their x y positions as you look head on - i need to fix this - these images show it better Uploading: Screenshot 2022-07-31 at 15.00.28.jpg…Uploading: Screenshot 2022-07-31 at 15.00.00.jpg…

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 31, 2022, 3:28pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/10 "2022-07-31T15:28:20Z")

</div>

You might try `ortho()` to remove perspective

---

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 3:48pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/11 "2022-07-31T15:48:23Z")

</div>

that does work - but the results are too strong - everything looks very boxed…  
i’m working on a solution using vector math to raycast to the points and work out a z translation based on the camera

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [July 31, 2022, 9:23pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/12 "2022-07-31T21:23:18Z")

</div>

Create a 3-D line from the camera eye point to your 3-D point. You can move points anywhere along that line and they should project onto the same screen point.

**Q** = **E** + ( **P** - **E** ) \* t

At t = 0, you’re at the camera. At t = 1, you’re at your original point. Any other value of t moves the new point closer or further away.

---

<div class="post-metadata">

**Author:** ![zenglenn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenglenn/32/5569_2.png) [@zenglenn](https://discourse.processing.org/u/zenglenn)\
**Post date:** [July 31, 2022, 9:43pm UTC](https://discourse.processing.org/t/how-to-translate-an-object-in-z-but-keep-its-screen-x-and-y-pos/38171/14 "2022-07-31T21:43:51Z")

</div>

yes that looks like it’s working for me! - i had been trying something similar with vector math - but didn’t add the E … was just using (P - E) \* t  
will try on my project and get back to close the thread if it works - thanks…
