Login  Register

Re: how to transform objects not using Transform3D

Posted by Mr. Broccoli on Jul 24, 2022; 2:29pm
URL: https://forum.jogamp.org/how-to-transform-objects-not-using-Transform3D-tp4041515p4041795.html

Phil,

First of all thank you for your replies. This really helps me a lot.
E.g. I don't see how I could've come up with this implementation of updateData method on my own.

When comes to progress, I've cleaned the file a bit.
One of the requirements I had was to use matrix multiplication for all transformations, so I implemented that.
I tried to use javax.vecmath import and Quat4f with Matrix4f to keep (float) as a uniform data type, but couldn't find any methods for multiplying a Quat4f with a Matrix4f (a point and appropriate transformation matrix).
Therefore I decided to just use RealMatrix for both 4f geometry points and transformation matrices and used following imports:
        import org.apache.commons.math3.linear.MatrixUtils;
        import org.apache.commons.math3.linear.RealMatrix;
        import org.apache.commons.math3.util.FastMath;

Key mapping is as follows:
WSAD - like walking in games,
Arrows - rotating camera up/down/left/right
ZX - zoom in/out
CV - rotate camera along Z axis

To get a better feel of what is the camera position, zoom and rotation, I wanted to place a text that would display all parameters in the upper left corner of the window, but I'm struggling to display text that would change dynamically.
I thought that this would be a case of changing the variable value (so no need for setting by ref pointer - btw couldn't find applicable methods either), but I'm missing something (since it does not change on display).
I only tried with 'x' camera position initially (A, D keys change that).

Also, I've got a question about updateData method, which I changed by adding additional translate array methods.
Why does the following code change all three cubes and not only cube_one?

        cube_one.updateData(new GeometryUpdater() {
                @Override
                public void updateData(Geometry geom) {
                        translateArray(cube_oneData, -dX, 0, 0);
                        translateArray(cube_twoData, -dX, 0, 0);
                        translateArray(cube_threeData, -dX, 0, 0);
                }
        });

I mean I see that we're updating the entire 'geom' in the inner updateData method, but the call comes only from cube_one. How should I understand this?

Finally, as the last part of the assignment I've got, I need to either:
a) implement an algorithm for visible surface determination in 3D (not Z-buffer, RT or RT-alike), might be 'our' scene, but need to add surfaces or at least colour lines,
b) implement simple light reflection algorithm (i.e. Phong) on a scene with a curved surface (i.e. a sphere) and a flat surface, using a single light source, with possibility to change reflection coefficients.

If I show the mix of a & b, that's also OK. Can you point me in the right direction to achieve this? I'm askig this because it seems to me that I lost a lot of time just by 'starting coding' without asking for a bit of guidance in the first place.
I probably didn't want to get labeled as being lazy, but the effectivness of this approach is just poor.

The file:
notusingtransform3D.java

Kind regards, Mr. B