//============================================================================== //移動位置の設定 //============================================================================== //[input] // pMouse:マウス用デバイス // pEnemy:敵クラス // pSceneMgr:シーン管理デバイス //============================================================================== void CPlayer::SetTargetPos( Selene::Peripheral::IMouse *pMouse, CEnemy *pEnemy, Scene::ISceneManager *pSceneMgr ) { Collision::CLine3D vRay( pSceneMgr->TransformFromScreen( Math::Vector3D(toF(pMouse->GetPosX()), toF(pMouse->GetPosY()), 0.0f) ), pSceneMgr->TransformFromScreen( Math::Vector3D(toF(pMouse->GetPosX()), toF(pMouse->GetPosY()), 1.0f) ) ); /*左クリックで乗り移り*/ if( pMouse->GetStateL() == MOUSE_PUSH && pEnemy->GetModelActor( SCREEN_MAIN )->Collision_Check( vRay )) { /*捕獲フラグを設定*/ pEnemy->SetCapdFlag( true ); /*捕獲位置をバックアップ*/ pEnemy->SetCatchBeforePos( pEnemy->GetPosition() ); m_vCapedPos = m_vPos; /*状態を捕獲状態にする*/ SetState( STATE_CAPSTART ); /*捕獲した敵を代入*/ m_pCapedEnemy = pEnemy; } }
//============================================================================== //移動処理(ツール用) //============================================================================== //[input] // pCam:カメラデバイス // pMouse:マウスデバイス // pField:フィールド // pSceneMgr:シーン管理デバイス //============================================================================== void CPlayer::Move( CCamera *pCam, Peripheral::IMouse *pMouse, CField *pField, Scene::ISceneManager *pSceneMgr ) { Collision::CLine3D vRay( pSceneMgr->TransformFromScreen( Math::Vector3D(toF(pMouse->GetPosX()), toF(pMouse->GetPosY()), 0.0f) ), pSceneMgr->TransformFromScreen( Math::Vector3D(toF(pMouse->GetPosX()), toF(pMouse->GetPosY()), 1.0f) ) ); Renderer::SCollisionResult Ret; if( pField->GetMapActor( SCREEN_MAIN )->HitCheckByRay( vRay, Ret ) ) { m_vTarget = Ret.vHitPosition; } m_vDirection.x = m_vTarget.x - m_vPos.x; m_vDirection.y = 0.0f; m_vDirection.z = m_vTarget.z - m_vPos.z; m_fSpeed = 0.3f ; /*移動チェック*/ if( m_vDirection.LengthSq() > 0.0f ) { m_Rot.x = toF( Math::ATan2( m_vDirection.z, m_vDirection.x ) ); float fLength = m_vDirection.Length(); /*正規化*/ m_vDirection /= fLength; if( pMouse->GetClickL() ) { m_vPos += m_vDirection * m_fSpeed; } } }
//TODO : passer sur producer //(attention aux appels GL) void Atmosphere::makeOpticalDepthBuffer(void) { const int nSize = 256; const int nSamples = 50; const float fScale = 1.0f / (info->m_fOuterRadius - info->m_fInnerRadius); const int m_nChannels=4; float* opticalBuffer=(float*)malloc(sizeof(float)*m_nChannels*nSize*nSize); int nIndex = 0; for(int nAngle=0; nAngle<nSize; nAngle++) { // As the y tex coord goes from 0 to 1, the angle goes from 0 to 180 degrees float fCos = 1.0f - (nAngle+nAngle) / (float)nSize; float fAngle = acosf(fCos); glm::vec3 vRay(sinf(fAngle), cosf(fAngle), 0); // Ray pointing to the viewpoint for(int nHeight=0; nHeight<nSize; nHeight++) { // As the x tex coord goes from 0 to 1, the height goes from the bottom of the atmosphere to the top float fHeight = DELTA + info->m_fInnerRadius + ((info->m_fOuterRadius - info->m_fInnerRadius) * nHeight) / nSize; glm::vec3 vPos(0, fHeight, 0); // The position of the camera // If the ray from vPos heading in the vRay direction intersects the inner radius (i.e. the planet), then this spot is not visible from the viewpoint float B = 2.0f * glm::dot(vPos,vRay); float Bsq = B * B; float Cpart = glm::dot(vPos, vPos); float C = Cpart - info->m_fInnerRadius*info->m_fInnerRadius; float fDet = Bsq - 4.0f * C; bool bVisible = ((fDet < 0 )|| ((0.5f * (-B - sqrtf(fDet)) <= 0) && (0.5f * (-B + sqrtf(fDet)) <= 0))); float fRayleighDensityRatio; float fMieDensityRatio; if(bVisible) { fRayleighDensityRatio = expf(-(fHeight - info->m_fInnerRadius) * fScale / info->m_fRayleighScaleDepth); fMieDensityRatio = expf(-(fHeight - info->m_fInnerRadius) * fScale / info->m_fMieScaleDepth); } else { // Smooth the transition from light to shadow (it is a soft shadow after all) fRayleighDensityRatio = opticalBuffer[nIndex - nSize*m_nChannels] * 0.75f; fMieDensityRatio = opticalBuffer[nIndex+2 - nSize*m_nChannels] * 0.75f; } // Determine where the ray intersects the outer radius (the top of the atmosphere) // This is the end of our ray for determining the optical depth (vPos is the start) C = Cpart - info->m_fOuterRadius*info->m_fOuterRadius; fDet = Bsq - 4.0f * C; float fFar = 0.5f * (-B + sqrtf(fDet)); // Next determine the length of each sample, scale the sample ray, and make sure position checks are at the center of a sample ray float fSampleLength = fFar / nSamples; float fScaledLength = fSampleLength * fScale; glm::vec3 vSampleRay = (vRay*fSampleLength); vPos = (vPos+(vSampleRay*0.5f)); // Iterate through the samples to sum up the optical depth for the distance the ray travels through the atmosphere float fRayleighDepth = 0; float fMieDepth = 0; for(int i=0; i<nSamples; i++) { float fHeight = glm::length(vPos); float fAltitude = (fHeight - info->m_fInnerRadius) * fScale; if(fAltitude<0.0f)fAltitude=0.0f; fRayleighDepth += expf(-fAltitude / info->m_fRayleighScaleDepth); fMieDepth += expf(-fAltitude / info->m_fMieScaleDepth); vPos = (vPos+vSampleRay); } // Multiply the sums by the length the ray traveled fRayleighDepth *= fScaledLength; fMieDepth *= fScaledLength; // Store the results for Rayleigh to the light source, Rayleigh to the camera, Mie to the light source, and Mie to the camera opticalBuffer[nIndex++] = fRayleighDensityRatio; opticalBuffer[nIndex++] = fRayleighDepth; opticalBuffer[nIndex++] = fMieDensityRatio; opticalBuffer[nIndex++] = fMieDepth; } } glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, nSize, nSize, 0, GL_RGBA, GL_FLOAT, opticalBuffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); //important glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //important glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); free(opticalBuffer); }