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 : CMM2: V5.07.00b12 - Various fixes
Page 7 of 9 | |||||
Author | Message | ||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
Need example code to check as my simplistic test is OK Edited 2021-05-13 01:12 by matherp |
||||
William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 386 |
I will have to wait until it happens again; I forgot where in a lengthy program it occurred, and I have since worked around the problem. It's not the first time it happened, so I should be able to produce it again. Sorry for not having a ready example. -Bill |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
I may have found a case where this isn't possible. Or something related. Below is the rotating cube example from the 3D engine manual. I made a few changes: 1) I changed the colour of the edges to 0 - black (same effect with 'notblack') 2) I changed the scaling to twice as big 3) I added a keypress to step through the rotations. Examination of individual frames shows the same issue of faces (drawn as filled polygons?) not filled in properly. And the DRAW3D CREATE command won't allow an integer vertex array. ========= On a related yet different matter, is there a suggestion for how to draw 3D objects on a non-black background? PAGE COPY with "don't copy black pixels" does part of it but the background has to be redrawn to erase the old image. Less background re-drawing would be possible if there were a means of determining (rectangular) extents (the bounding box) of the 3D object projection. DIM FLOAT vertices(2,7) = (-1,1,-1, 1,1,-1, 1,-1,-1, -1,-1,-1, -1,1,1, 1,1,1, 1,-1,1, -1,-1,1) DIM INTEGER facecount(5)=(4,4,4,4,4,4) DIM INTEGER faces(23)=(0,1,2,3, 1,5,6,2, 0,4,5,1, 5,4,7,6, 2,6,7,3, 0,3,7,4) DIM INTEGER colours(6)=(rgb(blue), rgb(green), rgb(yellow), rgb(cyan), rgb(red), rgb(magenta),0) DIM INTEGER edge(5)=(6,6,6,6,6,6) DIM INTEGER fill(5)=(0,1,2,3,4,5) DIM n=1, nv=8, nf=6, camera=1 MATH SCALE vertices(), 200.0, vertices() DRAW3D CREATE n, nv, nf, camera, vertices(), facecount(), faces(), colours(), edge(), fill() DIM FLOAT yaw=rad(1), pitch=rad(2), roll=rad(0.5) DIM FLOAT q(4) DIM INTEGER viewplane=500 DRAW3D CAMERA n, viewplane DIM INTEGER x=0, y=0, z=1000 PAGE WRITE 1 DRAW3D SHOW n, x, y, z DO MATH Q_EULER yaw, pitch, roll, q() DRAW3D ROTATE q(),n DRAW3D show n,x,y,z INC yaw,RAD(1) INC pitch,RAD(2) INC roll,RAD(0.5) PAGE COPY 1 to 0,B do : loop until inkey$ <> "" LOOP Visit Vegipete's *Mite Library for cool programs. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5768 |
Edited 2021-05-14 16:50 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
I can't see a simple fix to the fill issue. It arises from the different algorithms for triangle fill and line drawing. I've attached the code below. Feel free to translate to Basic and see if you can find a way through it. (4 sided shapes are filled as two triangles for efficiency) You can establish the bounding rectangle using the functions draw3d(XMAX n) etc. Line drawing algorithm // uses a variant of Bresenham's line algorithm: // https://en.wikipedia.org/wiki/Talk:Bresenham%27s_line_algorithm int absX = ABS(x1-x2); // absolute value of coordinate distances int absY = ABS(y1-y2); int offX = x2<x1 ? 1 : -1; // line-drawing direction offsets int offY = y2<y1 ? 1 : -1; int x = x2; // incremental location int y = y2; int err; DrawPixelFast(x, y, Colour); if (absX > absY) { // line is more horizontal; increment along x-axis err = absX / 2; while (x != x1) { err = err - absY; if (err < 0) { y += offY; err += absX; } x += offX; DrawPixelFast(x, y, Colour); } } else { // line is more vertical; increment along y-axis err = absY / 2; while (y != y1) { err = err - absX; if (err < 0) { x += offX; err += absY; } y += offY; DrawPixelFast(x, y, Colour); } } Triangle fill algorthm //we are drawing a filled triangle which may also have an outline int a, b, y, last; if (y0 > y1) { swap(y0, y1); swap(x0, x1); } if (y1 > y2) { swap(y2, y1); swap(x2, x1); } if (y0 > y1) { swap(y0, y1); swap(x0, x1); } if(y1 == y2) { last = y1; //Include y1 scanline } else { last = y1 - 1; // Skip it } for (y = y0; y <= last; y++){ a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); DrawHLineFast(a, y, b, Colour); } while (y <= y2){ a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); DrawHLineFast(a, y, b, Colour); y = y + 1; } |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
V5.07.00b32 now available http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip This re-engineers the triangle drawing routine to ensure the border and fill match properly - serious testing needed Re-times the MAP SET command to avoid artifacts on the last line |
||||
epsilon Senior Member Joined: 30/07/2020 Location: BelgiumPosts: 255 |
Thank you! I'll check it out. A quick question about MAP SET: I timed it and the results are all over the place which makes me think that MAP SET blocks until VSync, i.e. it's not a deferred operation like PAGE COPY D. Is that correct? Epsilon CMM2 projects |
||||
epsilon Senior Member Joined: 30/07/2020 Location: BelgiumPosts: 255 |
Sorry, that was a bit vague. In the meantime I verified MAP SET timing with a standalone test program: OPTION EXPLICIT OPTION DEFAULT NONE OPTION BASE 0 DIM t!, v! DO v!= RND*13: PAUSE v! t!=TIMER:MAP SET:t!=TIMER-t! PRINT "v+t="+STR$(v!+t!)+" t="+STR$(t!) LOOP END The results show that v+t is more or less constant, which suggests MAP SET syncs to the frame rate. v+t=15.876133 t=13.23 v+t=15.97213922 t=8.809 v+t=16.69374181 t=13.388 v+t=16.32962766 t=5.967 v+t=15.21458084 t=8.545 v+t=15.90818469 t=12.126 v+t=15.29405745 t=5.704 v+t=15.88671867 t=14.284 v+t=16.0750811 t=10.863 v+t=15.47299851 t=11.442 v+t=15.88896651 t=7.023 v+t=15.416201 t=15.083 v+t=16.52745739 t=12.179 v+t=15.41312528 t=14.035 v+t=16.61239922 t=12.337 v+t=15.78710054 t=5.917 v+t=15.49287802 t=13.497 v+t=15.61619191 t=5.075 v+t=16.12775504 t=3.654 Epsilon CMM2 projects |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
This re-engineers the triangle drawing routine to ensure the border and fill match properly - serious testing needed Considerably better, not quite perfect. What would happen if you changed "DrawHLineFast(a, y, b, Colour);" to "DrawHLineFast(a+1, y, b-1, Colour); // note a < b" ? I suppose that would leave the odd missing pixel inside. I'm working through the edge cases for combining the fill drawing with Bresenhaming (how's that for verbifying?) the edges in a single (well, upper and lower half) pass. The nuisance is lines that are more horizontal - iterating over x. Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
I think I've found the problem - it was caused by drawing the line from the opposite end in which case Bresenham may calculate different pixels. V5.07.00b33 now available http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip Also improves rotation of areas with even number of pixels Allows peek/poke access to the vartbl for simple variables and not just strings and arrays Edited 2021-05-16 04:42 by matherp |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
Triangles (and quadrangles) are so far appearing flawlessly now. Great work! Visit Vegipete's *Mite Library for cool programs. |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 430 |
http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip just for convenience's sake. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3865 |
Possible bug with Peek(Word addr%) 400MHz Colour Maximite 2 MMBasic Version 5.07.00b33 Copyright 2011-2021 Geoff Graham Copyright 2016-2021 Peter Mather Dim msg$ Cat msg$, Chr$(128) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Cat msg$, Chr$(0) Dim msg_addr% = Peek(VarAddr msg$) Dim i% For i% = 0 To 7 : Print Hex$(Peek(Byte msg_addr% + i%), 2) " "; : Next Print Hex$(Peek(Word msg_addr% - 1)) Print Hex$(Peek(Word msg_addr% + 0)) Print Hex$(Peek(Word msg_addr% + 1)) Print Hex$(Peek(Word msg_addr% + 2)) Print Hex$(Peek(Word msg_addr% + 3)) Print Hex$(Peek(Word msg_addr% + 4)) > *foo 08 80 00 00 00 00 00 00 0 8008 8008 8008 8008 0 Is Peek(Word addr%) rounding addr% to a 32-bit boundary ? Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
Yes, all peeks round to the relevant boundary |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3865 |
Yes, all peeks round to the relevant boundary "Curses", and Pokes too ? This should probably be added to the manual. MMBasic is not the easiest language to implement encryption algorithms in Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
epsilon Senior Member Joined: 30/07/2020 Location: BelgiumPosts: 255 |
I'm currently tuning my game loop so that it runs at (75/2) fps. However, I have a 480MHz device, so I currently can't test how the game behaves on a 400MHz device. I was wondering if it's a reasonable request to have a 400MHz OPTION flag, so 480MHz devices can be made to run a 400MHz. Peeking at the FW: ... /* Configure the system clock */ SystemClock_Config(); HardwareVersion=getVersion(); /* USER CODE BEGIN SysInit */ firsttime=MX_RTC_Init(); LoadOptions(); ... Maybe it's possible to tweak the SystemClock PLL settings after LoadOptions() depending on such an OPTION flag? Epsilon CMM2 projects |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
Options can't be read until the clocks are set so that can't work. This is why things like turbo mode are enabled by a link on the 40-pin header. Not everyone likes this approach because it can compromise or be compromised by connected peripherals. However, for my testing purposes there is a backdoor you can use with the beta which probably won't be in the final version. Connect pin 7 and pin 9 with a link when powering on and see what happens |
||||
epsilon Senior Member Joined: 30/07/2020 Location: BelgiumPosts: 255 |
But can't the clocks be reconfigured after options are read? i.e. the platform starts up at 480MHz as usual, but then switches to 400MHz, depending on the options? Epsilon CMM2 projects |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8604 |
Yes but it is bloody difficult - there are lots of clocks that all have to be consistent and I'm not going to do it |
||||
epsilon Senior Member Joined: 30/07/2020 Location: BelgiumPosts: 255 |
Fair enough. I'm fine with the pins, as long as that remains a possibility in beta FW. Epsilon CMM2 projects |
||||
Page 7 of 9 |
Print this page |