Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:16 05 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : The Great Colour Maximite 2 Octahedron Prize Challenge

     Page 4 of 11    
Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1129
Posted: 01:41am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 543
Posted: 02:23am 10 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  Oh yeah! Some serious unrolling and matrix shrinking gives me under 1585 milliseconds. And that's at 400MHz.


That's absolutely fantastic! Brilliant job.

  vegipete said  I gather you are finding too that the end position is not the same as the start position?

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: Canada
Posts: 543
Posted: 02:25am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 1129
Posted: 02:51am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 503
Posted: 03:11am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 543
Posted: 03:30am 10 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  z = 0? Those are projected coordinates?

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!

  vegipete said  I get one rotation of the octahedron every roughly 157 iterations. Which, curiously, is about pi divided by 2, multiplied by 100... ???

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: Canada
Posts: 543
Posted: 03:36am 10 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  
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.


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: Canada
Posts: 1129
Posted: 03:50am 10 Nov 2020
Copy link to clipboard 
Print this post

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
  matherp said  angles to be considered as follows:

X + 2 degrees rotates the top of the tetrahedron away from you
Y + 1 degrees rotates the left of the tetrahedron away from you
Z + 0.5 degrees rotates the tetrahedron clockwise from the perspective of the viewer

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: Canada
Posts: 543
Posted: 04:20am 10 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  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.


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.

  vegipete said  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.

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: Canada
Posts: 503
Posted: 06:56am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 1129
Posted: 07:18am 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 503
Posted: 07:37am 10 Nov 2020
Copy link to clipboard 
Print this post

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?

  matherp said  Looks too small. I'm expecting the octahedron will be about 400 pixels high ((250+250)/1000*800)
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1129
Posted: 08:10am 10 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  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.

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: Canada
Posts: 503
Posted: 03:54pm 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 543
Posted: 04:49pm 10 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  Finally, I got a time less than 1600ms... and I have some new ideas to optimize the code  


Fantastic! Great job!

  vegipete said  I just ran a check in a CAD program that allows scripting.
.......
   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}
......


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: Canada
Posts: 1129
Posted: 09:45pm 10 Nov 2020
Copy link to clipboard 
Print this post

  PeteCotton said  Is it possible to use that Set3DRot command to rotate all 3 axis at once? Does that provide a different answer?

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: Canada
Posts: 1129
Posted: 10:12pm 10 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  My concern is the polygon size. Before any rotation my octahedron has 200x200 due the viewplane and z distances.


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: Canada
Posts: 503
Posted: 10:49pm 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 1129
Posted: 11:26pm 10 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 543
Posted: 11:44pm 10 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  
  LeoNicolas said  My concern is the polygon size. Before any rotation my octahedron has 200x200 due the viewplane and z distances.


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.

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   )
 
     Page 4 of 11    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025