# My 3D Rendering Code

**URL:** https://forum.makecode.com/t/my-3d-rendering-code/4491
**Category:** Help
**Created:** [November 18, 2020, 9:31pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491 "2020-11-18T21:31:52Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 18, 2020, 9:31pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/1 "2020-11-18T21:31:52Z")

</div>

UPDATE

> **[Perspective6](https://arcade.makecode.com/48961-99945-18697-69200)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

not latest version!

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [November 18, 2020, 9:39pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/2 "2020-11-18T21:39:19Z")

</div>

UHVIUEWFLIUEWFLBIUHLIEF HOW DO PEOPLE DO THIS???

I’m honestly too scared to look at the code. How does this work?

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 18, 2020, 9:40pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/3 "2020-11-18T21:40:56Z")

</div>

It says in the description.

It’s broken though.  
And I don’t know why yet.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [November 18, 2020, 9:43pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/4 "2020-11-18T21:43:29Z")

</div>

It works fine for me, except if you go too far it doesn’t render or I just didn’t turn enough.

> [@charliegregg](#):
>
> Projects all points to a unit sphere disregarding near and far clip planes and uses matrix rotation and atan2 to find the borders of the screen on the sphere, maps the coordinates and boom.

Yeah I have exactly no idea what that means but I’ll take your word! I’ve heard of matrix rotation though somewhere…it’s a pain to do in Python at least without Numpy.

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 18, 2020, 9:44pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/5 "2020-11-18T21:44:46Z")

</div>

It’s just a bunch of sin cos -sin and atan2

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 18, 2020, 9:45pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/6 "2020-11-18T21:45:26Z")

</div>

The bugs are when you get inside / really close or go down far then look up

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 18, 2020, 9:47pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/7 "2020-11-18T21:47:19Z")

</div>

I think I might try to do the game jam thing. I wonder If I could make a 3d ocean?  
That would be epic

Ah, Fixxed It @UnsignedArduino

> **[Perspective](https://arcade.makecode.com/59161-48942-40353-93806)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Thinking about making a minecraft type clone.  
wasd ijkl and space

---

<div class="post-metadata">

### Author: ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)
#### Post date: [November 19, 2020, 1:16pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/8 "2020-11-19T13:16:10Z")

</div>

How- like how do you people do this?? This is hecking amazing!!

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 19, 2020, 7:59pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/9 "2020-11-19T19:59:23Z")

</div>

Well, have you done matrix multiplication? Because it uses that.

1. Rotate each point to be in front of the camera
2. Squish them all into a straight line (AKA a small cube)
3. Draw them based on the Z coordinate!

You can check the code if you’re interested.

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 20, 2020, 7:33am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/10 "2020-11-20T07:33:15Z")

</div>

UPDATE  
made resolution low for now to reduce lag

uses mesh to draw sides of cubes

> **[Perspective3](https://arcade.makecode.com/82940-92633-63788-04161)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 3:32am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/11 "2020-11-21T03:32:20Z")

</div>

UPDATE  
fixed resolution and completely scrapped and redid code for meshes (fast!)

> **[Perspective4](https://arcade.makecode.com/99057-34366-81567-36147)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![UnderwaterAstronaut](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/underwaterastronaut/32/2228_2.png) [@UnderwaterAstronaut](https://forum.makecode.com/u/UnderwaterAstronaut)
#### Post date: [November 21, 2020, 3:58am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/12 "2020-11-21T03:58:58Z")

</div>

Okay but- is this possible in blocks?? I doubt it but it’s worth asking

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 4:09am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/13 "2020-11-21T04:09:54Z")

</div>

Well Theoretically yes, but It would be way more confusing.

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 4:19am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/14 "2020-11-21T04:19:25Z")

</div>

I don’t believe you can have classes in blacks so It’d be very disorganised. (Like blocks normally look to me atleast!). If you don’t know what classes are I’d be happy to explain.

---

<div class="post-metadata">

### Author: ![UnderwaterAstronaut](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/underwaterastronaut/32/2228_2.png) [@UnderwaterAstronaut](https://forum.makecode.com/u/UnderwaterAstronaut)
#### Post date: [November 21, 2020, 4:26am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/15 "2020-11-21T04:26:36Z")

</div>

Please do explain

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 4:28am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/16 "2020-11-21T04:28:32Z")

</div>

A class is like a object you make yourself:  
Image is a class  
Sprite is a class  
If you want to create a new class you could use it for:  
Storing a position eg.  
stores an x and a y value  
can be rotated  
can tell distances

I will make a quick project

---

<div class="post-metadata">

### Author: ![UnderwaterAstronaut](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/underwaterastronaut/32/2228_2.png) [@UnderwaterAstronaut](https://forum.makecode.com/u/UnderwaterAstronaut)
#### Post date: [November 21, 2020, 4:28am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/17 "2020-11-21T04:28:51Z")

</div>

ohhh!!

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 4:42am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/18 "2020-11-21T04:42:07Z")

</div>

> **[class example](https://arcade.makecode.com/30619-59581-68788-86446)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
Bad example but you get the point

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [November 21, 2020, 5:42am UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/19 "2020-11-21T05:42:03Z")

</div>

I wonder if someone could work out what code I put on my profile pic… 🙂 it’s a bit blurry.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [November 21, 2020, 4:18pm UTC](https://forum.makecode.com/t/my-3d-rendering-code/4491/20 "2020-11-21T16:18:24Z")

</div>

Python 3? I saw the functions `range` and `len` at the very top. And there are colons everywhere; definitely Python syntax!

[Next page](https://forum.makecode.com/t/my-3d-rendering-code/4491.md?page=2)
