|
Forum Index : Microcontroller and PC projects : CMM2 3D Engine examples
| Author | Message | ||||
| joker Regular Member Joined: 06/02/2024 Location: GermanyPosts: 53 |
Hello, I found some videos on YouTube. One is a tank driving in circles and the other is a rotating football with lighting effects. Does anybody know where I can finde the source code for these examples? By the way, any example would help me to dive into this topic. Any suggestions? Cheers Matthias |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3872 |
Provide links to what you found. ;-) PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 623 |
I implemented those examples years ago, before the 3D API was released. They were written 100% in MMBasic. Ancient 3D engine implement in MMBasic https://github.com/leonicolas/cmm2-3d-api/blob/master/api-3d.bas Octahedron code ' Octahedron-20 – Leo Nicolas option explicit option keyboard repeat 400,40 option base 0 option default float option angle degrees timer=0 mode 1,8 ' Aux variables dim f,i,v, x(2),y(2),z,vi(2),vo(2),tt ' Object data - distance X,Y,Z - Viewplane distance - Vertices and Faces arrays size const dx=400,dy=300,dz=1000,vp=800,vs=5,fs=7 ' Projection matrix dim px(vs),py(vs) ' Vertices dim vt(2,vs)=(0,250,0, 250,0,0, -250,0,0, 0,-250,0, 0,0,250, 0,0,-250) ' Faces dim f1(fs)=(5,5,5,5,4,4,4,4) Graphics Programming on the Colour Maximite 2 67/68 dim f2(fs)=(2,3,1,0,3,1,0,2) dim f3(fs)=(3,1,0,2,2,3,1,0) ' Faces colors dim c(fs)=(rgb(yellow),rgb(cyan),rgb(green),rgb(magenta),rgb(red),rgb(blue),rgb(white),rgb(&H40,&H40,&H4 0)) ' Rotation - Angles X,Y,Z - Rotation matrix const ix=2,iy=1,iz=0.5 dim ax,ay,az, cx,sx, cy,sy, cz,sz, r(2,2) ' Main loop cls for i=1 to 720 box 192,92,416,416,,0,0 inc ax,ix inc ay,iy inc az,iz cx=cos(ax):sx=sin(ax) cy=cos(ay):sy=sin(ay) cz=cos(az):sz=sin(az) r(0,0)=cy*cz:r(0,1)=sx*sy*cz-sz*cx:r(0,2)=-sy*cx*cz-sx*sz r(1,0)=cy*sz:r(1,1)=cx*cz+sx*sy*sz:r(1,2)=sx*cz-sz*cx*sy r(2,0)=sy:r(2,1)=-sx*cy:r(2,2)=cx*cy for v=0 to vs math slice vt(),,v,vi() math v_mult r(),vi(),vo() z=vp/(dz+vo(2)):px(v)=vo(0)*z+dx:py(v)=vo(1)*z+dy if i=650 then pv(vo()) end if next for f=0 to fs v=f1(f):x(0)=px(v):y(0)=py(v) v=f2(f):x(1)=px(v):y(1)=py(v) v=f3(f):x(2)=px(v):y(2)=py(v) math v_cross x(),y(),vo() if math(sum vo())>0 then polygon 3,x(),y(),c(f),c(f) end if next next tt=timer ' Execution statistics page write 0 print "TOTAL AFTER "+str$(i-1)+" ITERATIONS: "+str$(tt,0,2)+" ms" print "TIME PER ITERATION: "+str$(tt/720,0,2)+" ms" print "FPS: "+str$(1000/(tt/720),0,2) sub pv(vrt()) tt=timer math v_print vrt() timer=tt end sub Check this manual as well Graphics Programming on the CMM2 |
||||
| LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 623 |
More here: https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=12896 Here: https://www.thebackshed.com/forum/ViewTopic.php?TID=13139 Battlezone implemented by VegiPete https://github.com/thwill1000/mmbasic-challenge/blob/main/2022/vegipete/StellarBattleinthe7GreenHillsZone.pdf |
||||
| joker Regular Member Joined: 06/02/2024 Location: GermanyPosts: 53 |
Hello, Thank's a lot for all this input. It will take some time to dig through them. Especially VegiPete's StellarBattle is extremely impressive. If I understood it correctly, the code was the base for the 3D engine but none of the programs were build with it, correct? Correct me if I'm wrong, but none of the examples mentioned above use any kind of lighting, correct? Because the 3D Engine does not support any light source, I assume that lighting effects can't be done (efficiently)?. Are there any examples out there that uses the 3D engine? Cheers Matthias |
||||
| joker Regular Member Joined: 06/02/2024 Location: GermanyPosts: 53 |
Hello, Sorry for my silliy questions. I had a deeper look into VegiPete's StelarBattle and it is using the 3D engine. Cheers Matthias |
||||
| LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 623 |
Yes, it is. My code was created before Peter added the 3D engine to MMBasic, and the inbuilt engine is way faster than my version in basic |
||||
| vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1183 |
A detail that may not be initially obvious about the 3D engine is where the camera is, and which direction it is looking. The camera is positioned at x,y,0 (x=0 and y=0 is easiest) and looks in the direction of positive z. Objects in the field of view will have (approximately) x and y values less than the z value (this is a simplification, depends on where the viewplane is.) I used this to quickly remove non-visible objects from the drawing list in Stellar Battle. (I also skipped very close objects because they often don't render cleanly.) As such, the camera doesn't move so view rotation (yaw) and translation is accomplished by moving all the objects in the X-Z plane. (Y unchanged.) When I get to it and add flying enemies to Stellar Battle, the Y value will change to show flight elevation. Camera pitch and roll will require object translation and rotation. Visit Vegipete's *Mite Library for cool programs. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |