Author Topic: TimeLine Demo / OgreMagic  (Read 3979 times)

0 Members and 1 Guest are viewing this topic.

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
TimeLine Demo / OgreMagic
« on: February 21, 2007 »
Hi all

Here is an other demo TimeLine ,that will teach you how to control your demo by timing.

It has 3 animations and 2 sound , the first one is GIF animation starts after 2 second from the beginning and still playing for 4 seconds then stop, the second one is Movie starts after 4 seconds from the  beginning and still playing for 8 seconds then stop, the 3th one is a animated Image starts after 6 second  from the beginning and still playing for 4 seconds then stop, the first sound starts after 1.5  second  and still play to the End , the second sound starts after 12  seconds and play 2.7 seconds.

It includes the correct MagicLibrary header file  MagicLibrary.bi  ,  so replace it with your old one.

Here is the link

http://bcxdx.spoilerspace.com/FreeBasic/TimeLine_fp.zip

Here is the code
Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  TimeLineDemo
''        Date    :  21/02/2007
''        Purpose :  Teaching  you that how to
''                   use Magic Library With
''                   FreeBasic.
''------------------------------------------------------------------------------

#include once "windows.bi"
#include once "win/d3d9.bi"

#include once "MagicLibrary.bi"


''-----------------------------------------------------------------------------
'' GLOBALS
''-----------------------------------------------------------------------------
dim shared as HWND              g_hWnd       = NULL
dim shared as LPDIRECT3D9       g_pD3D       = NULL
dim shared as LPDIRECT3DDEVICE9 g_pd3dDevice = NULL

dim shared as TimeLineData        ptr   Timer1
dim shared as TimeLineData        ptr   Timer2
dim shared as TimeLineData        ptr   Timer3
dim shared as TimeLineData        ptr   Timer4
dim shared as TimeLineData        ptr   Timer5
dim shared as BitmapFontData      ptr   Amigafont
dim shared as BitmapFontData      ptr   CourierNewFont
dim shared as AnimatedSpriteData  ptr   Mickey
dim shared as GIFAnimationData    ptr   GifAnim
dim shared as SpriteData          ptr   GifSprite
dim shared as MovieData           ptr   Movie
dim shared as SpriteData          ptr   MovieSprite

dim shared as SoundData           ptr   song
dim shared as SoundData           ptr   sample

''-----------------------------------------------------------------------------
'' PROTOTYPES
''-----------------------------------------------------------------------------
declare function WindowProc( byval hWnd as HWND, byval msg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
declare sub init()
declare sub shutDown()
declare sub render()

''-----------------------------------------------------------------------------
'' Name: init()
'' Desc: Initializes Direct3D under DirectX 9.0
''-----------------------------------------------------------------------------
sub init( )
    g_pD3D = Direct3DCreate9( D3D_SDK_VERSION )

    dim as D3DDISPLAYMODE d3ddm

    IDirect3D9_GetAdapterDisplayMode( g_pD3D, D3DADAPTER_DEFAULT, @d3ddm )

    dim as D3DPRESENT_PARAMETERS d3dpp
    clear( d3dpp, 0, len(d3dpp) )

    d3dpp.Windowed               = TRUE
    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD
    d3dpp.BackBufferFormat       = d3ddm.Format
    d3dpp.EnableAutoDepthStencil = TRUE
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE

    IDirect3D9_CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, _
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
                          @d3dpp, @g_pd3dDevice )

IDirect3DDevice9_SetRenderState(g_pd3dDevice,D3DRS_LIGHTING, FALSE)
IDirect3DDevice9_SetRenderState(g_pd3dDevice,D3DRS_CULLMODE, D3DCULL_NONE)

   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    ML_SetMediaDirectory("../MagicMedia/")
       
    ML_SetBaseTimeNow()
    Timer1 = ML_CreateNewTimeLine(2000,4000)  '// start after 2  seconds and play 4 seconds
    Timer2 = ML_CreateNewTimeLine(4000,8000)  '// start after 4  seconds and play 8 seconds
    Timer3 = ML_CreateNewTimeLine(6500,4000)  '// start after 6  seconds and play 4 seconds
    Timer4 = ML_CreateNewTimeLine(1500,0)     '// start after 1.5  second  and still play to the End
    Timer5 = ML_CreateNewTimeLine(12000,2700) '// start after 12  seconds and play 2.7 seconds
   
    Amigafont = ML_LoadBitmapFont("font/AmigaFont2.bmp",32,28,30)
    ML_SetSpriteColorKeyFromPoint(Amigafont,0,0)
    ML_SetActiveBitmapFont(Amigafont)

    CourierNewFont = ML_CreateWindowsSystemFont("Courier New",0,12,550)

    Mickey = ML_LoadAnimatedSprite("Sprites/Micky.bmp")
    ML_SetAnimatedSpriteFrameSize2(Mickey,84,62,0,0,252,248)
    ML_SetSpriteColorKeyFromPoint(Mickey,0,0)
    ML_SetAnimationSpeed(Mickey,10)
    ML_SetAutoAnimationUpdate(Mickey,false)

    dim as integer wwidth , height
    Movie = ML_LoadMovie("movie/Test.Avi")
    ML_SetMovieFramePerSocand(Movie,25)
    wwidth = ML_GetMovieWidth(Movie)
    height= ML_GetMovieHeight(Movie)
    MovieSprite = ML_CreateStaticSprite(wwidth,height)

    GifAnim = ML_LoadGIFAnimationData("gif/acomicmouse.gif")
    wwidth   = ML_GetGIFAnimationWidth(GifAnim)
    height  = ML_GetGIFAnimationHeight(GifAnim)
    GifSprite = ML_CreateStaticSprite(wwidth,height)

    FmodInit()
    song = ML_LoadSoundData("mod/SATELL.S3M",SongType)
    ML_SetSoundVolume(song,250)
    ML_SetSoundFreq(song,10)

    sample = ML_LoadSoundData("mod/Incorrect.Wav",SampleType)
   
end sub

''-----------------------------------------------------------------------------
'' Name: render()
'' Desc: Render or draw our scene to the monitor.
''-----------------------------------------------------------------------------
sub render( )
    IDirect3DDevice9_Clear( g_pd3dDevice, 0, NULL, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER, _
                            D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 )
''
'' begin drawing
''
IDirect3DDevice9_BeginScene(g_pd3dDevice)
   
   
    '' Magic Stuff
    ''
        ML_UseOrthogonalView()
        ML_SetBlendMode(ALPHABLEND)

        dim as single midWidth,midHeight,FullWidth,FullHeight
        midWidth  = ML_GetHalfScreenWidth()
        midHeight = ML_GetHalfScreenHeight()
        FullWidth = ML_GetScreenWidth()
        FullHeight= ML_GetScreenHeight()

        ML_SetAlpha(1.0)
        ML_SetColor(255,255,255)
        ML_SetScale(1,1)

        if(ML_CheckFireTime(Timer1)) then ML_GetNextGIFAnimationFrame(GifAnim)
        if(ML_CheckFireTime(Timer2)) then ML_GetNextMovieFrame(Movie)
        if(ML_CheckFireTime(Timer3)) then ML_UpdateAnimatedSprite(Mickey)
        if(ML_CheckStartFireTime(Timer4)) then ML_PlaySound(song)
        if(ML_CheckFireTime(Timer5))   then   ML_PlaySound(sample)

        Const as single uint = 35
        Const as single posY = 85
        ML_SetSpriteTexture(Amigafont)
        ML_SetActiveBitmapFont(Amigafont)
        ML_DrawString("TIMELINE DEMO",120,35)

        ML_SetColor(255,0,0)
        ML_DrawRectangle(10,posY,FullWidth-10,posY+140)
        ML_SetColor(255,255,140)
        ML_DrawRectangle(12,posY+2,FullWidth-12,posY+118)
        ML_DrawRectangle(12,posY+121,FullWidth-12,posY+138)
        ML_SetColor(255,105,37)
        ML_SetActiveBitmapFont(CourierNewFont)
        ML_SetSpriteTexture(CourierNewFont)
        ML_DrawString("0",32,         posY+130)
        ML_DrawString("2",32+uint*2,  posY+130)
        ML_DrawString("4",32+uint*4,  posY+130)
        ML_DrawString("6",32+uint*6,  posY+130)
        ML_DrawString("8",32+uint*8,  posY+130)
        ML_DrawString("10",32+uint*10,posY+130)
        ML_DrawString("12",32+uint*12,posY+130)
        ML_DrawString("14",32+uint*14,posY+130)
        ML_DrawString("16",32+uint*16,posY+130)
        for i=0 to 17
            ML_DrawLine(32+uint*i,posY+5,32+uint*i,posY+115)
        next

        dim as single x = 32+uint*ML_GetDurationFromBaseTime()/1000
        if(x > 610) then x=610
        ML_SetColor(0,255,0)
        ML_DrawRectangle(32+uint*2,  posY+20,32+uint*2+4*uint,  posY+23)
        ML_DrawRectangle(32+uint*4,  posY+40,32+uint*4+8*uint,  posY+43)
        ML_DrawRectangle(32+uint*6.5,posY+60,32+uint*6.5+4*uint,posY+63)
        ML_DrawRectangle(32+uint*1.5,posY+80, 32+uint*1.5+15*uint,posY+83)
        ML_DrawRectangle(32+uint*12, posY+100,32+uint*12+2.7*uint,posY+103)
        ML_SetColor(0,0,255)
        ML_SetAlpha(0.3)
        ML_DrawRectangle(32,posY+10,x,posY+130)
        ML_SetAlpha(1)
        ML_DrawLine(x,posY+5,x,posY+135)
        ML_DrawString("Mouse", 32+uint*2+50,  posY+19)
        ML_DrawString("Movie", 32+uint*4+125, posY+39)
        ML_DrawString("Mickey",32+uint*6.5+50,posY+59)
        ML_DrawString("Music", 32+uint*1.5+250,posY+79)
        ML_DrawString("Sound", 32+uint*12+30,posY+99)

        dim as integer  wwidth ,  height     
        ML_SetScale(0.5,0.5)
        wwidth = ML_GetMovieWidth(Movie)
        height= ML_GetMovieHeight(Movie)
        ML_DrawMovieFrameToSprite(MovieSprite,0,0,Movie,0,0,wwidth,height)
        ML_SetSpriteTexture(MovieSprite)
        ML_SetColor(255,255,255)
        ML_DrawSprite(MovieSprite,midWidth,320)

        ML_SetScale(1,1)
        wwidth = ML_GetGIFAnimationWidth(GifAnim)
        height= ML_GetGIFAnimationHeight(GifAnim)
        ML_DrawGIFAnimationToSprite(GifSprite,0,0,GifAnim,0,0,wwidth,height)
        ML_SetSpriteTexture(GifSprite)
        ML_DrawSprite(GifSprite,midWidth-200,320)

        ML_SetSpriteTexture(Mickey)
        ML_DrawAnimatedSprite(Mickey,midWidth+200,320)

        ML_UsePerspectiveView()
   
''
'' end drawing
''
IDirect3DDevice9_EndScene(g_pd3dDevice)
    IDirect3DDevice9_Present(g_pd3dDevice, NULL, NULL, NULL, NULL )
   
end sub


''-----------------------------------------------------------------------------
'' Name: WinMain()
'' Desc: The application's entry point
''-----------------------------------------------------------------------------
function WinMain(byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval lpCmdLine as string, _
byval nCmdShow as integer _
) as integer

dim as WNDCLASSEX winClass
dim as MSG        uMsg

with winClass
.lpszClassName = @"MY_WINDOWS_CLASS"
.cbSize        = len(WNDCLASSEX)
.style         = CS_HREDRAW or CS_VREDRAW
.lpfnWndProc   = @WindowProc
.hInstance     = hInstance
.hIcon        = LoadIcon(hInstance, cast(LPCTSTR,IDI_APPLICATION))
    .hIconSm    = LoadIcon(hInstance, cast(LPCTSTR,IDI_APPLICATION))
.hCursor       = LoadCursor(NULL, IDC_ARROW)
.hbrBackground = cast(HBRUSH,GetStockObject(BLACK_BRUSH))
.lpszMenuName  = NULL
.cbClsExtra    = 0
.cbWndExtra    = 0
end with

if( RegisterClassEx( @winClass ) = FALSE ) then
return E_FAIL
end if

g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", _
                             "Direct3D (DX9) - Primitive Types", _
     WS_OVERLAPPEDWINDOW or WS_VISIBLE, _
         0, 0, 640, 480, NULL, NULL, hInstance, NULL )

if( g_hWnd = NULL ) then
return E_FAIL
end if

    ShowWindow( g_hWnd, nCmdShow )
    UpdateWindow( g_hWnd )

init()

do while( uMsg.message <> WM_QUIT )
if( PeekMessage( @uMsg, NULL, 0, 0, PM_REMOVE ) ) then
TranslateMessage( @uMsg )
DispatchMessage( @uMsg )
        else
    render()
    sleep 10
end if
loop

shutDown()

    UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance )

return uMsg.wParam
end function

''-----------------------------------------------------------------------------
'' Name: WindowProc()
'' Desc: The window's message handler
''-----------------------------------------------------------------------------
function WindowProc( byval hWnd as HWND, _
byval msg as UINT, _
byval wParam as WPARAM, _
byval lParam as LPARAM _
   ) as LRESULT

    select case ( msg )
        case WM_KEYDOWN
select case( wParam )
case VK_ESCAPE
PostQuitMessage(0)

end select

case WM_CLOSE
PostQuitMessage(0)

        case WM_DESTROY
            PostQuitMessage(0)

case else
return DefWindowProc( hWnd, msg, wParam, lParam )
end select

return 0
end function

''-----------------------------------------------------------------------------
'' Name: shutDown()
'' Desc: Release all Direct3D resources.
''-----------------------------------------------------------------------------
sub shutDown( )

    if( g_pd3dDevice <> NULL ) then
        IDirect3DDevice9_Release(g_pd3dDevice)
    end if

    if( g_pD3D <> NULL ) then
        IDirect3D9_Release( g_pD3D )
    end if
end sub

''
''
''
end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )


Enjoy it.
« Last Edit: February 22, 2007 by Emil_halim »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: TimeLine Demo / OgreMagic
« Reply #1 on: February 22, 2007 »
404 Mate.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: TimeLine Demo / OgreMagic
« Reply #2 on: February 22, 2007 »
404 Mate.

Sorry I did not get it.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: TimeLine Demo / OgreMagic
« Reply #3 on: February 22, 2007 »
Not Found

The requested URL http:// was not found on this server.  :-\ Think there must be a spelling mistake in your link mate.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: TimeLine Demo / OgreMagic
« Reply #4 on: February 22, 2007 »
Oh , so sorry , i will fix it now , thanks

Edited:

Fixed & tested.
« Last Edit: February 22, 2007 by Emil_halim »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: TimeLine Demo / OgreMagic
« Reply #5 on: February 22, 2007 »
Works really well :)

I like that very much indeed.
If anyone wants to run this, remember it needs the dlls :)
Shockwave ^ Codigos
Challenge Trophies Won: