How to make a 3D projection in Python | Rendering a cube in 2D! (No OpenGL)

  Рет қаралды 92,780

Pythonista_

Pythonista_

Күн бұрын

Пікірлер: 134
@justinlua4848
@justinlua4848 2 жыл бұрын
This is the only tutorial I've seen so far that animated the matrix multiplication. That makes so much more sense now.
@hellishbro
@hellishbro 3 жыл бұрын
here is a fun way to avoid copy pasting in the beginning :) points = [] for x in (-1, 1): for y in (-1, 1): for z in (-1, 1): points.append(np.matrix([x, y, z]))
@nzuckman
@nzuckman 2 жыл бұрын
omg bless you
@remot1
@remot1 Жыл бұрын
WIDTH = 100 HEIGHT = 100 LENGTH = 100 points = [] for x in range(-1, WIDTH, WIDTH): for y in range(-1, WIDTH, WIDTH): for z in range(-1, WIDTH, WIDTH): points.append(np.matrix([[x], [y], [z]])) *Matrices so you dont have to copy, even tho I made mine a lil different.* *_Projection & Rotation_* projectionMatrix = np.matrix([ [1, 0, 0], [0, 1, 0], ]) def Rx(angle): return np.matrix([ [1, 0, 0], [0, math.cos(angle), -math.sin(angle)], [0, math.sin(angle), math.cos(angle)] ]) def Ry(angle): return np.matrix([ [math.cos(angle), 0, math.sin(angle)], [0, 1, 0], [-math.sin(angle), 0, math.cos(angle)] ]) def Rz(angle): return np.matrix([ [math.cos(angle), -math.sin(angle), 0], [math.sin(angle), math.cos(angle), 0], [0, 0, 1] ]) *[!] --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- [!]* *You dont have to use np.dot(), you can use the @, matrix multiplication operator.* *Example: Matrix1 @ Matrix2* *[!] --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- [!]*
@sudolea
@sudolea 2 жыл бұрын
Perfect in its simplicity. Thank you for this video, and for showing the way how to do matrix multiplication in Python (still not the language of my preference however) ! After looking for some theory, this was the perfect "next-step"-hit !
@brickolo_
@brickolo_ Жыл бұрын
I love how you got L's theme playing in the background lol, great tutorial
@halfsine
@halfsine 2 жыл бұрын
uhhhhhhhhhhhhhhhhh mine generates a plane????? task failed succesfully
@iron4537
@iron4537 Ай бұрын
When i tried doing it withouth matrixes using only trigonometry i had rhe same issue, i believe its because matrixes are assymetrical but what i did with trig wasnt
@cgiscript415
@cgiscript415 Жыл бұрын
I just cant find the right words to explain how i am appreciate this. Man i spent weeks to understand 3d projection and because my math background is weak i just disappointed and stopped to try. But God finally sent you to me :) Thanks man, this is awesome explanation for aliens to 3d(like me). Also thanks again for funny presentation.
@nikolastamenkovic7069
@nikolastamenkovic7069 2 жыл бұрын
Great tutorial! My piece of mind on the "bracket" issue". In order to multiply matrices, number of columns of matrix on the left needs to be equal to the number of rows of the matrix on the right. The projection matrix (P) is 3x3 matrix. M1 = [x, y, z] is 1x3 matrix. M2 = [[x]],[y],[z]] is 3x1 matrix. (It doesn't look so intuitive when there's only one element per row) P x M1 -> not possible P x M2 -> possible M2 = (M1) transposed So, even though you solved problem using reshape, I think that more accurate way is to use matrix transposition here. I've yet to start learning numpy, but i'm sure there is a function numpy.transpose() or something along those lines.
@kaklikcontapessoal129
@kaklikcontapessoal129 3 жыл бұрын
good video.teaches how to apply texture and apply a Z position and camera position and camera rotation
@atharvsharma2539
@atharvsharma2539 3 жыл бұрын
this is underated
@vinnn8694
@vinnn8694 Жыл бұрын
Thanks a lot, this was perfect for me as i could understand it and change it to my own needs. I used it to create a Hexagon viewed from an x-axis angle. Now I want to try making a game-grid for pygame from this.
@vinnn8694
@vinnn8694 Жыл бұрын
Although, I guess I will run into a problem. I am not sure what the right words are, but i guess i need orthographic perspective to get rid of the depth skewing? If anyone can help me with this, leave a comment pls :) Meanwhile I will try to figure it out myself.
@Sycro11
@Sycro11 6 ай бұрын
@@vinnn8694 im a bit late but orthographic projection is a completely different thing and the whole purpose of using perspective projection is to see depth and majority of games use it. orthographic projection is mainly used for things like engineering where they dont want this depth.
@peeper2070
@peeper2070 11 ай бұрын
Unexpected death note. Very unexpected.
@RenderingUser
@RenderingUser Жыл бұрын
man started this video like the monogatari series
@Dileuven
@Dileuven 2 жыл бұрын
I like that death note theme song in the background, makes it feel so dramatic.
@nio8739
@nio8739 3 жыл бұрын
freaking awesome dude!
@xixixitsme
@xixixitsme Жыл бұрын
this is art, congratulations!
@eagle_2712
@eagle_2712 3 жыл бұрын
incredible!! btw where did you get this cursor
@pythonista_333
@pythonista_333 3 жыл бұрын
it's the default dmz white from ubuntu
@ajarivas72
@ajarivas72 6 ай бұрын
@@pythonista_333 Arigato
@jonasstrabel
@jonasstrabel 2 жыл бұрын
Nice Video! Learned a lot while being entertained!
@tsukigva6130
@tsukigva6130 3 жыл бұрын
amazing video! learned a lot from it
@programm_mister9692
@programm_mister9692 9 ай бұрын
Good job bro, How to a make a frustum projection?
@maynermoran
@maynermoran Жыл бұрын
De aquí va a salir mi tesis gracias ❤
@linuslim3841
@linuslim3841 2 жыл бұрын
Could you map textures on the cube?
@evansmart-w9r
@evansmart-w9r 3 ай бұрын
amazing! its so easy! thx!
@_doofiis7420
@_doofiis7420 3 жыл бұрын
Nice use of the deathnote ost
@kevinquintana3085
@kevinquintana3085 Жыл бұрын
Man that's what I needed, an actual tutorial on drawing points and lines using a not so bloated library in a good language (fck java) in structured programming (fck classes), not to simple or starting from the ground and not too complex or starting with OpenGL (vulkan gives me nightmares)...
@64-bit63
@64-bit63 2 жыл бұрын
You can do this on pydroid it works and i verified it (pydroid has diffrent interpretations of window you also gotta screen = display.set_mode((0,0))
@SaferSephy
@SaferSephy Жыл бұрын
to solve the issue with matrix multiplication you have to match up the shapes in terms of mn * nm. Easiest to do this here is to transpose the point vertex with .T
@curcumin417
@curcumin417 6 ай бұрын
Awesome tutorial!
@tashadurrahman
@tashadurrahman 2 жыл бұрын
Oh man... you got the Death note music in the background
@BielDespair
@BielDespair 2 ай бұрын
Nice music from Death Note
@thingsss717
@thingsss717 Ай бұрын
amazing vid i finally understand
@9Lights
@9Lights Жыл бұрын
Wah! Your videos are too good for 385 subscribers. Thanks lot for the video tho.
@AntonioCesarAlves
@AntonioCesarAlves Ай бұрын
Welcome to Plato's Cave
@hezziacGames
@hezziacGames 10 ай бұрын
Great to code along simple to follow as well as learned a few things... and i got a spinning cube on my computer 😎
@lyrabruno1
@lyrabruno1 Ай бұрын
Valeu, brazuca! Deu pra entender bem o inglês.
@pythonista_333
@pythonista_333 Ай бұрын
esse video ficou meio cringe, olha o novo que eu postei, ficou daora :)
@ТимофейКарлин-е8с
@ТимофейКарлин-е8с 3 жыл бұрын
amazing thank you for video
@harigopaladamus9481
@harigopaladamus9481 7 ай бұрын
bro entered the matrix 💀
@brodoshorts
@brodoshorts 3 жыл бұрын
I LOVE YOU!!! 😍
@hessnin
@hessnin Жыл бұрын
the into says it all
@ranveerdev4514
@ranveerdev4514 Жыл бұрын
hi sir it is really good tutorial, can you tell me that how can we use arroy of other OBJ and then render that. Please reply me soon.
@renejr2006
@renejr2006 Жыл бұрын
any idea how i can connect points to a 4d square using the p in range
@ravethefox
@ravethefox 2 жыл бұрын
i dont know if its my additions but i tested the code you uploaded and edited the cube to have a new point at 0,0,-1. i added the ability to control the rotation and scale. ive found that if when you start the program and rotate it in the x axis the point will be on the closest side of the cube to the camera while if you rotate it in the y axis it will be on the far side of the cube edit: sometimes both axis give the same result when starting the program and sometimes its the opposite
@ravethefox
@ravethefox 2 жыл бұрын
Nvm i think its just an optical illusion
@MarlandoCrosdale
@MarlandoCrosdale 2 жыл бұрын
This was a really fun video and I enjoyed most of it, my only problem was that your approach on teaching wasn't what I was expecting, meaning you didn't explain everything. So a complete beginner or someone who had little to no knowledge of matrix or perspective would have been completely lost.
@1alexandermichael
@1alexandermichael 2 жыл бұрын
this video requires a basic understanding of linear algebra
@yongamamkolokotho9904
@yongamamkolokotho9904 2 жыл бұрын
Watch a video by coding train on projection 3d he explains it.
@pythonista_333
@pythonista_333 2 жыл бұрын
sorry about that ;( check out the coding train's video, im sure he can explain it better
@ziyadcodes
@ziyadcodes 2 жыл бұрын
How do I make it so that the line on the front appears over the line on the back?
@cheeseburgerinvr
@cheeseburgerinvr 9 ай бұрын
That intro makes me scared already I knew this was a bad idea.
@theguy2887
@theguy2887 3 жыл бұрын
i loved it!!! show to everybodyhow to make an first person!!! it will be awolsome.
@tonin8499
@tonin8499 3 жыл бұрын
Hi ! Great video, worked like a charm :) But I have a question : why is the order of the points so important ?
@atharvsharma2539
@atharvsharma2539 3 жыл бұрын
Because the order matters for multiplication of matrices (in this case are (x , y , z) cordinates
@tonin8499
@tonin8499 3 жыл бұрын
@@atharvsharma2539 Yes, you're right about multiplying the points with the rotation/projection matrixes, but what about the order of the points relative to one another ? He says the order in which the points are defined matters,at 9:00, but that, I don't get why
@dhpshow9277
@dhpshow9277 2 жыл бұрын
@@tonin8499 because the order decides what dots get a line drawn in between then
@elmondo.
@elmondo. 2 жыл бұрын
Thank for sharing
@person10103
@person10103 5 ай бұрын
is there a way to fill every face of the cube?
@westonkomar3767
@westonkomar3767 3 жыл бұрын
Thank you
@royal-h3e
@royal-h3e Жыл бұрын
Hi! Your video is really helpfull, ty!!!
@musicandlength
@musicandlength 2 жыл бұрын
I am kira
@burhanyasir4614
@burhanyasir4614 11 ай бұрын
thee shape problem you were having on which you spent a lot of time researching it could be fixed by just adding the [0,0,0] at the end of the projection matrix. That's how I fixed it. And by the way the projection matrix is useless
@itzmeB2
@itzmeB2 3 жыл бұрын
Is there anyway I can add textures to it?
@pythonista_333
@pythonista_333 3 жыл бұрын
well, that's a good question
@brainloading5543
@brainloading5543 3 жыл бұрын
You'd have to draw lines between the main lines
@itzmeB2
@itzmeB2 3 жыл бұрын
@@brainloading5543 what about points?
@brainloading5543
@brainloading5543 3 жыл бұрын
@@itzmeB2 wdym?
@itzmeB2
@itzmeB2 3 жыл бұрын
@@brainloading5543 can't u like get a points 3d position with the method in this video? Then u can just assign a color to that point and have textures
@commissarofpublicsafety
@commissarofpublicsafety 2 жыл бұрын
This is godly
@devfromthefuture506
@devfromthefuture506 3 жыл бұрын
🙏
@01bit
@01bit Жыл бұрын
Thanks!!!!
@SquirtingBlood
@SquirtingBlood 9 ай бұрын
when will there be new videos?(
@dynast7550
@dynast7550 2 жыл бұрын
how do u get that cursor?
@tonytony-hz1cg
@tonytony-hz1cg 3 жыл бұрын
You bloody bastard 😭 thank you bro it's for my project 😭 😭 😭 😭 😭 😭 😭 😭 😭
@erickcampos6651
@erickcampos6651 2 жыл бұрын
the only thing I really didn't like was the music at minute 6:10. It was like The Omen's soundtrack.
@mohmedahmed6696
@mohmedahmed6696 3 жыл бұрын
Hi thanks for the video can i snap mouse to any point and get its x, y and z coordinates?
@pythonista_333
@pythonista_333 3 жыл бұрын
I'm sure you can get the X and Y, but I'm not sure for the Z axis. I've used orthogonal projection, perhaps in perspective projection you can get the Z axis somehow
@dhpshow9277
@dhpshow9277 2 жыл бұрын
maybe get the x and y coordinates then do every thing you do to place dots in reverse
@ddoshostingeryeah9185
@ddoshostingeryeah9185 3 жыл бұрын
What type projection is this? Ortogonal or what?
@pythonista_333
@pythonista_333 3 жыл бұрын
it's an orthographic projection
@prod_guzz
@prod_guzz Жыл бұрын
can u make a texture tutorial?
@simplyjemelah8276
@simplyjemelah8276 2 жыл бұрын
hi I got this error with the code Traceback (most recent call last): File "C:/Users/Jemelah/AppData/Local/Programs/Python/Python310/cube1.py", line 1, in import pygame File "C:\Users/Jemelah/AppData/Local/Programs/Python/Python310\pygame.py", line 10, in pygame.display.set_caption("3D projection in pygame!") AttributeError: partially initialized module 'pygame' has no attribute 'display' (most likely due to a circular import)
@weversonch
@weversonch 2 жыл бұрын
I wrote in javascript and the object shrinks in size. :(
@ohnocoder
@ohnocoder 2 жыл бұрын
Why subtitles are blocked????!!!!?1!!!!!!111!/1?!/!?!!?
@qwaxi4512
@qwaxi4512 3 ай бұрын
In OpenGL you will do the same concept but OpenGL is harder than PyGame
@joshuac5233
@joshuac5233 3 жыл бұрын
Can you add sides on this cube?
@pythonista_333
@pythonista_333 3 жыл бұрын
you can use the pygame.draw.polygon to draw the sides. The problem is that, in this kind of projection, there is no sense of depth. This is something that I need to figure out. Probably One Lone Coder explains it
@joshuac5233
@joshuac5233 3 жыл бұрын
@@pythonista_333 thank you ^^
@charliegregg5691
@charliegregg5691 3 жыл бұрын
@@pythonista_333 x*=z/math.tan(fov[0]/2) y*=z/math.tan(fov[1]/2) z=(z-ncp)/(fcp-ncp)*2-1) perspective projection into unit cube (if point in veiw it will be inside -1,-1,-1 to 1,1,1. screen x and y are x and y of new point) You may have already found this but I'll share it anyway.
@tiktoks4579
@tiktoks4579 Жыл бұрын
it's cute
@chiranthchiranthmb2996
@chiranthchiranthmb2996 2 жыл бұрын
Do I hear death note baground
@oracuda
@oracuda Жыл бұрын
"how to make a 3d projection": shows orthographic projection
@iron4537
@iron4537 Ай бұрын
People searchin for 3d prolly rlly want orthographic
@oracuda
@oracuda Ай бұрын
@@iron4537 no they dont rofl
@iron4537
@iron4537 Ай бұрын
@@oracuda yeah ig i over generalized, but some people do and i'm one of them
@samyakmarathe3434
@samyakmarathe3434 3 жыл бұрын
If someone find it hard, try watching linear algebra series. In that way u can create this without even watching this video, like I did
@pythonista_333
@pythonista_333 3 жыл бұрын
nice, idk linear algebra, but i think i learned something with this project. If I go to university someday, I will study linear algebra for sure :)
@samyakmarathe3434
@samyakmarathe3434 3 жыл бұрын
@@pythonista_333 all the best
@sandiguha
@sandiguha Жыл бұрын
Hi I make games with pygame. I want to meet more people who fiddles with pygame and game developement. Is there any group or hub you can suggest me please?
@tonin8499
@tonin8499 3 жыл бұрын
does anyone know, or has a link on how to draw the faces ? thx :)
@jeas29
@jeas29 3 жыл бұрын
I think it's possible if you connect the points with polygons instead of lines. Then, you can set the color you want for the polygons. I don't know Pygame very well but I think there's a function to draw polygons.
@tonin8499
@tonin8499 3 жыл бұрын
@@jeas29 thank you, yes you are right, pygame.draw.poly(surface,color,position_list). But my main concern is that, by doing so, they are going to overlap. I would like each face to be drawn only if it's on the front...
@timdoring8571
@timdoring8571 Жыл бұрын
@@tonin8499 Hey I have the exact same problem, did you find a solution in the meantime?
@tonin8499
@tonin8499 Жыл бұрын
@@timdoring8571 oh hi haha, yes I did, you have two solutions (at least) : the painter's algorithm or per pixel rendering. Per pixel might be a bit overkill in this case, I'd suggest starting with painter's algorithm, it needs way less computing power. You basically have all your faces, you sort them by distance to the camera (you can average a point in the middle of the face for that), then draw them furthest to closest. But it's an approximation, you often get overlapping problems (that you won't have with per pixel). You also will get overdraw (drawing faces in top of each other), so the problem I pointed out previously about not wanting to draw hidden faces isn't solved. Still a good solution though. You can also choose to automatically subdivide large faces into several smaller faces to limit the size of artefacts. en.m.wikipedia.org/wiki/Painter%27s_algorithm I'd be glad to help you further if needed :), good luck, let me know if you managed to do what you wanted
@timdoring8571
@timdoring8571 Жыл бұрын
@@tonin8499 thanks for the quick reply! I'll get on it now :)
@spozniony5499
@spozniony5499 3 жыл бұрын
Wow and try make pyramid in the next video
@dhpshow9277
@dhpshow9277 2 жыл бұрын
Just use this points = [] # all the cube vertices points.append(np.matrix([0, -1, 0])) points.append(np.matrix([0, -1, 0])) points.append(np.matrix([1, 1, 1])) points.append(np.matrix([-1, 1, 1])) points.append(np.matrix([0, -1, 0])) points.append(np.matrix([0, -1, 0])) points.append(np.matrix([1, 1, -1])) points.append(np.matrix([-1, 1, -1]))
@havitjustimagine134
@havitjustimagine134 3 жыл бұрын
This is insine ! 👍
@carlosazuaje8381
@carlosazuaje8381 3 жыл бұрын
Someone can help me to understood how he create a cube using arrays of [1, 0, -1]? I mean, Can I do that with all the geomety shapes? Any article or concepts to read?
@fumano2679
@fumano2679 2 жыл бұрын
yes, 1,0,-1 are the coordinates of a point and so every point has 3 different values. it doesnt which shape basically. minecraft is good example how these coordinates work :)
@dhpshow9277
@dhpshow9277 2 жыл бұрын
[1,1,1] = [X,Y,Z] then the array is for each coordinate he makes a dot. After he just connects the dots and its a cube
@sergiopuccini
@sergiopuccini 2 жыл бұрын
Wat about projection in perspective ? %(((((
@srblender5327
@srblender5327 6 ай бұрын
i am comverting the code to work with geometry dash triggers XD
@coolmanthecool603
@coolmanthecool603 8 ай бұрын
Why are you using python for this?
@iron4537
@iron4537 Ай бұрын
Its not meant to be practical, and python is easy
@legendrags
@legendrags Жыл бұрын
Nice vid but WHY ON HELL DID U TEACH US ON LIGHT MODE DO U WANT TO BLIND US!?!?
@Crosbo13_yt
@Crosbo13_yt 8 ай бұрын
Ugh not again I made Minecraft i was trying to make a cube
@I_pvn
@I_pvn 17 күн бұрын
_vertex_
@WahranRai
@WahranRai 5 ай бұрын
Why mixing with pygame ! Just use numpy , your array multiplication (projection) and matplotlib to draw the figure. Keep it simple and stupid !
@pythonista_333
@pythonista_333 4 ай бұрын
You're right! But pygame would give more views lol
@brycepersello5331
@brycepersello5331 3 жыл бұрын
music annoying
@cyklop1977
@cyklop1977 3 ай бұрын
Thx
@bueno_excelente
@bueno_excelente Жыл бұрын
Good job, now enter Z depth. Filling of polygons by scaline, and shading. There we will congratulate you, newbie
@jasonboyd782
@jasonboyd782 Жыл бұрын
I can't stand stammering and stuttering speech, it drives me crazy.
Пишу 3D Движок на Python [ Pygame + Numpy ]
21:56
Standalone Coder
Рет қаралды 137 М.
The Math behind (most) 3D games - Perspective Projection
13:20
Brendan Galea
Рет қаралды 409 М.
Un coup venu de l’espace 😂😂😂
00:19
Nicocapone
Рет қаралды 13 МЛН
REAL 3D brush can draw grass Life Hack #shorts #lifehacks
00:42
MrMaximus
Рет қаралды 12 МЛН
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
Make Your Own Raycaster Part 1
16:52
3DSage
Рет қаралды 431 М.
3D Rotation & Projection using Python / Pygame
24:17
Yuta A.
Рет қаралды 36 М.
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 352 М.
Teaching myself C so I can build a particle simulation
11:52
Gradience
Рет қаралды 278 М.
Let's Program Doom - Part 1
25:13
3DSage
Рет қаралды 444 М.
Coding Challenge #112: 3D Rendering with Rotation and Projection
33:13
The Coding Train
Рет қаралды 205 М.
How to Make a First Person Shooter like Wolfenstein 3D
28:35
Coder Space
Рет қаралды 46 М.
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 5 МЛН