⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portals.cpp

📁 3D Game Engine Design Source Code非常棒
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    pkC00->GetPortal(2)->AdjacentRegion() = pkC20;
    pkC00->GetPortal(3)->AdjacentRegion() = pkCm20;
    pkC02->GetPortal(0)->AdjacentRegion() = pkC00;
    pkC02->GetPortal(1)->AdjacentRegion() = pkC04;
    pkC0m2->GetPortal(0)->AdjacentRegion() = pkC0m4;
    pkC0m2->GetPortal(1)->AdjacentRegion() = pkC00;
    pkC20->GetPortal(0)->AdjacentRegion() = pkC40;
    pkC20->GetPortal(1)->AdjacentRegion() = pkC00;
    pkCm20->GetPortal(0)->AdjacentRegion() = pkC00;
    pkCm20->GetPortal(1)->AdjacentRegion() = pkCm40;
    pkC04->GetPortal(0)->AdjacentRegion() = pkDMP;
    pkC04->GetPortal(1)->AdjacentRegion() = pkDPP;
    pkC04->GetPortal(2)->AdjacentRegion() = pkC02;
    pkC0m4->GetPortal(0)->AdjacentRegion() = pkDPM;
    pkC0m4->GetPortal(1)->AdjacentRegion() = pkDMM;
    pkC0m4->GetPortal(2)->AdjacentRegion() = pkC0m2;
    pkC40->GetPortal(0)->AdjacentRegion() = pkDPP;
    pkC40->GetPortal(1)->AdjacentRegion() = pkDPM;
    pkC40->GetPortal(2)->AdjacentRegion() = pkC20;
    pkCm40->GetPortal(0)->AdjacentRegion() = pkDMM;
    pkCm40->GetPortal(1)->AdjacentRegion() = pkDMP;
    pkCm40->GetPortal(2)->AdjacentRegion() = pkCm20;
    pkDPP->GetPortal(0)->AdjacentRegion() = pkC40;
    pkDPP->GetPortal(1)->AdjacentRegion() = pkC04;
    pkDMP->GetPortal(0)->AdjacentRegion() = pkC04;
    pkDMP->GetPortal(1)->AdjacentRegion() = pkCm40;
    pkDMM->GetPortal(0)->AdjacentRegion() = pkCm40;
    pkDMM->GetPortal(1)->AdjacentRegion() = pkC0m4;
    pkDPM->GetPortal(0)->AdjacentRegion() = pkC0m4;
    pkDPM->GetPortal(1)->AdjacentRegion() = pkC40;

    // depth-first attachment
    pkC->AttachLeftChild(0);
    pkC->AttachRightChild(pkR);
        pkR->AttachLeftChild(0);
        pkR->AttachRightChild(pkRR);
            pkRR->AttachLeftChild(pkRRL);
                pkRRL->AttachLeftChild(pkRRLL);
                    pkRRLL->AttachLeftChild(pkRRLLL);
                        pkRRLLL->AttachLeftChild(0);
                        pkRRLLL->AttachRightChild(pkDPP);
                    pkRRLL->AttachRightChild(0);
                pkRRL->AttachRightChild(pkRRLR);
                    pkRRLR->AttachLeftChild(pkRRLRL);
                        pkRRLRL->AttachLeftChild(pkRRLRLL);
                            pkRRLRLL->AttachLeftChild(0);
                            pkRRLRLL->AttachRightChild(pkDPM);
                        pkRRLRL->AttachRightChild(0);
                    pkRRLR->AttachRightChild(pkRRLRR);
                        pkRRLRR->AttachLeftChild(pkRRLRRL);
                            pkRRLRRL->AttachLeftChild(0);
                            pkRRLRRL->AttachRightChild(pkC40);
                        pkRRLRR->AttachRightChild(pkC20);
            pkRR->AttachRightChild(pkRRR);
                pkRRR->AttachLeftChild(pkRRRL);
                    pkRRRL->AttachLeftChild(pkRRRLL);
                        pkRRRLL->AttachLeftChild(pkRRRLLL);
                            pkRRRLLL->AttachLeftChild(0);
                            pkRRRLLL->AttachRightChild(pkDMP);
                        pkRRRLL->AttachRightChild(0);
                    pkRRRL->AttachRightChild(pkRRRLR);
                        pkRRRLR->AttachLeftChild(pkRRRLRL);
                            pkRRRLRL->AttachLeftChild(pkRRRLRLL);
                                pkRRRLRLL->AttachLeftChild(0);
                                pkRRRLRLL->AttachRightChild(pkDMM);
                            pkRRRLRL->AttachRightChild(0);
                        pkRRRLR->AttachRightChild(pkRRRLRR);
                            pkRRRLRR->AttachLeftChild(pkRRRLRRL);
                                pkRRRLRRL->AttachLeftChild(0);
                                pkRRRLRRL->AttachRightChild(pkCm40);
                            pkRRRLRR->AttachRightChild(pkCm20);
                pkRRR->AttachRightChild(pkRRRR);
                    pkRRRR->AttachLeftChild(pkRRRRL);
                        pkRRRRL->AttachLeftChild(pkRRRRLL);
                            pkRRRRLL->AttachLeftChild(0);
                            pkRRRRLL->AttachRightChild(pkC04);
                        pkRRRRL->AttachRightChild(pkC02);
                    pkRRRR->AttachRightChild(pkRRRRR);
                        pkRRRRR->AttachLeftChild(pkRRRRRL);
                            pkRRRRRL->AttachLeftChild(pkRRRRRLL);
                                pkRRRRRLL->AttachLeftChild(0);
                                pkRRRRRLL->AttachRightChild(pkC0m4);
                            pkRRRRRL->AttachRightChild(pkC0m2);
                        pkRRRRR->AttachRightChild(pkC00);
    return pkC;
}
//----------------------------------------------------------------------------
bool Portals::InitializeTextures ()
{
    Texture* pkTexture;
    Image* pkImage;

    pkTexture = new Texture;
    pkImage = Image::Load("Agate.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureAgate = new TextureState;
    m_spkTextureAgate->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Bark.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureBark = new TextureState;
    m_spkTextureBark->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Buff.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureBuff = new TextureState;
    m_spkTextureBuff->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Connector.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureConnector = new TextureState;
    m_spkTextureConnector->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Dave.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureDave = new TextureState;
    m_spkTextureDave->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Munch.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureMunch = new TextureState;
    m_spkTextureMunch->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Pebbles.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTexturePebbles = new TextureState;
    m_spkTexturePebbles->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Quartz.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureQuartz = new TextureState;
    m_spkTextureQuartz->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Sand.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureSand = new TextureState;
    m_spkTextureSand->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Shelly.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureShelly = new TextureState;
    m_spkTextureShelly->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Sky.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureSky = new TextureState;
    m_spkTextureSky->Set(0,pkTexture);

    pkTexture = new Texture;
    pkImage = Image::Load("Water.mif");
    if ( !pkImage ) return false;
    pkTexture->SetImage(pkImage);
    pkTexture->Filter() = Texture::FM_LINEAR;
    pkTexture->Mipmap() = Texture::MM_LINEAR;
    pkTexture->Wrap() = Texture::WM_CLAMP_S_CLAMP_T;
    m_spkTextureWater = new TextureState;
    m_spkTextureWater->Set(0,pkTexture);

    return true;
}
//----------------------------------------------------------------------------
bool Portals::OnInitialize ()
{
    if ( !Application::OnInitialize() )
        return false;

    // set up camera
    ms_spkCamera->SetFrustum(0.1f,100.0f,-0.055f,0.055f,0.04125f,-0.04125f);
    Vector3f kCLoc(0.0f,0.0f,1.0f);
    Vector3f kCLeft(-1.0f,0.0f,0.0f);
    Vector3f kCUp(0.0f,0.0f,1.0f);
    Vector3f kCDir(0.0f,1.0f,0.0f);
    ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir);

    // set up scene
    m_spkScene = new Node;

    m_spkWireframe = new WireframeState;
    m_spkWireframe->Enabled() = false;
    m_spkScene->SetRenderState(m_spkWireframe);

    m_spkZBuffer = new ZBufferState;
    m_spkZBuffer->Enabled() = true;
    m_spkZBuffer->Writeable() = true;
    m_spkZBuffer->Compare() = ZBufferState::CF_LEQUAL;
    m_spkScene->SetRenderState(m_spkZBuffer);

    if ( !InitializeTextures() )
        return true;

    ConvexRegionManager* pkCRM = CreateBspTree();
    pkCRM->AttachOutside(CreateOutside());
    m_spkScene->AttachChild(pkCRM);

    // initial update of objects
    ms_spkCamera->Update();
    m_spkScene->UpdateGS(0.0f);
    m_spkScene->UpdateRS();

    m_bTurretActive = true;
    SetTurretAxes();
    m_fTrnSpeed = 0.01f;
    m_fRotSpeed = 0.01f;

    m_bInitialized = true;
    return true;
}
//----------------------------------------------------------------------------
void Portals::OnTerminate ()
{
    m_spkZBuffer = NULL;
    m_spkWireframe = NULL;
    m_spkTextureAgate = NULL;
    m_spkTextureBark = NULL;
    m_spkTextureBuff = NULL;
    m_spkTextureConnector = NULL;
    m_spkTextureDave = NULL;
    m_spkTextureMunch = NULL;
    m_spkTexturePebbles = NULL;
    m_spkTextureQuartz = NULL;
    m_spkTextureSand = NULL;
    m_spkTextureShelly = NULL;
    m_spkTextureSky = NULL;
    m_spkTextureWater = NULL;
    m_spkScene = NULL;

    Application::OnTerminate();
}
//----------------------------------------------------------------------------
void Portals::OnIdle ()
{
    MeasureTime();

    MoveCamera();

    ms_spkRenderer->ClearBuffers();
    if ( ms_spkRenderer->BeginScene() )
    {
        if ( m_bInitialized )
        {
            ms_spkRenderer->Draw(m_spkScene);
            DrawFrameRate(8,GetHeight()-8,ColorRGB::WHITE);
        }
        else
        {
            ms_spkRenderer->Draw(8,16,ColorRGB::WHITE,
                "Load of texture images failed.");
            ms_spkRenderer->Draw(8,32,ColorRGB::WHITE,
                "Make sure these files are in the same directory as the "
                "executable.");
        }

        ms_spkRenderer->EndScene();
    }
    ms_spkRenderer->DisplayBackBuffer();

    UpdateClicks();
}
//----------------------------------------------------------------------------
void Portals::OnKeyDown (unsigned char ucKey, int, int)
{
    if ( ucKey == 'q' || ucKey == 'Q' || ucKey == KEY_ESCAPE )
    {
        RequestTermination();
        return;
    }

    switch ( ucKey )
    {
    case '0':  // reset frame rate measurements
        ResetTime();
        return;
    case 'w':
        m_spkWireframe->Enabled() = !m_spkWireframe->Enabled();
        return;
    }
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -