3d by Phaelax29th Jul 2004 0:21
|
---|
Summary projects a 3d point onto the screen Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on hide mouse null = make vector3(1) null = make vector3(2) null = make matrix4(3) : projection matrix4 3 null = make matrix4(4) : view matrix4 4 null = make matrix4(5) : world matrix4 5 rem just to give some 3d visual reference make object cube 1,20 position object 1,40,0,350 make matrix 1,1000,1000,30,30 do project3dTo2d(1,40,0,350) view matrix4 4 project vector3 1,2,3,4,5 gosub camera_stuff circle x vector3(1),y vector3(1),5 sync loop function project3dTo2d(result as integer,x as float, y as float, z as float) set vector3 2,x,y,z view matrix4 4 project vector3 1,2,3,4,5 endfunction camera_stuff: oldcx#=cx# oldcz#=cz# speed# = 5 if upkey()=1 cx#=newxvalue(cx#,a#,speed#) cz#=newzvalue(cz#,a#,speed#) endif if downkey()=1 cx#=newxvalue(cx#,a#,-speed#) cz#=newzvalue(cz#,a#,-speed#) endif if leftkey()=1 cx#=newxvalue(cx#,wrapvalue(a#-90.0),speed#) cz#=newzvalue(cz#,wrapvalue(a#-90.0),speed#) endif if rightkey()=1 cx#=newxvalue(cx#,wrapvalue(a#+90.0),speed#) cz#=newzvalue(cz#,wrapvalue(a#+90.0),speed#) endif if shiftkey() then inc cy#, 2 if controlkey() then dec cy#, 2 a#=wrapvalue(a#+(mousemovex()/3.0)) cxa#=cxa#+(mousemovey()/3.0) if cxa#<-90.0 then cxa#=-90.0 if cxa#>90.0 then cxa#=90.0 cy# = 0 position camera cx#,cy#+100,cz# rotate camera wrapvalue(cxa#),a#,0 RETURN |