Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 16:30 20 Apr 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 : Update to Graphics Programming manual

     Page 2 of 2    
Author Message
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 440
Posted: 06:10am 25 Nov 2020
Copy link to clipboard 
Print this post

Hey Doug

The following code is the updated version of the first quaternion example (cube rotation). I replaced the quaternion custom subs with the native math q_* commands. I'm thinking to move the cube initialization values to a data structure, what do you think?

Tomorrow I will update the second example.

quaternion1.bas.zip


option explicit
option default FLOAT

' 3D wire frame graphics demo using quaternions to rotate the coordinates
dim rotq(4),v(4),vout(4),i%,x1,y1,z1,x2,y2,z2,vertex
' define the coordinates of a cube with the z-axis towards the viewer
' coordinates of the cube
dim cube(3,7)=(-100,-100,100,0, -100,100,100,0, 100,-100,100,0, 100,100,100,0, -100,-100,-100,0, -100,100,-100,0, 100,-100,-100,0, 100,100,-100,0)
' define the coordinate pairs that make up the edges of the cube
dim cubelocation(2)=(mm.hres/2,MM.VRES/2,-500) 'actual location of the centre of the cube in space
' define the coordinate pairs that make up the edges of the cube
dim cubelines%(1,11)=(0,1, 0,2, 1,3, 2,3, 4,5, 4,6, 5,7, 6,7, 0,4, 1,5, 2,6, 3,7)
'define the projection plane
dim viewplane = -200
dim lines%(3,11) 'storage for the coordinates for lines drawn

for i%=0 to 7 'convert coordinates to normalised form
 x1=cube(0,i%)
 y1=cube(1,i%)
 z1=cube(2,i%)
 math q_vector x1,y1,z1,v()
 cube(0,i%)=v(1)
 cube(1,i%)=v(2)
 cube(2,i%)=v(3)
 cube(3,i%)=v(4)
next i%

'create a quarternion to rotate 2 degrees about x axis
'play with the x,y,z vector which is the sxis of rotation
math q_create rad(2), 1,0,0, rotq()
'draw lines in memory (page 1)
page write 1
do
 cls
 for i%=0 to 11 'project the coordinates onto the viewplane
   vertex=cubelines%(0,i%)
   z1=cube(2,vertex)*cube(3,vertex)+cubelocation(2)
   x1=(cube(0,vertex)*cube(3,vertex)*viewplane/z1+cubelocation(0))
   y1=(cube(1,vertex)*cube(3,vertex)*viewplane/z1+cubelocation(1))

   vertex=cubelines%(1,i%)
   z2=cube(2,vertex)*cube(3,vertex)+cubelocation(2)
   x2=(cube(0,vertex)*cube(3,vertex)*viewplane/z2+cubelocation(0))
   y2=(cube(1,vertex)*cube(3,vertex)*viewplane/z2+cubelocation(1))

   lines%(0,i%)=x1 : lines%(1,i%)=y1
   lines%(2,i%)=x2 : lines%(3,i%)=y2
 next i%
 for i%=0 to 7 'rotate coordinates
   v(1)=cube(0,i%) 'X
   v(2)=cube(1,i%) 'Y
   v(3)=cube(2,i%) 'X
   v(0)=cube(3,i%) 'magnitude
   v(4)=0
   math q_rotate rotq(),v(),vout()
   cube(0,i%)=vout(1) 'X
   cube(1,i%)=vout(2) 'Y
   cube(2,i%)=vout(3) 'Z
   cube(3,i%)=vout(0) 'magnitude
 next i%
 
 for i%=0 to 11 'draw the new lines
   line lines%(0,i%),lines%(1,i%),lines%(2,i%),lines%(3,i%),1,rgb(white)
 next i%
 'copy page 1 to the screen (page 0)
 page copy 1 to 0
loop
end
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 11:04pm 25 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  Doug

You should change the authorship to yourself!!!!

Trivial changes:
change 10 to 13 in first line
Mode 9 is not widescreen
Mode 10: 12-bit is allowed, monitor sees 848x480@60Hz
Paragraph starting VGA Monitors need correcting to match mode list
page 17 again mode 10 does allow 12-bit mode

Page 17 Comment at bottom on modes 10,11,12 should be that not everyone may have a widescreen monitor. They don't "permanently alter anything

Mode command chapter
Firmware now rounds up to 8Kbytes not 128Kbytes
Default modes can be 1,9, 10, 11, 12

page 31 memory is allocated in chunks of 8Kbyes


Thanks Peter, corrections are included for the next release - can you tell me what the pixel rate is for modes 8, 10, 11,12 and 13 are please.

I appreciate your comment about the authorship - the expression 'on the shoulders of giants' comes to mind!

Regards,
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 11:13pm 25 Nov 2020
Copy link to clipboard 
Print this post

For the 3 amigos from Canada (Pete, Pete and Leo)    or anyone else, is there anywhere I can get an intro to 3D graphics (particularly as it would apply to the CMM2) or perhaps one of you might throw together a few paragraphs for me?
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 01:49am 26 Nov 2020
Copy link to clipboard 
Print this post

I am mulling over my treatise on octahedral optimization and while I wasn't planning on much depth to the math behind 3D graphics, maybe I'll expand on it a bit more.

Although I'd wait a bit until the firmware has settled down and the potential new commands become real.
Visit Vegipete's *Mite Library for cool programs.
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 440
Posted: 02:21am 26 Nov 2020
Copy link to clipboard 
Print this post

  panky said  For the 3 amigos from Canada (Pete, Pete and Leo)    or anyone else, is there anywhere I can get an intro to 3D graphics (particularly as it would apply to the CMM2) or perhaps one of you might throw together a few paragraphs for me?
Doug.


I can write some lines about generic 3D math and link some good videos about this subject. Peter Mather is implementing new commands specifically to 3D rendering and soon we will have this capability directly implemented in the firmware, but the basic 3D math doesn't depend on this implementation.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 05:00am 26 Nov 2020
Copy link to clipboard 
Print this post

Thanks guys, as we all know, just keeping up with Peter is a mamoth task  
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 440
Posted: 05:24am 26 Nov 2020
Copy link to clipboard 
Print this post

Hey Doug

I've updated both quaternion examples. I removed the custom quaternion functions and cleaned up the code. I decided to keep the Painter's Algorithm in the second example. It's being used to render the faces in the correct order. Normally I only use this algorithm to define the render order of different objects, not for faces.

This version has a better performance compared to the original source code. I included new code comments as well.

Leo

quaternion1.bas.zip

quaternion2.bas.zip
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 440
Posted: 05:39am 26 Nov 2020
Copy link to clipboard 
Print this post

This is another nice example. It is the same code I used for the Octahedron challenge with small modifications (I'm not printing the statistics) but instead of rendering the Octahedron, I'm rendering an Icosahedron. The Icosahedron data was created by VegiPete.

This code is not using quaternions. I'm rotating the vertices using a 3D rotation matrix (https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions) and I'm using the face normal to determine if the face will be rendered or not.

icosahedron.bas.zip
Edited 2020-11-26 15:43 by LeoNicolas
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 07:28pm 26 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  This is another nice example. It is the same code I used for the Octahedron challenge with small modifications (I'm not printing the statistics) but instead of rendering the Octahedron, I'm rendering an Icosahedron. The Icosahedron data was created by VegiPete.

This code is not using quaternions. I'm rotating the vertices using a 3D rotation matrix (https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions) and I'm using the face normal to determine if the face will be rendered or not.

icosahedron.bas.zip


i read quaternions as quaterino :P is that a four part neutrino? :P
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024