C++ Errore idiota con classe
  • In diretta da GamesVillage.it
    • News
    • -
    • In Evidenza
    • -
    • Recensioni
    • -
    • RetroGaming
    • -
    • Anteprime
    • -
    • Video
    • -
    • Cinema

Visualizzazione risultati da 1 a 7 di 7

Discussione: C++ Errore idiota con classe

Cambio titolo
  1. #1
    Puppppppaaaaaaaaaaa L'avatar di Revan1985
    Registrato il
    01-06
    Località
    Solbiate Olona
    Messaggi
    1.655

    C++ Errore idiota con classe

    Ho VS2008 che come suo solito si trova problemi inesistenti...

    mi dà errore di questo tipo :
    Codice:
    1>------ Build started: Project: OGL01, Configuration: Debug Win32 ------
    1>Compiling...
    1>Application.cpp
    1>c:\users\revan1985\documents\visual studio 2008\projects\ogl01\ogl01\application.cpp(35) : error C2227: left of '->MoveUp' must point to class/struct/union/generic type
    1>c:\users\revan1985\documents\visual studio 2008\projects\ogl01\ogl01\application.cpp(38) : error C2227: left of '->MoveDown' must point to class/struct/union/generic type
    1>c:\users\revan1985\documents\visual studio 2008\projects\ogl01\ogl01\application.cpp(41) : error C2227: left of '->MoveLeft' must point to class/struct/union/generic type
    1>c:\users\revan1985\documents\visual studio 2008\projects\ogl01\ogl01\application.cpp(44) : error C2227: left of '->MoveRight' must point to class/struct/union/generic type
    1>Generating Code...
    1>Compiling...
    1>Camera.cpp
    1>Generating Code...
    1>Skipping... (no relevant changes detected)
    1>WMain.cpp
    1>Build log was saved at "file://c:\Users\Revan1985\Documents\Visual Studio 2008\Projects\OGL01\OGL01\Debug\BuildLog.htm"
    1>OGL01 - 4 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    ora, il fatto è che io cam l'ho dichiarato come Camera* cam;
    perchè c**** non me lo trova?!?
    e comunque qui il codice di camera

    [Camera.h]
    Codice:
    #ifndef __CAMERA_H__
    #define __CAMERA_H__
    
    #include "stdafx.h"
    
    class Camera
    {
    private:
        float speed;
        D3DXVECTOR3 position;
        D3DXVECTOR3 lookAt;
        D3DXMATRIX shaderMatrix;
        D3DXMATRIX viewMatrix;
        D3DXMATRIX worldMatrix;
        D3DXMATRIX projectionMatrix;
        LPD3D10EFFECTMATRIXVARIABLE effectWorldMatrix;
    public:
        Camera();
        ~Camera();
        void Init(LPD3D10EFFECT effect);
        void MoveUp();
        void MoveDown();
        void MoveLeft();
        void MoveRight();
        void Update(float deltaTime);
    };
    
    #endif
    [Camera.cpp]
    Codice:
    #include "Camera.h"
    #include "stdafx.h"
    
    Camera::Camera()
    {
        D3DXMatrixIdentity(&shaderMatrix);
        D3DXMatrixIdentity(&worldMatrix);
        D3DXMatrixIdentity(&viewMatrix);
        D3DXMatrixIdentity(&projectionMatrix);
        D3DXMatrixPerspectiveFovLH(&projectionMatrix, float(D3DX_PI) / 4.0f, 1.0f, 0.1f, 1000.0f);
    }
    
    Camera::~Camera()
    {
    }
    
    void Camera::MoveDown()
    {
        lookAt.y -= speed;
    }
    
    void Camera::MoveUp()
    {
        lookAt.y += speed;
    }
    
    void Camera::MoveRight()
    {
        lookAt.x -= speed;
    }
    
    void Camera::MoveLeft()
    {
        lookAt.x += speed;
    }
    
    void Camera::Update(float deltaTime)
    {
        D3DXMatrixTranslation(&worldMatrix, sinf(deltaTime), 0.0f, 0.0f);
        D3DXMatrixLookAtLH(&viewMatrix, &position, &lookAt, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
        shaderMatrix = viewMatrix * projectionMatrix * worldMatrix;
        effectWorldMatrix->SetMatrix((float*)&shaderMatrix);
    }
    
    void Camera::Init(LPD3D10EFFECT effect)
    {
        speed = 0.001f;
        effectWorldMatrix = effect->GetVariableByName("ShaderMatrix")->AsMatrix();
    }
    son sicuro di non aver sbagliato niente...
    infatti i metodi Update(); Init() et simili, con cam-> funzionano...

    qui il pezzo incriminato:
    [Application.cpp]
    Codice:
    /* Gestione dei messaggi di windows */
    LRESULT CALLBACK Application::WndProc( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam)
    {
        switch(message){
            case WM_CLOSE:
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            case WM_KEYDOWN:
                switch(wParam)
                {
                case VK_UP:
                    cam->MoveUp();
                    break;
                case VK_DOWN:
                    cam->MoveDown();
                    break;
                case VK_LEFT:
                    cam->MoveLeft();
                    break;
                case VK_RIGHT:
                    cam->MoveRight();
                    break;
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;
                }
                break;
        }
    
        return DefWindowProc(hWnd,message,wParam,lParam);
    }
    È stato detto che la democrazia è la peggior forma di governo, eccezion fatta per tutte quelle altre forme che si sono sperimentate finora.


  2. #2
    Utente L'avatar di devilheart
    Registrato il
    01-03
    Messaggi
    28.310
    WndProc da dove prende il puntatore cam? è utile postare anche quel pezzo di codice

  3. #3
    Puppppppaaaaaaaaaaa L'avatar di Revan1985
    Registrato il
    01-06
    Località
    Solbiate Olona
    Messaggi
    1.655
    sono un deficente io...
    tento di richiamare da un codice static uno non-static...
    come posso fare,a vendo WndProc statico, a richiamare cam che è non statico?

    posto il resto del codice...

    [Application.h]
    Codice:
    #ifndef __APPLICATION_H__
    #define __APPLICATION_H__
    
    #include "stdafx.h"
    #include "Camera.h"
    
    class Application
    {
    public:
    
        Application();
        ~Application();
    
        bool CreateD3DWindow(int width, int height);
    
        bool Initialize();
        void Render(float deltaTime);
        void MainLoop();
    
    private:
    
        bool InitEffect();
        bool InitVertexBuffer();
        bool InitRenderTargetView();
        bool InitDepthStencilView(int w, int h);
        static LRESULT CALLBACK WndProc( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam);
    
        HWND                            hWnd;
        IDXGISwapChain*                    pSwapChain;
        ID3D10RenderTargetView*            pRenderTargetView;
        ID3D10DepthStencilView*            pDepthStencilView;
        ID3D10Device*                    pDevice;
        int                                width, height;
    
        ID3D10Buffer*                    pVertexBuffer;
        ID3D10InputLayout*                pVertexLayout;
    
        LPD3D10EFFECT                    pEffect;
        LPD3D10EFFECTTECHNIQUE            pTechnique;
    
        Camera *cam;
    };
    
    #endif
    [Application.cpp]
    Codice:
    #include "Application.h"
    
    /* Costruttore */
    Application::Application()
    {
        cam = new Camera();
    }
    
    /* Distruttore */
    Application::~Application()
    {
        if(pDevice){ pDevice->ClearState(); }
        if(pSwapChain){ pSwapChain->Release(); }
        if(pRenderTargetView){ pRenderTargetView->Release(); }
        if(pDepthStencilView){ pDepthStencilView->Release(); }
        if(pVertexBuffer){ pVertexBuffer->Release(); }
        if(pVertexLayout){ pVertexLayout->Release(); }
        if(pEffect){ pEffect->Release(); }
        if(pDevice){ pDevice->Release(); }
        if(cam){ delete cam; }
    }
    
    /* Gestione dei messaggi di windows */
    LRESULT CALLBACK Application::WndProc( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam)
    {
        switch(message){
            case WM_CLOSE:
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            case WM_KEYDOWN:
                switch(wParam)
                {
                case VK_UP:
                    cam->MoveUp();
                    break;
                case VK_DOWN:
                    cam->MoveDown();
                    break;
                case VK_LEFT:
                    cam->MoveLeft();
                    break;
                case VK_RIGHT:
                    cam->MoveRight();
                    break;
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;
                }
                break;
        }
    
        return DefWindowProc(hWnd,message,wParam,lParam);
    }
    
    /* Crea la finestra Win32 */
    bool Application::CreateD3DWindow(int width, int height)
    {
        this->width = width;
        this->height = height;
        
    // Create A Window Class Structure
    WNDCLASSEX wc;
        ZeroMemory(&wc, sizeof(wc));        
    wc.cbSize = sizeof(wc);                
    wc.hInstance = GetModuleHandle(NULL);        
    wc.lpfnWndProc = WndProc;                    
    wc.lpszClassName = "GPORG";                        
    wc.style = CS_HREDRAW | CS_VREDRAW;            
        
    // Register Window Class
    RegisterClassEx(&wc);
        
    // Create Window
    hWnd = CreateWindowEx(0,
    "GPORG", "GameProgrammer.org Direct3D 10 Tutorial",
    WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, width, height,
    NULL,NULL,wc.hInstance,0);
        
    return true;
    }
    
    /* Inizializza le Directx10 */
    bool Application::Initialize()
    {
        DXGI_SWAP_CHAIN_DESC swapChainDesc;
        ZeroMemory( &swapChainDesc, sizeof(swapChainDesc) );
        swapChainDesc.BufferCount = 1;
        swapChainDesc.BufferDesc.Width = width;
        swapChainDesc.BufferDesc.Height = height;
        swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        swapChainDesc.OutputWindow = hWnd;
        swapChainDesc.SampleDesc.Count = 1;
        swapChainDesc.SampleDesc.Quality = 0;
        swapChainDesc.Windowed = TRUE;
    
        if( FAILED( D3D10CreateDeviceAndSwapChain( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL,
            0, D3D10_SDK_VERSION, &swapChainDesc, &pSwapChain, &pDevice ) ) )
        {
            if( FAILED( D3D10CreateDeviceAndSwapChain( NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL,
                0, D3D10_SDK_VERSION, &swapChainDesc, &pSwapChain, &pDevice ) ) )
            {
                MBError("Failed to create device and swap chain.");
                return false;
            }
        }
    
        if(InitRenderTargetView() == false){ return false; }
        if(InitDepthStencilView(width, height) == false){ return false; }
    
        pDevice->OMSetRenderTargets( 1, &pRenderTargetView, pDepthStencilView );
    
        D3D10_VIEWPORT vp = {0, 0, width, height, 0, 1};
        pDevice->RSSetViewports( 1, &vp );
    
        if(InitEffect() == false){ return false; }
        if(InitVertexBuffer() == false){ return false; }
    
        //Setta il Vertex Buffer
        UINT stride = sizeof(COLORED_VERTEX);
        UINT offset = 0;
        pDevice->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);
    
        //Setta la Topology delle primitive
        pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
    
        cam->Init(pEffect);
    
        return true;
    }
    
    /* Inizializza l'effetto [shader] */
    bool Application::InitEffect()
    {
        //Crea lo Shader (Effect)
        HRESULT res;
        ID3D10Blob* error;
        D3DX10CreateEffectFromFile("./shader.fx", NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS,
            0, pDevice, NULL, NULL, &pEffect, &error, &res);
        if(FAILED(res))
        {
            MBError((char*)error->GetBufferPointer());
            return false;
        }
        //Ottieni la tecnica
        pTechnique = pEffect->GetTechniqueByName("Render");
        return true;
    }
    /* Crea il Vertex Buffer */
    bool Application::InitVertexBuffer()
    {
        //Definisci l'InputLayout (Rimpiazzamento del VertexDeclaration per D3D9)
        D3D10_INPUT_ELEMENT_DESC elementDesc[] =
        {
            { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
            { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        };
        UINT numElements = sizeof(elementDesc) / sizeof(elementDesc[0]);
    
        //Crea l'inputLayout
        D3D10_PASS_DESC PassDesc;
        pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);
        if(FAILED(pDevice->CreateInputLayout(elementDesc, numElements, PassDesc.pIAInputSignature,
            PassDesc.IAInputSignatureSize, &pVertexLayout)))
        {
            MBError("Errore nella creazione dell Vertex Layout");
            return false;
        }
        //Setta l'Input Layout
        pDevice->IASetInputLayout(pVertexLayout);
    
        //Crea il Vertex Buffer
        COLORED_VERTEX pVertices[4];
        pVertices[0].Position = D3DXVECTOR3( -1.0f, -1.0f, 0.0f);    //L - B
        pVertices[0].Color = 0xffff0000;    //Red
        pVertices[1].Position = D3DXVECTOR3( -1.0f,  1.0f, 0.0f);    //L - T
        pVertices[1].Color = 0xff00ff00;    //Green
        pVertices[2].Position = D3DXVECTOR3(  1.0f, -1.0f, 0.0f);    //R - B
        pVertices[2].Color = 0xff0000ff;    //Blue
        pVertices[3].Position = D3DXVECTOR3(  1.0f,  1.0f, 0.0f);    //R - T
        pVertices[3].Color = 0xffffffff;    //White
    
        //Crea il Descrittore del Buffer
        D3D10_BUFFER_DESC bd;
        bd.Usage = D3D10_USAGE_DEFAULT;
        bd.ByteWidth = sizeof(COLORED_VERTEX) * 4;
        bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
        bd.CPUAccessFlags = 0;
        bd.MiscFlags = 0;
        
        D3D10_SUBRESOURCE_DATA InitData;
        InitData.pSysMem = &pVertices;
    
        //Finalmente creiamo il Vertex Buffer
        if(FAILED(pDevice->CreateBuffer(&bd, &InitData, &pVertexBuffer)))
        {
            MBError("Impossibile creare il Vertex Buffer");
            return false;
        }
        return true;
    }
    /* Inizializza il Render Target */
    bool Application::InitRenderTargetView()
    {
        ID3D10Texture2D *pBackBuffer;
        if( FAILED( pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), (LPVOID*)&pBackBuffer ) ) )
        {
            MBError("Failed to create back buffer.");
            return false;
        }
    
        if(FAILED( pDevice->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView )))
        {
            MBError("Failed to create render target view.");
            return false;
        }
    
        pBackBuffer->Release();
        return true;
    }
    /* Inizializza il Depth Buffer */
    bool Application::InitDepthStencilView(int w, int h)
    {
        D3D10_TEXTURE2D_DESC descDepth;
        descDepth.Width = w;
        descDepth.Height = h;
        descDepth.MipLevels = 1;
        descDepth.ArraySize = 1;
        descDepth.Format = DXGI_FORMAT_D32_FLOAT;
        descDepth.SampleDesc.Count = 1;
        descDepth.SampleDesc.Quality = 0;
        descDepth.Usage = D3D10_USAGE_DEFAULT;
        descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
        descDepth.CPUAccessFlags = 0;
        descDepth.MiscFlags = 0;
    
        ID3D10Texture2D* depthBuffer;
        if(FAILED(pDevice->CreateTexture2D(&descDepth, NULL, &depthBuffer)))
        {
            MBError("Failed to create the depth Buffer");
            return false;
        }
    
        D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
        descDSV.Format = descDepth.Format;
        descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
        descDSV.Texture2D.MipSlice = 0;
    
        if(FAILED(pDevice->CreateDepthStencilView(depthBuffer, &descDSV, &pDepthStencilView)))
        {
            MBError("Failed to create Depth Stencil View");
            return false;
        }
    
        depthBuffer->Release();
    
        return true;
    }
    /* Renderizza a schermo */
    void Application::Render(float deltaTime)
    {
        cam->Update(deltaTime);
    
        pDevice->ClearRenderTargetView( pRenderTargetView, D3DXVECTOR4(0.2f, 0.2f, 0.5f, 1) );
        pDevice->ClearDepthStencilView( pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
    
        //Renderizza il Quadrato
        D3D10_TECHNIQUE_DESC techDesc;
        pTechnique->GetDesc(&techDesc);
        for(UINT p = 0; p < techDesc.Passes; ++p)
        {
            pTechnique->GetPassByIndex(p)->Apply(0);
            pDevice->Draw(4, 0);
        }
    
        pSwapChain->Present( 0, 0 );
    }
    /* Loop principale */
    void Application::MainLoop()
    {
        MSG msg;
        long prevTime = GetTickCount(), curTime = GetTickCount();
        while(true)
        {
            if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                if(msg.message==WM_QUIT)
                    break;
    
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else{
                Render((curTime-prevTime)/1000.f);
                prevTime = curTime;
                curTime = GetTickCount();
            }
        }
    }
    come posso risolvere?
    È stato detto che la democrazia è la peggior forma di governo, eccezion fatta per tutte quelle altre forme che si sono sperimentate finora.


  4. #4
    Utente L'avatar di devilheart
    Registrato il
    01-03
    Messaggi
    28.310
    non credo che tu possa. se avrai sembre al massimo una istanza di Application in giro puoi mettere anche cam come static

  5. #5
    Puppppppaaaaaaaaaaa L'avatar di Revan1985
    Registrato il
    01-06
    Località
    Solbiate Olona
    Messaggi
    1.655
    trovato soluzione...
    bastava usare un metodo strambo per agganciare un wndproc non statica con quella statica...

    la statica
    Codice:
    LRESULT CALLBACK Application::StaticWndProc( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam)
    {
        Application* parent;
        if(message == WM_CREATE)
        {
            parent = (Application*)((LPCREATESTRUCT)lParam)->lpCreateParams;
            SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)parent);
        }
        else
        {
            parent = (Application*)GetWindowLongPtr(hWnd, GWL_USERDATA);
            if(!parent){ return DefWindowProc(hWnd,message,wParam,lParam); }
        }
    
        //parent->m_hWnd = hWnd;
        return parent->WndProc(hWnd, message, wParam, lParam);
    }
    poi quella non statica si una normalmente...
    È stato detto che la democrazia è la peggior forma di governo, eccezion fatta per tutte quelle altre forme che si sono sperimentate finora.


  6. #6
    Utente L'avatar di devilheart
    Registrato il
    01-03
    Messaggi
    28.310
    c'&#232; un motivo particolare per usare una WndProc statica?

  7. #7
    Puppppppaaaaaaaaaaa L'avatar di Revan1985
    Registrato il
    01-06
    Località
    Solbiate Olona
    Messaggi
    1.655
    se passi una WndProc non statica, il compilatore ti dice...
    ma dove cavolo la trovo io
    È stato detto che la democrazia è la peggior forma di governo, eccezion fatta per tutte quelle altre forme che si sono sperimentate finora.


Regole di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •