D3DPBRApp::D3DPBRApp(HINSTANCE hInstance) :D3DApp(hInstance),m_pIB(0),m_pVB(0) ,mDynamicCubeMapSRV(NULL) ,mDynamicCubeMapDSV(NULL) ,mLUTRTV(NULL) ,mLUTSRV(NULL) ,mLUTDSV(NULL) { mLastMousePos.x = 0; mLastMousePos.y = 0; mCam.SetPosition(0.0f, 2.0f, -15.0f); XMMATRIX MeshScale = XMMatrixScaling(0.5f, 0.5f, 0.5f); XMMATRIX MeshOffset = XMMatrixTranslation(0.0f, 1.0f, 0.0f); BuildCubeFaceCamera(0.0f, 1.0f, 0.0f); XMStoreFloat4x4(&mMeshWorld, XMMatrixMultiply(MeshScale, MeshOffset)); //mDirLights[0].Ambient = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f); mDirLights[0].Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); //mDirLights[0].Specular = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f); mDirLights[0].Direction = XMFLOAT3(0.f, 0.f, 1.0f); //mDirLights[0].Direction = XMFLOAT3(1.f, 0, 0); //mDirLights[1].Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); mDirLights[1].Diffuse = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); //mDirLights[1].Specular = XMFLOAT4(0.25f, 0.25f, 0.25f, 1.0f); mDirLights[1].Direction = XMFLOAT3(-0.57735f, -0.57735f, 0.57735f); //mDirLights[2].Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); mDirLights[2].Diffuse = XMFLOAT4(0.f, 0.f, 0.f, 1.0f); //mDirLights[2].Specular = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); mDirLights[2].Direction = XMFLOAT3(0.0f, -0.707f, -0.707f); //mMeshMat.Ambient = XMFLOAT4(0.4f, 0.4f, 0.4f, 1.0f); mMeshMat.Diffuse = XMFLOAT4(1.0f, 0.86f, 0.57f, 1.0f); mMeshMat.Specular = 0.5f; mMeshMat.roughness = 0.5f; mMeshMat.metal = 0.9f; m_pSky = NULL; }
// 行星天体的自转和公转 void SuperSolarSystemApp::StarAction( ) { XMMATRIX scale, offset, localRotate, globalRotate; for ( int i = MERCURY; i < STARNUMBER; i++ ) { scale = XMMatrixScaling( starinfo[i].equatorialRadius, starinfo[i].equatorialRadius, starinfo[i].equatorialRadius ); offset = XMMatrixTranslation( starinfo[i].distanceToSun, 0.0f, 0.0f ); localRotate = XMMatrixRotationY( mTimer.GetTimePassRate( ) * mTimer.TotalTime( ) / starinfo[i].rotationPeriod ); globalRotate = XMMatrixRotationY( mTimer.GetTimePassRate( ) * mTimer.TotalTime( ) / starinfo[i].orbitPeriod ); XMStoreFloat4x4( &mWorld[i], scale * localRotate * offset * globalRotate ); // 如果是金属球体的话, 别忘了更新6个照相机位置 if ( METAL == i ) { BuildCubeFaceCamera( mWorld[i]._41, mWorld[i]._42, mWorld[i]._43 ); } } }
SuperSolarSystemApp::SuperSolarSystemApp( HINSTANCE hInstance ) : D3dBase( hInstance ), mLightTexIB( 0 ), mLightTexVB( 0 ), mColorIB( 0 ), mColorVB( 0 ), mCamera( 1.5f*MathHelper::Pi, 0.5f*MathHelper::Pi, 200.0f ) { mEnable4xMsaa = false; // 默认照相机方向 mCamera.LookAt( XMFLOAT3( -200.0f, 0.0f, 10.0f ) /*XMFLOAT3(-150.0f, 50.0f, -50.0f)*/, XMFLOAT3( 0.0f, 0.0f, 0.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) ); BuildCubeFaceCamera( 0.0f, 0.0f, 0.0f ); InitLight( ); InitStarInformation( ); }