![]() |
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 |
Since everyone likes pictures, here is (a version of) the geometry to project a 3-D point onto a viewing plane. Shown is for x, y is the same, as in my previous posting. You can see that as pz moves closer to the eye, x increases even if px stays the same, and vice versa. This is the basic premise of perspective. ![]() Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Thank you vegipete I'm using the same calc for my projection. Today evening I'll post the new time for the RC16 version. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Ughh, I made a mistake in the similar triangle equation. It should be x / px = d / (rho-pz) Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
After some improvements and running using the RC5 firmware I reached 1198ms. ![]() Probably I can improve my rotation algorithm to be more efficient. I fixed an issue in my projection code and now the polygon is being cleared using a box with the dimensions shared by you (box 192,92,416,420,0,0,0). The rotation directions are exactly as asked by Peter. ![]() |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
Absolutely brilliant! Nice one! |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
I recorded 2 videos... Full speed rotation: https://youtu.be/MGgP_TLMwoY Rotation with page copy and 10ms pause between frames. https://youtu.be/ABSVgSg8jYc The RC15 has amazing performance improvements. Thank you Peter (matherp) Edited 2020-11-11 15:36 by LeoNicolas |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10201 |
I think this is wrong. You have to use the z position of each vertex individually to do the depth properly. Perhaps that is one reason why my version is so slow ![]() Edited 2020-11-11 18:23 by matherp |
||||
johnd Newbie ![]() Joined: 22/10/2020 Location: United StatesPosts: 30 |
It looks correct to me. px, py, pz is the vertex point. x,y is the viewplane coord for that vertex point. You need to run through this formula for each vertex (px,py,pz), so 6 times in our case for the octohedron. Another question though, how many people are keeping track of the Normals for each face, and using the 'nz' component of the normal to draw or not draw the triangle if nz > 0 or nz < 0? I suppose the other way is to use cross product of two triangle sides and only draw the face fronts, and not the backs. Not sure which method is faster. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10201 |
Perhaps just wording. This implied to me there was one Z distance for the whole "object" i.e. the tetrahedron |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
I'm recalculating the depth for each 3D vertex in each iteration. What I'm doing is calculating the 2D projected X and Y of each 3D vertex using the vertex X and Y values multiplied by the depth factor that is calculated using the vertex Z, the object Z distance and the view plane distance. For perspective projection, we need to recalculate the depth of each vertex in each iteration. I'm calculating the triangle normal using the cross product of two sides of it. This is the polygon position (and size) before the rotation process. ![]() Edited 2020-11-12 02:22 by LeoNicolas |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Peter, How will we share the source code with you? Should I post the code here after the end of the challenge? I still improving my code but it is good to know how to do it. Edited 2020-11-12 02:26 by LeoNicolas |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10201 |
On this thread is best then everyone can learn from each other |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
I'm calculating the triangle normal using the cross product of two sides of it. Same here. You need to make sure that all sides have the same "handidness". In my case they are all modelled with right-hand co-ordinates. if you use the following face/plane definitions then they should all be in the same format. I know this is a competition, but just in case it helps anyone, if the above vertices are numbered 0 to 5, then the numbering for the right hand rotated planes is: 0,5,2 0,1,5 0,2,4 0,4,1 3,2,5 3,5,1 3,1,4 3,4,2 |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
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 know you already have the skew code out there, but I've been working on this and am making progress. I've been reading through the required maths and to start with I'm building code that will read from a triangle (which in turn can be used to read from any shape including a rectangle). It works well, but still has some bugs and requires the triangle to be in a specific rotation. I'll fix these over the next few days and then throw the source code up here on the forum so that others can see if they can refine it. (Or if anyone else wants to have a crack at writing their own version from scratch?) If it makes it in to the firmware that's great, but I won't be insulted if it doesn't make the cut. Once again, I'm just enjoying the programming challenge. ![]() |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Pete, this is an impressive job, congratulations on the amazing result. It's not the same thing I'm doing, but I implemented a clipping algorithm... it needs some optimization but it's working very well. You can find the implementation on the link below in the method called ClipPolygons. Maybe it can be useful. https://github.com/leonicolas/cmm2-3d-api/blob/master/api-3d.bas Edited 2020-11-12 05:17 by LeoNicolas |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
It's not the same thing I'm doing, but I implemented a clipping algorithm... it needs some optimization but it's working very well. You can find the implementation on the link below in the method called ClipPolygons. Maybe it can be useful. https://github.com/leonicolas/cmm2-3d-api/blob/master/api-3d.bas Thanks! I've been very impressed with your demo videos of this. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
I too am calculating a 'cross-product' for the projected triangles. I don't need the 3D normal because there is no shading involved. That would be the next challenge - change the face brightness based on 3D light sources. My sequence, for each iteration is 1) rotate the 3D point cloud 2) project to the viewing plane 3) draw each triangle if visible (I wonder ... some of you are getting iteration 720 to match iteration 0. What exactly are you rotating each iteration?) ============= As I mused before, the firmware tools that would simplify this would be the ability to multiply each element of a one dimensional array of 'vectors' by a 4x4 transformation matrix and a triangle command that only drew right-handed triangles - 3 vertices in counter-clock-wise order. Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
(I wonder ... some of you are getting iteration 720 to match iteration 0. What exactly are you rotating each iteration?) I'm rotating around z, then around y, then around x. I always rotate off my base object (i.e. I always start with -250,0,0 etc.) and then rotate by the multiple of the step. So at the 720th iteration I am rotating x by 1440 degrees, y by 720 degrees and z by 360 degrees. This prevents any compounded rounding errors. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
In my Elite code there is actually the remmed out code for the normal as I did tinker with changing the light level as vegipete suggested. JohnD: Incidentally, when we are talking about calculating the cross product, I imagine we are all only calculating the Z of the 3D vector. This is enough to work out if the face is pointing towards or away from the viewer. The code for the other vectors is in the code blow, but that is also commented out. ![]() Edited 2020-11-12 06:03 by PeteCotton |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 503 |
Following the matherp instructions, the order might be X, Y and Z. 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 If you are using Euler angles then rotate in the order x,y,z Pete, one thing I didn't understand in your Elite code, how are you calculating the 2D projection for each iteration? |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |