Original Post
I've been working with the XAnimator library that can be found HERE to do some .x file animations. I'm having a lot of issues trying to get the library to actually work. Right now I'm working with the sample code that can be found on the library's website to try to get that working before moving on to using it in my own project. I followed the instructions for installing and have included the .lib how it says to, but i'm getting a lot of unresolved externals. Below are my current errors.
I am using Visual Studio 2008 and have the project in a desktop folder. The .lib files and header are in a folder inside the main project folder called XAnimator. I have went into tools->options->Projects and Solutions->VC++ Directories and made a entry for the XAnimator folder so the compiler knows its there. I've also done the steps in the installation section of the library's website. I'm really not sure what else to do >.< Any Advice would be much appreciated.
the main.cpp for the sample project
I am using Visual Studio 2008 and have the project in a desktop folder. The .lib files and header are in a folder inside the main project folder called XAnimator. I have went into tools->options->Projects and Solutions->VC++ Directories and made a entry for the XAnimator folder so the compiler knows its there. I've also done the steps in the installation section of the library's website. I'm really not sure what else to do >.< Any Advice would be much appreciated.
1>XAnimator.lib(MeshHierarchy.obj) : warning LNK4229: invalid directive '/FAILIFMISMATCH:_MSC_VER=1600' encountered; ignored
1>XAnimator.lib(MeshHierarchy.obj) : warning LNK4229: invalid directive '/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0' encountered; ignored
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in XAnimator.lib(XAnimator.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in XAnimator.lib(XAnimator.obj)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base0::_Orphan_all(void)" (__imp_?_Orphan_all@_Container_base0@std@@QAEXXZ)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::showmanyc(void)" (?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsgetn(char *,__int64)" (?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::xsputn(char const *,__int64)" (?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
1>XAnimator.lib(XFileManualSaving.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(XAnimator.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(Utility.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(MeshManager.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(__int64)" (__imp_?width@ios_base@std@@QAE_J_J@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(__int64)" (__imp_?width@ios_base@std@@QAE_J_J@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z)
1>XAnimator.lib(GfxModelAnim.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QBE_JXZ)
1>XAnimator.lib(MeshHierarchy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QBE_JXZ)
the main.cpp for the sample project
/*
Demonstration of using the XAnimator library
By Keith Ditchburn 2010
*/
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
// XAnimator header
#include <XAnimator_lib.h>
#if defined(DEBUG) | defined(_DEBUG)
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif
// Direct3D objects
LPDIRECT3D9 gD3dObject=NULL;
LPDIRECT3DDEVICE9 gD3dDevice=NULL;
// Globals
IXAnimator *gXAnimator=0;
int gModelId=0;
int gNumAnimationSets=0;
int gCurrentAnimationSet=0;
// Function prototypes
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool SetupDirect3D(HWND hWnd);
void ShutdownDirect3D();
void UpdateDemo();
bool LoadModel(const std::string &filename);
// Constants that can be tweaked:
// Transition time between animation sets in ms
float kTransitionTime=2500;
// Time before we switch to the next animation in ms
DWORD kTimeBeforeNextAnimation=4000;
// Windows API program entry point
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Leak checking
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 0;
wcex.hInstance= hInstance;
wcex.hIcon= 0;
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= 0;
wcex.lpszClassName= "XAnimatorTestWindowClass";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow("XAnimatorTestWindowClass", "XAnimatorTest, Keith Ditchburn 2010", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
NULL, NULL, hInstance, NULL);
// Create the D3D objects etc.
if (!SetupDirect3D(hWnd))
return 0;
// Init XAnimator
gXAnimator=CreateXAnimator(gD3dDevice);
if (!gXAnimator)
return 0;
// Load our animated model
if (!LoadModel("Data\\bones_all.x"))
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Message loop that calls our update function whenever there is no message
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
UpdateDemo();
}
}
// Clean up
delete gXAnimator;
ShutdownDirect3D();
return (int)msg.wParam;
}
// Window callback
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Setup Direct3D, matrices and add a light
bool SetupDirect3D(HWND hWnd)
{
gD3dObject=Direct3DCreate9(D3D_SDK_VERSION);
if (!gD3dObject)
return false;
D3DPRESENT_PARAMETERS presParams;
ZeroMemory(&presParams,sizeof(presParams));
presParams.Windowed=TRUE;
presParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat=D3DFMT_UNKNOWN;
presParams.PresentationInterval=D3DPRESENT_INTERVAL_ONE;
presParams.EnableAutoDepthStencil = TRUE;
presParams.AutoDepthStencilFormat = D3DFMT_D16;
// Try to get the best device possible e.g. harwdare processing
HRESULT hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
{
// the above failed so fallback to software processing
hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
return false;
}
gD3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView,&D3DXVECTOR3(0,1,-4),&D3DXVECTOR3(0,1,0), &D3DXVECTOR3(0,1,0) );
gD3dDevice->SetTransform( D3DTS_VIEW, &matView );
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 800.0f/600.0f, 1.0f, 200.0f );
gD3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
gD3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(80,80,80) );
// Fill in a light structure defining our light
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
light.Diffuse.a = 1.0f;
light.Range = 500.0f;
// Create a direction for our light - it must be normalized
D3DXVECTOR3 vecDir;
vecDir = D3DXVECTOR3(0.0f,-0.3f,0.5);
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
// Tell the device about the light and turn it on
gD3dDevice->SetLight( 0, &light );
gD3dDevice->LightEnable( 0, TRUE );
gD3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
return true;
}
// Release the D3D objects
void ShutdownDirect3D()
{
if (gD3dDevice)
{
gD3dDevice->Release();
gD3dDevice=0;
}
if (gD3dObject)
{
gD3dObject->Release();
gD3dObject=0;
}
}
// Demo main update
void UpdateDemo()
{
static DWORD lastTimeAnimationChanged=timeGetTime();
static DWORD lastUpdateTime=timeGetTime();
DWORD timeElapsedSinceAnimationChange=timeGetTime()-lastTimeAnimationChanged;
// Periodically advance to the next animation set
if (timeElapsedSinceAnimationChange>kTimeBeforeNextAnimation)
{
gCurrentAnimationSet++;
if (gCurrentAnimationSet>=gNumAnimationSets)
gCurrentAnimationSet=0;
gXAnimator->ChangeAnimationSet(gModelId,gCurrentAnimationSet,kTransitionTime);
lastTimeAnimationChanged=timeGetTime();
}
gD3dDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,50),1.0f,0);
gD3dDevice->BeginScene();
// Render our animated model
D3DXMATRIX world;
D3DXMatrixIdentity(&world);
// Slowly rotate it (comment out to keep it still)
D3DXMatrixRotationY(&world, timeGetTime()%3600*0.00174533f);
DWORD timeElapsedSinceLastUpdate=timeGetTime()-lastUpdateTime;
gXAnimator->Render(gModelId,world,(float)timeElapsedSinceLastUpdate);
lastUpdateTime=timeGetTime();
gD3dDevice->EndScene();
gD3dDevice->Present( NULL, NULL, NULL, NULL );
}
// Load the model using XAnimator and grab data
bool LoadModel(const std::string &filename)
{
if (!gXAnimator->LoadXFile(filename,&gModelId))
return false;
gNumAnimationSets=gXAnimator->GetNumberOfAnimationSets(gModelId);
gCurrentAnimationSet=1;
// First animation set to start with - note: v.small transition time as it is the first
gXAnimator->ChangeAnimationSet(gModelId,gCurrentAnimationSet,0.1f);
return true;
}