View 3D X Object by Peace30th Dec 2004 16:11
|
---|
Summary Simple viewer for 3d.x objects Description This code is only for beginners in 3d programming. It will show how to display any 3d.x object on screen. Use mousekeys to zoom object in and out, keys A, X, Y, Z change the angel rotation, W switch to wireframe, Return save actual display as bitmpap picture. You can download the View3DXObject_Example.zip archive including all mediafiles. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Remstart------------------------------------------------------------------Project:View 3D.X ObjectVersion:0.00.001 ;DAuthor:Peace of TestawareLanguage:DarkBASIC Professional v1.057Description:Display & rotate any 3d.x objectDate:30. December 2004 / 22:02:42------------------------------------------------------------------Hint 1:Only for beginners in 3d programmingHint 2:Use keys A, W, X, Y, Z, STRG, LMB/RMB to rotateHint 3:Key RETURN save actually display in Captured3D.bmp------------------------------------------------------------------Remendsync on : sync rate 100`* color backdrop 0: Rem * Try different rgb() valuesxo=1: Rem * Number of objecta$="Models/JETFIGHT2.x": Rem * Name of DirectX 3D fileb$="Models/JETFIGHT2.bmp" : Rem * Image for texturing_Load3DObject(xo,a$,b$): Rem * Install 3D Object_View3DObject(xo): Rem * Display 3D Object`* Examples for standard 3D Objectsfor i=1 to 7_Make3DObject(xo,i,b$)_View3DObject(xo)_ClearKey()next iFUNCTION _Load3DObject(xo,a$,b$)`* Load & install an object`* xo = Number of object`* a$ = Filename of object`* b$ = Image filename for texturing (if needed)`* ------------------------------------------------------------------if object exist(xo) then delete object xoload object a$,xoif b$<>""load image b$,1,1texture object xo,1endifENDFUNCTIONFUNCTION _Make3DObject(xo,m,b$)`* Create standard object`* xo = Number of object`* m = Mode, see case`* b$ = Image filename for texturing`* ------------------------------------------------------------------if object exist(xo) then delete object xoselect mcase 1 : make object cubexo,5: endcasecase 2 : make object spherexo,5,50,50: endcasecase 3 : make object boxxo,5,6,2: endcasecase 4 : make object conexo,5: endcasecase 5 : make object cylinderxo,5: endcasecase 6 : make object trianglexo,0,0,0,1,1,0,0,1,0 : endcasecase 7 : make object plainxo,5,5: endcasecase default : make object cube xo,5: endcaseendselectif b$<>""load image b$,1,1texture object xo,1endifENDFUNCTIONFUNCTION _View3DObject(xo)`* Display 3D.x object`* xo = Number of object`* ------------------------------------------------------------------po=10 : Rem * [LMB/RMB] Z-Position zoom in/outaw=1 : Rem * [A]All xyz rotations on/offwf=0 : Rem * [W]Wireframe on/offxw=1 : Rem * [X]X-Rotation on/offyw=1 : Rem * [Y]Y-Rotation on/offzw=1 : Rem * [Z]Z-Rotation on/offposition object xo,0,0,porepeat`* Returnkey to save actually view as bitmap fileif returnkey()<>0get image 2,0,0,screen width(),screen height(),1syncsave image "Captured3D.bmp",2_ClearKey()endif`* Controlkey to display object as it's defaultif controlkey()<>0x=0 : y=0 : z=0 : aw=0 : xw=0 : yw=0 : zw=0endif`* Use keys to switch angle rotationa$=inkey$()if a$<>""a$=upper$(a$)if a$="A" then aw=abs(aw-1) : xw=aw : yw=aw: zw=awif a$="W" then wf=abs(wf-1) : set object wireframe xo,wfif a$="X" then xw=abs(xw-1)if a$="Y" then yw=abs(yw-1)if a$="Z" then zw=abs(zw-1)_ClearKey()endif`* Left mousekey zoom in, right to zoom outif mouseclick()<>0a=mouseclick()if a=1 then dec po,2 else inc po,2position object xo,0,0,posyncendifx=x-xwy=y-ywz=z-zwrotate object xo,wrapvalue(x),wrapvalue(y),wrapvalue(z)syncuntil a$=" "delete object xoENDFUNCTIONFUNCTION _ClearKeyrepeat : sync : until inkey$()=""ENDFUNCTION |