Exemple #1
0
//-----------------------------------------------------------------------------
void GetStartShapeFromPreviousSearch (SHAPE &StartShape,     // out
        const SHAPE &PrevShape,     // in: final shape from previous search
        const SHAPE &MeanShape)     // in
{
if (MeanShape.nrows() == PrevShape.nrows())
    StartShape = PrevShape;
else if (MeanShape.nrows() < PrevShape.nrows())
    {
    StartShape = PrevShape;
    StartShape.dimKeep(MeanShape.nrows(), 2);
    }
else    // MeanShape.nrows() > PrevShape.nrows()
    {
    // The algorithm below is: use points from PrevShape where possible,
    // but of a point is unused in PrevShape, use the point from the
    // aligned MeanShape instead.

    // use "assign" not "=" because dims may be different
    StartShape.assign(MeanShape);
    SHAPE Combined(PrevShape);
    Combined.dimKeep(MeanShape.nrows(), 2);
    AlignShape(StartShape, Combined);
    const int nRows = PrevShape.nrows();
    for (unsigned iRow = 0; iRow < unsigned(nRows); iRow++)
        if (fPointUsed(StartShape, iRow))
            StartShape.row(iRow) = PrevShape.row(iRow);
    }
}
// Our Win32 main
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
    HWND hwnd = NULL; // Handle to our window
    MSG msg = {0};
    WNDCLASSEX wndclassex = {0};

    // Init fields we care about
    wndclassex.cbSize = sizeof(WNDCLASSEX); // Always set to size of WNDCLASSEX
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
    wndclassex.lpszClassName = kClassName;
    wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
                                            IMAGE_CURSOR, 0, 0, LR_SHARED);

    RegisterClassEx(&wndclassex); // Register the WNDCLASSEX

    RECT rect = { 0, 0, kWinWid, kWinHgt }; // Desired window client rect

    DWORD winStyleEx = WS_EX_CLIENTEDGE;
    DWORD winStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME;

    // Adjust window rect so it gives us our desired client rect when we
    // create the window
    AdjustWindowRectEx(&rect, winStyle, false, winStyleEx);

    // Create the window
    hwnd = CreateWindowEx(winStyleEx,
                          kClassName,
                          "www.GameTutorials.com -- Render Targets",
                          winStyle,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          rect.right - rect.left,
                          rect.bottom - rect.top,
                          NULL,
                          NULL,
                          hinstance,
                          NULL);

    // Get the client rect and make sure our client is the size we want
    GetClientRect(hwnd, &rect);
    assert(rect.right == kWinWid && rect.bottom == kWinHgt);



    // Init our global 3D object
    if(g3D->init(hwnd) == false)
        return EXIT_FAILURE; // There's been an error, lets get out of this joint

    if(!gBlurTexture1.createRenderTexture(256, 256, D3DFMT_A8R8G8B8))
        return false; // Couldn't create a off screen texture to render to

    if(!gBlurTexture2.createRenderTexture(256, 256, D3DFMT_A8R8G8B8))
        return false; // Couldn't create a off screen texture to render to

    if(!gDiffTex.load("texture.jpg"))
        return false;

    if(!gRenderTarget.init(256, 256, D3DFMT_A8R8G8B8, D3DFMT_D24S8))
        return false; // Couldn't create a render texture... Does your video card support this?

    Make3x3GuassianDistribution();

    // Set up our projection matrix once because it will not change
    g3D->setProjMatrix(DEG2RAD(60), 1.0f, 2048.0f);

    // We set up our view matrix once because it will never change
    g3D->setViewMatrix(kEyePos, CPos(0.0f, 0.0f, 0.0f));

    g3D->mShader->SetFloatArray("gEyePos", &kEyePos.x, 3); // Set the camera's eye position
    g3D->mShader->SetFloatArray("gBlurWeights", gBlurWeights, 9); // Gaussian blur weights

    // Show and update the window
    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);

    while(1) // While the app is alive
    {
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // If the OS has a message for us
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(LockFrameRate()) // Else, if it's time to draw
        {
            // Render the off screen texture (created directly above) to another
            // off screen texture using a Gaussian blur
            if(gToggle)
                Combined();
            else
                RenderSobelFilter();

            // Render the two textures to the screen
            RenderScene();
        }
        else
            Sleep(1); // Otherwise, give the OS some time to process other programs

    } // end of while(1)

    g3D->deinit(); // Free up the D3D object
    UnregisterClass(kClassName,hinstance); // Free up WNDCLASSEX
    return EXIT_SUCCESS; // Application was a success
}