Scol standard library package
0.3.1
Common and usefull functions for all Scol applications
|
3d_test/test_3d.pkg_
.typeof debug = I;;
.
.struct StrTEST3D = [
. t_iState : I, // 0 : no occured error
.
. t_o3dview : LIB3D_View,
. t_o3dsession : LIB3D_Session,
.
. t_oWinMother : ObjWin,
. t_iSize : [I I],
.
. t_oLogo : ObjBitmap,
.
. t_iErrMask : I,
. t_oErr : STD_ERROR
.
. ] mkStrTEST3D;;
.
.// check if debug = 1
.fun checkDebug ()=
. debug;;
.
.fun printDbg (p)=
. let p -> [str3d message] in
. std_errString str3d.t_oErr message str3d.t_iErrMask;
. 0;;
.
.fun printDebug (p)=
. std_if @checkDebug @printDbg p;;
.
.
.
.fun end (str3d)=
. let b3d_viewDestroy str3d.t_o3dview -> res in
. _fooS if !res then
. "3d structures destroyed successfully"
. else
. strcat "Error during the 3d destruction : " itoa res;
. _DSbitmap str3d.t_oLogo;
. std_errClose str3d.t_oErr;
. _closemachine;
. 0;;
.
.
.
.fun cbResize (win, str3d, neww, newh)=
. b3d_viewSetViewportSizeFromFullViewSize str3d.t_o3dview b3d_viewGetViewportDefault str3d.t_o3dview;
. 0;;
.
.fun cbEnd (win, str3d)=
. end str3d;;
.
.
.fun createWin (str3d)=
. (
. printDebug [str3d "ERROR : Application unitialized !"];
. 1
. )
. else
. let str3d.t_iSize -> [w h] in
. (
. set str3d.t_oWinMother = _CRwindow _channel nil 0 0 w h WN_NORMAL "Test 3D";
.
. _CBwinSize str3d.t_oWinMother @cbResize str3d;
. _CBwinDestroy str3d.t_oWinMother @cbEnd str3d;
. 0
. );;
.
.fun createBgLogo (str3d)=
. let b3d_viewGetSize str3d.t_o3dview -> [viewW viewH] in
. let SO3BitmapWidgetCreateBackground
. b3d_sessionGet str3d.t_o3dsession
. "bgLogo"
. 6 viewH-70
. 64 64
. -> widget in
. if SO3BitmapWidgetBlit widget str3d.t_oLogo then 0 else 1;;
.
.fun cbPreRender (strView, p)=
. if !str3d.t_iState then
. let p -> [str3d logo] in
. let b3d_bufferGetObj str3d.t_o3dview -> buffer in
. let sprintf "Worst FPS %f\nBest FPS %f\nAverage FPS %f"
. [SO3BufferGetWorstFPS buffer SO3BufferGetBestFPS buffer SO3BufferGetAverageFPS buffer]
. -> s in
. (
. set str3d.t_iState = if (!std_objIsNil b3d_objSetRotate logo 0.1 [0.0 negf 0.1 0.0] 0) then 0 else 1;
.
. SO3DebugSetText b3d_viewportGet b3d_viewGetViewportDefault str3d.t_o3dview s;
. 0
. )
. else
. end str3d;;
.
.fun createDebug (str3d)=
. let 0xff0000 -> fcolor in
. let fcolor & 255 -> r in
. let (fcolor>>8) & 255 -> g in
. let (fcolor>>16) & 255 -> b in
. let make_rgba r g b 127 -> crgba in
.
. if SO3DebugDisplayProperties b3d_sessionGet str3d.t_o3dsession b3d_viewportGet b3d_viewGetViewportDefault str3d.t_o3dview nil crgba [6 6] [200 45] 20 then
. if SO3WorldShowLines b3d_sessionGet str3d.t_o3dsession 1 then
. 0
. else
. set str3d.t_iState = 1
. else
. set str3d.t_iState = 1
. else
. set str3d.t_iState = 1;;
.
.fun cb3dViewInit (view, result, str3d)=
. if result!= 0 then
. (
. printDebug [str3d "Unable to initialize 3d view"];
. set str3d.t_iState = 1
. )
. else
. 0;;
.
.fun cb3dSessionInit (strSession, res, str3d)=
. set str3d.t_o3dsession = strSession;
. if res != 0 then
. (
. printDebug [str3d "Unable to initialize the 3d session"];
. set str3d.t_iState = 1
. )
. else
. let b3d_cameraGetFromInit str3d.t_o3dsession -> cam in
. let SO3SceneLoadEntity
. b3d_sessionGet str3d.t_o3dsession
. b3d_resourcesGetGroupNameDefault str3d.t_o3dsession
. "voyager_test_logo"
. _checkpack "locked/voyager/3d/logo.mesh"
. -> logo in
. (
. if (std_objIsNil b3d_viewportNew str3d.t_o3dview cam) || (str3d.t_iState) then let _fooS strcat "B " itoa str3d.t_iState -> _ in
. 2
. else
. set str3d.t_iState = if (!b3d_lightSetColors light [make_rgba 250 250 250 0 make_rgba 255 255 255 0]) &&
. (!b3d_objSetPosition light [-.30.0 30.0 (-.60.0)]) &&
. (!std_objIsNil SO3ObjectRotateYaw light 2.3 0) &&
. (!b3d_objSetRotatePitch light 0.5 SO3_LOCAL_TS) &&
.
. (!b3d_objSetPosition cam [0.0 0.0 6.0]) &&
. (!b3d_cameraSetParams cam nil 1.0 0.01 100000.0) &&
.
. (!b3d_viewEnable str3d.t_o3dview 1) &&
.
. (!b3d_gridShow str3d.t_o3dsession 1) &&
.
. (!std_objIsNil
. SO3SceneLoadResource
. b3d_sessionGet str3d.t_o3dsession
. b3d_resourcesGetGroupNameDefault str3d.t_o3dsession
. _checkpack "locked/voyager/3d/logo.material" SO3_RESOURCE_MATERIAL
. ) &&
. (!std_objIsNil
. SO3SceneLoadResource
. b3d_sessionGet str3d.t_o3dsession
. b3d_resourcesGetGroupNameDefault str3d.t_o3dsession
. _checkpack "locked/voyager/3d/logo.mesh" SO3_RESOURCE_MESH
. ) &&
.
. (!std_objIsNil SO3ObjectSetScale logo [0.01 0.01 0.01]) &&
. (!b3d_viewSetCbPreRender str3d.t_o3dview mkfun2 @cbPreRender [str3d logo]) &&
.
. (!createBgLogo str3d)
. then
. 0
. else
. 1
. );;
.
.
.
.fun init3d (str3d)=
. if str3d.t_iState != 0 then
. (
. printDebug [str3d "Initialization aborted"];
. 1
. )
. else
. if std_objIsNil (
. b3d_initSession str3d.t_o3dview nil mkfun3 @cb3dSessionInit str3d;
. ) then
. set str3d.t_iState = 1
. else
. (
. //b3d_viewSetCbPreRender str3d.t_o3dview @cbPreRender;
. 0
. );;
.
.fun init ()=
. mkStrTEST3D [
. 0
. nil nil
. nil [640 480]
. _LDbitmap _channel _checkpack "logo.bmp"
. b3d_errGetMaskError nil
. ];;
.
.fun showConsole (state)=
. if state then
. (
. _showconsole;
. set debug = 1
. )
. else
. set debug = 0;;
.
.fun main ()=
. showConsole 1;
. let init -> str3d in
. (
. b3d_errSetMaskOgre3D SO3_LL_LOW;
. createWin str3d;
. init3d str3d;
. b3d_viewEnable str3d.t_o3dview 1; //end of init, the 3d view can be enabled / shown
. createDebug str3d;
. if str3d.t_iState != 0 then
. _fooS "ERROR !"
. else
. _fooS "OK !";
. 0
. );;
Generated on Sat Jan 31 2015 19:15:42 for Scol standard library package by 1.8.1.2