2011-12-31 98 views
2

我已經問題在C#陣列。我在C#中很新,我習慣用java做程序。 我想從C++調用這個代碼爲C#。 這是C++陣列中結構C#

typedef struct point_3d {   // Structure for a 3-dimensional point (NEW) 
    double x, y, z; 
} POINT_3D; 

typedef struct bpatch {    // Structure for a 3rd degree bezier patch (NEW) 
    POINT_3D anchors[4][4];   // 4x4 grid of anchor points 
    GLuint  dlBPatch;    // Display List for Bezier Patch 
    GLuint  texture;    // Texture for the patch 
} BEZIER_PATCH; 

我已經在C#中的Vector3結構是浮動的X,Y,Z(我不需要雙...) 現在我試圖使結構用bpatch和我的代碼陣列的申報有問題

[StructLayout(LayoutKind.Sequential)] 
struct BPatch 
{ 
    Vector3[][] anchors = new Vector3[4][4]; //there is the problem 
    uint dblPatch; // I'll probably have to change this two lines but it doesn't matter now 
    uint texture; 

} 

我該怎麼做錯?我需要在結構阿雷4×4,它的類型應該是其被聲明爲浮動的x,浮子Y,浮子Ž結構的Vector3。 由於

+0

什麼讓你覺得C++'POINT_3D'轉換到.NET'Vector3'? – Oded 2011-12-31 15:58:40

+0

爲什麼不呢?我按照NEHE http://nehe.gamedev.net/tutorial/bezier_patches__fullscreen_fix/18003/ 的這個教程工作,point3D有座標x,y,z和Vector3我提到我已經準備好在圖書館裏使用它,它給了我們我們的大學老師,還有操作添加和其他人..所以我用它。 – user1097772 2011-12-31 16:45:06

回答

1

在C#,的Vector3 [] []是不是一個矩陣但數組的數組。所以,你需要這樣做:

anchors = new Vector3[4][]; 
for(var i=0;i<anchors.Length;i++) 
    anchors[i] = new Vector3[4]; 

下面是從MSDN http://msdn.microsoft.com/en-us/library/2s05feca.aspx

一些文檔的另一種方式,內聯:

Vector3[][] anchors = new Vector3[][]{new Vector3[4],new Vector3[4],new Vector3[4],new Vector3[4]}; 

希望它能幫助。

+0

我認爲@都鐸王朝的正確答案是...... – ivowiblo 2011-12-31 22:14:46

3

您可以使用:

Vector3[,] anchors = new Vector3[4,4]; 
+0

正是!這是在C#中的矩陣 – ivowiblo 2011-12-31 16:04:11