Instantly share code, notes, and snippets.

# Rogach/DemoViewer.java

Last active May 10, 2024 21:10
Show Gist options
• Save Rogach/f3dfd457d7ddb5fcfd99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

### Rogach commented Mar 25, 2023 • edited

@donell123

can this 3D engine be used for representing an l-system?

Sure, why not.

and how did you figured out the coordinates of each verticle in order to have a proper representation an the 3D onbjet, in this case the pyramid?

By thinking a lot and using trigonometry :) But for the tetrahedron ("the pyramid") the values are very simple, no trigonometry needed - if you align two of the edges with the axes.

### donell123 commented Mar 26, 2023

Hello, i was making some test with this rendering engine and I figured out something. I wanted to change the location of the tetrahedron
using a translation matrix in order to translate each single vertex of each triangle that composing it. But By doing so, the transformation change the size of the tetrahedron. But I just want to change the location without doing anything else transformation, how can achieve that ?

### Rogach commented Mar 26, 2023

@donell123 Can you show what translation matrix did you use?

### donell123 commented Mar 26, 2023

of course , i did something like this:
matrix4 T=new Matrix4(new double[] {
1, 0, 0, a,
0, 1, 0, b,
0, 0, 1, c,
0, 0, 0, 1
});
with a,b,c the value i wanted to add. I wanted to put two tetrahedron one above the other, to be precise I wanted on triangle to be located for example 100 unit in the y-axis above the other. So I thought that the following matrix could do the job:

[ 1, 0, 0, 0
0, 1, 0, 100
0, 0, 1, 0
0, 0, 0, 1 ]

I tried several times, but transforming each vertixes by a translation matrix manage to change the size of the tetrahedron.

### Rogach commented Mar 27, 2023 • edited

@donell123 I'm not sure (because I don't see your entire code), but if your Matrix4 class was simply my Matrix3 extended to 4th row and column, then your matrix needs to be transposed:

[ 1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
0, 100, 0, 1 ]

### kenvifire commented Oct 31, 2023

Why do we need this part in inflate function?
for (Triangle t : result) { for (Vertex v : new Vertex[] { t.v1, t.v2, t.v3 }) { double l = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z) / Math.sqrt(30000); v.x /= l; v.y /= l; v.z /= l; } }

### Rogach commented Nov 5, 2023

@kenvifire
This part moves all the vertices such that they will all be at the same distance from the origin (point 0,0,0). Without it the subdivided triangles will still be looking like the same original triangle.
Try removing this part and you will see what I mean.

### kenvifire commented Nov 12, 2023

@kenvifire This part moves all the vertices such that they will all be at the same distance from the origin (point 0,0,0). Without it the subdivided triangles will still be looking like the same original triangle. Try removing this part and you will see what I mean.

Got it, thanks.