About Monkey 2 › Forums › General Programming Discussion › Fancy Isometric Projection
This topic contains 2 replies, has 2 voices, and was last updated by 
 wiebow
 2 years, 9 months ago.
- 
		AuthorPosts
 - 
		
			
				
July 11, 2016 at 12:56 am #2018
This morning I started my third banana, an isometric voxel world thing.
Am quite pleased with progress so far. The isometric transform is done with far to near rendering order using a grid traversal pattern I came up with a few years back.
For each square of the grid I plan to sort sprites from near to far. Rotating by theta faces sprites towards camera, leaving them at 0 faces them towards the sky.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class PixelMap Extends PixmapMethod New(w:Int,h:Int)Super.New(w,h)endmethod Rect(rx:Int,ry:int,rw:int,rh:Int,c:Color)For Local y:=ry Until ry+rhFor Local x:=rx until rx+rwSetPixel(x,y,c)NextnextEndmethod Ball(rx:Int,ry:int,r:Int,c:Color)For Local y:=-r To rFor Local x:=-r To rLocal dd:=x*x+y*yIf dd<r*rSetPixel(rx+x,ry+y,c)endifNextnextEndEndClass TileField pixmap:=New PixelMap(32,32)Field image:ImageMethod New()pixmap.Clear(Color.None)pixmap.Rect(4,4,24,24,Color.Blue)pixmap.Rect(6,6,20,20,Color.DarkGrey)pixmap.Ball(16,16,10,Color.Black)For Local i:=5 to 27 Step 2pixmap.Rect(i,5,1,22,Color.White)nextimage=new Image(pixmap)endendClass GridWindow Extends WindowField framecount:IntField tile:TileMethod New()Super.New("Grid",800,480)ClearColor=Color.Blacktile=New Tile()EndMethod IsoView(c:Canvas, theta:Double, zoom:double)Local tx:=Cos(theta)*zoomLocal ty:=Sin(theta)*zoomzx=tyzy=txc.Matrix=new AffineMat3f(tx,ty*0.5,-ty,tx*0.5,400,240)EndField zx:DoubleField zy:DoubleGlobal Order4:=New Int[](1,0,0,1,0,1,-1,0,-1,0,0,-1,0,-1,1,0)Method OnRender( c:Canvas ) OverrideApp.RequestRender()Local zoom:=0.1*Mouse.Location.YLocal theta:=0.03*framecountIsoView(c,theta,zoom)' calulate draw order so we scan grid from far to nearLocal quadrant:Int=Int(2*theta/Pi)&3local ix:=Order4[quadrant*4+0]local jx:=Order4[quadrant*4+1]local iy:=Order4[quadrant*4+2]local jy:=Order4[quadrant*4+3]Local n:=20For Local i:=-n To nFor Local j:=-n To nLocal x:=i*ix+j*jxLocal y:=i*iy+j*jyFor Local z:=12 To 0 Step -3c.DrawImage(tile.image,x*34+z*zx,y*34+z*zy)' c.DrawImage(tile.image,x*24,y*24,theta)nextNextnextframecount+=1EndMethod OnKeyEvent( event:KeyEvent) OverrideIf event.Type=EventType.KeyDownIf event.Key=Key.EscapeApp.Terminate()Print "Escape"endifendifendEndFunction Main()New AppInstanceNew GridWindowApp.Run()EndAttachments:
July 11, 2016 at 1:08 am #2023The zoom on this demo is going to be quite something as the traverse algorithm can hopefully be applied recursively with ample opportunity for bake to texture cycle…
July 11, 2016 at 8:23 pm #2054Ohhh, very interesting!
Also the use of a custom matrix is an interesting option.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.
