0

这是我的 DirectXBase 类头:

#pragma once

#include "pch.h"

struct Vertex
{   
XMFLOAT3 pos;
XMFLOAT3 color;
};

struct ModelViewProjectionConstantBuffer
{
DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};

ref class DirectXBase abstract
{
internal:
DirectXBase();

virtual void Initialize(
    Windows::UI::Core::CoreWindow^ window,
    Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
    float dpi);

virtual void HandleDeviceLost();
virtual void CreateDeviceIndependentResources();
virtual void CreateDeviceResources();
virtual void SetDpi(float dpi);
virtual void UpdateForWindowSizeChanged();
virtual void CreateWindowSizeDependentResources();
virtual void Render() = 0;
virtual void Present();
void ValidateDevice();  
virtual float ConvertDipsToPixels(float dips);

protected private:
Windows::UI::Core::CoreWindow^ m_window;
Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_swapChainPanel;

// Transforms used for display orientation.
D2D1::Matrix3x2F                                m_rotationTransform2D;
DirectX::XMFLOAT4X4                             m_rotationTransform3D;
DXGI_MODE_ROTATION ComputeDisplayRotation();

//Directx Core Objects
Microsoft::WRL::ComPtr<ID3D11Device1>           m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1>    m_d3dContext;
Microsoft::WRL::ComPtr<IDXGISwapChain1>         m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  m_d3dRenderTargetView;

// Cached renderer properties.
D3D_FEATURE_LEVEL                               m_featureLevel;
Windows::Foundation::Size                       m_renderTargetSize;
Windows::Foundation::Rect                       m_windowBounds;
float                                           m_dpi;
Windows::Graphics::Display::DisplayOrientations m_orientation;
bool                                            m_stereoEnabled;

// Direct3D Rendering Objects. Required for 3D.
Microsoft::WRL::ComPtr<ID3D11DepthStencilView>  m_d3dDepthStencilView;

// Transform used for display orientation.
DirectX::XMFLOAT4X4 m_orientationTransform3D;
};

我收到以下错误消息:

syntax error : missing ';' before identifier 'pos'

我不知道为什么它不能识别我的结构。有趣的是,我只是从继承自该类的 CubeRenderer 类的标头中复制并粘贴了它,这样我就可以从任何继承类访问这些结构……代码运行在大约五分钟前复制。

如果它有帮助,这里是我的两个子类头文件,其中结构移动到这些头文件,编译和运行良好。

立方体渲染器.h:

#pragma once

#include "DirectXBase.h"
#include <DirectXMath.h>

using namespace DirectX;

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct CubeVertex
{   
XMFLOAT3 pos;
XMFLOAT3 color;
};

struct CubeMVPBuffer
{
DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};

ref class CubeRenderer : public DirectXBase
{
internal:
CubeRenderer();

virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;
void Update(float timeTotal, float timeDelta);
private:
bool m_loadingComplete;

Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;

uint32 m_indexCount;
CubeMVPBuffer m_constantBufferData;
};

HillRenderer.h:

#pragma once

#include "DirectXBase.h"
#include <DirectXMath.h>

using namespace DirectX;

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct HillVertex
{   
    XMFLOAT3 pos;
    XMFLOAT3 color;
};

struct HillMVPBuffer
{
    DirectX::XMFLOAT4X4 model;
    DirectX::XMFLOAT4X4 view;
    DirectX::XMFLOAT4X4 projection;
};

ref class HillRenderer : public DirectXBase
{
internal:
    HillRenderer();

    virtual void CreateDeviceResources() override;
    virtual void CreateWindowSizeDependentResources() override;
    virtual void Render() override;
    void Update(float timeTotal, float timeDelta);
private:
    bool m_loadingComplete;

    Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
    Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
    Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;

    uint32 m_indexCount;
    HillMVPBuffer m_constantBufferData;

    float GetHeight(float x, float z) const
    {
        return 0.3f*(z*sinf(0.1f*x) + x*cosf(0.1f*z));
    }
};
4

1 回答 1

0

您的结构类型“不起作用”是因为当您声明该结构时,编译器(尚)不知道是什么XMFLOAT3意思。

在你可以使用XMFLOAT3类型之前,它必须在某个地方声明。我的猜测是它是DirectXMath.h #include DirectXMath.h在开头声明的DirectXBase.h,它应该可以工作。

于 2013-10-17T21:22:51.827 回答