Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:32 18 May 2024 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 : CMM2: V5.07.00b12 - Various fixes

     Page 7 of 9    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8604
Posted: 03:11pm 12 May 2021
Copy link to clipboard 
Print this post

  Quote  Peter, I did notice one possible bug in 5.6.00; don't know if it has been fixed in 5.7.xx.


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 States
Posts: 386
Posted: 03:47pm 12 May 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1085
Posted: 05:26am 14 May 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  This suggests the polygon outline code is using different float rounding/truncating than the polygon fill code.


It uses floats rather than doubles for performance reasons - use integers


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 Kingdom
Posts: 5768
Posted: 06:49am 14 May 2021
Copy link to clipboard 
Print this post

  Quote  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.
Does simply drawing over the object in the background colour work? I've done this with polygons when I wanted to leave the rest of the background intact. It might not be great if the object is slow to draw though.
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 Kingdom
Posts: 8604
Posted: 08:15am 14 May 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8604
Posted: 08:07am 15 May 2021
Copy link to clipboard 
Print this post

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: Belgium
Posts: 255
Posted: 08:58am 15 May 2021
Copy link to clipboard 
Print this post

  matherp said  Re-times the MAP SET command to avoid artifacts on the last line


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: Belgium
Posts: 255
Posted: 10:04am 15 May 2021
Copy link to clipboard 
Print this post

  epsilon said   I timed it and the results are all over the place


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: Canada
Posts: 1085
Posted: 05:10pm 15 May 2021
Copy link to clipboard 
Print this post

  matherp said  V5.07.00b32 now available
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 Kingdom
Posts: 8604
Posted: 06:26pm 15 May 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1085
Posted: 07:54pm 15 May 2021
Copy link to clipboard 
Print this post

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 States
Posts: 430
Posted: 02:36am 16 May 2021
Copy link to clipboard 
Print this post

http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip

just for convenience's sake.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3865
Posted: 01:35pm 16 May 2021
Copy link to clipboard 
Print this post

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
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 Kingdom
Posts: 8604
Posted: 02:06pm 16 May 2021
Copy link to clipboard 
Print this post

  Quote  s Peek(Word addr%) rounding addr% to a 32-bit boundary ?

Yes, all peeks round to the relevant boundary
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3865
Posted: 02:12pm 16 May 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  s Peek(Word addr%) rounding addr% to a 32-bit boundary ?

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: Belgium
Posts: 255
Posted: 08:07am 18 May 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8604
Posted: 08:56am 18 May 2021
Copy link to clipboard 
Print this post

  Quote  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.


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: Belgium
Posts: 255
Posted: 09:48am 18 May 2021
Copy link to clipboard 
Print this post

  matherp said  Options can't be read until the clocks are set so that can't work.


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 Kingdom
Posts: 8604
Posted: 10:11am 18 May 2021
Copy link to clipboard 
Print this post

  Quote  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?


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: Belgium
Posts: 255
Posted: 10:51am 18 May 2021
Copy link to clipboard 
Print this post

  matherp said  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


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
© JAQ Software 2024