![]() |
Forum Index : Microcontroller and PC projects : The Great Colour Maximite 2 Octahedron Prize Challenge
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Some times: full draw : 1583 ms by commenting out sections no triangle draw : 705 ms no rotation : 1235 ms no image erase : 1419 ms no hidden face : 2475 ms The 'no hidden face' result is interesting. It looks like it is because only 4 triangles are drawn when hidden faces are removed, all 8 are drawn without hidden face removal. Suggests an average of about 120ms per triangle over the 720 iterations. My triangle code is triangle tx0+cx,ty0+cy,tx1+cx,ty1+cy,tx2+cx,ty2+cy,c(&h0),c(&h0) which includes some calculations to center the image on the screen.And of course my vertex coordinates at iteration 650 don't match anyone else's, plus my end position seems different too. ![]() Edited 2020-11-10 12:07 by vegipete Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
That's absolutely fantastic! Brilliant job. Mine ends up matching? Here are my iteration 650 numbers... but of course I have no idea if they are right or wrong as none of us have matched ![]() ![]() |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
P.S. Ignore the time at the top of the last picture -that's with RC15 Edited 2020-11-10 12:25 by PeteCotton |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
z = 0? Those are projected coordinates? I get one rotation of the octahedron every roughly 157 iterations. Which, curiously, is about pi divided by 2, multiplied by 100... ??? Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Vegipete and PeteCotton, you are awesome... amazing job. I only can work on my code in the evening, after my professional workday. I don't know if after 720 iterations the object should be in the start position. You can see in the photos I posted before the position that the octahedron ended, and it never stopped at the start position. If I rotate using only one axis the end position is the same as the start position. For clearing the previous frame I'm using a box slightly greater than the octahedron. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
Well spotted! I just realized I calculate and discard the z value with each rotation once I have calculated the perspective positions. So I added a bit of code to store them. It added 20ms to my time, so I'll remove it once it's done it's job, but full set of co-ordinates below. Thanks for spotting that! I used "option angle degrees" to make my life easier. I'm guessing you're seeing a rounding error? ![]() |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
I think it should be facing the same way. x rotation of 2 degrees, y of 1 and z of 0.5 every iteration. 720 iterations. That'll spin it four times on the x axis, twice on the y axis and one full rotation on the z axis. Unless I am mistaken ![]() The other thing I do that might make a difference is that I always calculate the full current rotation from the octohedrons original vertices. I don't know if you guys are incrementally changing the vertices with each loop? Edited 2020-11-10 13:51 by PeteCotton |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
There is something strange with your vertex coordinates. I just checked the first one and the vertex is not 250 from the origin. I would expect the square root of the sum of the squares of x, y and z to be 250. I can't tell for sure but I think LeoNicolas is getting a similar result to me, just with a reflection difference, perhaps from dealing with y axis up or down, etc. In one of the posts, matherp described which direction the image should rotate for each of the x, y and z rotations. I made sure my orientations matched that. Ah, tenth post, on first page My intuition suggests the combined moves will rotate the object faster than individual moves, hence the non-alignment after 720 iterations. Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
By Jove you're right! I worked out that I was displaying the values after they had been adjusted for the viewplane at 800 pixels (therefore the massively distorted perspective values). Here's the pre-perspective values. Thanks, another good catch. I had my Y going the wrong way. Fixed in the below picture. I might be slow, but I get there in the end ![]() ![]() Edited 2020-11-10 14:21 by PeteCotton |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Finally, I got a time less than 1600ms... and I have some new ideas to optimize the code ![]() ![]() |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
I just ran a check in a CAD program that allows scripting. I created a vector from 0,0,0 to 0,0,1 I wrote a short script that: 1) duplicates a selected object, 2) rotates the new object 2 degrees around the x-axis, 3) rotates the new object 1 degree around the y-axis, 4) rotates the new object 0.5 degrees around the z-axis. This shows the same, slightly over 157 iterations for a single orbit. Slightly over means that at 157 iterations, the vector hasn't quite made it back to the starting vector, 158 iterations has moved past the starting vector. (157.39 iterations for 1 orbit, as a first approximation.) {**********************************************} PROCEDURE RotVector; VAR h1, h2 : Handle; {to object} BEGIN h1 := FSActLayer; {get handle to first selected object} IF h1 = NIL THEN AlrtDialog('No objects selected, you doughhead!') ELSE BEGIN DSelectAll; {deselect everything} h2 := HDuplicate(h1, 0, 0); {duplicate object, no offset} SetSelect(h2); {select new object} Set3DRot(h2, 2,0,0, 0,0,0); {rotate it 2 degrees around x, no offset} Set3DRot(h2, 0,1,0, 0,0,0); { 1 degree around y} Set3DRot(h2, 0,0,0.5, 0,0,0); { 0.5 degrees around z} END; ReDraw; {update display, leave new object selected} END; RUN(RotVector); ![]() Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
You are right, I'll fix the rotation direction. The rotation process has different results depending on the axis rotation order. X->Y->Z will result in a different position compared to Z->Y->X rotation. Am I right? And I guess if I apply all the three axis rotation at once the result will be different as well. Another thing that I noticed was the difference between my vertices values and yours. Should the vertices, after calculating their value using viewplane and Z distance, be equal 200 or -200? |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Yes, x-y-z is different than z-y-x. However, how you build the 3-axis-at-once matrix determines the result. I do mine by first setting the full rotation matrix to the x-rotation. Then I multiply it by the y-rotation matrix. Then I multiply the result by the z-rotation matrix. Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
I'm doing exactly the same process and my end octahedron position (after fixing the rotation directions) is the same as yours image. My concern is the polygon size. Before any rotation my octahedron has 200x200 due the viewplane and z distances. Another challenge change is now we can use the RC15 as mentioned by Peter in the new firmware thread. Let's publish our times using the RC15 firmware |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
Fantastic! Great job! Is it possible to use that Set3DRot command to rotate all 3 axis at once? Does that provide a different answer? |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Yes, Set3DRot can do all three at once: Set3DRot(h2, 2,1,0.5, 0,0,0); The result appears identical to first x, then y, then z.The result _is_ slightly different if I change the order of x,y and z. If I superimpose 150 iterations of an octahedron in the CAD program, I get the image below. The rotation direction is opposite of my CMM2 version, but the resulting shape matches, except for perspective issues - the image below is orthogonal. (Comment out your image clearing BOX command to see the CMM2 equivalent.) Edited 2020-11-11 07:51 by vegipete Visit Vegipete's *Mite Library for cool programs. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
I suppose the best way to tell is the size of the box used to clear the image. My box command is: box 192,92,416,420,0,0,0 That's the smallest box I can use to erase all octahedron pixels. Well, it may be a few pixels too large because I picked x, y, width and height divisible by 4, just because. Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Vegipete (I'm sorry, I don't know your name) How are you calculating your 3d to 2d projection? I'm using the z coordinate to calculate the correct 2d X and Y positions. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
For a point at (px,py,pz): ze = rho - pz ' rho is distance from viewer to origin/object center x = d * px / ze ' d is distance from viewer to view plane y = d * py / ze ' (x,y) is projected point on view plane (x,y) get shifted to move the origin to the middle of the screen. d = 800, rho = 1000 Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
Well that bodes well. Mine is box 192,94,416,413,,0,0 which is close enough for me. (Skipping the third last parameter saves me a whole millisecond ![]() |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |