[2242] | 1 | /**
|
---|
| 2 | \brief Uploads the specified world/view/projection transformation matrices to the GPU.
|
---|
| 3 | */
|
---|
| 4 | void setWorldViewProj(D3DXMATRIXA16& mWorld, D3DXMATRIXA16& mView, D3DXMATRIXA16& mProj, ID3DXEffect* effect )
|
---|
| 5 | {
|
---|
| 6 | HRESULT hr;
|
---|
| 7 | D3DXMATRIXA16 mWorldView = mWorld * mView;
|
---|
| 8 | D3DXMATRIXA16 mWorldViewProjection = mWorldView * mProj;
|
---|
| 9 |
|
---|
| 10 | D3DXMATRIXA16 mWorldViewI, mWorldViewIT, mWorldI, mWorldIT;
|
---|
| 11 | D3DXMatrixInverse(&mWorldViewI, NULL, &mWorldView);
|
---|
| 12 | D3DXMatrixTranspose(&mWorldViewIT, &mWorldViewI);
|
---|
| 13 |
|
---|
| 14 | D3DXMatrixInverse(&mWorldI, NULL, &mWorld);
|
---|
| 15 | D3DXMatrixTranspose(&mWorldIT, &mWorldI);
|
---|
| 16 |
|
---|
| 17 | V( effect->SetMatrix( "World", &mWorld ) );
|
---|
| 18 | V( effect->SetMatrix( "WorldIT", &mWorldIT ) );
|
---|
| 19 | V( effect->SetMatrix( "WorldView", &mWorldView ) );
|
---|
| 20 | V( effect->SetMatrix( "WorldViewIT", &mWorldViewIT ) );
|
---|
| 21 | V( effect->SetMatrix( "WorldViewProj", &mWorldViewProjection ) );
|
---|
| 22 | V( effect->CommitChanges() );
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | Sets the given scaling and offset.
|
---|
| 27 | @return The resulting world transformation matrix.
|
---|
| 28 | */
|
---|
| 29 | D3DXMATRIXA16 ScaleAndOffset(D3DXVECTOR3 vScale, D3DXVECTOR3 vOffset)
|
---|
| 30 | {
|
---|
| 31 | D3DXMATRIXA16 mScale, mOffset;
|
---|
| 32 | D3DXMatrixIdentity(&mScale);
|
---|
| 33 | D3DXMatrixIdentity(&mOffset);
|
---|
| 34 |
|
---|
| 35 | D3DXMatrixTranslation( &mOffset, vOffset.x, vOffset.y, vOffset.z );
|
---|
| 36 | D3DXMatrixScaling( &mScale, vScale.x, vScale.y, vScale.z );
|
---|
| 37 |
|
---|
| 38 | return mScale * mOffset;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | Sets the given uniform scaling and an offset.
|
---|
| 43 | @return The resulting world transformation matrix.
|
---|
| 44 | */
|
---|
| 45 | D3DXMATRIXA16 ScaleAndOffset(float fScale, D3DXVECTOR3 vOffset)
|
---|
| 46 | {
|
---|
| 47 | return ScaleAndOffset( D3DXVECTOR3(fScale,fScale,fScale), vOffset );
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void getViewProjForCubeFace(D3DXMATRIXA16* mView, D3DXMATRIXA16* mProj, int cubeFace, D3DXVECTOR3 centerPos)
|
---|
| 51 | {
|
---|
| 52 | D3DXVECTOR3 vecEye(0,0,0);
|
---|
| 53 | D3DXVECTOR3 vecAt(0.0f, 0.0f, 0.0f);
|
---|
| 54 | D3DXVECTOR3 vecUp(0.0f, 0.0f, 0.0f);
|
---|
| 55 |
|
---|
| 56 | switch( cubeFace )
|
---|
| 57 | {
|
---|
| 58 | case D3DCUBEMAP_FACE_POSITIVE_X:
|
---|
| 59 | vecAt = D3DXVECTOR3( 1, 0, 0 );
|
---|
| 60 | vecUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
|
---|
| 61 | break;
|
---|
| 62 | case D3DCUBEMAP_FACE_NEGATIVE_X:
|
---|
| 63 | vecAt = D3DXVECTOR3(-1.0f, 0.0f, 0.0f );
|
---|
| 64 | vecUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
|
---|
| 65 | break;
|
---|
| 66 | case D3DCUBEMAP_FACE_POSITIVE_Y:
|
---|
| 67 | vecAt = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
|
---|
| 68 | vecUp = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
|
---|
| 69 | break;
|
---|
| 70 | case D3DCUBEMAP_FACE_NEGATIVE_Y:
|
---|
| 71 | vecAt = D3DXVECTOR3( 0.0f,-1.0f, 0.0f );
|
---|
| 72 | vecUp = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
|
---|
| 73 | break;
|
---|
| 74 | case D3DCUBEMAP_FACE_POSITIVE_Z:
|
---|
| 75 | vecAt = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
|
---|
| 76 | vecUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
|
---|
| 77 | break;
|
---|
| 78 | case D3DCUBEMAP_FACE_NEGATIVE_Z:
|
---|
| 79 | vecAt = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
|
---|
| 80 | vecUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
|
---|
| 81 | break;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | vecEye += centerPos;
|
---|
| 85 | vecAt += centerPos;
|
---|
| 86 |
|
---|
| 87 | D3DXMatrixLookAtLH(mView, &vecEye, &vecAt, &vecUp);
|
---|
| 88 | D3DXMatrixPerspectiveFovLH( mProj, D3DX_PI/2, 1, 0.001, 2.0 );
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | IDirect3DCubeTexture9* CreateCubeTexture( int size, D3DFORMAT Format, IDirect3DDevice9* pd3dDevice)
|
---|
| 92 | {
|
---|
| 93 | HRESULT hr;
|
---|
| 94 | IDirect3DCubeTexture9* pCubeTexture;
|
---|
| 95 |
|
---|
| 96 | if( FAILED(hr = D3DXCreateCubeTexture( pd3dDevice,
|
---|
| 97 | size, 1,
|
---|
| 98 | D3DUSAGE_RENDERTARGET,
|
---|
| 99 | Format,
|
---|
| 100 | D3DPOOL_DEFAULT,
|
---|
| 101 | &pCubeTexture )))
|
---|
| 102 | {
|
---|
| 103 | MessageBox(NULL, L"Cube texture creation failed!", L"Error", MB_OK|MB_TOPMOST);
|
---|
| 104 | exit(-1);
|
---|
| 105 | }
|
---|
| 106 | return pCubeTexture;
|
---|
| 107 | } |
---|