Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Can some help me add better cubes to my 3d engine?
- Coding3dnow
- Scratcher
15 posts
Can some help me add better cubes to my 3d engine?
hello i am currently making a 3d engine I have all the hard parts down I just need help adding a cube that you can rotate
https://scratch.mit.edu/projects/972151946/
https://scratch.mit.edu/projects/972151946/
scratch = 3d = true
- Create-Scratch101
- Scratcher
100+ posts
Can some help me add better cubes to my 3d engine?
hello i am currently making a 3d engine I have all the hard parts down I just need help adding a cube that you can rotate
https://scratch.mit.edu/projects/972151946/
Sorry sir, but 3d Engines are fairly hard to make. Searching “3D Engine” may help (look at the code)
Hi! I’m Create-Scratch101, and I work here in the forums, and make very random projects.Create-Scratch101
- Coding3dnow
- Scratcher
15 posts
Can some help me add better cubes to my 3d engine?
oh I already have a 3d engine I just need to add stuff in it like cubes but it is already workinghello i am currently making a 3d engine I have all the hard parts down I just need help adding a cube that you can rotate
https://scratch.mit.edu/projects/972151946/
Sorry sir, but 3d Engines are fairly hard to make. Searching “3D Engine” may help (look at the code)
scratch = 3d = true
- 10SmartGaming
- Scratcher
86 posts
Can some help me add better cubes to my 3d engine?
To create a cube, you need 6 faces. Each face is made up of either 1 quad or 2 triangles. For the sake of this example I will use quads.
At the very basics, a cube goes like this:
EXAMPLE P1(x, y, z), P2(x, y, z), P3(x, y, z) | P = Triangle Vertice
Tri 1: (0, 0, 0), (0, 1, 0) (1, 0, 0)
Tri 2: (1, 1, 0), (0, 1, 0) (1, 0, 0)
Tri 3: (0, 0, 0), (0, 1, 0), (0, 0, 1)
Tri 4: (0, 1, 1), (0, 1, 0), (0, 0, 1)
Tri 5: (1, 0, 0), (1, 1, 0), (1, 0, 1)
Tri 6: (1, 1, 1), (1, 1, 0), (1, 0, 1)
Tri 7: (0, 0, 1), (0, 1, 1) (1, 0, 1)
Tri 8: (1, 1, 1), (0, 1, 1) (1, 0, 1)
Tri 9: (0, 0, 0), (0, 0, 1) (1, 0, 0)
Tri 10: (1, 0, 1), (0, 0, 1) (1, 0, 0)
Tri 11: (0, 1, 0), (0, 1, 1) (1, 1, 0)
Tri 12: (1, 1, 1), (0, 1, 1) (1, 1, 0)
You can multiply every number by the desired size of the square
At the very basics, a cube goes like this:
EXAMPLE P1(x, y, z), P2(x, y, z), P3(x, y, z) | P = Triangle Vertice
Tri 1: (0, 0, 0), (0, 1, 0) (1, 0, 0)
Tri 2: (1, 1, 0), (0, 1, 0) (1, 0, 0)
Tri 3: (0, 0, 0), (0, 1, 0), (0, 0, 1)
Tri 4: (0, 1, 1), (0, 1, 0), (0, 0, 1)
Tri 5: (1, 0, 0), (1, 1, 0), (1, 0, 1)
Tri 6: (1, 1, 1), (1, 1, 0), (1, 0, 1)
Tri 7: (0, 0, 1), (0, 1, 1) (1, 0, 1)
Tri 8: (1, 1, 1), (0, 1, 1) (1, 0, 1)
Tri 9: (0, 0, 0), (0, 0, 1) (1, 0, 0)
Tri 10: (1, 0, 1), (0, 0, 1) (1, 0, 0)
Tri 11: (0, 1, 0), (0, 1, 1) (1, 1, 0)
Tri 12: (1, 1, 1), (0, 1, 1) (1, 1, 0)
You can multiply every number by the desired size of the square
Hello! My name is 10SmartGaming, and I love coding. I started on Scratch, then I moved on to Python, HTML, JavaScript, and much more. I hope to one day own a Computer Manufacturing Company with a little profit rate.
when green flag clicked
if <(Help) = [required]> then
repeat until <(Help) = [satisfied]>
say (pick random (a) to (ZZZZZZZZZZZZZZZZZZZZZZZZZ))
end
wait (1) secs
say [ez]
end
- Coding3dnow
- Scratcher
15 posts
Can some help me add better cubes to my 3d engine?
ok but how do I rotate that cube by the x y and z axis To create a cube, you need 6 faces. Each face is made up of either 1 quad or 2 triangles. For the sake of this example I will use quads.
At the very basics, a cube goes like this:
EXAMPLE P1(x, y, z), P2(x, y, z), P3(x, y, z) | P = Triangle Vertice
Tri 1: (0, 0, 0), (0, 1, 0) (1, 0, 0)
Tri 2: (1, 1, 0), (0, 1, 0) (1, 0, 0)
Tri 3: (0, 0, 0), (0, 1, 0), (0, 0, 1)
Tri 4: (0, 1, 1), (0, 1, 0), (0, 0, 1)
Tri 5: (1, 0, 0), (1, 1, 0), (1, 0, 1)
Tri 6: (1, 1, 1), (1, 1, 0), (1, 0, 1)
Tri 7: (0, 0, 1), (0, 1, 1) (1, 0, 1)
Tri 8: (1, 1, 1), (0, 1, 1) (1, 0, 1)
Tri 9: (0, 0, 0), (0, 0, 1) (1, 0, 0)
Tri 10: (1, 0, 1), (0, 0, 1) (1, 0, 0)
Tri 11: (0, 1, 0), (0, 1, 1) (1, 1, 0)
Tri 12: (1, 1, 1), (0, 1, 1) (1, 1, 0)
You can multiply every number by the desired size of the square
scratch = 3d = true
- MineTurte
- Scratcher
500+ posts
Can some help me add better cubes to my 3d engine?
ok but how do I rotate that cube by the x y and z axis To create a cube, you need 6 faces. Each face is made up of either 1 quad or 2 triangles. For the sake of this example I will use quads.
At the very basics, a cube goes like this:
EXAMPLE P1(x, y, z), P2(x, y, z), P3(x, y, z) | P = Triangle Vertice
Tri 1: (0, 0, 0), (0, 1, 0) (1, 0, 0)
Tri 2: (1, 1, 0), (0, 1, 0) (1, 0, 0)
Tri 3: (0, 0, 0), (0, 1, 0), (0, 0, 1)
Tri 4: (0, 1, 1), (0, 1, 0), (0, 0, 1)
Tri 5: (1, 0, 0), (1, 1, 0), (1, 0, 1)
Tri 6: (1, 1, 1), (1, 1, 0), (1, 0, 1)
Tri 7: (0, 0, 1), (0, 1, 1) (1, 0, 1)
Tri 8: (1, 1, 1), (0, 1, 1) (1, 0, 1)
Tri 9: (0, 0, 0), (0, 0, 1) (1, 0, 0)
Tri 10: (1, 0, 1), (0, 0, 1) (1, 0, 0)
Tri 11: (0, 1, 0), (0, 1, 1) (1, 1, 0)
Tri 12: (1, 1, 1), (0, 1, 1) (1, 1, 0)
You can multiply every number by the desired size of the square
You'd just gradually change it's generation x, y, and z I believe (idk much about how 3D projects work lol)
Example:
Stamp 1: Tri 1: (0,1,1), (0,1,0),(0,0,1)
Stamp 2: Tri 1: (0,1,2), (0,1,1),(0,0,2)
Last edited by MineTurte (March 14, 2024 14:22:56)
(pronouns are she/her). Advanced Alpha Game Studios Manager. Our website: https://aags2.w3spaces.com
This is JuniperActias. AKA Moth mommy. If I helped you out consider following Juni-Bug (my new account)!
If you found this secret, say uwu
Signature gradients here
- 10SmartGaming
- Scratcher
86 posts
Can some help me add better cubes to my 3d engine?
I don't know the specifics, but you would definitely use some trig.ok but how do I rotate that cube by the x y and z axis To create a cube, you need 6 faces. Each face is made up of either 1 quad or 2 triangles. For the sake of this example I will use quads.
At the very basics, a cube goes like this:
EXAMPLE P1(x, y, z), P2(x, y, z), P3(x, y, z) | P = Triangle Vertice
Tri 1: (0, 0, 0), (0, 1, 0) (1, 0, 0)
Tri 2: (1, 1, 0), (0, 1, 0) (1, 0, 0)
Tri 3: (0, 0, 0), (0, 1, 0), (0, 0, 1)
Tri 4: (0, 1, 1), (0, 1, 0), (0, 0, 1)
Tri 5: (1, 0, 0), (1, 1, 0), (1, 0, 1)
Tri 6: (1, 1, 1), (1, 1, 0), (1, 0, 1)
Tri 7: (0, 0, 1), (0, 1, 1) (1, 0, 1)
Tri 8: (1, 1, 1), (0, 1, 1) (1, 0, 1)
Tri 9: (0, 0, 0), (0, 0, 1) (1, 0, 0)
Tri 10: (1, 0, 1), (0, 0, 1) (1, 0, 0)
Tri 11: (0, 1, 0), (0, 1, 1) (1, 1, 0)
Tri 12: (1, 1, 1), (0, 1, 1) (1, 1, 0)
You can multiply every number by the desired size of the square
Hello! My name is 10SmartGaming, and I love coding. I started on Scratch, then I moved on to Python, HTML, JavaScript, and much more. I hope to one day own a Computer Manufacturing Company with a little profit rate.
when green flag clicked
if <(Help) = [required]> then
repeat until <(Help) = [satisfied]>
say (pick random (a) to (ZZZZZZZZZZZZZZZZZZZZZZZZZ))
end
wait (1) secs
say [ez]
end
- Malicondi
- Scratcher
1000+ posts
Can some help me add better cubes to my 3d engine?
Because this was brought back up, I felt that I should answer this and it's quite simple, it just uses a little trigonometry. The formula to rotate around the y axis(left right) is this: ok but how do I rotate that cube by the x y and z axis
x' = (x * cos of (y dir)) - (z * sin of (y dir))
z' = (x * sin of (y dir)) + (z * cos of (y dir))
for the x axis (up down) it's this:
y' = (y * cos of (x dir)) - (z * sin of (x dir))
z' = (y * sin of (x dir)) + (z * cos of (x dir))
and for the z axis (imagine turning your head to the side) it's this:
x' = (x * cos of (z dir)) - (y * sin of (z dir))
y' = (x * sin of (z dir)) + (y * cos of (z dir))
For these, its best to use a custom block to store the original x, y, and z values or this won't work, as x', y', and z' all stand for the changed variables, but the formulas depend on the original values.
For 3d projects, since sin and cos are computationally expensive, using sin and cos in all of these formulas a total of 12 times for a single object is very slow. So i recommend first getting the cos and sin values at the start of every tick before you any formulas to speed this up greatly, like so: (directions will also need variables)
define calc trigin scratch blocks the way to use these formulas will be as so: (i will be using cos and sin variables for this)
set [cosX v] to ([cos v] of (x dir))
set [sinX v] to ([sin v] of (x dir))
set [cosY v] to ([cos v] of (y dir))
set [sinY v] to ([sin v] of (y dir))
set [cosZ v] to ([cos v] of (z dir))
set [sinZ v] to ([sin v] of (z dir))
for y rotation (left right):
set [x v] to (((x) * (cosY)) - ((z) * (sinYfor x rotation (up down):
set [z v] to (((x) * (sinY)) - ((z) * (sinY
set [y v] to (((y) * (cosX)) - ((z) * (sinXfor z rotation (turning head to side):
set [z v] to (((y) * (sinX)) - ((z) * (sinX
set [x v] to (((x) * (cosZ)) - ((y) * (sinZIf you want a little more explanation, see this tutorial.
set [y v] to (((x) * (sinZ)) - ((y) * (sinZ
Hope this helps!
Last edited by Malicondi (March 27, 2024 17:21:13)
post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.
coming soon :)
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.
coming soon :)
- Coding3dnow
- Scratcher
15 posts
Can some help me add better cubes to my 3d engine?
ya your a little work I already added this it was simpler than I thought but thank you for the helpBecause this was brought back up, I felt that I should answer this and it's quite simple, it just uses a little trigonometry. The formula to rotate around the y axis(left right) is this: ok but how do I rotate that cube by the x y and z axis
x' = (x * cos of (y dir)) - (z * sin of (y dir))
z' = (x * sin of (y dir)) + (z * cos of (y dir))
for the x axis (up down) it's this:
y' = (y * cos of (x dir)) - (z * sin of (x dir))
z' = (y * sin of (x dir)) + (z * cos of (x dir))
and for the z axis (imagine turning your head to the side) it's this:
x' = (x * cos of (z dir)) - (y * sin of (z dir))
y' = (x * sin of (z dir)) + (y * cos of (z dir))
For these, its best to use a custom block to store the original x, y, and z values or this won't work, as x', y', and z' all stand for the changed variables, but the formulas depend on the original values.
For 3d projects, since sin and cos are computationally expensive, using sin and cos in all of these formulas a total of 12 times for a single object is very slow. So i recommend first getting the cos and sin values at the start of every tick before you any formulas to speed this up greatly, like so: (directions will also need variables)define calc trigin scratch blocks the way to use these formulas will be as so: (i will be using cos and sin variables for this)
set [cosX v] to ([cos v] of (x dir))
set [sinX v] to ([sin v] of (x dir))
set [cosY v] to ([cos v] of (y dir))
set [sinY v] to ([sin v] of (y dir))
set [cosZ v] to ([cos v] of (z dir))
set [sinZ v] to ([sin v] of (z dir))
for y rotation (left right):set [x v] to (((x) * (cosY)) - ((z) * (sinYfor x rotation (up down):
set [z v] to (((x) * (sinY)) - ((z) * (sinYset [y v] to (((y) * (cosX)) - ((z) * (sinXfor z rotation (turning head to side):
set [z v] to (((y) * (sinX)) - ((z) * (sinXset [x v] to (((x) * (cosZ)) - ((y) * (sinZIf you want a little more explanation, see this tutorial.
set [y v] to (((x) * (sinZ)) - ((y) * (sinZ
Hope this helps!
scratch = 3d = true
- Discussion Forums
- » Help with Scripts
- » Can some help me add better cubes to my 3d engine?