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 2 of 11 | |||||
Author | Message | ||||
qwerty823 Newbie Joined: 30/07/2020 Location: United StatesPosts: 30 |
vegipete, I ran that on my 400Mhz CMM2 running the RC14 code and it didn't crash (though it might be one of the earlier RC14's and not the slightly later reuploads). One thing you can try (and its helped me), put a "trace on" at the top of the program and run it. Right before the crash, note the last line number it printed out. David |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2870 |
Hi All, 20 minutes in and the first face appeared on my screen.. woohoo. Nah, only joking, you all know I can’t program very well and with no GOTO or GOSUB rule would toss me into the sin bin.. Interesting to see how this one progresses. Regards, MICK Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
lol, don't wait for a beautiful code... optimization is antonyms of readability... and the prize is for better performance. |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1082 |
Good idea. The last line shown is one of the calls (line 23) to the subroutine. I am still mystified. (MMBasic Version 5.05.06RC7) Visit Vegipete's *Mite Library for cool programs. |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1082 |
Flashed 5.05.06RC14 and now the program runs fine. Obviously something was fixed. Good work, Peter M! Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
In answer to a previous question, the code should not use the specific properties of a tetrahedron to optimise but should be as generic as possible So for example if we remove the lower vertex to make a pyramid and define the square bottom surface with two triangles then, other than array dimension changes, the code should still work. Please can you all make sure that if you single step the iterations you get a clean image at each point. Also please ensure that you are doing the depth projection properly such that proper perspective is achieved. I'm amazed at the frame rates you are achieving Please ensure you start the timer right at the top of the code and before any initialisation or other calculations and that the time is taken after the 720 iteration. All of the initialisation is an important part of the code efficiency My objective is to see if I can integrate a generic 3D engine into the CMM2 firmware. This would probably have the following inputs for a 3D object: Number of vertices Array with coordinates of vertices centred on a logical 0,0,0 Number of triangles Array with definition of triangular faces as a triplet of vertices per triangle (clockwise ordering) + colour Rotation to be applied x,y,z position of centre of object in real space viewplane position in Z viewer position in x,y,z In a perfect implementation the 3D object would act like a sprite so could be moved without the Basic coder having to do anything. This means a "removal" capability is important but that could just use the sprite mechanism of a saving/restoring a bounding rectangle Edited 2020-11-08 18:44 by matherp |
||||
johnd Newbie Joined: 22/10/2020 Location: United StatesPosts: 30 |
I like the sprite idea. It would be like a 3D sprite, instead of 2D. Interesting... What would also be nice (and maybe is already in the command set, still getting my feet wet with the CMM2), would be a routine that takes a texture (or BMP image) and maps it into a four sided polygon, so we could quickly add textures to 3D maze walls and such. It looks like this is happening in the "Into the Darkness" program, but I haven't looked at the code to see how it's done in that program. |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 316 |
Currently one of my optimisations relies on the fact that the viewer is looking flat across the plane. Do you want us to redesign it so that it can be used from any position and viewplane? |
||||
MauroXavier Guru Joined: 06/03/2016 Location: BrazilPosts: 303 |
In the INTO THE DARKNESS I´m not using mapped textures on the walls, all the things are slices of raycasting using the IMAGE RESIZE_FAST command, something similar that I used on the Wolf3D engine. If we have some texture map support on the firmware, for sure I would try to develop some BSP engine as used in Doom or something more modest, but for sure would be faster, better and more beautiful than the current engine. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Pete Not needed for the competition but it would certainly be a nice to have for the firmware. As you are clearly good at this stuff and online..... As per johnd's suggestion I'm thinking about how to do a generalised mapping of each pixel in an arbitrary convex quadrilateral onto the best fit pixel in a rectangle. I think this could also be very useful for the stuff Mauro is doing if it can be made efficient. I've got code already running that can iterate though each pixel in a quadrilateral. I need the most efficient algorithm to identify the best single pixel in a rectangle to copy. I've found relevant references here and here but I'm sure there are others out there. If this is something you could help with it would be greatly appreciated. Typically with these things I code in Basic first and then port to C once I get it working. Attached is the code for iterating through the quadrilateral. option explicit option default integer dim polyx(3)=(100,300,250,75) dim polyy(3)=(50,75,300,250) dim count=4,ystart=50,yend=300 line polyx(0),polyy(0),polyx(1),polyy(1) line polyx(1),polyy(1),polyx(2),polyy(2) line polyx(2),polyy(2),polyx(3),polyy(3) line polyx(3),polyy(3),polyx(0),polyy(0) ' load some sort of image to copy into the quadrilateral ' load jpg "amigapics/bigtut",400,0 fillint(4,ystart,yend) do:loop sub fillint(count, ystart, yend) local FLOAT nodeX(count) local nodes, y, i, j, k local float temp local f=rgb(red) local c=rgb(green) local xstart, xend for y = ystart to yend-1 nodes = 0 j = count-1 for i = 0 to count-1 if (polyY(i) < y and polyY(j) >= y) or (polyY(j)<y and polyY(i) >= y) then nodeX(nodes) = (polyX(i) + (y - polyY(i)) / (polyY(j) - polyY(i)) * (polyX(j) - polyX(i))) nodes=nodes+1 endif j = i next i for i = 1 to nodes-1 temp = nodeX(i) for j = i to 1 step -1 if temp >= nodeX(j-1) then exit for nodeX(j) = nodeX(j-1) next j nodeX(j) = temp next i for i = 0 to nodes-1 step 2 xstart=int(nodeX(i))+1 xend=int(nodeX(i+0.999999999))-1 for k=xstart to xend pixel k,y,f 'replace this with lookup into a rectangle next k next i next y end sub Edited 2020-11-09 03:08 by matherp |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 316 |
I love this competion, however, to be honest I am doing it for the joy of programming, not the prize. While I appreciate the prize (a CMM2) I already have one, and don't really need a second one. So, I will quite happily update my code so that it is more useful to you (including viewplane and location etc). This will slow it down obviously, but I'm really happy just tinkering with this machine - I'll quite happily see the prize for the original competition go to a more worthy winner! As per johnd's suggestion I'm thinking about how to do a generalised mapping of each pixel in an arbitrary convex quadrilateral onto the best fit pixel in a rectangle. I think this could also be very useful for the stuff Mauro is doing if it can be made efficient. ...... If this is something you could help with it would be greatly appreciated. Typically with these things I code in Basic first and then port to C once I get it working. Attached is the code for iterating through the quadrilateral. I would love to try and help. I did look in to this briefly when I did the Elite ship rotating (textured panels). I will be offline today, however will probably have time tomorrow to take a stab at it. To be honest, this would also make a great friendly competion? There doesn't have to be a prize, just simply who can come up with the most efficient algorithm. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Pete For interest is your CMM2 used in the Elite demo 400 or 480MHz? |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 316 |
For interest is your CMM2 used in the Elite demo 400 or 480MHz? 480mhz |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Excellent - with RC14 my 400MHz is definitely faster than you were seeing with 480 |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
Pete Not needed for the competition but it would certainly be a nice to have for the firmware. I love this competion, however, to be honest I am doing it for the joy of programming, not the prize. While I appreciate the prize (a CMM2) I already have one, and don't really need a second one. So, I will quite happily update my code so that it is more useful to you (including viewplane and location etc). This will slow it down obviously, but I'm really happy just tinkering with this machine - I'll quite happily see the prize for the original competition go to a more worthy winner! As per johnd's suggestion I'm thinking about how to do a generalised mapping of each pixel in an arbitrary convex quadrilateral onto the best fit pixel in a rectangle. I think this could also be very useful for the stuff Mauro is doing if it can be made efficient. ...... If this is something you could help with it would be greatly appreciated. Typically with these things I code in Basic first and then port to C once I get it working. Attached is the code for iterating through the quadrilateral. I would love to try and help. I did look in to this briefly when I did the Elite ship rotating (textured panels). I will be offline today, however will probably have time tomorrow to take a stab at it. To be honest, this would also make a great friendly competion? There doesn't have to be a prize, just simply who can come up with the most efficient algorithm. I agree with Pete. I'm implementing the code for fun, not for the prize, and the optimizations I'm doing in my code I will use in my 3D API. My CMM2 is a Waveshare (480MHz) |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
My last optimized code is running in 1811.17 ms without page copy. With page copy is running in 5358.88 ms. My octahedron end position, after 720 iterations, is not the same as the initial position. I'm using rotation matrices with the given angles. They are being applied in the correct order (X,Y,Z). I'm starting the timer in the first line of the program, before all initialization phase. I'm still optimizing the code. Let's try to gain some ms Peter M., how will we share the code with you? Video of the code without page copy: https://youtu.be/vgUnrGQTpMg Video of the code with page copy: https://youtu.be/gVie6pOZOFo |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
If the future competition winner would like to do it, I propose to donate the prize to @yock1960. He killed his CMM2 https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=13000. |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
After my last optimization, I reached 1789ms I'm doing my best but @Pete your time is awesome. Probably I can improve the 2D projection code, maybe I can gain some ms. Edited 2020-11-09 15:05 by LeoNicolas |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 316 |
I'm doing my best but @Pete your time is awesome. Thank you. But I just realised I might have been cheating a little bit. I moved the object to 1100 points away from the user instead of 1000. I did this because the center of the object is 1000 away from the user, and the viewplane is 800 away, so with the extremities of the object being 250 from center, at some stages the vertices were projecting up to 50 points through the viewplane and this was messing up my perspective calcs. I had forgotten I had done that - which means my drawn triangles will be slightly smaller than yours - which might account for the difference. |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 316 |
I'm doing my best but @Pete your time is awesome. Thank you. But I just realised I might have been cheating a little bit. I moved the object to 1100 points away from the user instead of 1000. ..... I had forgotten I had done that - which means my drawn triangles will be slightly smaller than yours - which might account for the difference. I just checked my code, and through all of the refinements, the program no longer cares if the object is poking through the viewplane, so I have changed that values back so that the object is 1000 units away from the viewer and it's working fine. New time (with the octohedron at 1000 distance) is 1582ms. Yes, I know that's faster than before, but I managed to come up with another refinement which offset the larger drawing areas. Phew. Edited 2020-11-09 16:22 by PeteCotton |
||||
Page 2 of 11 |
Print this page |