The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

graphics engine rotations not working

It's my first time here so be gently.

I've had this old graphics project laying around (written in oberon) and since i wrote it as one of my first projects it looks kinda chaotic.
So I descided that, since i'm bored anyway, i would rewrite it in java.

Everything so far seems to work... Until i try to rotate and do my eye-point transformation.
If i simply draw the image without rotating or changing the "eye's" position it works fine.

However the moment i try to do any of the operations that require me to multiply a point with a transformation matrix it all goes bad.

1. the eye point transformation generates stupidly small numbers with end co÷rdinates like [-0.002027571306540029, 0.05938634628270456, -123.30022583847628]
this causes the resulting image to look empty but upon multiplying each coordinate with 1000 it turns out it's just moved around the screen rather than being rotated

if i then ignore the eye point and simply focus on my rotations the results are also pretty strange:

2. setting xRotation to 90░ only makes the image very narrow and way too high (resolution should be 1000x1000 and is then 138x1000
3. setting yRotation to 90░ makes it very wide (1000x138)
4. setting zRotation to 90░ simply seems to translate the image all the way to the right side of the screen.

What i have checked so far:

1. i have checked and re-checked my rotation matrices at least 15 times now so they are correct
2. doing a test multiplication with a vector and the identity matrix does return the original vector
3. my matrices are initialized as identity matrices prior to being used as rotation matrices
4. the angles in the files are in degrees but are converted to radian when read.

Having said that i have 2 more notes:

1. a vector in this case is a simple 3 value array of doubles (obviously representing the x, y and z values)
2. a matrix is a 4x4 array of doubles initialized as the identity matrix

The reason i gave them their own classes is for code readability and to make it easier when doing operations on them.

So without further ado here are a couple of code snippets...

here's the code responsible for initializing the rotation matrices based on an angle or the eye-point vector if it's the eye-transformation matrix
[spoiler]

Re: graphics engine rotations not working

Can you show the difference in the math results from the old code to the Java translation and post just the Java code that provides those results? I'm trying to get you to narrow the question down to what really matters, and I'm not even sure I know what that is, but you seem to be surprised at the very small numbers generated by the Java code. Show those results compared to the Oberon code's results and the Java code than gave those numbers.

I could be wrong, but it sounds like you're happy with the results overall, but there's an issue with the scaling. Is there a scaling factor somewhere you can point to or manipulate to change the results? Maybe I'm not even on the right track, but that's what I've gathered so far.

Don't give up. Good luck.

Oh, and as for the spoiler feature, I'm fairly new myself, but I've never used it on the other forums I belong to so didn't think about using it here. I never saw much use for it other than really hiding something I wanted someone to consciously decide to view. (And I consider every word I type to be viewable and a gem to be discovered and cherished by all.) If you consider it an important feature, ask for it in Forum Feedback, and maybe it's something that can be turned on.

Re: graphics engine rotations not working

well, i used a specific compiler that was licensed to the university i used to study at. Since i formatted my computer i'm stuck with just the source code but no compiler :\
So I'm afraid running them side by side will be impossible (i wish i could, i really do).

I can, however, say that the resulting co÷rdinates have to be positive and between 0 and image width for the x-co÷rdinates and between 0 and image-Y for the y-co÷rdinates (with a 0.95 factor offset to have a little border around the image).

here's a little snippet of the list of points from a 2D image that does generate correctly:

the list holds thousands and thousands of these points going from 0,0 all the way up to imagewidth, imageheight

It's also certain that is has nothing to do with the scaling factor because it is set at 1 and will not (and should not) influence the image. Even if i were to scale up the image it would not come out the way i want it to come out (which is rotated rather than translated).