├── xextool.exe ├── Media ├── font.xpr ├── success.wmv ├── launch-Hdd.xex ├── lhelper-Hdd.xex ├── MediaEncSesh.wme ├── launch-Mass0.xex └── lhelper-Mass0.xex ├── Dashlaunch.h ├── FreebootPatches.h ├── stdafx.cpp ├── Common ├── stdafx.cpp ├── AtgVer.h ├── AtgSceneAll.h ├── stdafx.h ├── AtgWavebank.h ├── AtgDevice.h ├── AtgMediaLocator.h ├── AtgNuiCommon.h ├── AtgSpectralDisplay.h ├── AtgApp.h ├── AtgNuiRelativeCoordinates.h ├── AtgScene.h ├── AtgInput.h ├── AtgScene.cpp ├── AtgModel.h ├── AtgApp.cpp ├── AtgXmlWriter.h ├── AtgBound.h ├── XTLOnPC.cpp ├── AtgSimpleShaders.h ├── AtgCamera.h ├── AtgHelp.h ├── AtgConsole.h.OG ├── AtgJson.h ├── AtgConsole.h ├── AtgSignIn.h ├── AtgLight.cpp ├── AtgDebugDraw.h ├── AtgMetaVMX.h ├── AtgCamera.cpp ├── AtgModel.cpp ├── AtgFrame.h ├── AtgSceneFileParser.h ├── AtgDsp.cpp ├── AtgResource.h ├── AtgSceneMesh.cpp ├── AtgXmlParser.h ├── AtgFrameworkWin322010.vcxproj.filters ├── AtgEnumStrings.h ├── AtgAvatarRenderer.h ├── AtgSceneMesh.h ├── AtgDevice.cpp ├── XTLOnPC.h ├── AtgMediaLocator.cpp ├── AtgAudio.h ├── AtgNamedTypedObject.h └── AtgNuiRelativeCoordinates.cpp ├── AppConf_SectRes.xml ├── ReadMe.txt ├── Locale.h ├── XeUnshackle.sln ├── XeUnshackle.vcxproj.filters ├── Utils.h ├── HVFuncs.h ├── XeUnshackle.vcxproj ├── Dashlaunch.cpp └── README.md /xextool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/xextool.exe -------------------------------------------------------------------------------- /Media/font.xpr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/font.xpr -------------------------------------------------------------------------------- /Media/success.wmv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/success.wmv -------------------------------------------------------------------------------- /Media/launch-Hdd.xex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/launch-Hdd.xex -------------------------------------------------------------------------------- /Media/lhelper-Hdd.xex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/lhelper-Hdd.xex -------------------------------------------------------------------------------- /Media/MediaEncSesh.wme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/MediaEncSesh.wme -------------------------------------------------------------------------------- /Media/launch-Mass0.xex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/launch-Mass0.xex -------------------------------------------------------------------------------- /Media/lhelper-Mass0.xex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Byrom90/XeUnshackle/HEAD/Media/lhelper-Mass0.xex -------------------------------------------------------------------------------- /Dashlaunch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | extern WCHAR wDLStatusBuf[]; 5 | extern BOOL bDLisLoaded; 6 | INT SysLoadDashlaunch(); 7 | -------------------------------------------------------------------------------- /FreebootPatches.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | 5 | BOOL ApplyFreebootHVPatches(); 6 | BOOL ApplyFreebootKernPatches(); 7 | VOID RevertBadExploitPatches(); 8 | VOID RestoreRoL(); 9 | 10 | VOID ApplyAdditionalPatches(); 11 | -------------------------------------------------------------------------------- /stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // XeUnshackle.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Common/stdafx.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // stdafx.cpp 3 | // 4 | // This will create a .pch file which will let other source files compile faster. 5 | // 6 | // All other source files must include "stdafx.h" as the first line of non-comment code. 7 | // 8 | // Xbox Advanced Technology Group. 9 | // Copyright (C) Microsoft Corporation. All rights reserved. 10 | //-------------------------------------------------------------------------------------- 11 | #include "stdafx.h" 12 | -------------------------------------------------------------------------------- /Common/AtgVer.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgVer.h 3 | // 4 | // Copyright information for samples and tools 5 | // 6 | // XNA Developer Connection. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGVER_H 11 | #define ATGVER_H 12 | 13 | #ifndef ATG_COPYRIGHT_STR 14 | # define ATG_COPYRIGHT_STR "Copyright (c) 2000-2010 Microsoft Corporation. All rights reserved.\n\n" 15 | #endif 16 | 17 | #ifndef ATG_ABOUT_COPYRIGHT_STR 18 | # define ATG_ABOUT_COPYRIGHT_STR "\251 2010 Microsoft Corporation. All rights reserved." 19 | #endif 20 | 21 | #endif // ATGVER_H 22 | -------------------------------------------------------------------------------- /Common/AtgSceneAll.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgSceneAll.h 3 | // 4 | // Convenience header file that includes all of the ATG scene-related header files. 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //----------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATGSCENEALL_H 12 | #define ATGSCENEALL_H 13 | 14 | #include "AtgBound.h" 15 | #include "AtgCollision.h" 16 | #include "AtgFrame.h" 17 | #include "AtgResourceDatabase.h" 18 | #include "AtgScene.h" 19 | #include "AtgLight.h" 20 | #include "AtgMaterials.h" 21 | #include "AtgSceneMesh.h" 22 | #include "AtgModel.h" 23 | #include "AtgCamera.h" 24 | #include "AtgXmlParser.h" 25 | #include "AtgSceneFileParser.h" 26 | #include "AtgAnimation.h" 27 | #include "AtgSkeletalAnimation.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Common/stdafx.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // stdafx.h 3 | // 4 | // This is a good place to include commonly used header files that rarely change, in 5 | // order to speed up build times. 6 | // 7 | // Xbox Advanced Technology Group. 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //-------------------------------------------------------------------------------------- 10 | #ifndef ATGFRAMEWORK_STDAFX_H 11 | 12 | #ifdef _XBOX 13 | 14 | #include 15 | #include 16 | 17 | #endif // _XBOX 18 | 19 | #ifdef _PC 20 | 21 | #include 22 | #include 23 | #include 24 | #pragma warning(disable:4100) 25 | 26 | #include "XTLOnPC.h" 27 | 28 | #endif // _PC 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | // C4127: conditional expression is constant 37 | #pragma warning(disable:4127) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /AppConf_SectRes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Xbox 360 APPLICATION : XeUnshackle Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this XeUnshackle application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your XeUnshackle application. 9 | 10 | XeUnshackle.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | XeUnshackle.cpp 17 | This is the main application source file. 18 | 19 | 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | Other notes: 23 | 24 | AppWizard uses "TODO:" comments to indicate parts of the source code you 25 | should add to or customize. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | -------------------------------------------------------------------------------- /Locale.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | // IMPORTANT NOTE!!! 5 | // The standard font used by this app DOES NOT support the characters required for some languages. 6 | // Unfortunately I have no idea how to create a new font that does. 7 | 8 | // Localised language support - Credit FreeMyXe, this is how it's handled there. 9 | 10 | typedef struct _LocalisationMessages_t 11 | { 12 | // Error Messagebox 13 | wchar_t* ErrorandExit; 14 | wchar_t* ExitConfirm; 15 | // Dashlaunch load status 16 | wchar_t* DL_Loaded; 17 | wchar_t* DL_Mode_Hdd; 18 | wchar_t* DL_Mode_Usb; 19 | wchar_t* DL_Fail_SecData; 20 | wchar_t* DL_Fail_Mount; 21 | wchar_t* DL_Fail_Write; 22 | wchar_t* DL_Fail_Launch_SecData; 23 | wchar_t* DL_Fail_Status; 24 | // Dump 1BL Notify 25 | wchar_t* D1bl_Fail_Nonzero; 26 | wchar_t* D1bl_Savedto; 27 | wchar_t* D1bl_Fail_Write; 28 | // Save Console Info Notify 29 | wchar_t* SaveConInfo_Success; 30 | wchar_t* SaveConInfo_Failed; 31 | // Save Orig MAC 32 | wchar_t* Dump_MAC_Success; 33 | wchar_t* Dump_MAC_Fail; 34 | // Main Screen Text 35 | wchar_t* MainInfo; 36 | wchar_t* MainScrDL; 37 | wchar_t* MainScrBtnSaveInfo; 38 | wchar_t* MainScrBtnDump1BL; 39 | wchar_t* MainScrBtnExit; 40 | 41 | } LocalisationMessages_t; 42 | 43 | 44 | extern LocalisationMessages_t* currentLocalisation; 45 | 46 | VOID SetLocale(); -------------------------------------------------------------------------------- /XeUnshackle.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.33529.622 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XeUnshackle", "XeUnshackle.vcxproj", "{BF064E30-8592-454E-A655-0D0E5C6328C4}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {91D208A6-9936-47FD-9659-67205C3EB0AB} = {91D208A6-9936-47FD-9659-67205C3EB0AB} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AtgFramework", "Common\AtgFramework2010.vcxproj", "{91D208A6-9936-47FD-9659-67205C3EB0AB}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Release_LTCG|Xbox 360 = Release_LTCG|Xbox 360 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {BF064E30-8592-454E-A655-0D0E5C6328C4}.Release_LTCG|Xbox 360.ActiveCfg = Release_LTCG|Xbox 360 19 | {BF064E30-8592-454E-A655-0D0E5C6328C4}.Release_LTCG|Xbox 360.Build.0 = Release_LTCG|Xbox 360 20 | {91D208A6-9936-47FD-9659-67205C3EB0AB}.Release_LTCG|Xbox 360.ActiveCfg = Release_LTCG|Xbox 360 21 | {91D208A6-9936-47FD-9659-67205C3EB0AB}.Release_LTCG|Xbox 360.Build.0 = Release_LTCG|Xbox 360 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(ExtensibilityGlobals) = postSolution 27 | SolutionGuid = {434FD805-C131-44FD-A652-E19D60CEE455} 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /Common/AtgWavebank.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // CWavebank.h 3 | // 4 | // Class for handling wavebank 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | 11 | #include 12 | namespace ATG 13 | { 14 | //-------------------------------------------------------------------------------------- 15 | // Name: CWavebank 16 | // Desc: Class to handle the Wavebank file 17 | //-------------------------------------------------------------------------------------- 18 | class CWavebank 19 | { 20 | public: 21 | CWavebank(); 22 | ~CWavebank(); 23 | 24 | // Initialization 25 | // Open a wavebank. The function allocates buffer for a wavebank 26 | HRESULT Open( const CHAR* strFileName ); 27 | // Close the wavebank 28 | VOID Close(); 29 | // Get # of wave entries in the wavebank 30 | DWORD GetEntryCount( void ) const; 31 | // Get a wave format of the wave entry 32 | HRESULT GetEntryFormat( const DWORD dwEntry, WAVEFORMATEX* pFormat ) const; 33 | // Get a duration of the wave entry 34 | DWORD GetEntryLengthInBytes( const DWORD dwEntry ) const; 35 | // Get offset of the wave entry in the bank file 36 | DWORD GetEntryOffset( const DWORD dwEntry ) const; 37 | // Get samples of the wave entry 38 | HRESULT GetEntryData( const DWORD dwEntry, void** pData ) const; 39 | private: 40 | DWORD m_dwFileSize; 41 | WAVEBANKHEADER m_wavebankHeader; 42 | WAVEBANKDATA m_wavebankData; 43 | WAVEBANKENTRY* m_pDataEntry; 44 | BYTE* m_pSeekData; 45 | HANDLE m_hFile; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /Common/AtgDevice.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgDevice.h 3 | // 4 | // Over-loaded device to trap and optimize certain calls to D3D 5 | // 6 | // Microsoft Game Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGDEVICE_H 11 | #define ATGDEVICE_H 12 | 13 | namespace ATG 14 | { 15 | 16 | //-------------------------------------------------------------------------------------- 17 | // Name: CreatePooledVertexDeclaration() 18 | // Desc: Function to coalesce vertex declarations into a shared pool of vertex declarations 19 | //-------------------------------------------------------------------------------------- 20 | HRESULT WINAPI CreatePooledVertexDeclaration( const D3DVERTEXELEMENT9* pVertexElements, 21 | D3DVertexDeclaration** ppVertexDeclaration ); 22 | } 23 | 24 | #ifdef _XBOX 25 | 26 | namespace ATG 27 | { 28 | 29 | //-------------------------------------------------------------------------------------- 30 | // struct ATG::D3DDevice 31 | // Over-loaded device to trap and optimize certain calls to D3D 32 | //-------------------------------------------------------------------------------------- 33 | struct D3DDevice : public ::D3DDevice 34 | { 35 | D3DVOID WINAPI SetVertexShader( D3DVertexShader *pShader ); 36 | D3DVOID WINAPI SetPixelShader( D3DPixelShader* pShader ); 37 | D3DVOID WINAPI SetVertexDeclaration( D3DVertexDeclaration *pDecl); 38 | HRESULT WINAPI CreateVertexDeclaration( const D3DVERTEXELEMENT9* pVertexElements, 39 | D3DVertexDeclaration **ppVertexDeclaration ); 40 | }; 41 | 42 | 43 | } // namespace ATG 44 | 45 | #endif // _XBOX 46 | 47 | #endif // ATGDEVICE_H 48 | -------------------------------------------------------------------------------- /Common/AtgMediaLocator.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgMediaLocator.h 3 | // 4 | // Helper functions and class providing support for locating media files inside and xzp 5 | // archive. 6 | // 7 | // Xbox Advanced Technology Group. 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //-------------------------------------------------------------------------------------- 10 | 11 | 12 | #pragma once 13 | #ifndef ATGMEDIALOCATOR_H 14 | #define ATGMEDIALOCATOR_H 15 | 16 | 17 | namespace ATG 18 | { 19 | 20 | 21 | const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 22 | 23 | 24 | BOOL LocateMediaFolder( LPWSTR szMediaPath, DWORD dwMediaPathSize, LPWSTR szPackage ); 25 | 26 | BOOL ComposeResourceLocator( LPWSTR szLocator, DWORD dwLocatorSize, LPCWSTR szPackage, LPCWSTR szBaseDirectory, LPCWSTR szPath, LPCWSTR szFile ); 27 | 28 | 29 | //-------------------------------------------------------------------------------------- 30 | // Name: class MediaLocator 31 | // Desc: Find paths to files in the media folder that sits inside an xzp archive. 32 | //-------------------------------------------------------------------------------------- 33 | class MediaLocator 34 | { 35 | public: 36 | MediaLocator(); 37 | MediaLocator( LPCWSTR szPackage ); 38 | ~MediaLocator() {} 39 | 40 | VOID SetPackage( LPCWSTR szPackage ); 41 | LPCWSTR GetMediaPath() const; 42 | 43 | BOOL ComposeResourceLocator( LPWSTR szLocator, DWORD dwpLocatorSize, LPCWSTR szPath, LPCWSTR szFile ) const; 44 | 45 | private: 46 | MediaLocator( const MediaLocator& mediaLocator ); 47 | MediaLocator& operator =( const MediaLocator& mediaLocator ); 48 | 49 | WCHAR m_szPackage[ LOCATOR_SIZE ]; 50 | mutable WCHAR m_szMediaPath[ LOCATOR_SIZE ]; 51 | }; 52 | 53 | 54 | } // namespace ATG 55 | 56 | 57 | #endif // ATGMEDIARESOURCE_H -------------------------------------------------------------------------------- /Common/AtgNuiCommon.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgNuiCommon.h 3 | // 4 | // Common defines and macros for NUI samples 5 | // 6 | // Advanced Technology Group (ATG) 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATG_NUI_COMMON_H 12 | #define ATG_NUI_COMMON_H 13 | 14 | #include 15 | #include "AtgUtil.h" 16 | 17 | namespace ATG 18 | { 19 | // NuiSkeletonGetNextFrame and NuiImageStreamGetNextFrame require a maximum wait time to be passed into the function. 20 | // If this is 0, then the app can easily become 1 frame behind the camera introducing lag into the system. 21 | // This value is a maximum time so the app will likely return before the 10 ms. 22 | // 10 to 15 ms has been a good amount of time to wait. 23 | // Alternatively an application could do 10 to 15 ms of work and pass in 0. 24 | #define NUI_CAMERA_TIMEOUT_DEFAULT 10 25 | 26 | // The event set via NuiSetFrameEndEvent is used to synchronize reads with NuiSkeletonGetNextFrame and NuiImageStreamGetNextFrame. 27 | // When waiting on this event, the timeout needs to be long enough that frame processing will complete and be synchronized. 28 | // 100 ms ensures proper synchronization with NUI when using NuiSetFrameEndEvent. 29 | // When using NuiSetFrameEndEvent, calls to NuiSkeletonGetNextFrame and NuiImageStreamGetNextFrame should use a timeout of 0. 30 | #define NUI_FRAME_END_TIMEOUT_DEFAULT 100 31 | 32 | VOID NuiPrintError( HRESULT hResult, const CHAR* szFunctionName ); 33 | 34 | VOID ApplyTiltCorrectionInPlayerSpace( NUI_SKELETON_FRAME* pDstSkeleton, const NUI_SKELETON_FRAME* pSrcSkeleton ); 35 | 36 | const WCHAR* GetIdentityQualityFlagPrompt( DWORD dwIdentityQualityFlags ); 37 | const WCHAR* GetHeadOrientationQualityFlagPrompt( DWORD dwHeadOrientationQualityFlags ); 38 | }; 39 | 40 | #endif // ATG_NUI_COMMON_H -------------------------------------------------------------------------------- /XeUnshackle.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Header Files 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | Source Files 57 | 58 | 59 | -------------------------------------------------------------------------------- /Common/AtgSpectralDisplay.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // SpectralDisplay.h 3 | // 4 | // XNA Developer Connection 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //-------------------------------------------------------------------------------------- 7 | #pragma once 8 | #include 9 | #include 10 | #include "ATGAPOBase.h" 11 | #include "AtgLockFreePipe.h" 12 | 13 | namespace ATG 14 | { 15 | 16 | #ifndef MONITOR_APO_PIPE_LEN 17 | #define MONITOR_APO_PIPE_LEN 14 18 | #endif 19 | 20 | typedef ATG::LockFreePipe MonitorAPOPipe; 21 | 22 | struct MonitorAPOParams 23 | { 24 | MonitorAPOPipe *pipe; 25 | }; 26 | 27 | class __declspec( uuid("{A4945B8A-EB14-4c96-8067-DF726B528091}")) 28 | CMonitorAPO 29 | : public CSampleXAPOBase 30 | { 31 | public: 32 | CMonitorAPO(); 33 | ~CMonitorAPO(); 34 | 35 | void DoProcess( const MonitorAPOParams&, FLOAT32* __restrict pData, UINT32 cFrames, UINT32 cChannels, BOOL bEnabled ); 36 | }; 37 | 38 | class CWaveDisplay 39 | { 40 | public: 41 | CWaveDisplay(); 42 | ~CWaveDisplay(); 43 | 44 | const static DWORD NSAMPLESLOG2 = 8; 45 | const static DWORD nSamples = 1 << NSAMPLESLOG2; 46 | 47 | HRESULT Initialize( ::IDirect3DDevice9* pDevice, UINT nSamples ); 48 | HRESULT Update( float* __restrict pSamples, const BOOL bMonitorTimeDomain = TRUE ); 49 | HRESULT Render( ::IDirect3DDevice9* pDevice, const D3DRECT& pBounds ); 50 | 51 | void SetRange( float min, float max ); 52 | private: 53 | // unity table, used with FFT 54 | const static int nBinsLog2 = 8; 55 | const static int nBins = 1 << nBinsLog2; 56 | __vector4 m_UnityTable[nBins]; 57 | 58 | CRITICAL_SECTION m_cs; 59 | UINT m_nSamples; 60 | FLOAT* m_pSampleBuffer; 61 | 62 | // FX objects 63 | FXLEffect* m_pEffect; 64 | 65 | // Handles for the effect 66 | FXLHANDLE m_hAmplitudeSampler; 67 | FXLHANDLE m_hSampleCount; 68 | FXLHANDLE m_hMin; 69 | FXLHANDLE m_hMax; 70 | 71 | IDirect3DTexture9* m_pAmplitudeTexture; 72 | 73 | }; 74 | 75 | 76 | } // NameSpace ATG 77 | -------------------------------------------------------------------------------- /Common/AtgApp.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgApp.h 3 | // 4 | // Application class for samples 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGAPP_H 11 | #define ATGAPP_H 12 | 13 | // Use the overloaded D3DDevice class 14 | #include "AtgDevice.h" 15 | 16 | 17 | // Disable warning C4324: structure padded due to __declspec(align()) 18 | // Warning C4324 comes up often in samples derived from the Application class, since 19 | // they use XMVECTOR, XMMATRIX, and other member data types that must be aligned. 20 | #pragma warning( disable:4324 ) 21 | 22 | 23 | namespace ATG 24 | { 25 | 26 | // Global access to the main D3D device 27 | extern D3DDevice* g_pd3dDevice; 28 | 29 | 30 | //-------------------------------------------------------------------------------------- 31 | // Error codes 32 | //-------------------------------------------------------------------------------------- 33 | #define ATGAPPERR_MEDIANOTFOUND 0x82000003 34 | 35 | 36 | //-------------------------------------------------------------------------------------- 37 | // A base class for creating sample Xbox applications. To create a simple 38 | // Xbox application, simply derive this class and override the following 39 | // functions: 40 | // Initialize() - To initialize the device-dependant objects 41 | // Update() - To animate the scene 42 | // Render() - To render the scene 43 | //-------------------------------------------------------------------------------------- 44 | class Application 45 | { 46 | public: 47 | // Main objects used for creating and rendering the 3D scene 48 | static D3DPRESENT_PARAMETERS m_d3dpp; 49 | static D3DDevice* m_pd3dDevice; 50 | static DWORD m_dwDeviceCreationFlags; 51 | 52 | // Overridable functions 53 | virtual HRESULT Initialize() = 0; 54 | virtual HRESULT Update() = 0; 55 | virtual HRESULT Render() = 0; 56 | 57 | // Function to create and run the application 58 | VOID Run(); 59 | }; 60 | 61 | } // namespace ATG 62 | 63 | #endif // ATGAPP_H 64 | -------------------------------------------------------------------------------- /Common/AtgNuiRelativeCoordinates.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgNuiReletiveCoordinates.h 3 | // 4 | // This class maintains a body reletive coordainte system for NUI Samples 5 | // 6 | // Microsoft Advanced Technology Group 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #ifndef _ATG_NUI_BODY_RELETIVE_COORDINATES_ 13 | #define _ATG_NUI_BODY_RELETIVE_COORDINATES_ 14 | 15 | #include 16 | #include 17 | #include "ATGNuiJointFilter.h" 18 | #include "AtgUtil.h" 19 | 20 | #pragma warning( disable:4324 ) 21 | 22 | namespace ATG 23 | { 24 | 25 | static const FLOAT BODY_RELATIVE_SPINE_UPDATE_RATE = 0.95f; 26 | static const FLOAT BODY_RELATIVE_BODY_SIZE_UPDATE_RATE = 0.98f; 27 | 28 | class SpineRelativeCameraSpaceCoordinateSystem 29 | { 30 | public: 31 | 32 | SpineRelativeCameraSpaceCoordinateSystem( ); 33 | 34 | VOID SetUpdateRates( FLOAT fSpineUpdateRate = BODY_RELATIVE_SPINE_UPDATE_RATE, FLOAT fBodySizeUpdateRate = BODY_RELATIVE_BODY_SIZE_UPDATE_RATE ); 35 | 36 | VOID Reset( ); 37 | 38 | VOID Update( const NUI_SKELETON_FRAME* pRawSkeletonFrame, INT iSkeletonIndex, XMVECTOR vLeft, XMVECTOR vRight ); 39 | 40 | XMVECTOR GetRightHandReletive( ); 41 | XMVECTOR GetLeftHandReletive( ); 42 | XMVECTOR GetAverageSpine( ) { return m_vAverageSpine; }; 43 | XMMATRIX GetRotateToNormalToGravityMatrix() { return m_matRotateToNormalToGravity; }; 44 | XMVECTOR GetEstiamtedPivotOffsetLeft() { return m_vEstiamtedPivotOffsetLeft; }; 45 | XMVECTOR GetEstiamtedPivotOffsetRight() { return m_vEstiamtedPivotOffsetRight; }; 46 | FLOAT GetAverageSpineHeadLength() { return m_fAverageSpineHeadLength; }; 47 | 48 | private: 49 | 50 | DWORD m_dwLastTrackingID; 51 | 52 | XMVECTOR m_vAverageSpine; 53 | FLOAT m_fAverageSpineHeadLength; 54 | 55 | FLOAT m_fBodySizeUpdateRate; 56 | FLOAT m_fSpineUpdateRate; 57 | 58 | XMVECTOR m_vAverageNormalToGravity; 59 | XMVECTOR m_vRightHandRelative; 60 | XMVECTOR m_vLeftHandRelative; 61 | XMMATRIX m_matRotateToNormalToGravity; 62 | XMVECTOR m_vEstiamtedPivotOffsetLeft; 63 | XMVECTOR m_vEstiamtedPivotOffsetRight; 64 | 65 | 66 | }; 67 | 68 | } // namespace ATG 69 | 70 | #endif // _ATG_NUI_BODY_RELETIVE_COORDINATES_ -------------------------------------------------------------------------------- /Common/AtgScene.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgScene.h 3 | // 4 | // describes a scene which can own per-scene materials and animations 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //----------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATG_SCENE_H 12 | #define ATG_SCENE_H 13 | 14 | #include 15 | #include "AtgFrame.h" 16 | #include 17 | 18 | namespace ATG 19 | { 20 | 21 | class ResourceDatabase; 22 | class EffectGlobalParameterPool; 23 | 24 | //----------------------------------------------------------------------------- 25 | // Name: Scene 26 | // Desc: A database containing meshes, materials, and model instances 27 | //----------------------------------------------------------------------------- 28 | class Scene : public Frame 29 | { 30 | DEFINE_TYPE_INFO(); 31 | public: 32 | Scene(); 33 | ~Scene(); 34 | 35 | ResourceDatabase* GetResourceDatabase() { return m_pResourceDatabase; } 36 | 37 | VOID AddObject( NamedTypedObject *pObject ) { m_InstanceDatabase.Add( pObject ); } 38 | NamedTypedObject* FindObject( CONST WCHAR* szName ) { return m_InstanceDatabase.Find( szName ); } 39 | NamedTypedObject* FindObjectOfType( CONST WCHAR* szName, const StringID TypeID ) { return m_InstanceDatabase.FindTyped( szName, TypeID ); } 40 | VOID RemoveObject( NamedTypedObject *pObject ) { m_InstanceDatabase.Remove( pObject ); } 41 | FXLEffectPool* GetEffectParameterPool() { return m_pGlobalParameterPool; } 42 | NameIndexedCollection* GetInstanceList() { return &m_InstanceDatabase; } 43 | 44 | VOID SetFileName( const CHAR* strFileName ) { strcpy_s( m_strFileName, strFileName ); } 45 | VOID SetMediaRootPath( const CHAR* strMediaRootPath ) { strcpy_s( m_strMediaRootPath, 46 | strMediaRootPath ); } 47 | const CHAR* GetFileName() const { return m_strFileName; } 48 | const CHAR* GetMediaRootPath() const { return m_strMediaRootPath; } 49 | 50 | VOID Render( ::D3DDevice* pd3dDevice, BOOL bSetTextures = TRUE ); 51 | 52 | private: 53 | FXLEffectPool* m_pGlobalParameterPool; 54 | ResourceDatabase* m_pResourceDatabase; 55 | NameIndexedCollection m_InstanceDatabase; 56 | CHAR m_strFileName[MAX_PATH]; 57 | CHAR m_strMediaRootPath[MAX_PATH]; 58 | }; 59 | 60 | } // namespace ATG 61 | 62 | #endif // ATG_SCENE_H 63 | -------------------------------------------------------------------------------- /Common/AtgInput.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgInput.h 3 | // 4 | // Input helper functions for samples 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGINPUT_H 11 | #define ATGINPUT_H 12 | 13 | namespace ATG 14 | { 15 | 16 | //-------------------------------------------------------------------------------------- 17 | // Name: struct ATGGAMEPAD 18 | // Desc: Structure for holding Gamepad data 19 | //-------------------------------------------------------------------------------------- 20 | struct GAMEPAD : public XINPUT_GAMEPAD 21 | { 22 | // The following members are inherited from XINPUT_GAMEPAD: 23 | // WORD wButtons; 24 | // BYTE bLeftTrigger; 25 | // BYTE bRightTrigger; 26 | // SHORT sThumbLX; 27 | // SHORT sThumbLY; 28 | // SHORT sThumbRX; 29 | // SHORT sThumbRY; 30 | 31 | // Thumb stick values converted to range [-1,+1] 32 | FLOAT fX1; 33 | FLOAT fY1; 34 | FLOAT fX2; 35 | FLOAT fY2; 36 | 37 | // Records the state (when last updated) of the buttons. 38 | // These remain set as long as the button is pressed. 39 | WORD wLastButtons; 40 | BOOL bLastLeftTrigger; 41 | BOOL bLastRightTrigger; 42 | 43 | // Records which buttons were pressed this frame - only set on 44 | // the frame that the button is first pressed. 45 | WORD wPressedButtons; 46 | BOOL bPressedLeftTrigger; 47 | BOOL bPressedRightTrigger; 48 | 49 | // Device properties 50 | XINPUT_CAPABILITIES caps; 51 | BOOL bConnected; 52 | 53 | // Flags for whether game pad was just inserted or removed 54 | BOOL bInserted; 55 | BOOL bRemoved; 56 | 57 | // The user index associated with this gamepad 58 | DWORD dwUserIndex; 59 | 60 | // Deadzone pseudo-constants for the thumbsticks 61 | static SHORT LEFT_THUMB_DEADZONE; 62 | static SHORT RIGHT_THUMB_DEADZONE; 63 | }; 64 | 65 | 66 | //-------------------------------------------------------------------------------------- 67 | // Name: class Input 68 | // Desc: Class to manage input devices 69 | //-------------------------------------------------------------------------------------- 70 | class Input 71 | { 72 | public: 73 | // Global access to input states 74 | static GAMEPAD m_Gamepads[4]; 75 | static GAMEPAD m_DefaultGamepad; 76 | 77 | // Processes input from the game pad 78 | static VOID GetInput( GAMEPAD* pGamepads = NULL ); 79 | 80 | // Processes input from all 4 gamepads and merge it into one input 81 | static GAMEPAD* GetMergedInput( DWORD dwMask = 0, DWORD* pdwActiveGamePadsMask = NULL ); 82 | }; 83 | 84 | } // namespace ATG 85 | 86 | #endif // ATGINPUT_H 87 | -------------------------------------------------------------------------------- /Utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | VOID cprintf(const char* s, ...); 5 | 6 | BOOL MountUsb(); 7 | BOOL MountHdd(); 8 | 9 | BOOL FileExists(PCHAR lpFileName); 10 | 11 | class MemoryBuffer 12 | { 13 | public: 14 | 15 | MemoryBuffer(DWORD dwSize = 512) 16 | { 17 | m_pBuffer = NULL; 18 | m_dwDataLength = 0; 19 | m_dwBufferSize = 0; 20 | 21 | if ((dwSize < UINT_MAX) && (dwSize != 0)) 22 | { 23 | m_pBuffer = (BYTE*)malloc(dwSize + 1); // one more char, in case when using string funcions 24 | if (m_pBuffer) 25 | { 26 | m_dwBufferSize = dwSize; 27 | m_pBuffer[0] = 0; 28 | } 29 | } 30 | }; 31 | 32 | ~MemoryBuffer() 33 | { 34 | if (m_pBuffer) 35 | free(m_pBuffer); 36 | 37 | m_pBuffer = NULL; 38 | m_dwDataLength = 0; 39 | m_dwBufferSize = 0; 40 | }; 41 | 42 | // Add chunk of memory to buffer 43 | BOOL Add(const void* p, DWORD dwSize) 44 | { 45 | if (CheckSize(dwSize)) 46 | { 47 | memcpy(m_pBuffer + m_dwDataLength, p, dwSize); 48 | m_dwDataLength += dwSize; 49 | *(m_pBuffer + m_dwDataLength) = 0; // fill end zero 50 | return TRUE; 51 | } 52 | else 53 | { 54 | return FALSE; 55 | } 56 | }; 57 | 58 | // Get the data in buffer 59 | BYTE* GetData() const 60 | { 61 | return m_pBuffer; 62 | }; 63 | 64 | // Get the length of data in buffer 65 | DWORD GetDataLength() const 66 | { 67 | return m_dwDataLength; 68 | }; 69 | 70 | // Rewind the data pointer to the begining 71 | VOID Rewind() 72 | { 73 | m_dwDataLength = 0; 74 | m_pBuffer[0] = 0; 75 | }; 76 | 77 | // Automatically adjust increase buffer size if necessary 78 | BOOL CheckSize(DWORD dwSize) 79 | { 80 | if (m_dwBufferSize >= (m_dwDataLength + dwSize)) 81 | { 82 | return TRUE; // Enough space 83 | } 84 | else 85 | { 86 | // Try to double it 87 | DWORD dwNewSize = max(m_dwDataLength + dwSize, m_dwBufferSize * 2); 88 | BYTE* pNewBuffer = (UCHAR*)realloc(m_pBuffer, dwNewSize + 1); // one more char 89 | if (pNewBuffer) 90 | { 91 | m_pBuffer = pNewBuffer; 92 | m_dwBufferSize = dwNewSize; 93 | return TRUE; 94 | } 95 | else 96 | { 97 | // Failed 98 | return FALSE; 99 | } 100 | } 101 | } 102 | 103 | private: 104 | 105 | BYTE* m_pBuffer; 106 | 107 | DWORD m_dwDataLength; 108 | 109 | DWORD m_dwBufferSize; 110 | }; 111 | 112 | BOOL CReadFile(const CHAR* FileName, MemoryBuffer& pBuffer); 113 | BOOL CWriteFile(const CHAR* FilePath, const VOID* Data, DWORD Size); 114 | 115 | DWORD ApplyPatches(CHAR* FilePath, const VOID* DefaultPatches = NULL); 116 | 117 | VOID ShowErrorAndExit(int Stage); 118 | 119 | VOID ShowNotify(PWCHAR NotifyText); 120 | 121 | VOID LaunchTitle(LPCSTR szLaunchPath, LPCSTR szMountPath = NULL, LPCSTR szCmdLine = NULL, DWORD dwFlags = 0x10); 122 | 123 | VOID RelaunchApp(); // Relaunch this app 124 | 125 | string GetMoboByHWFlags(); 126 | 127 | extern BOOL DisableButtons; 128 | VOID Dump1blRomToFile(); 129 | 130 | VOID SaveConsoleDataToFile(); 131 | 132 | VOID BackupOrigMAC(); -------------------------------------------------------------------------------- /Common/AtgScene.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // scene.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "stdafx.h" 9 | #include "AtgMaterials.h" 10 | #include "AtgModel.h" 11 | #include "AtgScene.h" 12 | #include "AtgSceneMesh.h" 13 | #include "AtgResourceDatabase.h" 14 | 15 | namespace ATG 16 | { 17 | 18 | CONST StringID Scene::TypeID( L"Scene" ); 19 | 20 | //----------------------------------------------------------------------------- 21 | // Name: Scene::Scene 22 | //----------------------------------------------------------------------------- 23 | Scene::Scene() 24 | { 25 | m_pResourceDatabase = NULL; 26 | FXLCreateEffectPool( &m_pGlobalParameterPool ); 27 | m_pResourceDatabase = new ResourceDatabase(); 28 | } 29 | 30 | Scene::~Scene() 31 | { 32 | m_pGlobalParameterPool->Release(); 33 | m_pGlobalParameterPool = NULL; 34 | delete m_pResourceDatabase; 35 | m_pResourceDatabase = NULL; 36 | } 37 | 38 | VOID Scene::Render( ::D3DDevice* pd3dDevice, BOOL bSetTextures ) 39 | { 40 | ATG::NameIndexedCollection::iterator i; 41 | 42 | for( i = GetInstanceList()->begin(); i != GetInstanceList()->end(); i++ ) 43 | { 44 | // Select models from the object list. 45 | if( ( *i )->IsDerivedFrom( ATG::Model::TypeID ) ) 46 | { 47 | ATG::Model* pModel = ( ATG::Model* )( *i ); 48 | 49 | // Loop over mesh mappings. 50 | DWORD dwMeshMappingCount = pModel->GetNumMeshMappings(); 51 | for( DWORD dwMapIndex = 0; dwMapIndex < dwMeshMappingCount; ++dwMapIndex ) 52 | { 53 | ATG::MeshMapping& mm = pModel->GetMeshMapping( dwMapIndex ); 54 | ATG::BaseMesh* pMesh = mm.pMesh; 55 | 56 | // Loop over mesh subsets. 57 | DWORD dwSubsetCount = pMesh->GetNumSubsets(); 58 | for( DWORD dwSubsetIndex = 0; dwSubsetIndex < dwSubsetCount; ++dwSubsetIndex ) 59 | { 60 | if( bSetTextures ) 61 | { 62 | ATG::MaterialInstance* pMaterial = mm.Materials[ dwSubsetIndex ]; 63 | 64 | for( DWORD j = 0; j < pMaterial->GetRawParameterCount(); ++j ) 65 | { 66 | // Retrieve diffuse texture and normalmaps and set it 67 | ATG::MaterialParameter& param = pMaterial->GetRawParameter( j ); 68 | if( param.pValue != NULL ) 69 | { 70 | ATG::Texture2D* pTex2D = ( ATG::Texture2D* )param.pValue; 71 | 72 | pd3dDevice->SetTexture( j, pTex2D->GetD3DTexture() ); 73 | } 74 | } 75 | } 76 | 77 | // Render the mesh subset. 78 | pMesh->RenderSubset( dwSubsetIndex, pd3dDevice ); 79 | } 80 | } 81 | } 82 | } 83 | } 84 | 85 | } // namespace ATG 86 | -------------------------------------------------------------------------------- /Common/AtgModel.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgModel.h 3 | // 4 | // A model can has several meshes. Each mesh may or may not have materials 5 | // assigned to its subsets. Note that the meshes may be shadow proxies, 6 | // optimized shadows buffer meshes, etc. 7 | // 8 | // $OPTIMIZE: Pool Allocate 9 | // 10 | // Xbox Advanced Technology Group. 11 | // Copyright (C) Microsoft Corporation. All rights reserved. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | #ifndef ATG_MODEL_H 16 | #define ATG_MODEL_H 17 | 18 | #include 19 | #include "AtgFrame.h" 20 | #include "AtgBound.h" 21 | 22 | namespace ATG 23 | { 24 | 25 | class MaterialInstance; 26 | class BaseMesh; 27 | 28 | //----------------------------------------------------------------------------- 29 | // Name: MeshMapping 30 | // Desc: A model can contain several meshes. Each mesh has materials assigned to it. 31 | //----------------------------------------------------------------------------- 32 | struct MeshMapping 33 | { 34 | enum MeshMappingFlags 35 | { 36 | NoFlags = 0, 37 | IsShadowCaster = 0x1, 38 | IsShadowReceiver = 0x2, 39 | IsTransparent = 0x4, 40 | ForceDWORD = 0x7fffffff 41 | }; 42 | 43 | BaseMesh* pMesh; 44 | DWORD dwFlags; 45 | std::vector Materials; 46 | }; 47 | 48 | 49 | //----------------------------------------------------------------------------- 50 | // Name: Model 51 | //----------------------------------------------------------------------------- 52 | class Model : public Frame 53 | { 54 | DEFINE_TYPE_INFO(); 55 | public: 56 | // Adds meshes and materials to the model. 57 | VOID AddMesh( BaseMesh* pMesh, DWORD dwMeshMappingFlags ); 58 | VOID AddMaterial( UINT MeshIndex, UINT MaterialIndex, MaterialInstance* pMaterial ); 59 | 60 | // Gets the union of all the mesh flags on this model (MeshFlags enum in the Mesh class ) 61 | DWORD GetMeshFlagUnion() CONST; 62 | 63 | // Gets the union of all the mesh instance flags (MeshMappingFlags enum above) 64 | DWORD GetMeshMappingFlagUnion() CONST; 65 | 66 | // Get the mesh instances (mesh instance = mesh + assigned materials) 67 | UINT GetNumMeshMappings() CONST { return m_MeshMappings.size(); } 68 | MeshMapping& GetMeshMapping( UINT Index ) { return m_MeshMappings[Index]; } 69 | BaseMesh* GetMesh( CONST WCHAR* strName ) CONST; 70 | BOOL RemoveMesh( CONST BaseMesh* pMesh ); 71 | BOOL ContainsTransparentSubsets() const; 72 | BOOL ContainsOpaqueSubsets() const; 73 | 74 | // Get the light groups this model is in. In order to be lit by a light, the 75 | // model and light must be in the same group and their bounds must be intersecting. 76 | std::vector & GetLightGroups() 77 | { 78 | return m_LightGroups; 79 | } 80 | 81 | private: 82 | std::vector m_LightGroups; 83 | std::vector m_MeshMappings; 84 | }; 85 | 86 | } // namespace ATG 87 | 88 | #endif // ATG_MODEL_H 89 | -------------------------------------------------------------------------------- /Common/AtgApp.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgApp.cpp 3 | // 4 | // Application class for samples 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #include "stdafx.h" 10 | #include "AtgApp.h" 11 | #include "AtgUtil.h" 12 | 13 | // Ignore warning about "unused" pD3D variable 14 | #pragma warning( disable: 4189 ) 15 | 16 | namespace ATG 17 | { 18 | 19 | //-------------------------------------------------------------------------------------- 20 | // Globals 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Global access to the main D3D device 24 | D3DDevice* g_pd3dDevice = NULL; 25 | 26 | // Private access to the main D3D device 27 | D3DDevice* Application::m_pd3dDevice = NULL; 28 | 29 | // The device-creation presentation params with reasonable defaults 30 | D3DPRESENT_PARAMETERS Application::m_d3dpp = 31 | { 32 | 640, // BackBufferWidth; 33 | 480, // BackBufferHeight; 34 | D3DFMT_A8R8G8B8, // BackBufferFormat; 35 | 1, // BackBufferCount; 36 | D3DMULTISAMPLE_NONE,// MultiSampleType; 37 | 0, // MultiSampleQuality; 38 | D3DSWAPEFFECT_DISCARD, // SwapEffect; 39 | NULL, // hDeviceWindow; 40 | FALSE, // Windowed; 41 | TRUE, // EnableAutoDepthStencil; 42 | D3DFMT_D24S8, // AutoDepthStencilFormat; 43 | 0, // Flags; 44 | 0, // FullScreen_RefreshRateInHz; 45 | D3DPRESENT_INTERVAL_IMMEDIATE, // FullScreen_PresentationInterval; 46 | }; 47 | 48 | // Extra flags to use at Direct3D device creation time 49 | DWORD Application::m_dwDeviceCreationFlags = 0; 50 | 51 | //-------------------------------------------------------------------------------------- 52 | // Name: Run() 53 | // Desc: Creates the D3D device, calls Initialize() and enters an infinite loop 54 | // calling Update() and Render() 55 | //-------------------------------------------------------------------------------------- 56 | VOID Application::Run() 57 | { 58 | HRESULT hr; 59 | 60 | // Create Direct3D 61 | LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION ); 62 | 63 | // Create the D3D device 64 | if( FAILED( hr = pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL, 65 | m_dwDeviceCreationFlags, 66 | &m_d3dpp, ( ::D3DDevice** )&m_pd3dDevice ) ) ) 67 | { 68 | ATG_PrintError( "Could not create D3D device!\n" ); 69 | DebugBreak(); 70 | } 71 | 72 | pD3D->Release(); 73 | 74 | // Allow global access to the device 75 | g_pd3dDevice = m_pd3dDevice; 76 | 77 | // Initialize the app's device-dependent objects 78 | if( FAILED( hr = Initialize() ) ) 79 | { 80 | ATG_PrintError( "Call to Initialize() failed!\n" ); 81 | DebugBreak(); 82 | } 83 | 84 | // Run the game loop 85 | for(; ; ) 86 | { 87 | // Update the scene 88 | Update(); 89 | 90 | // Render the scene 91 | Render(); 92 | } 93 | } 94 | 95 | } // namespace ATG 96 | -------------------------------------------------------------------------------- /Common/AtgXmlWriter.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // AtgXmlWriter.h 3 | // 4 | // A simple XML writer. 5 | // 6 | // Xbox Advanced Technology Group 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATGXMLWRITER_H 12 | #define ATGXMLWRITER_H 13 | 14 | #include 15 | #include 16 | 17 | namespace ATG 18 | { 19 | 20 | #define XMLWRITER_NAME_STACK_SIZE 255 21 | 22 | class XMLWriter 23 | { 24 | public: 25 | XMLWriter(); 26 | XMLWriter( CHAR* strBuffer, UINT uBufferSize ); 27 | XMLWriter( const CHAR* strFileName ); 28 | ~XMLWriter(); 29 | 30 | VOID Initialize( CHAR* strBuffer, UINT uBufferSize ); 31 | VOID Initialize( const CHAR* strFileName ); 32 | VOID Close(); 33 | 34 | VOID SetIndentCount( UINT uSpaces ); 35 | VOID EnableNewlines( BOOL bWriteNewLines ) 36 | { 37 | m_bWriteNewlines = bWriteNewLines; 38 | } 39 | 40 | BOOL StartElement( const CHAR* strName ); 41 | BOOL EndElement(); 42 | BOOL WriteElement( const CHAR* strName, const CHAR* strBody ); 43 | BOOL WriteElement( const CHAR* strName, INT iBody ); 44 | BOOL WriteElement( const CHAR* strName, FLOAT fBody ); 45 | BOOL WriteElementFormat( const CHAR* strName, _In_z_ _Printf_format_string_ const CHAR* strFormat, ... ); 46 | 47 | BOOL StartCDATA(); 48 | BOOL EndCDATA(); 49 | BOOL WriteCDATA( const CHAR* strData, DWORD dwDataLength ); 50 | 51 | BOOL StartComment( BOOL bInline = FALSE ); 52 | BOOL EndComment(); 53 | BOOL WriteComment( const CHAR* strComment, BOOL bInline = FALSE ); 54 | 55 | BOOL AddAttributeFormat( const CHAR* strName, _In_z_ _Printf_format_string_ const CHAR* strFormat, ... ); 56 | BOOL AddAttribute( const CHAR* strName, const CHAR* strValue ); 57 | BOOL AddAttribute( const CHAR* strName, const WCHAR* wstrValue ); 58 | BOOL AddAttribute( const CHAR* strName, INT iValue ); 59 | BOOL AddAttribute( const CHAR* strName, FLOAT fValue ); 60 | 61 | BOOL WriteString( const CHAR* strText ); 62 | BOOL WriteStringFormat( _In_z_ _Printf_format_string_ const CHAR* strFormat, ... ); 63 | 64 | private: 65 | 66 | VOID PushName( const CHAR* strName ); 67 | const CHAR* PopName(); 68 | 69 | inline BOOL EndOpenTag(); 70 | inline BOOL WriteNewline(); 71 | inline BOOL WriteIndent(); 72 | 73 | inline BOOL OutputString( const CHAR* strText ); 74 | inline BOOL OutputStringFast( const CHAR* strText, UINT uLength ); 75 | VOID FlushBufferToFile(); 76 | 77 | HANDLE m_hFile; 78 | CHAR* m_strBuffer; 79 | CHAR* m_strBufferStart; 80 | UINT m_uBufferSizeRemaining; 81 | 82 | CHAR m_strNameStack[XMLWRITER_NAME_STACK_SIZE]; 83 | CHAR* m_strNameStackTop; 84 | UINT m_uNameStackSize; 85 | std::vector m_NameStackPositions; 86 | UINT m_uIndentCount; 87 | CHAR m_strIndent[9]; 88 | BOOL m_bWriteNewlines; 89 | 90 | BOOL m_bOpenTagFinished; 91 | BOOL m_bWriteCloseTagIndent; 92 | BOOL m_bInlineComment; 93 | }; 94 | 95 | } // namespace ATG 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /Common/AtgBound.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgBound.h 3 | // 4 | // A bound in a union of four basic bound types: frustum, AAbb, Obb, and 5 | // sphere. Bounds can be collided against one another. 6 | // 7 | // Xbox Advanced Technology Group. 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //----------------------------------------------------------------------------- 10 | 11 | #pragma once 12 | #ifndef ATG_BOUND_H 13 | #define ATG_BOUND_H 14 | 15 | namespace ATG 16 | { 17 | 18 | struct AxisAlignedBox; 19 | struct OrientedBox; 20 | struct Frustum; 21 | struct Sphere; 22 | 23 | //----------------------------------------------------------------------------- 24 | // Name: EnumStringMap 25 | // Desc: Maps values to strings 26 | //----------------------------------------------------------------------------- 27 | #ifndef ENUMSTRINGMAP_DEFINED 28 | struct EnumStringMap 29 | { 30 | DWORD Value; 31 | const WCHAR* szName; 32 | }; 33 | #define ENUMSTRINGMAP_DEFINED 34 | #endif 35 | 36 | //$TODO: try to get the bounds in a union, once xboxmath.h has had empty 37 | // constructors removed 38 | //----------------------------------------------------------------------------- 39 | class Bound 40 | { 41 | public: 42 | enum BoundType 43 | { 44 | No_Bound, 45 | Sphere_Bound, 46 | Frustum_Bound, 47 | OBB_Bound, 48 | AABB_Bound, 49 | ForceDWORD = 0x7FFFFFFF 50 | }; 51 | 52 | static const EnumStringMap BoundType_StringMap[]; 53 | 54 | // construct/destruct a bound 55 | Bound() { Clear(); } 56 | Bound( const Sphere& Sphere ) { SetSphere( Sphere ); } 57 | Bound( const Frustum& Frustum ){ SetFrustum( Frustum ); } 58 | Bound( const AxisAlignedBox& Aabb ){ SetAabb( Aabb ); } 59 | Bound( const OrientedBox& Obb ){ SetObb( Obb ); } 60 | Bound( const Bound& Other ){ *this = Other; } 61 | 62 | VOID Clear() { m_Type = Bound::No_Bound; } 63 | 64 | // collision with other primitives 65 | BOOL Collide( const Bound& Other ) const; 66 | BOOL Collide( const Frustum& Frustum ) const; 67 | BOOL Collide( const Sphere& Sphere ) const; 68 | BOOL Collide( const AxisAlignedBox& Aabb ) const; 69 | BOOL Collide( const OrientedBox& pObb ) const; 70 | 71 | // merge with another bound 72 | VOID Merge( const Bound& Other ); 73 | 74 | // transformation 75 | Bound operator*( CXMMATRIX Matrix ) const; 76 | 77 | // get-sets 78 | // Note that the get functions will assert if you try to 79 | // get a type not equal to the bounds current BoundType 80 | BoundType GetType() const { return m_Type; } 81 | const Sphere& GetSphere() const; 82 | VOID SetSphere( const Sphere& Sphere ); 83 | const Frustum& GetFrustum() const; 84 | VOID SetFrustum( const Frustum& Frustum ); 85 | const AxisAlignedBox& GetAabb() const; 86 | VOID SetAabb( const AxisAlignedBox& Aabb ); 87 | const OrientedBox& GetObb() const; 88 | VOID SetObb( const OrientedBox& Obb ); 89 | 90 | // gets the center of the bound. 91 | XMFLOAT3 GetCenter() const; 92 | 93 | // gets the bound's maximum radius 94 | FLOAT GetMaxRadius() const; 95 | 96 | private: 97 | BoundType m_Type; 98 | 99 | // Data must be big enough to hold the union of all the bound types. 100 | BYTE m_Data[ sizeof( FLOAT ) * 13 ]; 101 | 102 | }; 103 | 104 | } // namespace ATG 105 | 106 | #endif // ATG_BOUND_H 107 | -------------------------------------------------------------------------------- /Common/XTLOnPC.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // XTLOnPC.cpp 3 | // 4 | // This module contains functions that allow most of the samples framework to compile 5 | // on Windows using the Win32 XDK libraries. 6 | // 7 | // Some of the XTL memory functions are implemented here since the XTL libraries are 8 | // not implemented in the Win32 XDK libraries. 9 | // 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //-------------------------------------------------------------------------------------- 12 | #include "stdafx.h" 13 | #include 14 | 15 | #ifdef _PC 16 | 17 | LPVOID 18 | WINAPI 19 | XPhysicalAlloc( 20 | SIZE_T dwSize, 21 | ULONG_PTR ulPhysicalAddress, 22 | ULONG_PTR ulAlignment, 23 | DWORD flProtect 24 | ) 25 | { 26 | DWORD vaProtect = 0; 27 | 28 | if (flProtect & PAGE_READONLY) 29 | vaProtect = PAGE_READONLY; 30 | else if (flProtect & PAGE_READWRITE) 31 | vaProtect = PAGE_READWRITE; 32 | else 33 | return NULL; 34 | 35 | // Always 4K aligned 36 | return VirtualAlloc( NULL, dwSize, MEM_COMMIT, vaProtect ); 37 | } 38 | 39 | VOID 40 | WINAPI 41 | XPhysicalFree( 42 | LPVOID lpAddress 43 | ) 44 | { 45 | VirtualFree( lpAddress, 0, MEM_RELEASE ); 46 | } 47 | 48 | LPVOID 49 | WINAPI 50 | XMemAlloc( 51 | SIZE_T dwSize, 52 | DWORD dwAllocAttributes 53 | ) 54 | { 55 | const PXALLOC_ATTRIBUTES alloc = (PXALLOC_ATTRIBUTES)(&dwAllocAttributes); 56 | 57 | void *ptr = NULL; 58 | 59 | if ( alloc->dwMemoryType == XALLOC_MEMTYPE_HEAP) 60 | { 61 | size_t align = 16; 62 | 63 | switch ( alloc->dwAlignment ) 64 | { 65 | case XALLOC_ALIGNMENT_DEFAULT: 66 | case XALLOC_ALIGNMENT_16: 67 | break; 68 | 69 | case XALLOC_ALIGNMENT_4: 70 | align = 4; 71 | break; 72 | 73 | case XALLOC_ALIGNMENT_8: 74 | align = 8; 75 | break; 76 | } 77 | 78 | ptr = _aligned_malloc( dwSize, align ); 79 | } 80 | else if ( alloc->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL ) 81 | { 82 | // Always 4K aligned, which works for everything except XALLOC_PHYSICAL_ALIGNMENT_8K, _16K, and _32K 83 | ptr = VirtualAlloc( NULL, dwSize, MEM_COMMIT, PAGE_READWRITE ); 84 | } 85 | 86 | if (ptr && alloc->dwZeroInitialize ) 87 | { 88 | memset( ptr, 0, dwSize ); 89 | } 90 | 91 | return ptr; 92 | } 93 | 94 | VOID 95 | WINAPI 96 | XMemFree( 97 | PVOID pAddress, 98 | DWORD dwAllocAttributes 99 | ) 100 | { 101 | if ( !pAddress ) 102 | return; 103 | 104 | const PXALLOC_ATTRIBUTES alloc = (PXALLOC_ATTRIBUTES)(&dwAllocAttributes); 105 | 106 | if ( alloc->dwMemoryType == XALLOC_MEMTYPE_HEAP) 107 | { 108 | _aligned_free( pAddress ); 109 | } 110 | else if ( alloc->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL ) 111 | { 112 | VirtualFree( pAddress, 0, MEM_RELEASE ); 113 | } 114 | } 115 | 116 | VOID 117 | WINAPI 118 | XGetVideoMode( 119 | PXVIDEO_MODE pVideoMode 120 | ) 121 | { 122 | // This requires knowing the device, access to DXGI, and other video parameters. For Windows we just return zero data for simplicity 123 | ZeroMemory( pVideoMode, sizeof( XVIDEO_MODE ) ); 124 | } 125 | 126 | #endif // ifdef _PC 127 | -------------------------------------------------------------------------------- /Common/AtgSimpleShaders.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgSimpleShaders.h 3 | // 4 | // A library of standard shaders, vertex structs, and vertex declarations for use in 5 | // simple rendering. In a way, this is a replacement for what the fixed function 6 | // pipeline provided. 7 | // 8 | // This code is dependent on a piece of content - media/simpleshaders.fx 9 | // 10 | // Xbox Advanced Technology Group. 11 | // Copyright (C) Microsoft Corporation. All rights reserved. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | #ifndef ATGSIMPLESHADERS_H 16 | #define ATGSIMPLESHADERS_H 17 | 18 | #include 19 | #include 20 | 21 | namespace ATG 22 | { 23 | 24 | struct MeshVertexP 25 | { 26 | public: 27 | XMFLOAT3 Position; 28 | static size_t Size() 29 | { 30 | return sizeof( MeshVertexP ); 31 | } 32 | }; 33 | 34 | struct MeshVertexPTransformed 35 | { 36 | public: 37 | XMFLOAT4 PositionT; 38 | static size_t Size() 39 | { 40 | return sizeof( MeshVertexPTransformed ); 41 | } 42 | }; 43 | 44 | struct MeshVertexPC 45 | { 46 | public: 47 | XMFLOAT3 Position; 48 | D3DCOLOR Color; 49 | static size_t Size() 50 | { 51 | return sizeof( MeshVertexPC ); 52 | } 53 | }; 54 | 55 | struct MeshVertexPT 56 | { 57 | public: 58 | XMFLOAT3 Position; 59 | XMFLOAT2 TexCoord; 60 | static size_t Size() 61 | { 62 | return sizeof( MeshVertexPT ); 63 | } 64 | }; 65 | 66 | struct MeshVertexPCT 67 | { 68 | public: 69 | XMFLOAT3 Position; 70 | D3DCOLOR Color; 71 | XMFLOAT2 TexCoord; 72 | static size_t Size() 73 | { 74 | return sizeof( MeshVertexPCT ); 75 | } 76 | }; 77 | 78 | class SimpleShaders 79 | { 80 | public: 81 | static VOID Initialize( const CHAR* strShaderFileName, FXLEffectPool* pEffectPool ); 82 | static VOID Terminate(); 83 | 84 | static VOID BindToNewDevice( ::D3DDevice* pNewDevice ); 85 | 86 | static VOID SetDeclPos(); 87 | static VOID SetDeclPosT(); 88 | static VOID SetDeclPosColor(); 89 | static VOID SetDeclPosTex(); 90 | static VOID SetDeclPosColorTex(); 91 | 92 | static VOID BeginShader_Transformed_ConstantColor( const XMMATRIX& matWVP, D3DCOLOR Color ); 93 | static VOID BeginShader_Transformed_VertexColor( const XMMATRIX& matWVP ); 94 | static VOID BeginShader_Transformed_Textured( const XMMATRIX& matWVP, const D3DBaseTexture* pTexture ); 95 | static VOID BeginShader_Transformed_TexturedConstantColor( const XMMATRIX& matWVP, const D3DBaseTexture* pTexture, D3DCOLOR Color ); 96 | static VOID BeginShader_Transformed_TexturedVertexColor( const XMMATRIX& matWVP, const D3DBaseTexture* pTexture ); 97 | static VOID BeginShader_Transformed_DepthOnly( const XMMATRIX& matWVP ); 98 | 99 | static VOID BeginShader_PreTransformed_ConstantColor( D3DCOLOR Color ); 100 | static VOID BeginShader_PreTransformed_VertexColor(); 101 | static VOID BeginShader_PreTransformed_Textured( const D3DBaseTexture* pTexture ); 102 | static VOID BeginShader_PreTransformed_DepthTextured( const D3DBaseTexture* pDepthTexture ); 103 | static VOID BeginShader_PreTransformed_TexturedConstantColor( const D3DBaseTexture* pTexture, D3DCOLOR Color ); 104 | static VOID BeginShader_PreTransformed_TexturedVertexColor( const D3DBaseTexture* pTexture ); 105 | static VOID BeginShader_PreTransformed_DepthOnly(); 106 | static VOID BeginShader_PreTransformed_DownsampleDepth( const D3DBaseTexture* pDepthTexture ); 107 | static VOID BeginShader_PreTransformed_DownsampleDepthArray( const D3DBaseTexture* pDepthArrayTexture, DWORD dwSliceIndex ); 108 | 109 | static VOID EndShader(); 110 | }; 111 | 112 | } // namespace ATG 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /HVFuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | #define MEM_1BL_LOC 0x8000020000000000ULL 5 | #define MEM_1BL_SZ 0x8000 6 | 7 | typedef unsigned __int64 QWORD; 8 | #define SPACE_FUSES 0x8000020000020000ULL 9 | extern DWORD HvPeekPokeExpID; 10 | namespace Hvx 11 | { 12 | 13 | // syscalls 14 | QWORD HvGetVersion(DWORD magic, DWORD mode, UINT64 dest = NULL, UINT64 src = NULL, UINT32 len = NULL, UINT64 arg_r8 = NULL); 15 | QWORD HvPostOutput(BYTE code, UINT64 shellCodeAddress); 16 | QWORD HvKeysExecute(PVOID pvPayload, DWORD cbPayload, QWORD arg1, QWORD arg2, QWORD arg3, QWORD arg4); 17 | QWORD HvExpansionInstall(DWORD PhysicalAddress, DWORD CodeSize); 18 | QWORD HvExpansionCall(DWORD ExpansionId, QWORD Param1, QWORD Param2, QWORD Param3, QWORD Param4); 19 | 20 | 21 | typedef enum _PEEK_POKE_TYPE { 22 | PEEK_BYTE = 0, 23 | PEEK_WORD = 1, 24 | PEEK_DWORD = 2, 25 | PEEK_QWORD = 3, 26 | PEEK_BYTES = 4, 27 | POKE_BYTE = 5, 28 | POKE_WORD = 6, 29 | POKE_DWORD = 7, 30 | POKE_QWORD = 8, 31 | POKE_BYTES = 9, 32 | PEEK_SPR = 10, 33 | POKE_SPR = 11 34 | } PEEK_POKE_TYPE; 35 | typedef enum _SOC_SPRS { 36 | SPR_XER = 0x1, 37 | SPR_LR = 0x8, 38 | SPR_CTR = 0x9, 39 | SPR_DSISR = 0x12, 40 | SPR_DAR = 0x13, 41 | SPR_DEC = 0x16, 42 | SPR_SDR1 = 0x19, 43 | SPR_SRR0 = 0x1A, 44 | SPR_SRR1 = 0x1B, 45 | SPR_ACCR = 0x1D, 46 | SPR_CTRL_R = 0x88, 47 | SPR_CTRL_W = 0x98, 48 | SPR_VRSAVE = 0x100, 49 | SPR_SPRG3_R = 0x103, 50 | SPR_TB_R = 0x10C, 51 | SPR_TBU_R = 0x10D, 52 | SPR_SPRG0 = 0x110, 53 | SPR_SPRG1 = 0x111, 54 | SPR_SPRG2 = 0x112, 55 | SPR_SPRG3 = 0x113, 56 | SPR_TBL_W = 0x11C, 57 | SPR_TBU_W = 0x11D, 58 | SPR_PVR = 0x11F, 59 | SPR_HSPRG0 = 0x130, 60 | SPR_HSPRG1 = 0x131, 61 | SPR_HDEC = 0x136, 62 | SPR_HIOR = 0x137, 63 | SPR_RMOR = 0x138, 64 | SPR_HRMOR = 0x139, 65 | SPR_HSRR0 = 0x13A, 66 | SPR_HSRR1 = 0x13B, 67 | SPR_LPCR = 0x13E, 68 | SPR_LPIDR = 0x13F, 69 | SPR_TSRL = 0x380, 70 | SPR_TSRR = 0x381, 71 | SPR_TSCR = 0x399, 72 | SPR_TTR = 0x39A, 73 | SPR_TLB_HINT = 0x3B2, 74 | SPR_TLB_INDEX = 0x3B3, 75 | SPR_TLB_VPN = 0x3B4, 76 | SPR_TLB_RPN = 0x3B5, 77 | SPR_TLB_RMT = 0x3B7, 78 | SPR_DRSR0 = 0x3B8, 79 | SPR_DRMR0 = 0x3B9, 80 | SPR_DCIDR0 = 0x3BA, 81 | SPR_DRSR1 = 0x3BB, 82 | SPR_DRMR1 = 0x3BC, 83 | SPR_DCIDR1 = 0x3BD, 84 | SPR_IRSR0 = 0x3D0, 85 | SPR_IRMR0 = 0x3D1, 86 | SPR_ICIDR0 = 0x3D2, 87 | SPR_IRSR1 = 0x3D3, 88 | SPR_IRMR1 = 0x3D4, 89 | SPR_ICIDR1 = 0x3D5, 90 | SPR_HID0 = 0x3F0, 91 | SPR_HID1 = 0x3F1, 92 | SPR_IABR = 0x3F2, 93 | SPR_HID4 = 0x3F4, 94 | SPR_DABR = 0x3F5, 95 | SPR_HID5 = 0x3F6, 96 | SPR_DABRX = 0x3F7, 97 | SPR_TDABRX = 0x3F8, 98 | SPR_HID6 = 0x3F9, 99 | SPR_HID7 = 0x3FA, 100 | SPR_TIABR = 0x3FB, 101 | SPR_BKMK = 0x3FC, 102 | SPR_TDABR = 0x3FD, 103 | SPR_PIR = 0x3FF 104 | } SOC_SPRS; 105 | 106 | 107 | // reading with the expansion 108 | BYTE HvPeekBYTE(QWORD Address); 109 | WORD HvPeekWORD(QWORD Address); 110 | DWORD HvPeekDWORD(QWORD Address); 111 | QWORD HvPeekQWORD(QWORD Address); 112 | HRESULT HvPeekBytes(QWORD Address, PVOID Buffer, DWORD Size); 113 | // writing with the expansion 114 | HRESULT HvPokeBYTE(QWORD Address, BYTE Value); 115 | HRESULT HvPokeWORD(QWORD Address, WORD Value); 116 | HRESULT HvPokeDWORD(QWORD Address, DWORD Value); 117 | HRESULT HvPokeQWORD(QWORD Address, QWORD Value); 118 | HRESULT HvPokeBytes(QWORD Address, PVOID Buffer, DWORD Size); 119 | // get/set SPR 120 | QWORD HvPeekSPR(SOC_SPRS SPR); 121 | QWORD HvPokeSPR(SOC_SPRS SPR, QWORD Value); 122 | // get fuselines 123 | QWORD HvGetFuseline(DWORD fuse); 124 | 125 | 126 | BOOL CheckPPExpHVAccess(); 127 | BOOL SetupPPExpHVAccess(); 128 | 129 | DWORD Dump1blMagic(); 130 | HRESULT HvDump1blRom(PVOID Buffer); 131 | 132 | 133 | #define SET_PROT_ON 3 134 | #define SET_PROT_OFF 2 135 | BOOL ToggleMemProtect(BOOL state); 136 | 137 | BOOL DisableExpChecks(); 138 | } -------------------------------------------------------------------------------- /Common/AtgCamera.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgCamera.h 3 | // 4 | // describes a camera in the scene 5 | // 6 | // $OPTIMIZE: Pool Allocate 7 | // 8 | // Xbox Advanced Technology Group. 9 | // Copyright (C) Microsoft Corporation. All rights reserved. 10 | //----------------------------------------------------------------------------- 11 | 12 | #pragma once 13 | #ifndef ATG_CAMERA_H 14 | #define ATG_CAMERA_H 15 | 16 | #include "AtgFrame.h" 17 | 18 | namespace ATG 19 | { 20 | 21 | //----------------------------------------------------------------------------- 22 | // Name: Projection 23 | // Desc: simple projection class to handle various projection types. 24 | //----------------------------------------------------------------------------- 25 | class Projection 26 | { 27 | public: 28 | 29 | enum ProjectionType 30 | { 31 | Perspective, 32 | Orthographic, 33 | 34 | ForceDWORD = 0x7fffffff 35 | }; 36 | 37 | static CONST EnumStringMap ProjectionType_StringMap[]; 38 | 39 | // set projection 40 | VOID SetFovXFovY( FLOAT FovX, FLOAT FovY, FLOAT ZNear, FLOAT ZFar ); 41 | VOID SetFovYAspect( FLOAT FovY, FLOAT Aspect, FLOAT ZNear, FLOAT ZFar ); 42 | VOID SetFovXAspect( FLOAT FovX, FLOAT Aspect, FLOAT ZNear, FLOAT ZFar ); 43 | VOID SetOrthographic( FLOAT Width, FLOAT Height, FLOAT ZNear, FLOAT ZFar ); 44 | 45 | // get projection data 46 | XMMATRIX GetMatrix() CONST; 47 | Frustum GetFrustum() CONST; 48 | FLOAT GetFovX() CONST; 49 | FLOAT GetFovY() CONST; 50 | ProjectionType GetType() CONST { return m_Type; } 51 | FLOAT GetZNear() CONST { return m_ZNear; } 52 | FLOAT GetZFar() CONST { return m_ZFar; } 53 | FLOAT GetWidth() CONST { return m_Width; } 54 | FLOAT GetHeight() CONST { return m_Height; } 55 | 56 | private: 57 | ProjectionType m_Type; 58 | FLOAT m_ZNear; 59 | FLOAT m_ZFar; 60 | FLOAT m_Width; 61 | FLOAT m_Height; 62 | }; 63 | 64 | //----------------------------------------------------------------------------- 65 | // Name: Camera 66 | // Desc: basic camera class 67 | //----------------------------------------------------------------------------- 68 | class Camera : public Frame 69 | { 70 | DEFINE_TYPE_INFO(); 71 | public: 72 | // viewport 73 | VOID SetViewport( CONST D3DVIEWPORT9& Viewport ) { m_Viewport = Viewport; } 74 | CONST D3DVIEWPORT9& GetViewport() CONST { return m_Viewport; } 75 | 76 | // view matrices 77 | XMMATRIX GetLocalView() CONST { XMVECTOR pD; return XMMatrixInverse( &pD, GetLocalTransform() ); } 78 | XMMATRIX GetWorldView() { XMVECTOR pD; return XMMatrixInverse( &pD, GetWorldTransform() ); } 79 | XMMATRIX GetLocalInvView() CONST { return GetLocalTransform(); } 80 | XMMATRIX GetWorldInvView() { return GetWorldTransform(); } 81 | 82 | // Focal length 83 | FLOAT GetFocalLength() CONST { return m_fFocalLength; } 84 | VOID SetFocalLength( FLOAT fFocalLength ) { m_fFocalLength = fFocalLength; } 85 | 86 | // Projection 87 | CONST Projection& GetProjection() CONST { return m_Projection; } 88 | VOID SetProjection( CONST Projection& Proj ) { m_Projection = Proj; UpdateBound(); } 89 | 90 | // Clear color 91 | DWORD GetClearColor() CONST { return m_dwClearColor; } 92 | VOID SetClearColor( DWORD ClearColor ) { m_dwClearColor = ClearColor; } 93 | 94 | private: 95 | VOID UpdateBound(); 96 | 97 | Projection m_Projection; 98 | FLOAT m_fFocalLength; 99 | D3DVIEWPORT9 m_Viewport; 100 | DWORD m_dwClearColor; 101 | }; 102 | 103 | } // namespace ATG 104 | 105 | #endif // ATG_CAMERA_H 106 | -------------------------------------------------------------------------------- /Common/AtgHelp.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgHelp.h 3 | // 4 | // Support class for rendering a help image of a gamepad with labelled callouts to the 5 | // gamepad controls. 6 | // 7 | // Xbox Advanced Technology Group. 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //-------------------------------------------------------------------------------------- 10 | #pragma once 11 | #ifndef ATGHELP_H 12 | #define ATGHELP_H 13 | 14 | #include "AtgFont.h" 15 | #include "AtgResource.h" 16 | 17 | namespace ATG 18 | { 19 | 20 | 21 | //-------------------------------------------------------------------------------------- 22 | // Name: struct ATGHELP_CALLOUT 23 | // Desc: Structure for callout information, used to label controls when rendering an 24 | // image of an Xbox gamepad. An app will define an array of of these, one for 25 | // each game pad control used. 26 | //-------------------------------------------------------------------------------------- 27 | struct HELP_CALLOUT 28 | { 29 | WORD wControl; // An index to identify a control, as enum'ed below 30 | WORD wPlacement; // An offset to pick from one of the possible placements 31 | WCHAR* strText; // Text to draw when rendering this callout 32 | }; 33 | 34 | 35 | //-------------------------------------------------------------------------------------- 36 | // Name: class Help 37 | // Desc: Class for rendering a help image of a gamepad with labelled callouts. 38 | //-------------------------------------------------------------------------------------- 39 | class Help 40 | { 41 | PackedResource m_xprResource; 42 | D3DTexture* m_pGamepadTexture; 43 | D3DTexture* m_pLineTexture; 44 | 45 | public: 46 | Help() 47 | { 48 | } 49 | ~Help() 50 | { 51 | } 52 | 53 | // Functions to create and destroy the internal objects 54 | HRESULT Create( const CHAR* pResource ); 55 | HRESULT Create( const PackedResource* pResource ); 56 | 57 | // Renders the help screen (using a caller-supplied font) 58 | VOID Render( Font* pFont, const HELP_CALLOUT* pTags, DWORD dwNumCallouts ); 59 | }; 60 | 61 | 62 | //-------------------------------------------------------------------------------------- 63 | // Constants used to identify callout positions 64 | //-------------------------------------------------------------------------------------- 65 | enum 66 | { 67 | HELP_LEFT_STICK, 68 | HELP_RIGHT_STICK, 69 | HELP_DPAD, 70 | HELP_BACK_BUTTON, 71 | HELP_START_BUTTON, 72 | HELP_X_BUTTON, 73 | HELP_Y_BUTTON, 74 | HELP_A_BUTTON, 75 | HELP_B_BUTTON, 76 | HELP_LEFT_SHOULDER, 77 | HELP_RIGHT_SHOULDER, 78 | HELP_BOTTOM_LEFT, 79 | HELP_BOTTOM_CENTER, 80 | HELP_BOTTOM_RIGHT, 81 | HELP_LEFT_TRIGGER, 82 | HELP_RIGHT_TRIGGER, 83 | 84 | // Temporary mappings until the samples are ported over to the new names 85 | HELP_WHITE_BUTTON = HELP_LEFT_SHOULDER, 86 | HELP_BLACK_BUTTON = HELP_RIGHT_SHOULDER, 87 | HELP_LEFT_BUTTON = HELP_BOTTOM_LEFT, 88 | HELP_RIGHT_BUTTON = HELP_BOTTOM_RIGHT, 89 | HELP_LEFTSTICK = HELP_LEFT_STICK, 90 | HELP_RIGHTSTICK = HELP_RIGHT_STICK, 91 | HELP_MISC_CALLOUT = HELP_BOTTOM_LEFT, 92 | HELP_MISC_CALLOUT_2 = HELP_BOTTOM_CENTER, 93 | HELP_MISC_CALLOUT_3 = HELP_BOTTOM_RIGHT, 94 | }; 95 | 96 | 97 | //-------------------------------------------------------------------------------------- 98 | // Placement options for each callout, used as an offset into the above list 99 | //-------------------------------------------------------------------------------------- 100 | enum 101 | { 102 | HELP_PLACEMENT_1 = 0, // Callout has one line of text 103 | HELP_PLACEMENT_2 = 1 // Callout has two lines of text 104 | }; 105 | 106 | } // namespace ATG 107 | 108 | #endif // ATGHELP_H 109 | -------------------------------------------------------------------------------- /Common/AtgConsole.h.OG: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgConsole.h 3 | // 4 | // Console class for simple applications that need no input and only console output. 5 | // Use this INSTEAD of AtgApplication. 6 | // 7 | // Requires .TGA/.ABC files for the console font. 8 | // 9 | // Xbox Advanced Technology Group. 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //-------------------------------------------------------------------------------------- 12 | #pragma once 13 | #ifndef ATGCONSOLE_H 14 | #define ATGCONSOLE_H 15 | 16 | #include 17 | #include "AtgDevice.h" 18 | #include "AtgFont.h" 19 | 20 | namespace ATG 21 | { 22 | 23 | //-------------------------------------------------------------------------------------- 24 | // Name: class Console 25 | // Desc: Class to implement the console. 26 | //-------------------------------------------------------------------------------------- 27 | class Console 28 | { 29 | public: 30 | Console(); 31 | ~Console(); 32 | 33 | // Initialization 34 | HRESULT Create( LPCSTR strFontFileName, 35 | D3DCOLOR colBackColor, 36 | D3DCOLOR colTextColor, 37 | UINT nLines = 0 ); 38 | 39 | VOID Destroy(); 40 | 41 | // Clear the screen 42 | VOID Clear(); 43 | 44 | // Console output 45 | virtual VOID Format( _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); 46 | virtual VOID Format( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); 47 | virtual VOID FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ); 48 | virtual VOID FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ); 49 | 50 | // Send output to debug channel 51 | VOID SendOutputToDebugChannel( BOOL bOutputToDebugChannel ) 52 | { 53 | m_bOutputToDebugChannel = bOutputToDebugChannel; 54 | } 55 | 56 | // method for rendering the console 57 | VOID Render(); 58 | 59 | // method for scrolling the text window up/down 60 | VOID ScrollUp( INT nLines ); 61 | 62 | static const INT PAGE_UP = +255; 63 | static const INT PAGE_DOWN = -255; 64 | 65 | private: 66 | // Constants 67 | static const UINT SCREEN_SIZE_X_DEFAULT = 640; 68 | static const UINT SCREEN_SIZE_Y_DEFAULT = 480; 69 | static const UINT SCREEN_SIZE_X_720p = 1280; 70 | static const UINT SCREEN_SIZE_Y_720p = 720; 71 | 72 | static const UINT SAFE_AREA_PCT_4x3 = 85; 73 | static const UINT SAFE_AREA_PCT_HDTV = 90; 74 | 75 | // Safe area dimensions 76 | UINT m_cxSafeArea; 77 | UINT m_cySafeArea; 78 | 79 | UINT m_cxSafeAreaOffset; 80 | UINT m_cySafeAreaOffset; 81 | 82 | // Send console output to debug channel 83 | BOOL m_bOutputToDebugChannel; 84 | 85 | // Main objects used for creating and rendering the 3D scene 86 | static D3DPRESENT_PARAMETERS m_d3dpp; 87 | static D3DDevice* m_pd3dDevice; 88 | 89 | // Font for rendering text 90 | Font m_Font; 91 | 92 | // Colors 93 | D3DCOLOR m_colBackColor; 94 | D3DCOLOR m_colTextColor; 95 | 96 | // Text Buffers 97 | UINT m_cScreenHeight; // height in lines of screen area 98 | UINT m_cScreenHeightVirtual; // height in lines of text storage buffer 99 | UINT m_cScreenWidth; // width in characters 100 | FLOAT m_fLineHeight; // height of a single line in pixels 101 | 102 | WCHAR* m_Buffer; // buffer big enough to hold a full screen 103 | WCHAR** m_Lines; // pointers to individual lines 104 | UINT m_nCurLine; // index of current line being written to 105 | UINT m_cCurLineLength; // length of the current line 106 | INT m_nScrollOffset; // offset to display text (in lines) 107 | 108 | BOOL m_bSuspendFlag; // Device suspended tracking flag 109 | 110 | // Add a character to the current line 111 | VOID Add( CHAR ch ); 112 | VOID Add( WCHAR wch ); 113 | 114 | // Increment to the next line 115 | VOID IncrementLine(); 116 | }; 117 | 118 | } 119 | // namespace ATG 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /Common/AtgJson.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //-------------------------------------------------------------------------------------- 5 | // Light Weight JSON reader reader based on XJSON 6 | // 7 | // Xbox Advanced Technology Group. 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //-------------------------------------------------------------------------------------- 10 | 11 | #pragma once 12 | #ifndef ATGJSON_H 13 | #define ATGJSON_H 14 | 15 | 16 | //-------------------------------------------------------------------------------------- 17 | // INCLUDES 18 | //-------------------------------------------------------------------------------------- 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | namespace ATG 27 | { 28 | namespace JSON 29 | { 30 | 31 | //-------------------------------------------------------------------------------------- 32 | // DEFINES 33 | //-------------------------------------------------------------------------------------- 34 | #define MAXTOKENSIZE 3000 35 | 36 | 37 | //-------------------------------------------------------------------------------------- 38 | // STRUCTS 39 | //-------------------------------------------------------------------------------------- 40 | enum DATATYPE 41 | { 42 | DT_NONE = 0, 43 | DT_STRING, 44 | DT_INT, 45 | DT_INT64, 46 | DT_ARRAY 47 | }; 48 | 49 | 50 | //-------------------------------------------------------------------------------------- 51 | // struct PropertyTag 52 | // 53 | // this is used to define a RESTful object for reading 54 | //-------------------------------------------------------------------------------------- 55 | struct PropertyTag 56 | { 57 | WCHAR *fieldname; // e.g. "titleId" 58 | DATATYPE dt; 59 | DWORD offset; 60 | DWORD stringSize; 61 | }; 62 | 63 | 64 | //-------------------------------------------------------------------------------------- 65 | // class ICollectionBase 66 | // 67 | // pure virtual base class 68 | // generic interface for all nested user defined objects to be deserialized 69 | // awesome as the JSON serializer can access the nested objects through this interface 70 | // and not care about the underlying user type 71 | //-------------------------------------------------------------------------------------- 72 | class ICollectionBase 73 | { 74 | public: 75 | virtual VOID *GetNewObject() = 0; 76 | virtual VOID *GetTags() = 0; 77 | virtual int GetTagSize() = 0; 78 | }; 79 | 80 | 81 | //-------------------------------------------------------------------------------------- 82 | // class Collection : public ICollectionBase 83 | // 84 | // with this awesome abstraction with a pure virtual interface base class we can remove 85 | // the need to known what Type we are actually deserializing in the parser as it is 86 | // implicit in the template declaration of the user type 87 | //-------------------------------------------------------------------------------------- 88 | template class Collection : public ICollectionBase 89 | { 90 | public: 91 | Collection() {} 92 | 93 | ~Collection() 94 | { 95 | object_array.clear(); 96 | } 97 | 98 | VOID *GetNewObject() 99 | { 100 | Type *t = new Type(); 101 | object_array.push_back(t); 102 | return t; 103 | } 104 | 105 | Type *operator[](int i) 106 | { 107 | return object_array[i]; 108 | } 109 | 110 | VOID *GetTags() 111 | { 112 | return Type::tags; 113 | } 114 | 115 | int GetTagSize() 116 | { 117 | return Type::tagsize; 118 | } 119 | 120 | int GetArraySize() 121 | { 122 | return object_array.size(); 123 | } 124 | 125 | private: 126 | std::vector object_array; 127 | }; 128 | 129 | 130 | //-------------------------------------------------------------------------------------- 131 | // class AtgJsonReader 132 | // 133 | //-------------------------------------------------------------------------------------- 134 | class AtgJsonReader 135 | { 136 | public: 137 | static HRESULT Parse(CONST BYTE *inbuf, VOID *bp, PropertyTag *pt, DWORD size); 138 | 139 | private: 140 | static HRESULT ParseJSON(HJSONPARSER &p, VOID *bp, PropertyTag *pt, DWORD size, VOID *parent); 141 | }; 142 | 143 | } // end namespace JSON 144 | } // end namespace ATG 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /Common/AtgConsole.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgConsole.h 3 | // 4 | // Console class for simple applications that need no input and only console output. 5 | // Use this INSTEAD of AtgApplication. 6 | // 7 | // Requires .TGA/.ABC files for the console font. 8 | // 9 | // Xbox Advanced Technology Group. 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //-------------------------------------------------------------------------------------- 12 | #pragma once 13 | #ifndef ATGCONSOLE_H 14 | #define ATGCONSOLE_H 15 | 16 | #include 17 | #include "AtgDevice.h" 18 | #include "AtgFont.h" 19 | 20 | namespace ATG 21 | { 22 | 23 | //-------------------------------------------------------------------------------------- 24 | // Name: class Console 25 | // Desc: Class to implement the console. 26 | //-------------------------------------------------------------------------------------- 27 | class Console 28 | { 29 | public: 30 | Console(); 31 | ~Console(); 32 | 33 | // Initialization 34 | HRESULT Create( LPCSTR strFontFileName, 35 | D3DCOLOR colBackColor, 36 | D3DCOLOR colTextColor, 37 | UINT nLines = 0 ); 38 | 39 | VOID Destroy(); 40 | 41 | // Clear the screen 42 | VOID Clear(); 43 | 44 | // Console output 45 | virtual VOID Display( LPCSTR strDisplay ); 46 | virtual VOID Display( LPCWSTR wstrDisplay ); 47 | virtual VOID Format( _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); 48 | virtual VOID Format( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); 49 | virtual VOID FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ); 50 | virtual VOID FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ); 51 | 52 | // Send output to debug channel 53 | VOID SendOutputToDebugChannel( BOOL bOutputToDebugChannel ) 54 | { 55 | m_bOutputToDebugChannel = bOutputToDebugChannel; 56 | } 57 | 58 | // method for rendering the console 59 | VOID Render(); 60 | 61 | // method for scrolling the text window up/down 62 | VOID ScrollUp( INT nLines ); 63 | 64 | static const INT PAGE_UP = +255; 65 | static const INT PAGE_DOWN = -255; 66 | 67 | private: 68 | // Constants 69 | static const UINT SCREEN_SIZE_X_DEFAULT = 640; 70 | static const UINT SCREEN_SIZE_Y_DEFAULT = 480; 71 | static const UINT SCREEN_SIZE_X_720p = 1280; 72 | static const UINT SCREEN_SIZE_Y_720p = 720; 73 | 74 | static const UINT SAFE_AREA_PCT_4x3 = 85; 75 | static const UINT SAFE_AREA_PCT_HDTV = 90; 76 | 77 | // Safe area dimensions 78 | UINT m_cxSafeArea; 79 | UINT m_cySafeArea; 80 | 81 | UINT m_cxSafeAreaOffset; 82 | UINT m_cySafeAreaOffset; 83 | 84 | // Send console output to debug channel 85 | BOOL m_bOutputToDebugChannel; 86 | 87 | // Main objects used for creating and rendering the 3D scene 88 | static D3DPRESENT_PARAMETERS m_d3dpp; 89 | static D3DDevice* m_pd3dDevice; 90 | 91 | // Font for rendering text 92 | Font m_Font; 93 | 94 | // Colors 95 | D3DCOLOR m_colBackColor; 96 | D3DCOLOR m_colTextColor; 97 | 98 | // Text Buffers 99 | UINT m_cScreenHeight; // height in lines of screen area 100 | UINT m_cScreenHeightVirtual; // height in lines of text storage buffer 101 | UINT m_cScreenWidth; // width in characters 102 | FLOAT m_fLineHeight; // height of a single line in pixels 103 | 104 | WCHAR* m_Buffer; // buffer big enough to hold a full screen 105 | WCHAR** m_Lines; // pointers to individual lines 106 | UINT m_nCurLine; // index of current line being written to 107 | UINT m_cCurLineLength; // length of the current line 108 | INT m_nScrollOffset; // offset to display text (in lines) 109 | 110 | BOOL m_bSuspendFlag; // Device suspended tracking flag 111 | 112 | // Add a character to the current line 113 | VOID Add( CHAR ch ); 114 | VOID Add( WCHAR wch ); 115 | 116 | // Increment to the next line 117 | VOID IncrementLine(); 118 | }; 119 | 120 | } 121 | // namespace ATG 122 | 123 | #endif -------------------------------------------------------------------------------- /Common/AtgSignIn.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgSignIn.h 3 | // 4 | // Helper class to automatically handle signin 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGSIGNIN_H 11 | #define ATGSIGNIN_H 12 | 13 | namespace ATG 14 | { 15 | 16 | //-------------------------------------------------------------------------------------- 17 | // Name: class SignIn 18 | // Desc: Class to manage maintaining signed-in users. This class is a singleton; all 19 | // members are static 20 | //-------------------------------------------------------------------------------------- 21 | class SignIn 22 | { 23 | public: 24 | // Flags that can be returned from Update() 25 | static enum SIGNIN_UPDATE_FLAGS 26 | { 27 | SIGNIN_USERS_CHANGED = 0x00000001, 28 | SYSTEM_UI_CHANGED = 0x00000002, 29 | CONNECTION_CHANGED = 0x00000004 30 | }; 31 | 32 | // Check users that are signed in 33 | static DWORD GetSignedInUserCount() 34 | { 35 | return m_dwNumSignedInUsers; 36 | } 37 | static DWORD GetSignedInUserMask() 38 | { 39 | return m_dwSignedInUserMask; 40 | } 41 | static BOOL IsUserSignedIn( DWORD dwController ) 42 | { 43 | return ( m_dwSignedInUserMask & ( 1 << dwController ) ) != 0; 44 | } 45 | 46 | static BOOL AreUsersSignedIn() 47 | { 48 | return ( m_dwNumSignedInUsers >= m_dwMinUsers ) && 49 | ( m_dwNumSignedInUsers <= m_dwMaxUsers ); 50 | } 51 | 52 | // Get the first signed-in user 53 | static DWORD GetSignedInUser() 54 | { 55 | return m_dwFirstSignedInUser; 56 | } 57 | 58 | // Check users that are signed into live 59 | static DWORD GetOnlineUserMask() 60 | { 61 | return m_dwOnlineUserMask; 62 | } 63 | static BOOL IsUserOnline( DWORD dwController ) 64 | { 65 | return ( m_dwOnlineUserMask & ( 1 << dwController ) ) != 0; 66 | } 67 | 68 | // Check the presence of system UI 69 | static BOOL IsSystemUIShowing() 70 | { 71 | return m_bSystemUIShowing || m_bNeedToShowSignInUI; 72 | } 73 | 74 | // Function to reinvoke signin UI 75 | static VOID ShowSignInUI() 76 | { 77 | m_bNeedToShowSignInUI = TRUE; 78 | } 79 | 80 | // Check privileges for a signed-in users 81 | static BOOL CheckPrivilege( DWORD dwController, XPRIVILEGE_TYPE priv ); 82 | 83 | // Methods to drive autologin 84 | static VOID Initialize( 85 | DWORD dwMinUsers, 86 | DWORD dwMaxUsers, 87 | BOOL bRequireOnlineUsers, 88 | DWORD dwSignInPanes ); 89 | 90 | static DWORD Update(); 91 | 92 | private: 93 | 94 | // Private constructor to prevent instantiation 95 | SignIn(); 96 | 97 | // Parameters 98 | static DWORD m_dwMinUsers; // minimum users to accept as signed in 99 | static DWORD m_dwMaxUsers; // maximum users to accept as signed in 100 | static BOOL m_bRequireOnlineUsers; // online profiles only 101 | static DWORD m_dwSignInPanes; // number of panes to show in signin UI 102 | 103 | // Internal variables 104 | static HANDLE m_hNotification; // listener to accept notifications 105 | static DWORD m_dwSignedInUserMask; // bitfields for signed-in users 106 | static DWORD m_dwFirstSignedInUser; // first signed-in user 107 | static DWORD m_dwNumSignedInUsers; // number of signed-in users 108 | static DWORD m_dwOnlineUserMask; // users who are online 109 | static BOOL m_bSystemUIShowing; // system UI present 110 | static BOOL m_bNeedToShowSignInUI; // invoking signin UI necessary 111 | static BOOL m_bMessageBoxShowing; // is retry signin message box showing? 112 | static BOOL m_bSigninUIWasShown; // was the signin ui shown at least once? 113 | static XOVERLAPPED m_Overlapped; // message box overlapped struct 114 | static LPCWSTR m_pwstrButtons[2]; // message box buttons 115 | static MESSAGEBOX_RESULT m_MessageBoxResult; // message box button pressed 116 | 117 | static VOID QuerySigninStatus(); // Query signed in users 118 | 119 | }; 120 | 121 | } // namespace ATG 122 | 123 | #endif // ATGSIGNIN_H 124 | -------------------------------------------------------------------------------- /XeUnshackle.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release_LTCG 6 | Xbox 360 7 | 8 | 9 | 10 | {BF064E30-8592-454E-A655-0D0E5C6328C4} 11 | Xbox360Proj 12 | 13 | 14 | 15 | Application 16 | true 17 | MultiByte 18 | 2010-01 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | false 29 | 30 | 31 | 32 | Level3 33 | Use 34 | Full 35 | true 36 | true 37 | ProgramDatabase 38 | Size 39 | false 40 | false 41 | $(OutDir)$(ProjectName).pch 42 | MultiThreaded 43 | NDEBUG;_XBOX;LTCG 44 | Common;%(AdditionalIncludeDirectories) 45 | 46 | 47 | true 48 | true 49 | true 50 | $(OutDir)$(ProjectName).pdb 51 | true 52 | xmedia2.lib;xnet.lib;xaudio2.lib;xmcoreltcg.lib;d3d9ltcg.lib;d3dx9.lib;xgraphics.lib;xapilib.lib;x3daudioltcg.lib;xboxkrnl.lib;%(AdditionalDependencies) 53 | 54 | 55 | AppConf_SectRes.xml 56 | 57 | 58 | mkdir "$(OutDir)COPY_TO_BadUpdatePayload_FOLDER" 59 | "$(ProjectDir)xextool.exe" -m r -r a -o "$(OutDir)COPY_TO_BadUpdatePayload_FOLDER\default.xex" "$(ImageXexOutput)" 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Create 80 | 81 | 82 | 83 | 84 | 85 | 86 | {91d208a6-9936-47fd-9659-67205c3eb0ab} 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Common/AtgLight.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgLight.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "stdafx.h" 9 | #include "AtgCollision.h" 10 | #include "AtgBound.h" 11 | #include "AtgLight.h" 12 | 13 | namespace ATG 14 | { 15 | 16 | CONST StringID Light::TypeID( L"Light" ); 17 | CONST StringID AmbientLight::TypeID( L"AmbientLight" ); 18 | CONST StringID PointLight::TypeID( L"PointLight" ); 19 | CONST StringID SpotLight::TypeID( L"SpotLight" ); 20 | CONST StringID DirectionalLight::TypeID( L"DirectionalLight" ); 21 | 22 | CONST EnumStringMap Light::FalloffType_StringMap[] = 23 | { 24 | { Light::LinearFalloff, L"LINEAR" }, 25 | { Light::SquaredFalloff, L"SQUARED" }, 26 | { Light::NoFalloff, L"NONE" }, 27 | { 0, NULL }, 28 | }; 29 | 30 | CONST EnumStringMap Light::LightFlags_StringMap[] = 31 | { 32 | { Light::NoFlags, L"NONE" }, 33 | { Light::IsShadowCaster, L"SHADOWCASTER" }, 34 | { 0, NULL }, 35 | }; 36 | 37 | D3DCOLOR Light::GetD3DColor() const 38 | { 39 | XMVECTOR vColor = GetColor(); 40 | vColor = XMVectorClamp( vColor, XMVectorZero(), XMVectorReplicate( 1.0f ) ); 41 | 42 | XMFLOAT4A vec; 43 | XMStoreFloat4A( &vec, vColor ); 44 | 45 | D3DCOLOR Color = D3DCOLOR_COLORVALUE( vec.x, vec.y, vec.z, vec.w ); 46 | return Color; 47 | } 48 | 49 | //----------------------------------------------------------------------------- 50 | // Name: PointLight::SetLocalRange 51 | //----------------------------------------------------------------------------- 52 | VOID PointLight::SetLocalRange( FLOAT fRange ) 53 | { 54 | Sphere sphere; 55 | 56 | m_fRange = fRange; 57 | 58 | // build new bound 59 | XMStoreFloat3( &( sphere.Center ), XMVectorZero() ); 60 | sphere.Radius = m_fRange; 61 | 62 | SetLocalBound( Bound( sphere ) ); 63 | } 64 | 65 | //----------------------------------------------------------------------------- 66 | // Name: PointLight::GetWorldRange 67 | //----------------------------------------------------------------------------- 68 | FLOAT PointLight::GetWorldRange() 69 | { 70 | // assume uniform scale. get scale from length of x axis 71 | XMVECTOR Scale = XMVector3Length( GetWorldTransform().r[0] ); 72 | return GetLocalRange() * XMVectorGetX( Scale ); 73 | } 74 | 75 | 76 | //-------------------------------------------------------------------------------------- 77 | // Name: PointLight::SetWorldRange() 78 | //-------------------------------------------------------------------------------------- 79 | VOID PointLight::SetWorldRange( FLOAT fRange ) 80 | { 81 | // assume uniform scale. get scale from length of x axis 82 | XMVECTOR Scale = XMVector3Length( GetWorldTransform().r[0] ); 83 | SetLocalRange( fRange / XMVectorGetX( Scale ) ); 84 | } 85 | 86 | 87 | //-------------------------------------------------------------------------------------- 88 | // Name: SpotLight::SetWorldRange() 89 | //-------------------------------------------------------------------------------------- 90 | VOID SpotLight::SetWorldRange( FLOAT fRange ) 91 | { 92 | // assume uniform scale. get scale from length of x axis 93 | XMVECTOR Scale = XMVector3Length( GetWorldTransform().r[0] ); 94 | SetLocalRange( fRange / XMVectorGetX( Scale ) ); 95 | } 96 | 97 | 98 | //----------------------------------------------------------------------------- 99 | // Name: SpotLight::RecalculateBound 100 | //----------------------------------------------------------------------------- 101 | VOID SpotLight::RecalculateBound() 102 | { 103 | Frustum frustum; 104 | 105 | /* 106 | FLOAT FovY = m_fOuterAngle; 107 | FLOAT ZNear = m_fRange * 1e-4f; 108 | FLOAT ZFar = m_fRange; 109 | FLOAT h = ( 2.0f * ZNear) / ( 1.0f/tanf(FovY/2.0f)) ; 110 | 111 | //$OPTIMIZE: store matrix in decomposed form 112 | XMMATRIX Projection = XMMatrixPerspectiveLH( h, h, ZNear, ZFar ); 113 | */ 114 | XMMATRIX Projection = GetLightProjection(); 115 | 116 | ComputeFrustumFromProjection( &frustum, &Projection ); 117 | 118 | SetLocalBound( Bound( frustum ) ); 119 | } 120 | 121 | 122 | //----------------------------------------------------------------------------- 123 | // Name: PointLight::GetWorldRange 124 | //----------------------------------------------------------------------------- 125 | FLOAT SpotLight::GetWorldRange() 126 | { 127 | // assume uniform scale. get scale from length of x axis 128 | XMVECTOR Scale = XMVector3Length( GetWorldTransform().r[0] ); 129 | return GetLocalRange() * XMVectorGetX( Scale ); 130 | } 131 | 132 | } // namespace ATG 133 | -------------------------------------------------------------------------------- /Common/AtgDebugDraw.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgDebugDraw.h 3 | // 4 | // A rendering library for drawing simple primitives. These are not optimized for 5 | // speed - just ease of use. 6 | // 7 | // You must initialize the SimpleShaders class in AtgSimpleShaders.h/.cpp before using 8 | // the debug primitives. 9 | // 10 | // Xbox Advanced Technology Group. 11 | // Copyright (C) Microsoft Corporation. All rights reserved. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | #ifndef ATGDEBUGDRAW_H 16 | #define ATGDEBUGDRAW_H 17 | 18 | #include 19 | #include "AtgBound.h" 20 | #include "AtgCollision.h" 21 | 22 | namespace ATG 23 | { 24 | 25 | class DebugDraw 26 | { 27 | public: 28 | // Call SetViewProjection with your camera matrix before using the draw calls. 29 | static VOID SetViewProjection( const XMMATRIX& matViewProjection ); 30 | 31 | // Debug draw commands. All vectors and sizes are in world space. 32 | static VOID DrawAxes( const XMMATRIX& matWorld ); 33 | static VOID DrawCubeWireframe( const XMFLOAT3& Center, const XMFLOAT3& HalfSize, D3DCOLOR Color ); 34 | static VOID DrawCubeWireframe( const XMMATRIX& matWorld, D3DCOLOR Color ); 35 | static VOID DrawLineSegment( const XMFLOAT3& Origin, const XMFLOAT3& End, D3DCOLOR Color ); 36 | static VOID DrawRay( const XMFLOAT3& Origin, const XMFLOAT3& Direction, BOOL bNormalize, D3DCOLOR Color ); 37 | static VOID DrawRing( const XMFLOAT3& Origin, const XMFLOAT3& MajorAxis, const XMFLOAT3& MinorAxis, 38 | D3DCOLOR Color ); 39 | static VOID DrawSphere( const XMFLOAT3& Origin, FLOAT fRadius, D3DCOLOR Color ); 40 | static VOID DrawGrid( const XMFLOAT3& XAxis, const XMFLOAT3& YAxis, const XMFLOAT3& Origin, INT iXDivisions, 41 | INT iYDivisions, D3DCOLOR Color ); 42 | static VOID DrawTriangle( const XMFLOAT3& PointA, const XMFLOAT3& PointB, const XMFLOAT3& PointC, D3DCOLOR Color ); 43 | static VOID DrawConeWireframe( const XMFLOAT3& CenterBase, const XMFLOAT3& Axis, FLOAT fBaseRadius, 44 | FLOAT fTopRadius, D3DCOLOR Color ); 45 | static VOID DrawConeWireframe( const XMMATRIX& matWorld, FLOAT fBaseRadius, FLOAT fTopRadius, D3DCOLOR Color ); 46 | static VOID DrawQuad( const XMFLOAT3& CornerA, const XMFLOAT3& CornerB, const XMFLOAT3& CornerC, D3DCOLOR Color ); 47 | static VOID DrawQuad( const XMFLOAT3& CornerA, const XMFLOAT3& CornerB, const XMFLOAT3& CornerC, const XMFLOAT3& CornerD, D3DCOLOR Color ); 48 | static VOID DrawTexturedQuad( const XMFLOAT3& CornerA, const XMFLOAT3& CornerB, const XMFLOAT3& CornerC, 49 | const XMFLOAT2& UVRepeat, D3DTexture* pTexture ); 50 | static VOID DrawCubeQuery( const XMFLOAT3& Center, const XMFLOAT3& HalfSize ); 51 | 52 | // Screen space debug draw primitives. The viewport is disabled when drawing these primitives. 53 | // If the line width is less than 0, the screen space rect is drawn solid. 54 | static VOID DrawScreenSpaceLine( const XMFLOAT2& Origin, const XMFLOAT2& End, D3DCOLOR Color, FLOAT fLineWidth = 1 ); 55 | static VOID DrawScreenSpaceLine( const XMFLOAT2& Origin, D3DCOLOR OriginColor, const XMFLOAT2& End, D3DCOLOR EndColor, FLOAT fLineWidth = 1 ); 56 | static VOID DrawScreenSpaceLineList( const XMFLOAT2 Points[], UINT PointCount, D3DCOLOR Color, FLOAT fLineWidth = 1 ); 57 | static VOID DrawScreenSpaceRect( const XMFLOAT2& Origin, const XMFLOAT2& Size, FLOAT fLineWidth, D3DCOLOR Color ); 58 | static VOID DrawScreenSpaceRect( const D3DRECT& Rect, FLOAT fLineWidth, D3DCOLOR Color ); 59 | static VOID DrawScreenSpaceTexturedRect( const D3DRECT& Rect, const D3DBaseTexture* pTexture, BOOL bDepthTexture = 60 | FALSE ); 61 | static VOID DrawScreenSpaceTexturedRectColored( const D3DRECT& Rect, const D3DBaseTexture* pTexture, D3DCOLOR Color ); 62 | 63 | static VOID DrawScreenSpaceTexturedRectPatch( const D3DRECT& Rect, XMFLOAT2 UVTopLeft, XMFLOAT2 UVTopRight, XMFLOAT2 UVBottomLeft, const D3DBaseTexture* pTexture, BOOL bDepthTexture = 64 | FALSE ); 65 | static VOID DrawScreenSpaceTexturedRectPatchPointSampled( const D3DRECT& Rect, XMFLOAT2 UVTopLeft, XMFLOAT2 UVTopRight, XMFLOAT2 UVBottomLeft, const D3DBaseTexture* pTexture, BOOL bDepthTexture = 66 | FALSE ); 67 | 68 | // Debug bounds drawing. 69 | static VOID DrawBound( const Bound& bound, D3DCOLOR Color ); 70 | static VOID DrawSphere( const Sphere& sphere, D3DCOLOR Color ); 71 | static VOID DrawFrustum( const Frustum& frustum, D3DCOLOR Color ); 72 | static VOID DrawObb( const OrientedBox& obb, D3DCOLOR Color ); 73 | static VOID DrawAabb( const AxisAlignedBox& box, D3DCOLOR Color ); 74 | }; 75 | 76 | } // namespace ATG 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Common/AtgMetaVMX.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AtgMeta.h" 4 | #include 5 | 6 | namespace ATG{ 7 | 8 | // 9 | // Recommended types for passing __vector4 10 | // 11 | typedef const __vector4 __declspec(passinreg) vector4_in; 12 | typedef __vector4 __declspec(passinreg)& vector4_out; 13 | typedef __vector4 __declspec(passinreg)& vector4_inout; 14 | typedef __vector4* __restrict vector4_ptr; 15 | 16 | // 17 | // Wrappers for VMX compiler intrinsics 18 | // 19 | // VMX intrinsics can't be used as functors--they look like functions 20 | // but they have no storage, which makes things all confused. Plus, they 21 | // are mostly defined with return types, which makes them harder to use 22 | // with CompileTimeLoop. Fortunately they can be wrapped in functions 23 | // with no loss of efficiency as long as the functions are inlined. 24 | // 25 | void __forceinline vor( vector4_out result, vector4_in a, vector4_in b ){ result = __vor( a, b ); } 26 | void __forceinline vand( vector4_out result, vector4_in a, vector4_in b ){ result = __vand( a, b ); } 27 | 28 | void __forceinline vcmpgefp( vector4_out result, vector4_in a, vector4_in b ){ result = __vcmpgefp( a, b ); } 29 | void __forceinline vcmpgtfp( vector4_out result, vector4_in a, vector4_in b ){ result = __vcmpgtfp( a, b ); } 30 | 31 | void __forceinline vcmpgefp_vor( vector4_out result, vector4_in a, vector4_in b ){ result = __vor( result, __vcmpgefp( a, b ) ); } 32 | void __forceinline vcmpgtfp_vor( vector4_out result, vector4_in a, vector4_in b ){ result = __vor( result, __vcmpgtfp( a, b ) ); } 33 | void __forceinline vcmpgefp_vand( vector4_out result, vector4_in a, vector4_in b ){ result = __vand( result, __vcmpgefp( a, b ) ); } 34 | void __forceinline vcmpgtfp_vand( vector4_out result, vector4_in a, vector4_in b ){ result = __vand( result, __vcmpgtfp( a, b ) ); } 35 | 36 | void __forceinline vmulfp( vector4_out result, vector4_in a, vector4_in b ){ result = __vmulfp( a, b ); } 37 | void __forceinline vaddfp( vector4_out result, vector4_in a, vector4_in b ){ result = __vaddfp( a, b ); } 38 | void __forceinline vsubfp( vector4_out result, vector4_in a, vector4_in b ){ result = __vsubfp( a, b ); } 39 | void __forceinline vmaddfp( vector4_out result, vector4_in mul1, vector4_in mul2, vector4_in add ){ result = __vmaddfp( mul1, mul2, add ); } 40 | void __forceinline vmsum4fp( vector4_out result, vector4_in mul1, vector4_in mul2 ){ result = __vmsum4fp( mul1, mul2 ); } 41 | void __forceinline vmsum3fp( vector4_out result, vector4_in mul1, vector4_in mul2 ){ result = __vmsum3fp( mul1, mul2 ); } 42 | 43 | 44 | // 45 | // Things do get a little tricky when the intrinsic takes a constant 46 | // parameter, because the value for the parameter has to be known at 47 | // compile time in order for the compiler to emit the right machine code. 48 | // This could be solved in many cases by wrapping the intrinsic in 49 | // a function template, but you can't pass a template function to another 50 | // template function if the second function isn't expecting a template. 51 | // We get around this problem by using functor structs--structures that 52 | // overload operator() and templatize the overload. The struct object 53 | // is what gets passed to CompileTimeLoop, which sees it as just another 54 | // function. When the operator actually gets called, the compiler 55 | // deduces the correct integer to call it with. 56 | // 57 | struct vspltw_t 58 | { 59 | template 60 | void __forceinline operator()(vector4_out result, vector4_in src, CompileTimeInt e ){ result = __vspltw( src, element ); } 61 | }; 62 | __declspec(selectany) vspltw_t vspltw; 63 | 64 | struct vinsert_t 65 | { 66 | template 67 | void __forceinline operator()(vector4_out result, vector4_in src, CompileTimeInt srcElement, CompileTimeInt destElement ) 68 | { 69 | result = __vrlimi( result, src, 8>>destE, ((destE-srcE)+3)%3); 70 | } 71 | }; 72 | __declspec(selectany) vinsert_t vinsert; 73 | 74 | union fdw{ DWORD dw; float f; }; 75 | const static fdw vpermX0 = { 0x00010203 }; 76 | const static fdw vpermY0 = { 0x04050607 }; 77 | const static fdw vpermZ0 = { 0x08090a0b }; 78 | const static fdw vpermW0 = { 0x0c0d0e0f }; 79 | const static fdw vpermX1 = { 0x10111213 }; 80 | const static fdw vpermY1 = { 0x14151617 }; 81 | const static fdw vpermZ1 = { 0x18191a1b }; 82 | const static fdw vpermW1 = { 0x1c1d1e1f }; 83 | 84 | union __declspec(align(16)) vdw{ DWORD dw[4]; __vector4 v; }; 85 | const static __vector4 Ones = { 1.0f, 1.0f, 1.0f, 1.0f }; 86 | const static vdw vectorSignBits = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; 87 | const static vdw vectorNonSignBits = { 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff }; 88 | } // namespace ATG -------------------------------------------------------------------------------- /Common/AtgCamera.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgCamera.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "stdafx.h" 9 | #include "AtgCollision.h" 10 | #include "AtgCamera.h" 11 | 12 | namespace ATG 13 | { 14 | 15 | CONST StringID Camera::TypeID( L"Camera" ); 16 | CONST EnumStringMap Projection::ProjectionType_StringMap[] = 17 | { 18 | { Projection::Perspective, L"Perspective" }, 19 | { Projection::Orthographic, L"Orthographic" }, 20 | { 0, NULL }, 21 | }; 22 | 23 | //----------------------------------------------------------------------------- 24 | // Name: Projection::GetFrustum 25 | //----------------------------------------------------------------------------- 26 | Frustum Projection::GetFrustum() CONST 27 | { 28 | Frustum Temp; 29 | XMMATRIX Proj = GetMatrix(); 30 | ComputeFrustumFromProjection( &Temp, &Proj ); 31 | return Temp; 32 | } 33 | 34 | 35 | //----------------------------------------------------------------------------- 36 | // Name: Projection::GetMatrix 37 | //----------------------------------------------------------------------------- 38 | XMMATRIX Projection::GetMatrix() CONST 39 | { 40 | XMMATRIX Proj; 41 | if( m_Type == Projection::Perspective ) 42 | { 43 | Proj = XMMatrixPerspectiveLH( m_Width, m_Height, m_ZNear, m_ZFar ); 44 | } 45 | else if( m_Type == Projection::Orthographic ) 46 | { 47 | Proj = XMMatrixOrthographicLH( m_Width, m_Height, m_ZNear, m_ZFar ); 48 | } 49 | else 50 | assert( FALSE ); 51 | 52 | return Proj; 53 | } 54 | 55 | 56 | //----------------------------------------------------------------------------- 57 | // Name: Projection::SetFovXFovY 58 | //----------------------------------------------------------------------------- 59 | VOID Projection::SetFovXFovY( FLOAT FovX, FLOAT FovY, FLOAT ZNear, FLOAT ZFar ) 60 | { 61 | m_ZNear = ZNear; 62 | m_ZFar = ZFar; 63 | m_Type = Projection::Perspective; 64 | 65 | m_Width = ( 2.0f * m_ZNear ) * tanf( FovX / 2.0f ); 66 | m_Height = ( 2.0f * m_ZNear ) * tanf( FovY / 2.0f ); 67 | } 68 | 69 | 70 | //----------------------------------------------------------------------------- 71 | // Name: Projection::SetFovYAspect 72 | //----------------------------------------------------------------------------- 73 | VOID Projection::SetFovYAspect( FLOAT FovY, FLOAT Aspect, FLOAT ZNear, FLOAT ZFar ) 74 | { 75 | m_ZNear = ZNear; 76 | m_ZFar = ZFar; 77 | m_Type = Projection::Perspective; 78 | 79 | 80 | m_Height = 2.0f * m_ZNear * tanf( FovY / 2 ); 81 | m_Width = m_Height * Aspect; 82 | } 83 | 84 | 85 | //----------------------------------------------------------------------------- 86 | // Name: Projection::SetFovXAspect 87 | //----------------------------------------------------------------------------- 88 | VOID Projection::SetFovXAspect( FLOAT FovX, FLOAT Aspect, FLOAT ZNear, FLOAT ZFar ) 89 | { 90 | m_ZNear = ZNear; 91 | m_ZFar = ZFar; 92 | m_Type = Projection::Perspective; 93 | 94 | 95 | m_Width = 2.0f * m_ZNear * tanf( FovX / 2 ); 96 | m_Height = m_Width / Aspect; 97 | 98 | } 99 | 100 | 101 | //----------------------------------------------------------------------------- 102 | // Name: Projection::SetOrthographic 103 | //----------------------------------------------------------------------------- 104 | VOID Projection::SetOrthographic( FLOAT Width, FLOAT Height, FLOAT ZNear, FLOAT ZFar ) 105 | { 106 | m_ZNear = ZNear; 107 | m_ZFar = ZFar; 108 | m_Type = Projection::Orthographic; 109 | m_Width = Width; 110 | m_Height = Height; 111 | } 112 | 113 | 114 | //----------------------------------------------------------------------------- 115 | // Name: Projection::GetFovX 116 | //----------------------------------------------------------------------------- 117 | FLOAT Projection::GetFovX() CONST 118 | { 119 | assert( m_Type == Projection::Perspective ); 120 | return atanf( m_Width / ( 2.0f * m_ZNear ) ) * 2.0f; 121 | } 122 | 123 | 124 | //---------------------------------------------------------------------------- 125 | // Name: Projection::GetFovY 126 | //----------------------------------------------------------------------------- 127 | FLOAT Projection::GetFovY() CONST 128 | { 129 | assert( m_Type == Projection::Perspective ); 130 | return atanf( m_Height / ( 2.0f * m_ZNear ) ) * 2.0f; 131 | } 132 | 133 | 134 | //----------------------------------------------------------------------------- 135 | // Name: Camera::UpdateBounds 136 | //----------------------------------------------------------------------------- 137 | VOID Camera::UpdateBound() 138 | { 139 | SetLocalBound( Bound( m_Projection.GetFrustum() ) ); 140 | } 141 | 142 | } // namespace ATG 143 | -------------------------------------------------------------------------------- /Dashlaunch.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | // Excuse the mess. A lot of this would be simplified if launch.xex was updated to not rely on static paths for lhelper 4 | 5 | BOOL bDLloaded = FALSE; 6 | #define lhPath_USB "\\Device\\Mass0\\lhelper.xex" 7 | #define lhPath_Mount_USB "Usb:\\lhelper.xex" 8 | 9 | #define lhPath_HDD "\\Device\\Harddisk0\\Partition1\\lhelper.xex" 10 | #define lhPath_Mount_HDD "Hdd:\\lhelper.xex" 11 | 12 | // Credit to c0z - Some of this was adapted from the Dashlaunch 2.11 source 13 | // Use functions taken from Dashlaunch to load Dashlaunch :-) 14 | 15 | DWORD g_status[2]; // 0 = return status, 1 = completion signal 16 | VOID* pLaunchXexData; 17 | DWORD dwLaunchXexSize; 18 | 19 | static VOID LoadDLPlugin() 20 | { 21 | g_status[0] = XexLoadImageFromMemory(pLaunchXexData, dwLaunchXexSize, "launch.xex", XEX_LOADIMG_TYPE_SYSTEM_DLL, 0, NULL); // XEX_LOADIMG_FLAG_DLL 22 | g_status[1] = 1; 23 | __dcbst(0, g_status); 24 | __sync(); 25 | __isync(); 26 | } 27 | 28 | WCHAR wDLStatusBuf[150]; 29 | BOOL bDLisLoaded = FALSE; 30 | INT SysLoadDashlaunch() 31 | { 32 | ZeroMemory(wDLStatusBuf, sizeof(wDLStatusBuf)); 33 | if (GetModuleHandle("launch.xex")) // Check it hasn't been loaded already 34 | { 35 | cprintf("[SysLoadDashlaunch] Already loaded!"); 36 | BOOL blhHDD = FileExists(lhPath_HDD); 37 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Loaded, blhHDD ? currentLocalisation->DL_Mode_Hdd : currentLocalisation->DL_Mode_Usb); 38 | bDLisLoaded = TRUE; 39 | return 2; // Already Loaded 40 | } 41 | 42 | cprintf("[SysLoadDashlaunch] Attempting to load launch.xex..."); 43 | 44 | // Check if the console has a Hdd attached so we can copy lhelper there. 45 | // Ideally Hdd would be preferred to allow users to unplug the Usb without disrupting dashlaunch functionality. 46 | // If not, fallback to using Usb 47 | BOOL bUseHdd = (XboxHardwareInfo->Flags & 0x20) == 0x20; 48 | if (!FileExists(bUseHdd ? lhPath_HDD : lhPath_USB)) 49 | { 50 | cprintf("[SysLoadDashlaunch] Attempting to copy lhelper.xex to %s root...", bUseHdd ? "HDD" : "USB"); 51 | VOID* pLHData; 52 | DWORD dwLHSize; 53 | if (!XGetModuleSection(GetModuleHandle(NULL), bUseHdd ? "LHHDD" : "LHUSB", &pLHData, &dwLHSize)) 54 | { 55 | cprintf("[SysLoadDashlaunch] Failed to load! Failed to get lhelper section data!"); 56 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_SecData); 57 | return 0; // Failed 58 | } 59 | 60 | if (bUseHdd) 61 | { 62 | if (!MountHdd()) 63 | { 64 | cprintf("[SysLoadDashlaunch] Failed to load! Failed to create Hdd mount point!"); 65 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_Mount); 66 | return 0; // Failed 67 | } 68 | } 69 | else 70 | { 71 | if (!MountUsb()) 72 | { 73 | cprintf("[SysLoadDashlaunch] Failed to load! Failed to create Usb mount point!"); 74 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_Mount); 75 | return 0; // Failed 76 | } 77 | } 78 | 79 | // Copy the embedded lhelper.xex to the root of storage device so the embedded launch.xex can use it once loaded 80 | if (!CWriteFile(bUseHdd ? lhPath_Mount_HDD : lhPath_Mount_USB, pLHData, dwLHSize)) // 7B error when not using a mount point 81 | { 82 | cprintf("[SysLoadDashlaunch] Failed to load! Failed to write lhelper.xex to %s root!", bUseHdd ? "HDD" : "USB"); 83 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_Write); 84 | return 0; // Failed 85 | } 86 | cprintf("[SysLoadDashlaunch] lhelper.xex copied to %s root!", bUseHdd ? "HDD" : "USB"); 87 | Sleep(200); 88 | } 89 | 90 | if (!XGetModuleSection(GetModuleHandle(NULL), bUseHdd ? "LXHDD" : "LXUSB", &pLaunchXexData, &dwLaunchXexSize)) 91 | { 92 | cprintf("[SysLoadDashlaunch] Failed to load! Failed to get launch section data!"); 93 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_Launch_SecData); 94 | return 0; // Failed 95 | } 96 | 97 | HANDLE pthread; 98 | DWORD pthreadid; 99 | DWORD sta; 100 | g_status[0] = 0; 101 | g_status[1] = 0; 102 | __dcbst(0, g_status); 103 | __sync(); 104 | __isync(); 105 | 106 | sta = ExCreateThread(&pthread, 0, &pthreadid, (PVOID)XapiThreadStartup, (LPTHREAD_START_ROUTINE)LoadDLPlugin, NULL, 0x2); 107 | XSetThreadProcessor(pthread, 4); 108 | SetThreadPriority(pthread, THREAD_PRIORITY_TIME_CRITICAL); 109 | ResumeThread(pthread); 110 | CloseHandle(pthread); 111 | 112 | // wait for thread to run it's course 113 | while (g_status[1] == 0) 114 | { 115 | Sleep(100); 116 | } 117 | 118 | if (!g_status[0]) 119 | { 120 | cprintf("[SysLoadDashlaunch] Loaded successfully"); 121 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Loaded, bUseHdd ? currentLocalisation->DL_Mode_Hdd : currentLocalisation->DL_Mode_Usb); 122 | bDLisLoaded = TRUE; 123 | return 1; // Success 124 | } 125 | else 126 | { 127 | cprintf("[SysLoadDashlaunch] Failed! Status: %X", g_status[0]); 128 | swprintf_s(wDLStatusBuf, currentLocalisation->DL_Fail_Status, g_status[0]); 129 | return 0; // Failed 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Common/AtgModel.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // model.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "stdafx.h" 9 | #include "AtgSceneMesh.h" 10 | #include "AtgMaterials.h" 11 | #include "AtgModel.h" 12 | 13 | namespace ATG 14 | { 15 | 16 | CONST StringID Model::TypeID( L"Model" ); 17 | 18 | //----------------------------------------------------------------------------- 19 | // Name: Model::AddMesh() 20 | //----------------------------------------------------------------------------- 21 | VOID Model::AddMesh( BaseMesh* pMesh, DWORD dwMeshMappingFlags ) 22 | { 23 | assert( pMesh ); 24 | MeshMapping mi; 25 | 26 | mi.pMesh = pMesh; 27 | mi.dwFlags = dwMeshMappingFlags; 28 | m_MeshMappings.push_back( mi ); 29 | } 30 | 31 | 32 | //----------------------------------------------------------------------------- 33 | // Name: Model::GetMesh() 34 | //----------------------------------------------------------------------------- 35 | BaseMesh* Model::GetMesh( CONST WCHAR* strName ) CONST 36 | { 37 | for( UINT i = 0; i < m_MeshMappings.size(); i++ ) 38 | { 39 | if( m_MeshMappings[i].pMesh->GetName() == strName ) 40 | return m_MeshMappings[i].pMesh; 41 | } 42 | return NULL; 43 | } 44 | 45 | 46 | //----------------------------------------------------------------------------- 47 | // Name: Model::RemoveMesh() 48 | //----------------------------------------------------------------------------- 49 | BOOL Model::RemoveMesh( CONST BaseMesh* pMesh ) 50 | { 51 | std::vector::iterator i; 52 | for( i = m_MeshMappings.begin(); i != m_MeshMappings.end(); i++ ) 53 | { 54 | if( i->pMesh == pMesh ) 55 | { 56 | m_MeshMappings.erase(i); 57 | return TRUE; 58 | } 59 | } 60 | return FALSE; 61 | } 62 | 63 | 64 | //----------------------------------------------------------------------------- 65 | // Name: Model::AddMaterial() 66 | //----------------------------------------------------------------------------- 67 | VOID Model::AddMaterial( UINT MeshIndex, UINT MaterialIndex, MaterialInstance* pMaterial ) 68 | { 69 | // assert that the mesh index is valid 70 | assert( MeshIndex < m_MeshMappings.size() ); 71 | 72 | // assign the material 73 | // $TODO: maybe do this a better way, if things are added out-of-order 74 | if( MaterialIndex == m_MeshMappings[MeshIndex].Materials.size() ) 75 | { 76 | m_MeshMappings[MeshIndex].Materials.push_back( pMaterial ); 77 | } 78 | else 79 | { 80 | m_MeshMappings[MeshIndex].Materials[MaterialIndex] = pMaterial; 81 | } 82 | }; 83 | 84 | //----------------------------------------------------------------------------- 85 | // Name: Model::GetMeshFlagUnion() 86 | //----------------------------------------------------------------------------- 87 | DWORD Model::GetMeshFlagUnion() CONST 88 | { 89 | DWORD dwFlagUnion = 0; 90 | for( UINT i = 0; i < m_MeshMappings.size(); i++ ) 91 | dwFlagUnion |= m_MeshMappings[i].pMesh->GetFlags(); 92 | return dwFlagUnion; 93 | } 94 | 95 | 96 | //----------------------------------------------------------------------------- 97 | // Name: Model::GetMeshMappingFlagUnion() 98 | //----------------------------------------------------------------------------- 99 | DWORD Model::GetMeshMappingFlagUnion() CONST 100 | { 101 | DWORD dwFlagUnion = 0; 102 | for( UINT i = 0; i < m_MeshMappings.size(); i++ ) 103 | dwFlagUnion |= m_MeshMappings[i].dwFlags; 104 | return dwFlagUnion; 105 | } 106 | 107 | 108 | BOOL Model::ContainsOpaqueSubsets() const 109 | { 110 | DWORD dwMeshMappingCount = ( DWORD )m_MeshMappings.size(); 111 | for( DWORD i = 0; i < dwMeshMappingCount; ++i ) 112 | { 113 | const MeshMapping& mm = m_MeshMappings[i]; 114 | DWORD dwMaterialCount = ( DWORD )mm.Materials.size(); 115 | for( DWORD j = 0; j < dwMaterialCount; ++j ) 116 | { 117 | MaterialInstance* pMaterial = mm.Materials[j]; 118 | if( !pMaterial->IsTransparent() ) 119 | return TRUE; 120 | } 121 | } 122 | return FALSE; 123 | } 124 | 125 | 126 | BOOL Model::ContainsTransparentSubsets() const 127 | { 128 | DWORD dwMeshMappingCount = ( DWORD )m_MeshMappings.size(); 129 | for( DWORD i = 0; i < dwMeshMappingCount; ++i ) 130 | { 131 | const MeshMapping& mm = m_MeshMappings[i]; 132 | DWORD dwMaterialCount = ( DWORD )mm.Materials.size(); 133 | for( DWORD j = 0; j < dwMaterialCount; ++j ) 134 | { 135 | MaterialInstance* pMaterial = mm.Materials[j]; 136 | if( pMaterial->IsTransparent() ) 137 | return TRUE; 138 | } 139 | } 140 | return FALSE; 141 | } 142 | 143 | } // namespace ATG 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XeUnshackle 2 | ![XeUnshackle_Banner](https://github.com/user-attachments/assets/af37d4ae-4ff6-4175-8f81-47869ff63ed6) 3 | 4 | Custom Xbox 360 application designed to be used with the [Xbox360BadUpdate](https://github.com/grimdoomer/Xbox360BadUpdate) exploit. 5 | 6 | > [!IMPORTANT] 7 | > **THIS APP IS RELEASED AS IS.** 8 | > **YOU ARE RESPONSIBLE FOR WHAT YOU CHOOSE TO LOAD AND ANY NEGATIVE EFFECTS THAT MAY COME AS A RESULT.** 9 | > **THIS IS NOT A PERMANENT SOFTMOD!** Your console will return to an unmodified state when powered off or rebooted. 10 | 11 | > [!CAUTION] 12 | > * **BACKUP YOUR NAND!** This should be the first thing you do. 13 | > * **DO NOT FLASH MODIFIED NAND IMAGES!** You will **brick** your console. 14 | > * **DO NOT REPLACE FILES IN FLASH!** This includes things like replacing the bootanim. 15 | > * Avoid using homebrew or plugins that make changes to FLASH (the nand). 16 | > * Read the **README - IMPORTANT.txt** in the release files for important notes regarding the use of Stealth Servers. 17 | 18 | Utilises the _alternate_ method of using a specially crafted PeekPoke HV expansion to apply **temporary** HV patches. 19 | This is usually the preferred method of HV access used by Stealth servers. 20 | Access via the Syscall0 backdoor is also available upon completion for apps requiring it (Simple 360 NAND Flasher for example). 21 | 22 | Nothing here is particularly new. It's simply a collection of existing code that has been adapted and packaged for use with this exploit. 23 | 24 | ## Features 25 | - Applies a full complete patchset of both HV & Kernel patches. These are the same exact patches that are usually applied when building a modified nand image using xeBuild for RGH/JTAG consoles. 26 | - Support for both Retail & Devkit signed xex files. Essentially any plugins or executables that run natively on RGH/JTAG modified consoles _should_ work. 27 | - Reverts any patches applied by the [Xbox360BadUpdate](https://github.com/grimdoomer/Xbox360BadUpdate) exploit we no longer need. 28 | - Restores the default state of the Ring of Light and allows controller syncing to function as normal. Thanks [InvoxiPlayGames](https://github.com/InvoxiPlayGames) 29 | - Loads a slightly modified version of launch.xex (Dashlaunch). Due to it not being stored within the nands filesystem it is loaded from app memory and lhelper.xex is copied to either Hdd or Usb root depending on what's available at load time. 30 | - Simple GUI consisting of a short boot animation video followed by a page displaying both the CPUKey and DVDKey of the console. 31 | - Ability to dump 1BL to file via button press. This may be particularly useful for those wanting to use the Low Level [Xenon](https://github.com/xenon-emu/xenon) Emulator. 32 | - Automatic dumping of the current MAC address on first load. This is often changed by stealth servers during the initial KV spoofing. Only other way to retrieve the original is from a nand backup taken BEFORE loading a stealth. 33 | - Applies Usbdsec patches to allow non-360 XInput controllers. Thanks [InvoxiPlayGames](https://github.com/InvoxiPlayGames) 34 | - Xbox 360 Bad Storage support for unlocking up to 2 TB internal storage. Read the official release notes [Here](https://fatxplorer.eaton-works.com/bad-storage/) for setup instructions. Thanks [EatonZ](https://github.com/EatonZ) 35 | 36 | ## Usage 37 | #### Dashlaunch Plugin Loading: 38 | 1. Add the plugins you want to load to the [Plugins] section of the launch.ini provided and copy it to the root of the usb. 39 | 2. Copy any plugin files to the usb. 40 | Upon successful exploit XeUnshackle will run and attempt to load launch.xex (Dashlaunch) in the background. 41 | Dashlaunch will then attempt to load any plugins set when exiting the app and returning to the dashboard. 42 | 43 | #### Save / Dump Options: 44 | Any files saved/dumped can be found in the BadUpdatePayload folder of the usb. 45 | 46 | ## Credits 47 | - [grimdoomer](https://github.com/grimdoomer) - [Xbox360BadUpdate](https://github.com/grimdoomer/Xbox360BadUpdate) exploit 48 | - cOz - xeBuild patches, Dashlaunch & much more 49 | - [Visual Studio / Goobycorp](https://github.com/GoobyCorp) 50 | - Diamond 51 | - [InvoxiPlayGames / Emma](https://github.com/InvoxiPlayGames) - [FreeMyXe](https://github.com/FreeMyXe), [Usbdsec patches](https://github.com/InvoxiPlayGames/UsbdSecPatch), Ring of Light fix, [DaTArrest save exploit](https://github.com/RBEnhanced/DaTArrest) & general help 52 | - [ihatecompvir](https://github.com/ihatecompvir) - [DaTArrest save exploit](https://github.com/RBEnhanced/DaTArrest) 53 | - ikari - freeBOOT 54 | - [Jeff Hamm](https://www.youtube.com/watch?v=PantVXVEVUg) - Chain break video 55 | - [EatonZ](https://github.com/EatonZ) - [Xbox 360 Bad Storage](https://github.com/EatonZ/BadStorage) 56 | - [Xbox360Hub Discord #coding-corner](https://xbox360hub.com/) 57 | - Anyone else who has contributed anything to the 360 scene. Apologies if any credits were missed. 58 | 59 | ## Community Translations 60 | - Spanish - [CiberStore](https://github.com/CiberStore) 61 | - Portuguese (Brazil) - [ronniegchagas](https://github.com/ronniegchagas) 62 | -------------------------------------------------------------------------------- /Common/AtgFrame.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgFrame.h 3 | // 4 | // Describes a frame in the scene- a frame is a named typed object 5 | // with a set of bounds and part of a transform heirarchy 6 | // 7 | // $OPTIMIZE: Pool Allocate 8 | // 9 | // Xbox Advanced Technology Group. 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //----------------------------------------------------------------------------- 12 | 13 | #pragma once 14 | #ifndef ATG_FRAME_H 15 | #define ATG_FRAME_H 16 | 17 | #include "AtgNamedTypedObject.h" 18 | #include "AtgBound.h" 19 | 20 | namespace ATG 21 | { 22 | 23 | //----------------------------------------------------------------------------- 24 | // Name: Frame 25 | // Desc: An named typed object with a frame of reference and a bound 26 | // Note: X is Right, Y is Up, and Z is Forward 27 | //----------------------------------------------------------------------------- 28 | class Frame : public NamedTypedObject 29 | { 30 | DEFINE_TYPE_INFO(); 31 | 32 | public: 33 | Frame(); 34 | Frame( const StringID& Name, CXMMATRIX matLocalTransform ); 35 | ~Frame(); 36 | 37 | // frame hierarchy 38 | VOID AddChild( Frame* pChild ); 39 | VOID SetParent( Frame* pParent ); // Set to NULL to unparent 40 | 41 | Frame* GetFirstChild() CONST { return m_pFirstChild; } 42 | Frame* GetNextSibling() CONST { return m_pNextSibling; } 43 | Frame* GetParent() CONST { return m_pParent; } 44 | BOOL IsAncestor( Frame* pOtherFrame ); 45 | BOOL IsChild( Frame* pOtherFrame ); 46 | 47 | // cloned object support 48 | VOID DisconnectFromParent(); 49 | 50 | // local position 51 | XMVECTOR GetLocalPosition() CONST { return m_LocalTransform.r[3]; } 52 | VOID SetLocalPosition( CONST XMVECTOR& NewPosition ) { SetCachedWorldTransformDirty(); m_LocalTransform.r[3] = NewPosition; } 53 | 54 | // world position 55 | XMVECTOR GetWorldPosition(); 56 | VOID SetWorldPosition( CONST XMVECTOR& NewPosition ); 57 | 58 | // local transform 59 | const XMMATRIX& GetLocalTransform() CONST { return m_LocalTransform; } 60 | VOID SetLocalTransform( CONST XMMATRIX& LocalTransform ) { SetCachedWorldTransformDirty(); m_LocalTransform = LocalTransform; } 61 | 62 | // world transform 63 | const XMMATRIX& GetWorldTransform(); 64 | VOID SetWorldTransform( CONST XMMATRIX& WorldTransform ); 65 | 66 | // basis vectors 67 | XMVECTOR GetLocalRight() CONST { return m_LocalTransform.r[0]; } 68 | XMVECTOR GetLocalUp() CONST { return m_LocalTransform.r[1]; } 69 | XMVECTOR GetLocalDirection() CONST { return m_LocalTransform.r[2]; } 70 | 71 | XMVECTOR GetWorldRight(); 72 | XMVECTOR GetWorldUp(); 73 | XMVECTOR GetWorldDirection(); 74 | 75 | // bound 76 | VOID SetLocalBound( const Bound& bound ) { m_LocalBound = bound; SetCachedWorldTransformDirty(); } 77 | CONST Bound& GetLocalBound() CONST { return m_LocalBound; } 78 | CONST Bound& GetWorldBound() { UpdateCachedWorldTransformIfNeeded(); return m_CachedWorldBound; } 79 | 80 | private: 81 | VOID UpdateCachedWorldTransformIfNeeded(); 82 | VOID SetCachedWorldTransformDirty(); 83 | // Set the first element of m_CachedWorldTransform to a magic value to indicate that the cached 84 | // transform is invalid. 85 | VOID SetCachedWorldTransformDirtyLocal() { *(DWORD*)&m_CachedWorldTransform = 0xFFFFFFFF; } 86 | // An integer compare is used to check for the cached transforms validity because this avoids 87 | // the cost of doing a floating-point compare. Also, an integer compare allows the 0xFFFFFFFF 88 | // value to be used, which would evaluate to an uncomparable NAN as a float. 89 | // An integer comparison is faster than a floating-point comparison on this case because the value 90 | // to be compared is in memory, rather than in the floating-point registers. 91 | BOOL IsCachedWorldTransformDirty() const { return *(const DWORD*)&m_CachedWorldTransform == 0xFFFFFFFF; } 92 | 93 | XMMATRIX m_LocalTransform; 94 | XMMATRIX m_CachedWorldTransform; 95 | 96 | Bound m_LocalBound; 97 | Bound m_CachedWorldBound; 98 | 99 | Frame* m_pParent; 100 | Frame* m_pNextSibling; 101 | Frame* m_pFirstChild; 102 | }; 103 | 104 | } // namespace ATG 105 | 106 | #endif // ATG_FRAME_H 107 | -------------------------------------------------------------------------------- /Common/AtgSceneFileParser.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // AtgSceneFileParser.h 3 | // 4 | // A SAX-based parser to read the ATG scene file format. 5 | // 6 | // Xbox Advanced Technology Group 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATG_SCENEFILEPARSER_H 12 | #define ATG_SCENEFILEPARSER_H 13 | 14 | #include 15 | #include "AtgXmlParser.h" 16 | #include "AtgSceneAll.h" 17 | 18 | namespace ATG 19 | { 20 | 21 | enum XATGObjectLoaderType 22 | { 23 | XATG_NONE = 0, 24 | XATG_MESH, 25 | XATG_SKINNEDMESHINFLUENCES, 26 | XATG_VERTEXBUFFER, 27 | XATG_INDEXBUFFER, 28 | XATG_VERTEXDECLELEMENT, 29 | XATG_INDEXBUFFERSUBSET, 30 | XATG_FRAME, 31 | XATG_MODEL, 32 | XATG_MATERIAL, 33 | XATG_AMBIENTLIGHT, 34 | XATG_DIRECTIONALLIGHT, 35 | XATG_POINTLIGHT, 36 | XATG_SPOTLIGHT, 37 | XATG_CAMERA, 38 | XATG_ANIMATION, 39 | }; 40 | 41 | struct XMLElementAttribute 42 | { 43 | WCHAR strName[100]; 44 | WCHAR strValue[256]; 45 | }; 46 | typedef std::vector XMLElementAttributeList; 47 | 48 | class XMLElementDesc 49 | { 50 | public: 51 | XMLElementDesc() 52 | { 53 | strElementName[0] = L'\0'; 54 | strElementBody[0] = L'\0'; 55 | bEndElement = FALSE; 56 | } 57 | WCHAR strElementName[128]; 58 | WCHAR strElementBody[1024]; 59 | XMLElementAttributeList Attributes; 60 | BOOL bEndElement; 61 | }; 62 | 63 | class Frame; 64 | class ParameterDesc; 65 | 66 | class XATGParserContext 67 | { 68 | public: 69 | XATGParserContext() : CurrentObjectType( XATG_NONE ), 70 | pCurrentObject( NULL ), 71 | pUserData( NULL ), 72 | pCurrentParentFrame( NULL ), 73 | pCurrentParentObject( NULL ) 74 | { 75 | } 76 | XATGObjectLoaderType CurrentObjectType; 77 | VOID* pCurrentObject; 78 | VOID* pUserData; 79 | DWORD dwUserDataIndex; 80 | Frame* pCurrentParentFrame; 81 | VOID* pCurrentParentObject; 82 | DWORD dwCurrentParameterIndex; 83 | }; 84 | 85 | class Scene; 86 | 87 | enum XATGLoaderFlags 88 | { 89 | XATGLOADER_DONOTINITIALIZEMATERIALS = 1, 90 | XATGLOADER_EFFECTSELECTORPARAMETERS = 2, 91 | XATGLOADER_DONOTBINDTEXTURES = 4, 92 | }; 93 | 94 | class SceneFileParser : public ISAXCallback 95 | { 96 | public: 97 | static HRESULT PrepareForThreadedLoad( CRITICAL_SECTION* pCriticalSection ); 98 | static HRESULT LoadXATGFile( const CHAR* strFileName, Scene* pScene, Frame* pRootFrame, DWORD dwFlags = 0, 99 | DWORD* pLoadProgress = NULL ); 100 | static const CHAR* GetParseErrorMessage(); 101 | 102 | virtual HRESULT StartDocument() 103 | { 104 | return S_OK; 105 | } 106 | virtual HRESULT EndDocument(); 107 | 108 | virtual HRESULT ElementBegin( const WCHAR* strName, UINT NameLen, 109 | const XMLAttribute* pAttributes, UINT NumAttributes ); 110 | virtual HRESULT ElementContent( const WCHAR* strData, UINT DataLen, BOOL More ); 111 | virtual HRESULT ElementEnd( const WCHAR* strName, UINT NameLen ); 112 | 113 | virtual HRESULT CDATABegin() 114 | { 115 | return S_OK; 116 | } 117 | virtual HRESULT CDATAData( const WCHAR* strCDATA, UINT CDATALen, BOOL bMore ) 118 | { 119 | return S_OK; 120 | } 121 | virtual HRESULT CDATAEnd() 122 | { 123 | return S_OK; 124 | } 125 | virtual VOID SetParseProgress( DWORD dwProgress ); 126 | 127 | virtual VOID Error( HRESULT hError, const CHAR* strMessage ); 128 | 129 | protected: 130 | XATGParserContext m_Context; 131 | XMLElementDesc m_CurrentElementDesc; 132 | 133 | VOID CopyAttributes( const XMLAttribute* pAttributes, UINT uAttributeCount ); 134 | VOID HandleElementData(); 135 | VOID HandleElementEnd(); 136 | VOID DistributeElementToLoaders(); 137 | 138 | BOOL FindAttribute( const WCHAR* strName, WCHAR* strDest, UINT uDestLength ); 139 | const WCHAR* FindAttribute( const WCHAR* strName ); 140 | BOOL SetObjectNameFromAttribute( NamedTypedObject* pNTO ); 141 | 142 | VOID AcquireDirect3D(); 143 | VOID ReleaseDirect3D(); 144 | 145 | VOID ProcessRootData(); 146 | VOID ProcessMeshData(); 147 | VOID ProcessFrameData(); 148 | VOID ProcessModelData(); 149 | VOID ProcessMaterialData(); 150 | VOID ProcessLightData(); 151 | VOID ProcessCameraData(); 152 | VOID ProcessAnimationData(); 153 | VOID CrackVertex( BYTE* pDest, const D3DVERTEXELEMENT9* pVertexElements, DWORD dwStreamIndex ); 154 | 155 | static VOID CollapseSceneFrames( Frame* pFrame ); 156 | }; 157 | 158 | } // namespace ATG 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /Common/AtgDsp.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ATGDsp.h" 3 | 4 | #define _USE_MATH_DEFINES 5 | #include 6 | 7 | namespace ATG 8 | { 9 | 10 | void CalcLowpassCoeffs( float Fc, float Q, vector4_out coeffsA, vector4_out coeffsB ) 11 | { 12 | Q = ( float )__fsel( Q, Q, .0001f ); 13 | Fc = ( float )__fsel( Fc, Fc, FLT_EPSILON * 2.0f ); 14 | 15 | float w0 = ( float )M_PI * Fc; 16 | float sin0 = sin( w0 ); 17 | float cos0 = cos( w0 ); 18 | 19 | float alpha = sin0 / ( 2.0f * Q ); 20 | 21 | float a0 = alpha + 1.0f; 22 | coeffsA.v[0] = ( -2.0f * cos0 ) / a0; 23 | coeffsA.v[1] = ( 1.0f - alpha ) / a0; 24 | coeffsA.v[2] = 0.0f; 25 | coeffsA.v[3] = 0.0f; 26 | 27 | coeffsB.v[0] = ( ( 1.0f - cos0 ) / 2.0f ) / a0; 28 | coeffsB.v[1] = ( 1.0f - cos0 ) / a0; 29 | coeffsB.v[2] = ( ( 1.0f - cos0 ) / 2.0f ) / a0; 30 | coeffsB.v[3] = 0.0f; 31 | } 32 | void CalcHighpassCoeffs( float Fc, float Q, vector4_out coeffsA, vector4_out coeffsB ) 33 | { 34 | Q = (float)__fsel( Q, Q, .0001f ); 35 | Fc = (float)__fsel( Fc, Fc, FLT_EPSILON * 2.0f ); 36 | 37 | float w0 = (float)M_PI*Fc; 38 | float sin0 = sin(w0); 39 | float cos0 = cos(w0); 40 | 41 | float alpha = sin0/(2.0f*Q); 42 | 43 | float a0 = alpha + 1.0f; 44 | coeffsA.v[0] =( -2.0f * cos0)/a0; 45 | coeffsA.v[1] = (1.0f - alpha)/a0; 46 | coeffsA.v[2] = 0.0f; 47 | coeffsA.v[3] = 0.0f; 48 | 49 | coeffsB.v[0] = ((1.0f + cos0)/2.0f)/a0; 50 | coeffsB.v[1] = (-(1.0f + cos0))/a0; 51 | coeffsB.v[2] = ((1.0f + cos0)/2.0f)/a0; 52 | coeffsB.v[3] = 0.0f; 53 | } 54 | 55 | void CalcBandpassCoeffs( float Fc, float Q, float gain, vector4_out coeffsA, vector4_out coeffsB ) 56 | { 57 | Q = ( float )__fsel( Q, Q, .0001f ); 58 | Fc = ( float )__fsel( Fc, Fc, FLT_EPSILON * 2.0f ); 59 | 60 | float w0 = ( float )M_PI * Fc; 61 | float sin0 = sin( w0 ); 62 | float cos0 = cos( w0 ); 63 | 64 | float alpha = sin0 / ( 2.0f * Q ); 65 | 66 | 67 | float a0 = alpha + 1.0f; 68 | coeffsA.v[0] = ( -2.0f * cos0 ) / a0; 69 | coeffsA.v[1] = ( 1.0f - alpha ) / a0; 70 | coeffsA.v[2] = 0.0f; 71 | coeffsA.v[3] = 0.0f; 72 | 73 | coeffsB.v[0] = gain * ( sin0 / 2.0f ) / a0; 74 | coeffsB.v[1] = 0.0f; 75 | coeffsB.v[2] = gain * ( -sin0 / 2.0f ) / a0; 76 | coeffsB.v[3] = 0.0f; 77 | } 78 | 79 | // 80 | // Distortion compressor used for Radioize effect 81 | // 82 | __vector4 CalcDistortionCompressorCoeffs( float t, float r, float k ) 83 | { 84 | __vector4 coeffs; 85 | 86 | float denom = -8*k*t - 3*t*t*t + t*t*t*t - 8*t*k*k -3*k*t*t*t + 2*k*k*t*t + 6*k*k +2*t*t + 11*k*t*t; 87 | coeffs.v[0] = -0.5f * ( ( -3*k + 4*t - 3 + 3*k*r - 4*t*r + 3*r ) / denom ); 88 | coeffs.v[1] = ( 2*k*k*r - 2*k*k + 2*k*r - 2*k - 3*t*t*r + 3*t*t + 2*r - 2 ) / denom; 89 | coeffs.v[2] = -0.5f * ( t * ( -8*k*k + 8*k*k*r - 9*r*k*t + 9*k*t - 8*k + 8*k*r - 9*t*r + 9*t - 8 + 8*r ) / denom ); 90 | coeffs.v[3] = ( 9*k*t*t - 8*t*k*k + 2*t*t*r + t*t*t*t*r - 3*t*t*t*r + 2*t*t*k*k*r + 2*k*t*t*r - 3*t*t*t*k*r - 8*k*t + 6*k*k ) / denom; 91 | 92 | return coeffs; 93 | } 94 | 95 | void WINAPI CalcSoftKneeCompressorParams( float t, float k, float r, SoftKneeCompressorParams* pParams ) 96 | { 97 | pParams->ratio.v[0] = r; 98 | pParams->ratio = __vspltw( pParams->ratio, 0 ); 99 | 100 | pParams->threshold1.v[0] = t - k / 2.0f; 101 | pParams->threshold1 = __vspltw( pParams->threshold1, 0 ); 102 | 103 | pParams->threshold2.v[0] = t + k / 2.0f; 104 | pParams->threshold2 = __vspltw( pParams->threshold2, 0 ); 105 | 106 | // 107 | // Generated from the following Maple code: 108 | // f := proc (x) options operator, arrow; a*x^4+b*x^3+c*x^2+d*x end proc; 109 | // s := proc (t, k, r) options operator, arrow; { 110 | // f(t-(1/2)*k) = t-(1/2)*k, eval(diff(f(x), x), x = t-(1/2)*k) = 1, 111 | // eval(diff(f(x), x), x = t+(1/2)*k) = r, 112 | // eval(diff(f(x), x), x = t) = r + ( 1- r )/2 } end proc; 113 | // solve(s(t,k,r),{a,b,c}) end proc; 114 | // 115 | float a = -2 * (r - 1) / (k * k + 4 * t * k + 4 * t * t) / k; 116 | float b = 8 * (r - 1) / (k * k + 4 * t * k + 4 * t * t) / k * t; 117 | float c = (1 / k * (-20 * t * t * r + 20 * t * t + 4 * t * k * r - 4 * t * k + 3 * k * k * r - 3 * k * k) / (k * k + 4 * t * k + 4 * t * t)) / (float)0.2e1; 118 | float d = ((k * k + k * k * r - 4 * t * k * r + 8 * t * k + 4 * t * t * r - 4 * t * t) / k / (2 * t + k)) / (float)0.2e1; 119 | 120 | pParams->coeffs.v[0] = a; 121 | pParams->coeffs.v[1] = b; 122 | pParams->coeffs.v[2] = c; 123 | pParams->coeffs.v[3] = d; 124 | 125 | // evaluate the transfer polynomial at t+ k/2--this gives us the 126 | // amplitude at the end of the knee 127 | if( k != 0 ) 128 | { 129 | float x = t + k / 2.0f; 130 | pParams->endOfKneeValue.v[0] = 131 | a * x * x * x * x 132 | + b * x * x * x 133 | + c * x * x 134 | + d * x; 135 | pParams->endOfKneeValue = __vspltw( pParams->endOfKneeValue, 0 ); 136 | } 137 | else 138 | { 139 | pParams->endOfKneeValue = pParams->threshold1; 140 | } 141 | } 142 | 143 | 144 | 145 | } 146 | // namespace ATG 147 | -------------------------------------------------------------------------------- /Common/AtgResource.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgResource.h 3 | // 4 | // Loads resources from an XPR (Xbox Packed Resource) file. 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #pragma once 10 | #ifndef ATGRESOURCE_H 11 | #define ATGRESOURCE_H 12 | 13 | namespace ATG 14 | { 15 | 16 | //-------------------------------------------------------------------------------------- 17 | // Name tag for resources. An app may initialize this structure, and pass 18 | // it to the resource's Create() function. From then on, the app may call 19 | // GetResource() to retrieve a resource using an ascii name. 20 | //-------------------------------------------------------------------------------------- 21 | struct RESOURCE 22 | { 23 | DWORD dwType; 24 | DWORD dwOffset; 25 | DWORD dwSize; 26 | CHAR* strName; 27 | }; 28 | 29 | 30 | // Resource types 31 | enum 32 | { 33 | RESOURCETYPE_USERDATA = ( ( 'U' << 24 ) | ( 'S' << 16 ) | ( 'E' << 8 ) | ( 'R' ) ), 34 | RESOURCETYPE_TEXTURE = ( ( 'T' << 24 ) | ( 'X' << 16 ) | ( '2' << 8 ) | ( 'D' ) ), 35 | RESOURCETYPE_CUBEMAP = ( ( 'T' << 24 ) | ( 'X' << 16 ) | ( 'C' << 8 ) | ( 'M' ) ), 36 | RESOURCETYPE_VOLUMETEXTURE = ( ( 'T' << 24 ) | ( 'X' << 16 ) | ( '3' << 8 ) | ( 'D' ) ), 37 | RESOURCETYPE_VERTEXBUFFER = ( ( 'V' << 24 ) | ( 'B' << 16 ) | ( 'U' << 8 ) | ( 'F' ) ), 38 | RESOURCETYPE_INDEXBUFFER = ( ( 'I' << 24 ) | ( 'B' << 16 ) | ( 'U' << 8 ) | ( 'F' ) ), 39 | RESOURCETYPE_EOF = 0xffffffff 40 | }; 41 | 42 | 43 | //-------------------------------------------------------------------------------------- 44 | // Name: PackedResource 45 | //-------------------------------------------------------------------------------------- 46 | class PackedResource 47 | { 48 | protected: 49 | BYTE* m_pSysMemData; // Alloc'ed memory for resource headers etc. 50 | DWORD m_dwSysMemDataSize; 51 | 52 | BYTE* m_pVidMemData; // Alloc'ed memory for resource data, etc. 53 | DWORD m_dwVidMemDataSize; 54 | 55 | RESOURCE* m_pResourceTags; // Tags to associate names with the resources 56 | DWORD m_dwNumResourceTags; // Number of resource tags 57 | BOOL m_bInitialized; // Resource is fully initialized 58 | 59 | public: 60 | // Loads the resources out of the specified bundle 61 | HRESULT Create( const CHAR* strFilename ); 62 | 63 | VOID Destroy(); 64 | 65 | BOOL Initialized() const; 66 | 67 | // Retrieves the resource tags 68 | VOID GetResourceTags( DWORD* pdwNumResourceTags, RESOURCE** ppResourceTags ) const; 69 | 70 | // Helper function to make sure a resource is registered 71 | D3DResource* RegisterResource( D3DResource* pResource ) const 72 | { 73 | return pResource; 74 | } 75 | 76 | // Functions to retrieve resources by their offset 77 | VOID* GetData( DWORD dwOffset ) const 78 | { 79 | return &m_pSysMemData[dwOffset]; 80 | } 81 | 82 | D3DResource* GetResource( DWORD dwOffset ) const 83 | { 84 | return RegisterResource( ( D3DResource* )GetData( dwOffset ) ); 85 | } 86 | 87 | D3DTexture* GetTexture( DWORD dwOffset ) const 88 | { 89 | return ( D3DTexture* )GetResource( dwOffset ); 90 | } 91 | 92 | D3DArrayTexture* GetArrayTexture( DWORD dwOffset ) const 93 | { 94 | return ( D3DArrayTexture* )GetResource( dwOffset ); 95 | } 96 | 97 | D3DCubeTexture* GetCubemap( DWORD dwOffset ) const 98 | { 99 | return ( D3DCubeTexture* )GetResource( dwOffset ); 100 | } 101 | 102 | D3DVolumeTexture* GetVolumeTexture( DWORD dwOffset ) const 103 | { 104 | return ( D3DVolumeTexture* )GetResource( dwOffset ); 105 | } 106 | 107 | D3DVertexBuffer* GetVertexBuffer( DWORD dwOffset ) const 108 | { 109 | return ( D3DVertexBuffer* )GetResource( dwOffset ); 110 | } 111 | 112 | // Functions to retrieve resources by their name 113 | VOID* GetData( const CHAR* strName ) const; 114 | 115 | D3DResource* GetResource( const CHAR* strName ) const 116 | { 117 | return RegisterResource( ( D3DResource* )GetData( strName ) ); 118 | } 119 | 120 | D3DTexture* GetTexture( const CHAR* strName ) const 121 | { 122 | return ( D3DTexture* )GetResource( strName ); 123 | } 124 | 125 | D3DArrayTexture* GetArrayTexture( const CHAR* strName ) const 126 | { 127 | return ( D3DArrayTexture* )GetResource( strName ); 128 | } 129 | 130 | D3DCubeTexture* GetCubemap( const CHAR* strName ) const 131 | { 132 | return ( D3DCubeTexture* )GetResource( strName ); 133 | } 134 | 135 | D3DVolumeTexture* GetVolumeTexture( const CHAR* strName ) const 136 | { 137 | return ( D3DVolumeTexture* )GetResource( strName ); 138 | } 139 | 140 | D3DVertexBuffer* GetVertexBuffer( const CHAR* strName ) const 141 | { 142 | return ( D3DVertexBuffer* )GetResource( strName ); 143 | } 144 | 145 | PackedResource(); 146 | ~PackedResource(); 147 | }; 148 | 149 | } // namespace ATG 150 | 151 | #endif // ATGRESOURCE_H 152 | -------------------------------------------------------------------------------- /Common/AtgSceneMesh.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // mesh.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "stdafx.h" 9 | #include "AtgDevice.h" 10 | #include "AtgSceneMesh.h" 11 | #include "AtgResourceDatabase.h" 12 | 13 | namespace ATG 14 | { 15 | 16 | extern D3DDevice* g_pd3dDevice; 17 | 18 | CONST StringID BaseMesh::TypeID( L"Mesh" ); 19 | CONST StringID StaticMesh::TypeID( L"StaticMesh" ); 20 | CONST StringID SkinnedMesh::TypeID( L"SkinnedMesh" ); 21 | const StringID CatmullClarkMesh::TypeID( L"CatmullClarkMesh" ); 22 | 23 | //----------------------------------------------------------------------------- 24 | // Name: StaticMesh::StaticMesh() 25 | //----------------------------------------------------------------------------- 26 | StaticMesh::StaticMesh() 27 | { 28 | m_pVertexData = NULL; 29 | m_pIndexData = NULL; 30 | m_dwFlags = BaseMesh::IsRenderable; 31 | } 32 | 33 | 34 | //----------------------------------------------------------------------------- 35 | // Name: StaticMesh::GetNumVertices() 36 | //----------------------------------------------------------------------------- 37 | UINT StaticMesh::GetNumVertices() CONST 38 | { 39 | assert( m_pVertexData ); 40 | return m_pVertexData->GetNumVertices(); 41 | } 42 | 43 | 44 | //----------------------------------------------------------------------------- 45 | // Name: StaticMesh::GetNumPrimitives() 46 | //----------------------------------------------------------------------------- 47 | UINT StaticMesh::GetNumPrimitives() CONST 48 | { 49 | UINT NumPrims = 0; 50 | for( UINT i = 0; i < m_Subsets.size(); i++ ) 51 | NumPrims += m_Subsets[i]->GetNumPrimitives(); 52 | 53 | return NumPrims; 54 | } 55 | 56 | 57 | //----------------------------------------------------------------------------- 58 | // Name: StaticMesh::HasVertexElementType() 59 | //----------------------------------------------------------------------------- 60 | BOOL StaticMesh::HasVertexElementType( UINT Index, D3DDECLUSAGE Usage ) CONST 61 | { 62 | static D3DVERTEXELEMENT9 VertexElements[128]; 63 | UINT NumElements = 128; 64 | 65 | assert( Index == 0 ); 66 | 67 | // $ERRORREPORT 68 | BOOL bResult = FAILED( m_pVertexData->GetVertexDecl()->GetDeclaration( VertexElements, &NumElements ) ); 69 | assert( !bResult ); 70 | // get rid of warning in release build 71 | bResult = ( NumElements == 0 ); 72 | 73 | UINT DeclSize = D3DXGetDeclLength( VertexElements ); 74 | for( UINT i = 0; i < DeclSize; i++ ) 75 | { 76 | if( VertexElements[i].Usage == Usage ) 77 | return TRUE; 78 | } 79 | 80 | return FALSE; 81 | } 82 | 83 | 84 | //----------------------------------------------------------------------------- 85 | // Name: StaticMesh::RenderSubset() 86 | //----------------------------------------------------------------------------- 87 | UINT StaticMesh::RenderSubset( UINT SubsetIndex, ::D3DDevice* pd3dDevice, DWORD dwFlags ) CONST 88 | { 89 | if( pd3dDevice == NULL ) 90 | pd3dDevice = g_pd3dDevice; 91 | assert( pd3dDevice != NULL ); 92 | 93 | SubsetDesc* pDesc = m_Subsets[ SubsetIndex ]; 94 | 95 | assert( m_pVertexData ); 96 | assert( m_pIndexData ); 97 | assert( pDesc ); 98 | BOOL bResult = FALSE; 99 | 100 | LPDIRECT3DVERTEXDECLARATION9 pVertexDecl = m_pVertexData->GetVertexDecl(); 101 | 102 | // streams 103 | for( UINT i = 0; i < m_pVertexData->GetNumVertexStreams(); i++ ) 104 | { 105 | UINT Stride = m_pVertexData->GetVertexStream( i )->Stride; 106 | 107 | if( dwFlags & BaseMesh::ZeroStreamStrides ) 108 | Stride = 0; 109 | 110 | // $ERRORREPORT 111 | bResult = FAILED( pd3dDevice->SetStreamSource( i, 112 | m_pVertexData->GetVertexStream( i )->pVertexBuffer, 113 | 0, 114 | Stride ) ); 115 | assert( !bResult ); 116 | } 117 | 118 | // $ERRORREPORT 119 | if( !( dwFlags & BaseMesh::NoVertexDecl ) ) 120 | { 121 | bResult = FAILED( pd3dDevice->SetVertexDeclaration( pVertexDecl ) ); 122 | assert( !bResult ); 123 | } 124 | 125 | // $ERRORREPORT 126 | bResult = FAILED( pd3dDevice->SetIndices( m_pIndexData->GetIndexBuffer() ) ); 127 | assert( !bResult ); 128 | 129 | // $ERRORREPORT 130 | bResult = FAILED( pd3dDevice->DrawIndexedPrimitive( pDesc->GetPrimitiveType(), 0, 0, 131 | m_pVertexData->GetNumVertices(), 132 | pDesc->GetStartIndex(), 133 | pDesc->GetNumPrimitives() ) ); 134 | assert( !bResult ); 135 | 136 | return pDesc->GetNumPrimitives(); 137 | } 138 | 139 | SkinnedMesh::SkinnedMesh() 140 | { 141 | m_pVertexData = NULL; 142 | m_pIndexData = NULL; 143 | m_dwFlags = BaseMesh::IsRenderable | BaseMesh::IsSkinnable; 144 | } 145 | 146 | CatmullClarkMesh::CatmullClarkMesh() 147 | { 148 | m_pVertexData = NULL; 149 | m_pIndexData = NULL; 150 | m_dwFlags = BaseMesh::IsRenderable | BaseMesh::IsSkinnable; 151 | } 152 | 153 | } // namespace ATG 154 | -------------------------------------------------------------------------------- /Common/AtgXmlParser.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // AtgXmlParser.h 3 | // 4 | // XMLParser and SAX interface declaration 5 | // 6 | // Xbox Advanced Technology Group 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATGXMLPARSER_H 12 | #define ATGXMLPARSER_H 13 | 14 | namespace ATG 15 | { 16 | 17 | //----------------------------------------------------------------------------- 18 | // error returns from XMLParse 19 | //----------------------------------------------------------------------------- 20 | #define _ATGFAC 0x61B 21 | #define E_COULD_NOT_OPEN_FILE MAKE_HRESULT(1, _ATGFAC, 0x0001 ) 22 | #define E_INVALID_XML_SYNTAX MAKE_HRESULT(1, _ATGFAC, 0x0002 ) 23 | 24 | 25 | CONST UINT XML_MAX_ATTRIBUTES_PER_ELEMENT = 32; 26 | CONST UINT XML_MAX_NAME_LENGTH = 128; 27 | CONST UINT XML_READ_BUFFER_SIZE = 2048; 28 | CONST UINT XML_WRITE_BUFFER_SIZE = 2048; 29 | 30 | // No tag can be longer than XML_WRITE_BUFFER_SIZE - an error will be returned if 31 | // it is 32 | 33 | //------------------------------------------------------------------------------------- 34 | struct XMLAttribute 35 | { 36 | WCHAR* strName; 37 | UINT NameLen; 38 | WCHAR* strValue; 39 | UINT ValueLen; 40 | }; 41 | 42 | //------------------------------------------------------------------------------------- 43 | class ISAXCallback 44 | { 45 | friend class XMLParser; 46 | public: 47 | ISAXCallback() {}; 48 | virtual ~ISAXCallback() {}; 49 | 50 | virtual HRESULT StartDocument() = 0; 51 | virtual HRESULT EndDocument() = 0; 52 | 53 | virtual HRESULT ElementBegin( CONST WCHAR* strName, UINT NameLen, 54 | CONST XMLAttribute *pAttributes, UINT NumAttributes ) = 0; 55 | virtual HRESULT ElementContent( CONST WCHAR *strData, UINT DataLen, BOOL More ) = 0; 56 | virtual HRESULT ElementEnd( CONST WCHAR *strName, UINT NameLen ) = 0; 57 | 58 | virtual HRESULT CDATABegin( ) = 0; 59 | virtual HRESULT CDATAData( CONST WCHAR *strCDATA, UINT CDATALen, BOOL bMore ) = 0; 60 | virtual HRESULT CDATAEnd( ) = 0; 61 | 62 | virtual VOID Error( HRESULT hError, CONST CHAR *strMessage ) = 0; 63 | 64 | virtual VOID SetParseProgress( DWORD dwProgress ) { } 65 | 66 | const CHAR* GetFilename() { return m_strFilename; } 67 | UINT GetLineNumber() { return m_LineNum; } 68 | UINT GetLinePosition() { return m_LinePos; } 69 | 70 | private: 71 | CONST CHAR *m_strFilename; 72 | UINT m_LineNum; 73 | UINT m_LinePos; 74 | }; 75 | 76 | 77 | //------------------------------------------------------------------------------------- 78 | class XMLParser 79 | { 80 | public: 81 | XMLParser(); 82 | ~XMLParser(); 83 | 84 | // Register an interface inheiriting from ISAXCallback 85 | VOID RegisterSAXCallbackInterface( ISAXCallback *pISAXCallback ); 86 | 87 | // Get the registered interface 88 | ISAXCallback* GetSAXCallbackInterface(); 89 | 90 | // ParseXMLFile returns one of the following: 91 | // E_COULD_NOT_OPEN_FILE - couldn't open the file 92 | // E_INVALID_XML_SYNTAX - bad XML syntax according to this parser 93 | // E_NOINTERFACE - RegisterSAXCallbackInterface not called 94 | // E_ABORT - callback returned a fail code 95 | // S_OK - file parsed and completed 96 | 97 | HRESULT ParseXMLFile( CONST CHAR *strFilename ); 98 | 99 | // Parses from a buffer- if you pass a WCHAR buffer (and cast it), it will 100 | // correctly detect it and use unicode instead. Return codes are the 101 | // same as for ParseXMLFile 102 | 103 | HRESULT ParseXMLBuffer( CONST CHAR* strBuffer, UINT uBufferSize ); 104 | 105 | private: 106 | HRESULT MainParseLoop(); 107 | 108 | HRESULT AdvanceCharacter( BOOL bOkToFail = FALSE ); 109 | VOID SkipNextAdvance(); 110 | 111 | HRESULT ConsumeSpace(); 112 | HRESULT ConvertEscape(); 113 | HRESULT AdvanceElement(); 114 | HRESULT AdvanceName(); 115 | HRESULT AdvanceAttrVal(); 116 | HRESULT AdvanceCDATA(); 117 | HRESULT AdvanceComment(); 118 | 119 | VOID FillBuffer(); 120 | 121 | #ifdef _Printf_format_string_ // VC++ 2008 and later support this annotation 122 | VOID Error( HRESULT hRet, _In_z_ _Printf_format_string_ CONST CHAR* strFormat, ... ); 123 | #else 124 | VOID Error( HRESULT hRet, CONST CHAR* strFormat, ... ); 125 | #endif 126 | 127 | ISAXCallback* m_pISAXCallback; 128 | 129 | HANDLE m_hFile; 130 | CONST CHAR* m_pInXMLBuffer; 131 | UINT m_uInXMLBufferCharsLeft; 132 | DWORD m_dwCharsTotal; 133 | DWORD m_dwCharsConsumed; 134 | 135 | BYTE m_pReadBuf[ XML_READ_BUFFER_SIZE + 2 ]; // room for a trailing NULL 136 | WCHAR m_pWriteBuf[ XML_WRITE_BUFFER_SIZE ]; 137 | 138 | BYTE* m_pReadPtr; 139 | WCHAR* m_pWritePtr; // write pointer within m_pBuf 140 | 141 | BOOL m_bUnicode; // TRUE = 16-bits, FALSE = 8-bits 142 | BOOL m_bReverseBytes; // TRUE = reverse bytes, FALSE = don't reverse 143 | 144 | BOOL m_bSkipNextAdvance; 145 | WCHAR m_Ch; // Current character being parsed 146 | }; 147 | 148 | } // namespace ATG 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /Common/AtgFrameworkWin322010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | Source Files 22 | 23 | 24 | Source Files 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | 85 | 86 | Header Files 87 | 88 | 89 | Header Files 90 | 91 | 92 | Header Files 93 | 94 | 95 | Header Files 96 | 97 | 98 | Header Files 99 | 100 | 101 | Header Files 102 | 103 | 104 | Header Files 105 | 106 | 107 | Header Files 108 | 109 | 110 | Header Files 111 | 112 | 113 | Header Files 114 | 115 | 116 | Header Files 117 | 118 | 119 | Header Files 120 | 121 | 122 | Header Files 123 | 124 | 125 | Header Files 126 | 127 | 128 | Header Files 129 | 130 | 131 | Header Files 132 | 133 | 134 | Header Files 135 | 136 | 137 | Header Files 138 | 139 | 140 | Header Files 141 | 142 | 143 | Header Files 144 | 145 | 146 | Header Files 147 | 148 | 149 | Header Files 150 | 151 | 152 | Header Files 153 | 154 | 155 | Header Files 156 | 157 | 158 | Header Files 159 | 160 | 161 | -------------------------------------------------------------------------------- /Common/AtgEnumStrings.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgEnumStrings.h 3 | // 4 | // converts ATG and D3D enums to and frome strings 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //----------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATG_ENUMSTRINGS_H 12 | #define ATG_ENUMSTRINGS_H 13 | 14 | namespace ATG 15 | { 16 | 17 | //----------------------------------------------------------------------------- 18 | // holds a single entry in the enum table 19 | //----------------------------------------------------------------------------- 20 | #ifndef ENUMSTRINGMAP_DEFINED 21 | struct EnumStringMap 22 | { 23 | DWORD Value; 24 | CONST WCHAR* szName; 25 | }; 26 | #define ENUMSTRINGMAP_DEFINED 27 | #endif 28 | //----------------------------------------------------------------------------- 29 | // what kind of d3d state does this value represent 30 | //----------------------------------------------------------------------------- 31 | enum StateType 32 | { 33 | STATE_TYPE_ENUM, 34 | STATE_TYPE_ENUM_WITH_FLAGS, 35 | STATE_TYPE_FLOAT, 36 | STATE_TYPE_COLOR, 37 | STATE_TYPE_MASK, 38 | STATE_TYPE_BOOL, 39 | STATE_TYPE_UINT, 40 | STATE_TYPE_INT, 41 | STATE_TYPE_UINT_WITH_FLAGS, 42 | STATE_TYPE_DWORD_COMPILE = 0x7fffffff, 43 | }; 44 | 45 | //----------------------------------------------------------------------------- 46 | // contains a single entry in the state table 47 | //----------------------------------------------------------------------------- 48 | struct StateStringMap 49 | { 50 | DWORD Value; 51 | CONST WCHAR* szName; 52 | StateType Type; 53 | EnumStringMap* EnumValues; 54 | EnumStringMap* FlagValues; 55 | }; 56 | 57 | //----------------------------------------------------------------------------- 58 | // gets a DWORD value from a state 59 | //----------------------------------------------------------------------------- 60 | BOOL GetValueFromString( CONST WCHAR* szValue, 61 | CONST EnumStringMap* pEnumStringMap, 62 | DWORD& Value ); 63 | 64 | //----------------------------------------------------------------------------- 65 | // gets a string from state 66 | //----------------------------------------------------------------------------- 67 | BOOL GetStringFromValue( CONST DWORD Value, 68 | CONST EnumStringMap* pEnumStringMap, 69 | CONST WCHAR*& strString ); 70 | 71 | //----------------------------------------------------------------------------- 72 | // gets a DWORD value from a state 73 | // first partial substring match from the table wins 74 | //----------------------------------------------------------------------------- 75 | BOOL GetValueFromStringPartial( CONST WCHAR* szValue, 76 | CONST EnumStringMap* pEnumStringMap, 77 | DWORD& Value ); 78 | 79 | //----------------------------------------------------------------------------- 80 | // given a string representation of the state and its value, returns the 81 | // DWORD state and value. 82 | // The value string may be bools, floats, color, enum with mask, etc. 83 | //----------------------------------------------------------------------------- 84 | BOOL GetStateAndValueFromStrings( CONST WCHAR* szState, CONST WCHAR* szValue, 85 | StateStringMap* pStateStringMap, 86 | DWORD &State, DWORD &Value ); 87 | 88 | //----------------------------------------------------------------------------- 89 | // enum and state tables 90 | //----------------------------------------------------------------------------- 91 | extern EnumStringMap D3DX_FILTER_StringMap[]; 92 | extern EnumStringMap D3DXREGISTER_SET_StringMap[]; 93 | extern EnumStringMap D3DXPARAMETER_CLASS_StringMap[]; 94 | extern EnumStringMap D3DXPARAMETER_TYPE_StringMap[]; 95 | extern EnumStringMap D3DFORMAT_StringMap[]; 96 | extern EnumStringMap D3DDECLTYPE_StringMap[]; 97 | extern EnumStringMap D3DDECLMETHOD_StringMap[]; 98 | extern EnumStringMap D3DDECLUSAGE_StringMap[]; 99 | extern EnumStringMap D3DFILLMODE_StringMap[]; 100 | extern EnumStringMap D3DBLEND_StringMap[]; 101 | extern EnumStringMap D3DBLENDOP_StringMap[]; 102 | extern EnumStringMap D3DTEXTUREADDRESS_StringMap[]; 103 | extern EnumStringMap D3DCULL_StringMap[]; 104 | extern EnumStringMap D3DCMPFUNC_StringMap[]; 105 | extern EnumStringMap D3DSTENCILOP_StringMap[]; 106 | extern EnumStringMap D3DFOGMODE_StringMap[]; 107 | extern EnumStringMap D3DZBUFFERTYPE_StringMap[]; 108 | extern EnumStringMap D3DPRIMITIVETYPE_StringMap[]; 109 | extern EnumStringMap D3DTRANSFORMSTATETYPE_StringMap[]; 110 | extern EnumStringMap D3DWRAP_StringMap[]; 111 | extern EnumStringMap D3DMATERIALCOLORSOURCE_StringMap[]; 112 | extern EnumStringMap D3DDEBUGMONITORTOKENS_StringMap[]; 113 | extern EnumStringMap D3DVERTEXBLENDFLAGS_StringMap[]; 114 | extern EnumStringMap D3DPATCHEDGESTYLE_StringMap[]; 115 | extern EnumStringMap D3DDEGREETYPE_StringMap[]; 116 | extern EnumStringMap D3DTEXTUREFILTERTYPE_StringMap[]; 117 | extern EnumStringMap D3DTEXTUREOP_StringMap[]; 118 | extern EnumStringMap D3DTA_StringMap[]; 119 | extern EnumStringMap D3DTA_FLAGS_StringMap[]; 120 | extern EnumStringMap D3DTEXTURETRANSFORMFLAGS_StringMap[]; 121 | extern EnumStringMap D3DTSS_TCI_FLAGS_StringMap[]; 122 | extern EnumStringMap D3DCLEAR_StringMap[]; 123 | extern StateStringMap D3DRENDERSTATETYPE_StateStringMap[]; 124 | extern StateStringMap D3DSAMPLERSTATETYPE_StateStringMap[]; 125 | extern StateStringMap D3DTEXTURESTAGESTATETYPE_StateStringMap[]; 126 | extern EnumStringMap D3DTRILINEARTHRESHOLD_StringMap[]; 127 | extern EnumStringMap D3DMULTISAMPLE_TYPE_StringMap[]; 128 | 129 | } // namespace ATG 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /Common/AtgAvatarRenderer.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AvatarRenderer.h 3 | // 4 | // A class for rendering an Xbox avatar. This class is similar to the IXAvatarRenderer 5 | // interface provided in the XDK 6 | // 7 | // Microsoft Advanced Technology Group 8 | // Copyright (C) Microsoft Corporation. All rights reserved. 9 | //-------------------------------------------------------------------------------------- 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "AtgUtil.h" 16 | 17 | namespace ATG 18 | { 19 | #define GPU_MEMORY_BUFFER_ALIGN 4096 // 4k alignment for textures 20 | #define SAMPLE_ALLOCATOR_ID 0 21 | 22 | static const DWORD JOINT_BUFFER_COUNT = 2; // double buffered to allow skinning using vfetch 23 | 24 | class AvatarRenderer 25 | { 26 | public: 27 | AvatarRenderer( D3DDevice* pDevice, XAVATAR_METADATA& metadata ) : m_pAssets(NULL), 28 | m_pGpuBuffer(NULL) 29 | { 30 | m_pd3dDevice = pDevice; 31 | CreateAvatar( metadata ); 32 | } 33 | ~AvatarRenderer() 34 | { 35 | if( m_pAssets ) 36 | { 37 | XMemFree( m_pAssets, MAKE_XALLOC_ATTRIBUTES( 0, 38 | TRUE, 39 | TRUE, 40 | FALSE, 41 | SAMPLE_ALLOCATOR_ID, 42 | XALLOC_ALIGNMENT_4, 43 | XALLOC_MEMPROTECT_READWRITE, 44 | FALSE, XALLOC_MEMTYPE_HEAP ) ); 45 | 46 | m_pAssets = NULL; 47 | } 48 | 49 | if( m_pGpuBuffer ) 50 | { 51 | XPhysicalFree( m_pGpuBuffer ); 52 | m_pGpuBuffer = NULL; 53 | } 54 | 55 | if( m_pJointBuffer ) 56 | { 57 | XPhysicalFree( m_pJointBuffer ); 58 | m_pJointBuffer = NULL; 59 | } 60 | 61 | // Remove appropriate references to each declaration and shader. 62 | for ( INT i = 0; i < ARRAYSIZE( m_D3dShaders ); ++i ) 63 | { 64 | // Remove the reference to this vertex declarations, shaders and pixel shaders if we have them 65 | SAFE_RELEASE( m_D3dShaders[ i ].m_VertexDeclaration ); 66 | SAFE_RELEASE( m_D3dShaders[ i ].m_VertexShader ); 67 | SAFE_RELEASE( m_D3dShaders[ i ].m_PixelShader ); 68 | } 69 | } 70 | VOID Render( XMMATRIX matWorld, XMMATRIX matView, XMMATRIX matProj ); 71 | VOID Update( ) 72 | { 73 | RebuildJoints(); 74 | } 75 | VOID SetJoints( XAVATAR_SKELETON_POSE_JOINT joints[] ) 76 | { 77 | for( DWORD i = 0; i < XAVATAR_MAX_SKELETON_JOINTS; i++ ) 78 | { 79 | m_AvatarJointPose[i] = joints[i]; 80 | } 81 | } 82 | 83 | XAVATAR_SKELETON* GetSkeleton(){ return m_pAssets->pSkeleton;} 84 | 85 | private: 86 | HRESULT CreateAvatar( XAVATAR_METADATA& metaData ); 87 | HRESULT RebuildJoints( ); 88 | 89 | WORD GetShaderTextureIndex( const XAVATAR_SHADER_PARAM& param, XAVATAR_SHADER shader ) const; 90 | VOID SetShaderTexturesAndConstants( DWORD dwModelIndex, 91 | const XAVATAR_SHADER_INSTANCE* shaderInstance, 92 | const XAVATAR_TEXTURE* modelTextures, 93 | const DWORD* animatedTextureLayers ) ; 94 | 95 | BYTE GetPixelConstantRegister( const XAVATAR_SHADER_PARAM* param ) const; 96 | BYTE GetVertexConstantRegister( const XAVATAR_SHADER_PARAM* param, 97 | XAVATAR_SHADER shader ) const; 98 | 99 | 100 | HRESULT PreRender( const XMMATRIX* modelTransform, 101 | const XMMATRIX* viewTransform, 102 | const XMMATRIX* projectionTransform ); 103 | HRESULT RenderOpaque( DWORD dwModelIndex, D3DVertexBuffer* pJointBuffer ); 104 | HRESULT RenderTransparent( DWORD dwModelIndex, D3DVertexBuffer* pJointBuffer ); 105 | HRESULT PostRender( ); 106 | 107 | HRESULT ClearShaderTexturesAndConstants( ); 108 | 109 | private: 110 | // Raw avatar asset buffers. These hold the data retrieved by XAvatarGetAssets() 111 | XAVATAR_ASSETS* m_pAssets; // asset buffer 112 | BYTE* m_pGpuBuffer; // GPU buffer 113 | BYTE* m_pJointBuffer; 114 | 115 | // Shaders and vertex decls 116 | struct D3dShaders_t 117 | { 118 | D3DVertexDeclaration* m_VertexDeclaration; 119 | D3DVertexShader* m_VertexShader; 120 | D3DPixelShader* m_PixelShader; 121 | }; 122 | D3dShaders_t m_D3dShaders[ XAVATAR_SHADER_COUNT ]; 123 | 124 | // Lookup tables for converting shader parameters to GPU registers 125 | BYTE m_ShaderTextureIndexMap [ XAVATAR_SHADER_PARAM_USAGE_COUNT ][ XAVATAR_SHADER_COUNT ]; 126 | BYTE m_VertexConstantRegisterMap[ XAVATAR_SHADER_PARAM_USAGE_COUNT ][ XAVATAR_SHADER_COUNT ]; 127 | BYTE m_PixelConstantRegisterMap [ XAVATAR_SHADER_PARAM_USAGE_COUNT ]; 128 | 129 | // Vertex buffers, index buffers, and texture headers for each of the components 130 | D3DVertexBuffer m_VertexBuffers[ XAVATAR_COMPONENT_COUNT ]; 131 | D3DIndexBuffer m_IndexBuffers [ XAVATAR_COMPONENT_COUNT ]; 132 | D3DTexture m_Textures [ XAVATAR_COMPONENT_COUNT ][ XAVATAR_MAX_TEXTURES_PER_MODEL ][ XAVATAR_MAX_LAYERS_PER_TEXTURE ]; 133 | 134 | // Animation data - updated every frame from the animation assets 135 | XAVATAR_SKELETON_POSE_JOINT m_AvatarJointPose[ XAVATAR_MAX_SKELETON_JOINTS ]; // animated pos/rot/scale for the cur frame 136 | 137 | // Lights 138 | XMVECTOR m_vLightColor[3]; 139 | XMVECTOR m_vLightDirection[3]; 140 | 141 | // Texture animation data 142 | DWORD m_dwTextureLayers[ XAVATAR_ANIMATED_TEXTURE_COUNT ]; // animated texture IDs for the cur frame 143 | 144 | D3DVertexBuffer m_JointBufferVBs[ JOINT_BUFFER_COUNT ]; // Joints ready to be consumed by GPU 145 | DWORD m_dwJointBufferIndex; // current joint buffer in use 146 | 147 | D3DDevice* m_pd3dDevice; 148 | 149 | }; 150 | 151 | }; // namespace ATG -------------------------------------------------------------------------------- /Common/AtgSceneMesh.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // AtgSceneMesh.h 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #pragma once 9 | #ifndef ATG_MESH_H 10 | #define ATG_MESH_H 11 | 12 | #include 13 | #include "AtgNamedTypedObject.h" 14 | 15 | namespace ATG 16 | { 17 | 18 | class VertexData; 19 | class IndexData; 20 | class SubsetDesc; 21 | 22 | class BaseMesh : public NamedTypedObject 23 | { 24 | DEFINE_TYPE_INFO(); 25 | public: 26 | enum RenderSubsetFlags 27 | { 28 | NoVertexDecl = 1, 29 | ZeroStreamStrides = 2, 30 | }; 31 | 32 | enum MeshFlags 33 | { 34 | NoFlags = 0x0, 35 | IsSkinnable = 0x1, 36 | IsMorphable = 0x2, 37 | IsRenderable = 0x4, 38 | IsStencilShadowCasting = 0x8, 39 | IsShadowBufferCasting = 0x10, 40 | IsSortable = 0x20, 41 | IsEnabled = 0x40, 42 | 43 | ForceDWORD = 0x7fffffff 44 | }; 45 | 46 | BaseMesh() : m_dwFlags( BaseMesh::NoFlags ) {} 47 | 48 | // IsSkinnable 49 | virtual VOID Skin( XMMATRIX* pPallet ) {} 50 | 51 | // IsMorphable 52 | virtual VOID Morph( FLOAT* pWeights ) {} 53 | 54 | // IsRenderable 55 | virtual UINT GetNumSubsets() CONST { return 0; } 56 | virtual UINT RenderSubset( UINT Index, ::D3DDevice* pd3dDevice = NULL, DWORD dwFlags = 0 ) CONST { return 0; } 57 | virtual SubsetDesc* GetSubsetDesc( UINT Index ) CONST { return NULL; } 58 | virtual VOID AddSubsetDesc( SubsetDesc *pSD ) {} 59 | virtual VOID SetSubsetDesc( UINT Index ) {} 60 | virtual BOOL HasVertexElementType( UINT Index, D3DDECLUSAGE Usage ) CONST { return FALSE; } 61 | 62 | // IsStencilShadowCasting 63 | virtual UINT RenderStencilShadow( CONST XMVECTOR& LightPos, FLOAT ExtensionAmmount ) CONST { return 0; } 64 | 65 | // IsShadowBufferCasting 66 | virtual UINT RenderShadowBuffer() CONST { return 0; } 67 | 68 | // IsSortable 69 | virtual VOID Sort( CONST XMVECTOR& Plane ) { return; } 70 | 71 | // Number of primitives and vertices, for debug output 72 | virtual UINT GetNumVertices() CONST { return 0; } 73 | virtual UINT GetNumPrimitives() CONST { return 0; } 74 | 75 | // get vertex data from mesh 76 | virtual UINT GetNumVertexDatas() CONST { return 0; } 77 | virtual VertexData* GetVertexData( UINT Index ) CONST { return NULL; } 78 | virtual VOID SetVertexData( UINT Index, VertexData* pData ) {} 79 | 80 | // Get index data from mesh 81 | virtual UINT GetNumIndexDatas() CONST { return 0; } 82 | virtual IndexData* GetIndexData( UINT Index ) CONST { return NULL; } 83 | virtual VOID SetIndexData( UINT Index, IndexData* pData ) {} 84 | 85 | // Flags 86 | DWORD GetFlags() { return m_dwFlags; } 87 | VOID ClearFlag( MeshFlags dwFlag ) { m_dwFlags &= ~dwFlag; } 88 | VOID SetFlag( MeshFlags dwFlag ) { m_dwFlags |= dwFlag; } 89 | 90 | protected: 91 | DWORD m_dwFlags; 92 | }; 93 | 94 | 95 | 96 | //----------------------------------------------------------------------------- 97 | // Represents a static, non-skinned mesh 98 | //----------------------------------------------------------------------------- 99 | 100 | class StaticMesh : public BaseMesh 101 | { 102 | DEFINE_TYPE_INFO(); 103 | public: 104 | StaticMesh(); 105 | 106 | virtual UINT GetNumVertices() CONST; 107 | virtual UINT GetNumPrimitives() CONST; 108 | 109 | virtual UINT GetNumSubsets() CONST { return m_Subsets.size(); }; 110 | virtual SubsetDesc* GetSubsetDesc( UINT Index ) CONST { return m_Subsets[ Index ]; } 111 | virtual VOID SetSubsetDesc( UINT Index, SubsetDesc* pDesc ) { m_Subsets[ Index ] = pDesc; } 112 | virtual VOID AddSubsetDesc( SubsetDesc *pSD ) { m_Subsets.push_back( pSD ); } 113 | virtual UINT RenderSubset( UINT Index, ::D3DDevice* pd3dDevice = NULL, DWORD dwFlags = 0 ) CONST; 114 | virtual BOOL HasVertexElementType( UINT Index, D3DDECLUSAGE Usage ) CONST; 115 | 116 | 117 | virtual UINT GetNumVertexDatas() CONST { return 1; }; 118 | virtual VertexData* GetVertexData( UINT Index ) CONST { return m_pVertexData; }; 119 | virtual VOID SetVertexData( UINT Index, VertexData* pData ) { m_pVertexData = pData; } 120 | 121 | virtual UINT GetNumIndexDatas() CONST { return 1; }; 122 | virtual IndexData* GetIndexData( UINT Index ) CONST { return m_pIndexData; } 123 | virtual VOID SetIndexData( UINT Index, IndexData* pData ) { m_pIndexData = pData; } 124 | 125 | protected: 126 | std::vector m_Subsets; 127 | VertexData* m_pVertexData; 128 | IndexData* m_pIndexData; 129 | }; 130 | 131 | class SkinnedMesh : public StaticMesh 132 | { 133 | DEFINE_TYPE_INFO(); 134 | public: 135 | SkinnedMesh(); 136 | 137 | VOID AddInfluence( StringID strInfluenceName ) { m_InfluenceNames.push_back( strInfluenceName ); } 138 | DWORD GetInfluenceCount() const { return (DWORD)m_InfluenceNames.size(); } 139 | const StringID GetInfluence( DWORD dwIndex ) const { return m_InfluenceNames[dwIndex]; } 140 | 141 | protected: 142 | std::vector m_InfluenceNames; 143 | }; 144 | 145 | class CatmullClarkMesh : public SkinnedMesh 146 | { 147 | DEFINE_TYPE_INFO(); 148 | public: 149 | CatmullClarkMesh(); 150 | }; 151 | 152 | } // namespace ATG 153 | 154 | #endif // ATG_MESH_H 155 | -------------------------------------------------------------------------------- /Common/AtgDevice.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgDevice.cpp 3 | // 4 | // Over-loaded device to trap and optimize certain calls to D3D 5 | // 6 | // Microsoft Game Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | #include "stdafx.h" 10 | #include 11 | #include "AtgDevice.h" 12 | #include "AtgUtil.h" 13 | 14 | namespace ATG 15 | { 16 | 17 | // Data structure to pair vertex elements with a previously-created vertex decl 18 | struct VTX_DECL 19 | { 20 | D3DVERTEXELEMENT9 pElements[MAXD3DDECLLENGTH]; 21 | DWORD dwNumElements; 22 | D3DVertexDeclaration* pDeclaration; 23 | }; 24 | 25 | //-------------------------------------------------------------------------------------- 26 | // Name: CreatePooledVertexDeclaration() 27 | // Desc: Function to coalesce vertex declarations into a shared pool of vertex declarations 28 | //-------------------------------------------------------------------------------------- 29 | HRESULT WINAPI CreatePooledVertexDeclaration( const D3DVERTEXELEMENT9* pVertexElements, 30 | D3DVertexDeclaration** ppVertexDeclaration ) 31 | { 32 | static std::vector m_VertexDecls; 33 | 34 | // Count the number of vertex elements 35 | DWORD dwNumElements = 0; 36 | while( pVertexElements[dwNumElements].Stream < 16 ) 37 | dwNumElements++; 38 | 39 | assert( dwNumElements <= MAXD3DDECLLENGTH ); 40 | 41 | // Check for a previously-created vertex decl 42 | for( unsigned int i = 0; i < m_VertexDecls.size(); i++ ) 43 | { 44 | if( ( m_VertexDecls[i].dwNumElements == dwNumElements ) && 45 | ( !memcmp( m_VertexDecls[i].pElements, pVertexElements, sizeof( D3DVERTEXELEMENT9 ) * dwNumElements ) ) ) 46 | { 47 | // If found, return it 48 | ( *ppVertexDeclaration ) = m_VertexDecls[i].pDeclaration; 49 | return S_OK; 50 | } 51 | } 52 | 53 | // No previously-created vertex decl was found, so create one 54 | ( *ppVertexDeclaration ) = D3DDevice_CreateVertexDeclaration( pVertexElements ); 55 | 56 | // And save a record of it 57 | VTX_DECL d; 58 | XMemCpy( d.pElements, pVertexElements, sizeof( D3DVERTEXELEMENT9 ) * dwNumElements ); 59 | d.dwNumElements = dwNumElements; 60 | d.pDeclaration = ( *ppVertexDeclaration ); 61 | d.pDeclaration->AddRef(); 62 | m_VertexDecls.push_back( d ); 63 | 64 | return S_OK; 65 | } 66 | 67 | } // namespace ATG 68 | 69 | #ifdef _XBOX 70 | 71 | namespace ATG 72 | { 73 | 74 | //-------------------------------------------------------------------------------------- 75 | // Name: CreateVertexDeclaration() 76 | // Desc: Overloaded function to coalesce vertex declarations 77 | //-------------------------------------------------------------------------------------- 78 | HRESULT WINAPI D3DDevice::CreateVertexDeclaration( const D3DVERTEXELEMENT9* pVertexElements, 79 | D3DVertexDeclaration** ppVertexDeclaration ) 80 | { 81 | return CreatePooledVertexDeclaration( pVertexElements, ppVertexDeclaration ); 82 | } 83 | 84 | 85 | //-------------------------------------------------------------------------------------- 86 | // Name: SetVertexDeclaration() 87 | // Desc: Overloaded function to avoid redundant calls to D3D 88 | //-------------------------------------------------------------------------------------- 89 | D3DVOID WINAPI D3DDevice::SetVertexDeclaration( D3DVertexDeclaration* pDecl ) 90 | { 91 | static D3DVertexDeclaration* g_pDecl = NULL; 92 | // Synchronize with current D3D device state, to catch subsystems that do not go 93 | // through this codepath 94 | D3DVertexDeclaration* pCurrentDecl = D3DDevice_GetVertexDeclaration( this ); 95 | g_pDecl = pCurrentDecl; 96 | if( pCurrentDecl != NULL ) 97 | pCurrentDecl->Release(); 98 | // Only update decl if it has changed 99 | if( g_pDecl != pDecl ) 100 | { 101 | D3DDevice_SetVertexDeclaration( this, pDecl ); 102 | g_pDecl = pDecl; 103 | } 104 | D3DVOIDRETURN; 105 | } 106 | 107 | 108 | //-------------------------------------------------------------------------------------- 109 | // Name: SetVertexShader() 110 | // Desc: Overloaded function to avoid redundant calls to D3D 111 | //-------------------------------------------------------------------------------------- 112 | D3DVOID WINAPI D3DDevice::SetVertexShader( D3DVertexShader* pShader ) 113 | { 114 | static D3DVertexShader* g_pShader = NULL; 115 | // Synchronize with current D3D device state, to catch subsystems that do not go 116 | // through this codepath 117 | D3DVertexShader* pCurrentVS = NULL; 118 | D3DDevice_GetVertexShader( this, &pCurrentVS ); 119 | g_pShader = pCurrentVS; 120 | if( pCurrentVS != NULL ) 121 | pCurrentVS->Release(); 122 | // Only update shader if it has changed 123 | if( g_pShader != pShader ) 124 | { 125 | D3DDevice_SetVertexShader( this, pShader ); 126 | g_pShader = pShader; 127 | } 128 | D3DVOIDRETURN; 129 | } 130 | 131 | 132 | //-------------------------------------------------------------------------------------- 133 | // Name: SetPixelShader() 134 | // Desc: Overloaded function to avoid redundant calls to D3D 135 | //-------------------------------------------------------------------------------------- 136 | D3DVOID WINAPI D3DDevice::SetPixelShader( D3DPixelShader* pShader ) 137 | { 138 | static D3DPixelShader* g_pShader = NULL; 139 | // Synchronize with current D3D device state, to catch subsystems that do not go 140 | // through this codepath 141 | D3DPixelShader* pCurrentPS = NULL; 142 | D3DDevice_GetPixelShader( this, &pCurrentPS ); 143 | g_pShader = pCurrentPS; 144 | if( pCurrentPS != NULL ) 145 | pCurrentPS->Release(); 146 | // Only update shader if it has changed 147 | if( g_pShader != pShader ) 148 | { 149 | D3DDevice_SetPixelShader( this, pShader ); 150 | g_pShader = pShader; 151 | } 152 | D3DVOIDRETURN; 153 | } 154 | 155 | 156 | } // namespace ATG 157 | 158 | #endif // _XBOX 159 | -------------------------------------------------------------------------------- /Common/XTLOnPC.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // XTLOnPC.h 3 | // 4 | // This module contains functions that allow most of the samples framework to compile 5 | // on Windows using the Win32 XDK libraries. 6 | // 7 | // Some of the XTL memory functions are implemented here since the XTL libraries are 8 | // not implemented in the Win32 XDK libraries. 9 | // 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //-------------------------------------------------------------------------------------- 12 | #pragma once 13 | #ifndef XTLONPC_H 14 | #define XTLONPC_H 15 | 16 | #ifdef _PC 17 | 18 | #include 19 | 20 | #define XMemCpy memcpy 21 | #define XMemSet memset 22 | 23 | LPVOID 24 | WINAPI 25 | XPhysicalAlloc( 26 | __in SIZE_T dwSize, 27 | __in_opt ULONG_PTR ulPhysicalAddress, 28 | __in_opt ULONG_PTR ulAlignment, 29 | __in DWORD flProtect 30 | ); 31 | 32 | VOID 33 | WINAPI 34 | XPhysicalFree( 35 | __in LPVOID lpAddress 36 | ); 37 | 38 | LPVOID 39 | WINAPI 40 | XMemAlloc( 41 | __in SIZE_T dwSize, 42 | __in DWORD dwAllocAttributes 43 | ); 44 | 45 | VOID 46 | WINAPI 47 | XMemFree( 48 | __in_opt PVOID pAddress, 49 | __in DWORD dwAllocAttributes 50 | ); 51 | 52 | #define XALLOC_MEMTYPE_HEAP 0 53 | #define XALLOC_MEMTYPE_PHYSICAL 1 54 | 55 | #define XALLOC_MEMPROTECT_WRITECOMBINE_LARGE_PAGES 0 56 | #define XALLOC_MEMPROTECT_NOCACHE 1 57 | #define XALLOC_MEMPROTECT_READWRITE 2 58 | #define XALLOC_MEMPROTECT_WRITECOMBINE 3 59 | 60 | #define XALLOC_ALIGNMENT_DEFAULT 0x0 61 | #define XALLOC_ALIGNMENT_4 0x1 62 | #define XALLOC_ALIGNMENT_8 0x2 63 | #define XALLOC_ALIGNMENT_16 0x4 64 | 65 | #define XALLOC_PHYSICAL_ALIGNMENT_DEFAULT 0x0 // Default is 4K alignment 66 | #define XALLOC_PHYSICAL_ALIGNMENT_4 0x2 67 | #define XALLOC_PHYSICAL_ALIGNMENT_8 0x3 68 | #define XALLOC_PHYSICAL_ALIGNMENT_16 0x4 69 | #define XALLOC_PHYSICAL_ALIGNMENT_32 0x5 70 | #define XALLOC_PHYSICAL_ALIGNMENT_64 0x6 71 | #define XALLOC_PHYSICAL_ALIGNMENT_128 0x7 72 | #define XALLOC_PHYSICAL_ALIGNMENT_256 0x8 73 | #define XALLOC_PHYSICAL_ALIGNMENT_512 0x9 74 | #define XALLOC_PHYSICAL_ALIGNMENT_1K 0xA 75 | #define XALLOC_PHYSICAL_ALIGNMENT_2K 0xB 76 | #define XALLOC_PHYSICAL_ALIGNMENT_4K 0xC 77 | #define XALLOC_PHYSICAL_ALIGNMENT_8K 0xD 78 | #define XALLOC_PHYSICAL_ALIGNMENT_16K 0xE 79 | #define XALLOC_PHYSICAL_ALIGNMENT_32K 0xF 80 | 81 | typedef enum _XALLOC_ALLOCATOR_IDS 82 | { 83 | eXALLOCAllocatorId_GameMin = 0, 84 | eXALLOCAllocatorId_GameMax = 127, 85 | eXALLOCAllocatorId_MsReservedMin = 128, 86 | eXALLOCAllocatorId_D3D = 128, 87 | eXALLOCAllocatorId_D3DX, 88 | eXALLOCAllocatorId_XAUDIO, 89 | eXALLOCAllocatorId_XAPI, 90 | eXALLOCAllocatorId_XACT, 91 | eXALLOCAllocatorId_XBOXKERNEL, 92 | eXALLOCAllocatorId_XBDM, 93 | eXALLOCAllocatorId_XGRAPHICS, 94 | eXALLOCAllocatorId_XONLINE, 95 | eXALLOCAllocatorId_XVOICE, 96 | eXALLOCAllocatorId_XHV, 97 | eXALLOCAllocatorId_USB, 98 | eXALLOCAllocatorId_XMV, 99 | eXALLOCAllocatorId_SHADERCOMPILER, 100 | eXALLOCAllocatorId_XUI, 101 | eXALLOCAllocatorId_XASYNC, 102 | eXALLOCAllocatorId_XCAM, 103 | eXALLOCAllocatorId_XVIS, 104 | eXALLOCAllocatorId_XIME, 105 | eXALLOCAllocatorId_XFILECACHE, 106 | eXALLOCAllocatorId_XRN, 107 | eXALLOCAllocatorId_MsReservedMax = 191, 108 | eXALLOCAllocatorId_MiddlewareReservedMin = 192, 109 | eXALLOCAllocatorId_MiddlewareReservedMax = 255, 110 | } XALLOC_ALLOCATOR_IDS; 111 | 112 | #if defined(_M_PPCBE) 113 | #pragma bitfield_order(push) 114 | #pragma bitfield_order(lsb_to_msb) 115 | #endif 116 | 117 | typedef struct _XALLOC_ATTRIBUTES { 118 | DWORD dwObjectType:13; 119 | DWORD dwHeapTracksAttributes:1; 120 | DWORD dwMustSucceed:1; 121 | DWORD dwFixedSize:1; 122 | DWORD dwAllocatorId:8; 123 | DWORD dwAlignment:4; 124 | DWORD dwMemoryProtect:2; 125 | DWORD dwZeroInitialize:1; 126 | DWORD dwMemoryType:1; 127 | } XALLOC_ATTRIBUTES, *PXALLOC_ATTRIBUTES; 128 | 129 | #if defined(_M_PPCBE) 130 | #pragma bitfield_order(pop) 131 | #endif 132 | 133 | #define MAKE_XALLOC_ATTRIBUTES(ObjectType,\ 134 | HeapTracksAttributes,\ 135 | MustSucceed,\ 136 | FixedSize,\ 137 | AllocatorId,\ 138 | Alignment,\ 139 | MemoryProtect,\ 140 | ZeroInitialize,\ 141 | MemoryType)\ 142 | ((DWORD)( ObjectType | \ 143 | (HeapTracksAttributes << 13) | \ 144 | (MustSucceed << 14) | \ 145 | (FixedSize << 15) | \ 146 | (AllocatorId << 16) | \ 147 | (Alignment << 24) | \ 148 | (MemoryProtect << 28) | \ 149 | (ZeroInitialize << 30) | \ 150 | (MemoryType << 31))) 151 | 152 | #define XALLOC_IS_PHYSICAL(Attributes) ((BOOL)(Attributes & 0x80000000)!=0) 153 | 154 | typedef struct _XVIDEO_MODE { 155 | DWORD dwDisplayWidth; 156 | DWORD dwDisplayHeight; 157 | BOOL fIsInterlaced; 158 | BOOL fIsWideScreen; 159 | BOOL fIsHiDef; 160 | float RefreshRate; 161 | DWORD VideoStandard; 162 | DWORD Reserved[5]; 163 | } XVIDEO_MODE, *PXVIDEO_MODE; 164 | 165 | #define XC_VIDEO_STANDARD_NTSC_M 1 166 | #define XC_VIDEO_STANDARD_NTSC_J 2 167 | #define XC_VIDEO_STANDARD_PAL_I 3 168 | 169 | VOID 170 | WINAPI 171 | XGetVideoMode( 172 | __out PXVIDEO_MODE pVideoMode 173 | ); 174 | 175 | #endif // ifdef _PC 176 | 177 | #endif // XTLONPC_H 178 | -------------------------------------------------------------------------------- /Common/AtgMediaLocator.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgMediaLocator.cpp 3 | // 4 | // Xbox Advanced Technology Group. 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //-------------------------------------------------------------------------------------- 7 | 8 | 9 | #include "stdafx.h" 10 | #include 11 | #include "AtgMediaLocator.h" 12 | 13 | 14 | namespace ATG 15 | { 16 | 17 | 18 | const WCHAR XZP_SEPARATOR = L'#'; 19 | const WCHAR MEDIA_FOLDER[] = { L"media/" }; 20 | 21 | //-------------------------------------------------------------------------------------- 22 | // Name: LocateMediaFolder() 23 | // Desc: Retrieve the path to the media folder that sits inside the xzp archive 24 | // specified in szPackage. If the function succeeds, it returns TRUE and 25 | // szMediaPath contains the relative path to the media folder 26 | // (eg: "..\..\media\"). If the function fails, it returns FALSE and szMediaPath 27 | // is unaffected. 28 | //-------------------------------------------------------------------------------------- 29 | BOOL LocateMediaFolder( LPWSTR szMediaPath, DWORD dwMediaPathSize, LPCWSTR szPackage ) 30 | { 31 | // Open the archive file 32 | HXUIPACKAGE hPackage; 33 | HRESULT hr = XuiResourceOpenPackage( const_cast< LPWSTR >( szPackage ), &hPackage, FALSE ); 34 | if( hr != S_OK ) 35 | return FALSE; 36 | 37 | UINT entryCount = XuiResourceGetPackageEntryCount( hPackage ); 38 | WCHAR szLocator[ LOCATOR_SIZE ]; 39 | UINT LocatorSize = ARRAYSIZE( szLocator ); 40 | for( UINT i = 0; i < entryCount; ++ i ) 41 | { 42 | hr = XuiResourceGetPackageEntryInfo( hPackage, i, szLocator, &LocatorSize, NULL, NULL, NULL ); 43 | 44 | LPWSTR szPathStart = wcschr( szLocator, XZP_SEPARATOR ) + 1; 45 | assert( szPathStart != NULL ); 46 | 47 | LPWSTR szMediaFolder = wcsstr( szPathStart, MEDIA_FOLDER ); 48 | if( szMediaFolder != NULL ) 49 | { 50 | wcsncpy_s( szMediaPath, 51 | dwMediaPathSize, 52 | szPathStart, 53 | szMediaFolder + wcslen( MEDIA_FOLDER ) - szPathStart ); 54 | XuiResourceReleasePackage( hPackage ); 55 | return TRUE; 56 | break; 57 | } 58 | } 59 | 60 | XuiResourceReleasePackage( hPackage ); 61 | return FALSE; 62 | } 63 | 64 | 65 | //-------------------------------------------------------------------------------------- 66 | // Name: ComposeResourceLocator() 67 | // Desc: Combines the strings from szPackage, szBaseDirectory, szPath and szFile into a 68 | // valid resource locator. If successful, the function returns TRUE and szLocator 69 | // points to the newly composed resource locator. If it fails, the function 70 | // returns FALSE and the content of szLocator is undetermined. 71 | // 72 | // Note: szPackage is required and cannot be NULL, the other input parameters can be set 73 | // to NULL if desired. 74 | //-------------------------------------------------------------------------------------- 75 | BOOL ComposeResourceLocator( LPWSTR szLocator, DWORD dwLocatorSize, 76 | LPCWSTR szPackage, LPCWSTR szBaseDirectory, LPCWSTR szPath, LPCWSTR szFile ) 77 | { 78 | assert( szPackage != NULL ); 79 | 80 | if( wcscpy_s( szLocator, dwLocatorSize, szPackage ) != 0 ) 81 | return FALSE; 82 | 83 | if( wcscat_s( szLocator, dwLocatorSize, L"#" ) != 0 ) 84 | return FALSE; 85 | 86 | if( szBaseDirectory != NULL ) 87 | { 88 | if( wcscat_s( szLocator, dwLocatorSize, szBaseDirectory ) != 0 ) 89 | return FALSE; 90 | } 91 | 92 | if( szPath != NULL ) 93 | { 94 | if( wcscat_s( szLocator, dwLocatorSize, szPath ) != 0 ) 95 | return FALSE; 96 | } 97 | 98 | if( szFile != NULL ) 99 | { 100 | if( wcscat_s( szLocator, dwLocatorSize, szFile ) != 0 ) 101 | return FALSE; 102 | } 103 | 104 | return TRUE; 105 | } 106 | 107 | 108 | //-------------------------------------------------------------------------------------- 109 | // Name: MediaLocator::MediaLocator() 110 | // Desc: Constructs a MediaLocator object with default values. The caller should call 111 | // SetPackage() before using the class. 112 | //-------------------------------------------------------------------------------------- 113 | MediaLocator::MediaLocator() 114 | { 115 | m_szPackage[ 0 ] = L'\0'; 116 | m_szMediaPath[ 0 ] = L'\0'; 117 | } 118 | 119 | 120 | //-------------------------------------------------------------------------------------- 121 | // Name: MediaLocator::MediaLocator() 122 | // Desc: Constructs a MediaLocator object for use with the specified xzp archive. 123 | //-------------------------------------------------------------------------------------- 124 | MediaLocator::MediaLocator( LPCWSTR szPackage ) 125 | { 126 | wcscpy_s( m_szPackage, szPackage ); 127 | m_szMediaPath[ 0 ] = L'\0'; 128 | } 129 | 130 | 131 | //-------------------------------------------------------------------------------------- 132 | // Name: MediaLocator::SetPackage() 133 | // Desc: Replace the current working xzp archive with a new one. 134 | //-------------------------------------------------------------------------------------- 135 | VOID MediaLocator::SetPackage( LPCWSTR szPackage ) 136 | { 137 | wcscpy_s( m_szPackage, szPackage ); 138 | m_szMediaPath[ 0 ] = L'\0'; 139 | } 140 | 141 | //-------------------------------------------------------------------------------------- 142 | // Name: MediaLocator::GetMediaPath() 143 | // Desc: Retrieves the path to the media folder that sits inside the xzp archive. 144 | //-------------------------------------------------------------------------------------- 145 | LPCWSTR MediaLocator::GetMediaPath() const 146 | { 147 | if( m_szMediaPath[ 0 ] == L'\0' && m_szPackage[ 0 ] != L'\0' ) 148 | { 149 | LocateMediaFolder( m_szMediaPath, ARRAYSIZE( m_szMediaPath ), m_szPackage ); 150 | } 151 | 152 | return m_szMediaPath; 153 | } 154 | 155 | 156 | //-------------------------------------------------------------------------------------- 157 | // Name: MediaLocator::ComposeResourceLocator() 158 | // Desc: If succesful, returns TRUE and szLocator contains the resource locator for the 159 | // file identified by szPath and szFile that sits inside the media folder of the 160 | // xzp archive. It returns FALSE upon failure. 161 | //-------------------------------------------------------------------------------------- 162 | BOOL MediaLocator::ComposeResourceLocator( LPWSTR szLocator, DWORD dwLocatorSize, 163 | LPCWSTR szPath, LPCWSTR szFile ) const 164 | { 165 | if( m_szPackage[ 0 ] == L'\0' ) 166 | return FALSE; 167 | 168 | return ATG::ComposeResourceLocator( szLocator, dwLocatorSize, m_szPackage, GetMediaPath(), szPath, szFile ); 169 | } 170 | 171 | 172 | } // namespace ATG -------------------------------------------------------------------------------- /Common/AtgAudio.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgAudio.h 3 | // 4 | // Simple WAV file reader and other audio utilities. 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATGAUDIO_H 12 | #define ATGAUDIO_H 13 | 14 | #include 15 | #include 16 | 17 | namespace ATG 18 | { 19 | //-------------------------------------------------------------------------------------- 20 | // FourCC definitions 21 | //-------------------------------------------------------------------------------------- 22 | const DWORD ATG_FOURCC_RIFF = 'RIFF'; 23 | const DWORD ATG_FOURCC_WAVE = 'WAVE'; 24 | const DWORD ATG_FOURCC_XWMA = 'XWMA'; 25 | const DWORD ATG_FOURCC_DPDS = 'dpds'; 26 | const DWORD ATG_FOURCC_SEEK = 'seek'; 27 | const DWORD ATG_FOURCC_FORMAT = 'fmt '; 28 | const DWORD ATG_FOURCC_DATA = 'data'; 29 | const DWORD ATG_FOURCC_WSMP = 'wsmp'; 30 | const DWORD ATG_FOURCC_SMPL = 'lsmp'; 31 | 32 | 33 | 34 | //-------------------------------------------------------------------------------------- 35 | // Misc type definitions 36 | //-------------------------------------------------------------------------------------- 37 | typedef DWORD FOURCC, *PFOURCC, *LPFOURCC; 38 | 39 | 40 | //-------------------------------------------------------------------------------------- 41 | // For parsing WAV files 42 | //-------------------------------------------------------------------------------------- 43 | struct RIFFHEADER 44 | { 45 | FOURCC fccChunkId; 46 | DWORD dwDataSize; 47 | }; 48 | 49 | #define RIFFCHUNK_FLAGS_VALID 0x00000001 50 | 51 | 52 | //-------------------------------------------------------------------------------------- 53 | // Name: class RiffChunk 54 | // Desc: RIFF chunk utility class 55 | //-------------------------------------------------------------------------------------- 56 | class RiffChunk 57 | { 58 | FOURCC m_fccChunkId; // Chunk identifier 59 | const RiffChunk* m_pParentChunk; // Parent chunk 60 | HANDLE m_hFile; 61 | DWORD m_dwDataOffset; // Chunk data offset 62 | DWORD m_dwDataSize; // Chunk data size 63 | DWORD m_dwFlags; // Chunk flags 64 | 65 | public: 66 | RiffChunk(); 67 | 68 | // Initialization 69 | VOID Initialize( FOURCC fccChunkId, const RiffChunk* pParentChunk, 70 | HANDLE hFile ); 71 | HRESULT Open(); 72 | BOOL IsValid() const 73 | { 74 | return !!( m_dwFlags & RIFFCHUNK_FLAGS_VALID ); 75 | } 76 | 77 | // Data 78 | HRESULT ReadData( LONG lOffset, VOID* pData, DWORD dwDataSize, OVERLAPPED* pOL ) const; 79 | 80 | // Chunk information 81 | FOURCC GetChunkId() const 82 | { 83 | return m_fccChunkId; 84 | } 85 | DWORD GetDataSize() const 86 | { 87 | return m_dwDataSize; 88 | } 89 | 90 | private: 91 | // prevent copying so that we don't have to duplicate file handles 92 | RiffChunk( const RiffChunk& ); 93 | RiffChunk& operator =( const RiffChunk& ); 94 | }; 95 | 96 | //-------------------------------------------------------------------------------------- 97 | // Name: class WaveFile 98 | // Desc: Wave file utility class 99 | //-------------------------------------------------------------------------------------- 100 | class WaveFile 101 | { 102 | HANDLE m_hFile; // File handle 103 | RiffChunk m_RiffChunk; // RIFF chunk 104 | RiffChunk m_FormatChunk; // Format chunk 105 | RiffChunk m_DataChunk; // Data chunk 106 | RiffChunk m_WaveSampleChunk; // Wave Sample chunk 107 | RiffChunk m_SamplerChunk; // Sampler chunk 108 | RiffChunk m_DpdsChunk; // Packet cumulative bytes chunk (XWMA only) 109 | RiffChunk m_SeekChunk; // Seek chunk (XMA only) 110 | 111 | public: 112 | WaveFile(); 113 | ~WaveFile(); 114 | 115 | // Initialization 116 | HRESULT Open( const CHAR* strFileName ); 117 | VOID Close(); 118 | 119 | // File format 120 | HRESULT GetFormat( WAVEFORMATEXTENSIBLE* pwfxFormat, XMA2WAVEFORMATEX* pXma2Format = NULL ) const; 121 | 122 | // File data 123 | HRESULT ReadSample( DWORD dwPosition, VOID* pBuffer, DWORD dwBufferSize, 124 | DWORD* pdwRead ) const; 125 | 126 | // File data - no endianness conversion is performed 127 | HRESULT ReadSampleRaw( DWORD dwPosition, VOID* pBuffer, DWORD dwBufferSize, 128 | DWORD* pdwRead ) const; 129 | 130 | // Loop region 131 | HRESULT GetLoopRegion( DWORD* pdwStart, DWORD* pdwLength ) const; 132 | HRESULT GetLoopRegionBytes( DWORD* pdwStart, DWORD* pdwLength ) const; 133 | 134 | // File properties 135 | VOID GetDuration( DWORD* pdwDuration ) const 136 | { 137 | *pdwDuration = m_DataChunk.GetDataSize(); 138 | } 139 | DWORD Duration() const 140 | { 141 | return m_DataChunk.GetDataSize(); 142 | } 143 | 144 | // The 'dpds' chunk - packet cumulative bytes. Returns the packet count and the total structure size, in bytes. 145 | // The packet count is for the client to index the structure returned by GetPacketCumulativeBytes. 146 | // The buffer size is the total size, in bytes, of the structure. The client can use this value to allocate a pointer to 147 | // pass to GetPacketCumulativeBytes. 148 | // This function should be used with XWMA files only. 149 | HRESULT GetPacketCumulativeBytesSize( DWORD* pdwPacketCount, DWORD* pdwBufferSize ); 150 | 151 | // The 'dpds' chunk - packet cumulative bytes. Returns the structure data. 152 | // 'pdwData' should point to a memory block large enough to hold all the data. The exact number of bytes 153 | // required can be obtained by calling GetPacketCumulativeBytes. 154 | // This function should be used with XWMA files only. 155 | HRESULT GetPacketCumulativeBytes( DWORD* pdwData ); 156 | 157 | // The 'seek' chunk - seek table. Returns the total structure size, in bytes. 158 | // The buffer size is the total size, in bytes, of the structure. The client can use this value to allocate a pointer to 159 | // pass to GetSeekTable. 160 | // This function should be used with XMA files only. 161 | HRESULT GetSeekTableSize( DWORD* pdwBufferSize ); 162 | 163 | // The 'seek' chunk - seek table. Returns the structure data. 164 | // 'pdwData' should point to a memory block large enough to hold all the data. The exact number of bytes 165 | // required can be obtained by calling GetSeekTableSize. 166 | // This function should be used with XMA files only. 167 | HRESULT GetSeekTable( DWORD* pdwData ); 168 | 169 | private: 170 | // prevent copying so that we don't have to duplicate file handles 171 | WaveFile( const WaveFile& ); 172 | WaveFile& operator =( const WaveFile& ); 173 | }; 174 | 175 | 176 | } // namespace ATG 177 | 178 | 179 | #endif // ATGAUDIO_H 180 | -------------------------------------------------------------------------------- /Common/AtgNamedTypedObject.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // ATGNamedTypedObject.h 3 | // 4 | // Base class for all scene objects that are named and typed 5 | // 6 | // Xbox Advanced Technology Group. 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //----------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | #ifndef ATG_NamedTypedObject_H 12 | #define ATG_NamedTypedObject_H 13 | 14 | // C4127: conditional expression is constant 15 | // this shows up when using STL without exception handling 16 | #pragma warning(disable:4127) 17 | 18 | #include 19 | 20 | namespace ATG 21 | { 22 | 23 | //----------------------------------------------------------------------------- 24 | // Name: DEFINE_TYPE_INFO 25 | // Desc: Creates a type based on the NamedTypedObject class. Use this in any 26 | // classes derived from NamedTypedObject to get the IsDerived() functionality. 27 | //----------------------------------------------------------------------------- 28 | #ifndef DEFINE_TYPE_INFO 29 | #define DEFINE_TYPE_INFO() \ 30 | public: \ 31 | virtual BOOL IsDerivedFrom( ATG::StringID _TypeID ) CONST { if( _TypeID == TypeID ) return TRUE; return __super::IsDerivedFrom( _TypeID ); } \ 32 | virtual const ATG::StringID Type() CONST { return TypeID; } \ 33 | static const ATG::StringID TypeID; 34 | #endif 35 | 36 | 37 | //----------------------------------------------------------------------------- 38 | // Name: StringID 39 | // Desc: Memory management for strings- strings will be inserted into a hash 40 | // table uniquely, and can be referenced by pointer. If you want to 41 | // insert a string case-insensitively, use SetCaseInsensitive 42 | //----------------------------------------------------------------------------- 43 | 44 | // This is the number of lists in the string hashtable - should be prime 45 | const int StringID_HASHSIZE = 61; 46 | 47 | class StringID 48 | { 49 | public: 50 | // Constructors 51 | StringID() { m_strString = s_EmptyString; } 52 | StringID( CONST WCHAR* strString ) { m_strString = AddString( strString ); } 53 | StringID( CONST StringID& other ) { m_strString = other.m_strString; } 54 | 55 | // Assignment 56 | StringID& operator= ( CONST StringID& RHS ) { m_strString = RHS.m_strString; return *this; } 57 | StringID& operator= ( CONST WCHAR* strRHS ) { m_strString = AddString( strRHS ); return *this; } 58 | 59 | // Comparison 60 | BOOL operator== ( CONST StringID& RHS ) CONST { return m_strString == RHS.m_strString; } 61 | BOOL operator== ( CONST WCHAR* strRHS ) CONST; 62 | BOOL IsEmptyString() const { return m_strString == s_EmptyString; } 63 | 64 | // Casting 65 | operator CONST WCHAR* () CONST { return m_strString; } 66 | CONST WCHAR* GetSafeString() CONST { return ( m_strString ? m_strString : L"null" ); } 67 | 68 | // Hash lookup function 69 | static DWORD HashString( CONST WCHAR* strString ); 70 | protected: 71 | static CONST WCHAR* AddString( CONST WCHAR* strString ); 72 | static std::list* GetStringTable(); 73 | 74 | protected: 75 | CONST WCHAR* m_strString; 76 | static CONST WCHAR* s_EmptyString; 77 | }; 78 | 79 | //----------------------------------------------------------------------------- 80 | // Name: EnumStringMap 81 | // Desc: Maps values to strings 82 | //----------------------------------------------------------------------------- 83 | #ifndef ENUMSTRINGMAP_DEFINED 84 | struct EnumStringMap 85 | { 86 | DWORD Value; 87 | CONST WCHAR* szName; 88 | }; 89 | #define ENUMSTRINGMAP_DEFINED 90 | #endif 91 | 92 | //----------------------------------------------------------------------------- 93 | // Name: NamedTypedObject 94 | // Desc: The base class that all name-referenced objects inheirit from. 95 | // They have a StringID name and a static class StringID type. 96 | //----------------------------------------------------------------------------- 97 | 98 | //! class name="NamedTypedObject" Desc="Base class for exposed objects" 99 | //! property name="Name" Desc="Name of the Object" Get=GetName Set=SetName 100 | 101 | class NamedTypedObject 102 | { 103 | // Because NamedTypedObject has no base class we explicitly define the type info here- most classes 104 | // will us the DEFINE_TYPE_INFO macro, with an explicit callout in the .cpp file. 105 | // TypeID is public so you can use NamedTypedObject::TypeID for comparisons without an instance. 106 | 107 | public: 108 | virtual BOOL IsDerivedFrom( StringID _TypeID ) CONST { return ( _TypeID == TypeID ); } 109 | virtual const StringID Type() CONST { return TypeID; } 110 | static const StringID TypeID; 111 | 112 | public: 113 | CONST StringID& GetName() CONST { return m_Name; }; 114 | VOID SetName( CONST StringID& Name ) { m_Name = Name; } 115 | 116 | private: 117 | StringID m_Name; 118 | }; 119 | 120 | 121 | //----------------------------------------------------------------------------- 122 | // Name: NameIndexedCollection 123 | // Desc: A hash table, referenceable by name of NamedTypedObject objects 124 | //----------------------------------------------------------------------------- 125 | 126 | // This is the number of lists in the collection hashtable - should be prime 127 | // $TODO: Allow the size to be settable on a collection basis 128 | 129 | const int DEFAULT_COLLECTION_HASHSIZE = 61; 130 | 131 | class NameIndexedCollection 132 | { 133 | public: 134 | // iterator for the collection - it is made so you can 135 | // delete the object at the current position and STILL do a ++ 136 | // safely afterwards 137 | class iterator 138 | { 139 | friend class NameIndexedCollection; 140 | public: 141 | iterator(); 142 | 143 | NamedTypedObject* operator*(); 144 | iterator& operator++( int ); // only postfix defined 145 | iterator& operator=( CONST iterator& iRHS ); 146 | BOOL operator==( CONST iterator& iRHS ); 147 | BOOL operator!=( CONST iterator& iRHS ); 148 | private: 149 | NameIndexedCollection* m_pCollection; 150 | std::list::iterator m_iter; 151 | int m_iCurBucket; 152 | }; 153 | friend class NameIndexedCollection::iterator; 154 | 155 | VOID Add( NamedTypedObject *pObjectToAdd ); // Add a NamedTypedObject to the collection 156 | VOID Remove( NamedTypedObject *pObjectToRemove ); // Remove a NamedTypedObject from the collection 157 | NamedTypedObject* Find( CONST WCHAR* strName ); // Find a NamedTypedObject in the collection 158 | NamedTypedObject* FindTyped( CONST WCHAR* strName, const StringID TypeID ); // Find a NamedTypedObject of a certain type in the collection 159 | DWORD Size(); 160 | 161 | iterator begin(); 162 | iterator end(); 163 | private: 164 | std::list s_Lists[ DEFAULT_COLLECTION_HASHSIZE ]; 165 | }; 166 | 167 | } // namespace ATG 168 | 169 | #endif // ATG_NamedTypedObject_H 170 | -------------------------------------------------------------------------------- /Common/AtgNuiRelativeCoordinates.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // AtgNuiReletiveCoordinates.cpp 3 | // 4 | // This class maintains a body reletive coordainte system for NUI Samples 5 | // 6 | // Microsoft Advanced Technology Group 7 | // Copyright (C) Microsoft Corporation. All rights reserved. 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #include "stdafx.h" 11 | #include "AtgNuiRelativeCoordinates.h" 12 | #include "AtgUtil.h" 13 | 14 | namespace ATG 15 | { 16 | //------------------------------------------------------------------------------------- 17 | // Name: Lerp() 18 | // Desc: Linear interpolation between two floats 19 | //------------------------------------------------------------------------------------- 20 | inline FLOAT Lerp( FLOAT f1, FLOAT f2, FLOAT fBlend ) 21 | { 22 | return f1 + (f2-f1) * fBlend; 23 | } 24 | 25 | 26 | SpineRelativeCameraSpaceCoordinateSystem::SpineRelativeCameraSpaceCoordinateSystem( ) : 27 | m_dwLastTrackingID( 0 ), 28 | m_fAverageSpineHeadLength( 0.0f ), 29 | m_vAverageNormalToGravity( XMVectorZero() ) 30 | { 31 | m_vAverageSpine = XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f ); 32 | m_vRightHandRelative = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); 33 | m_vLeftHandRelative = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); 34 | 35 | // Call the updates function with default parameters 36 | SetUpdateRates(); 37 | } 38 | 39 | //-------------------------------------------------------------------------------------- 40 | // Name: SetUpdateRates() 41 | // Desc: Initializes the update rates used for filtering the spine coordinates and 42 | // body size related lengths used in this class. These are left and right hand length, 43 | // shoulder length, and spine to head length. An update rate closer to 1.0f results 44 | // in more smoothing and adds some lagging when there is a fast body movement. 45 | //-------------------------------------------------------------------------------------- 46 | VOID SpineRelativeCameraSpaceCoordinateSystem::SetUpdateRates( FLOAT fSpineUpdateRate, FLOAT fBodySizeUpdateRate ) 47 | { 48 | m_fBodySizeUpdateRate = max( 0.0f, min( 1.0f, fBodySizeUpdateRate ) ); 49 | m_fSpineUpdateRate = max( 0.0f, min( 1.0f, fSpineUpdateRate ) ); 50 | } 51 | 52 | //-------------------------------------------------------------------------------------- 53 | // Name: Reset() 54 | // Desc: Resets the coordinate system. This method should be called if this class 55 | // is to be used for a new player skeleton. 56 | //-------------------------------------------------------------------------------------- 57 | VOID SpineRelativeCameraSpaceCoordinateSystem::Reset( ) 58 | { 59 | m_vAverageNormalToGravity = XMVectorZero(); 60 | m_dwLastTrackingID = 0; 61 | m_fAverageSpineHeadLength = 0.0f; 62 | m_vAverageSpine = XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f ); 63 | m_vRightHandRelative = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); 64 | m_vLeftHandRelative = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); 65 | } 66 | 67 | //-------------------------------------------------------------------------------------- 68 | // Name: Update() 69 | // Desc: Adds a new frame of positions, updates the coordiante system, and calculates 70 | // left and right hand. 71 | //-------------------------------------------------------------------------------------- 72 | VOID SpineRelativeCameraSpaceCoordinateSystem::Update( const NUI_SKELETON_FRAME* pRawSkeletonFrame, INT iSkeletonIndex, XMVECTOR vLeft, XMVECTOR vRight ) 73 | { 74 | if ( pRawSkeletonFrame == NULL ) return; 75 | if ( iSkeletonIndex < 0 || iSkeletonIndex >= NUI_SKELETON_COUNT ) return; 76 | CONST XMVECTOR *pSkeletonPosition = &pRawSkeletonFrame->SkeletonData[iSkeletonIndex].SkeletonPositions[0]; 77 | 78 | if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID ) 79 | { 80 | m_vAverageNormalToGravity = pRawSkeletonFrame->vNormalToGravity; 81 | } 82 | else 83 | { 84 | m_vAverageNormalToGravity = m_fSpineUpdateRate * m_vAverageNormalToGravity + 85 | pRawSkeletonFrame->vNormalToGravity * ( 1.0f - m_fSpineUpdateRate ); 86 | } 87 | 88 | #if 0 89 | CHAR out[255]; 90 | sprintf_s( out, "x=%f,y=%f,z=%f,w=%f\n", pRawSkeletonFrame->vNormalToGravity.x, pRawSkeletonFrame->vNormalToGravity.y, pRawSkeletonFrame->vNormalToGravity.z, pRawSkeletonFrame->vNormalToGravity.w ); 91 | OutputDebugString( out ); 92 | #endif 93 | m_matRotateToNormalToGravity = NuiTransformMatrixLevel( m_vAverageNormalToGravity ); 94 | XMVECTOR vSpineTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_SPINE], m_matRotateToNormalToGravity ); 95 | XMVECTOR vHeadTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_HEAD], m_matRotateToNormalToGravity ); 96 | m_vLeftHandRelative = XMVector3Transform( vLeft, m_matRotateToNormalToGravity ); 97 | m_vRightHandRelative = XMVector3Transform( vRight, m_matRotateToNormalToGravity ); 98 | 99 | 100 | FLOAT fSpineHeadLength = XMVectorGetY( vHeadTilted ) - XMVectorGetY( vSpineTilted ); 101 | if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID ) 102 | { 103 | m_dwLastTrackingID = pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID; 104 | m_vAverageSpine = vSpineTilted; 105 | m_fAverageSpineHeadLength = fSpineHeadLength; 106 | } 107 | else 108 | { 109 | m_vAverageSpine = m_vAverageSpine * m_fSpineUpdateRate + 110 | vSpineTilted * ( 1.0f - m_fSpineUpdateRate ); 111 | m_fAverageSpineHeadLength = ATG::Lerp( fSpineHeadLength, m_fAverageSpineHeadLength, m_fBodySizeUpdateRate ); 112 | } 113 | 114 | m_vEstiamtedPivotOffsetLeft = XMVectorSet( m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f ); 115 | m_vEstiamtedPivotOffsetRight = XMVectorSet( -m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f ); 116 | m_vRightHandRelative -= m_vAverageSpine; 117 | m_vRightHandRelative += m_vEstiamtedPivotOffsetRight; 118 | m_vLeftHandRelative -= m_vAverageSpine; 119 | m_vLeftHandRelative += m_vEstiamtedPivotOffsetLeft; 120 | static XMVECTOR vFlipZ = XMVectorSet( 1.0f, 1.0f, -1.0f, 1.0f ); 121 | m_vRightHandRelative *= vFlipZ; 122 | m_vLeftHandRelative *= vFlipZ; 123 | 124 | } 125 | 126 | //-------------------------------------------------------------------------------------- 127 | // Name: Update() 128 | // Desc: Returns the Right hand in the body reletive coordinate system. 129 | //-------------------------------------------------------------------------------------- 130 | XMVECTOR SpineRelativeCameraSpaceCoordinateSystem::GetRightHandReletive() 131 | { 132 | return m_vRightHandRelative; 133 | } 134 | 135 | //-------------------------------------------------------------------------------------- 136 | // Name: Update() 137 | // Desc: Returns the left hand in the body reletive coordinate system. 138 | //-------------------------------------------------------------------------------------- 139 | XMVECTOR SpineRelativeCameraSpaceCoordinateSystem::GetLeftHandReletive() 140 | { 141 | return m_vLeftHandRelative; 142 | } 143 | 144 | } // namespace ATG 145 | 146 | --------------------------------------------------------------------------------