Archived

This topic is now archived and is closed to further replies.

Cube Function

This topic is 5574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a function under visual basic,which should create a simple cube (Direct3D 8). But it doesn''t work.I have one function which creates a plain.In the cube function i use 6 of these plain functions for each side...so here is the code: Public Sub AddPlain(ByRef Vertices() As UnlitVertex, Vec1 As D3DVECTOR, Vec2 As D3DVECTOR, Optional StartIndex As Integer = 0) ''// Erzeugt einfache Fläche On Error GoTo d3derror Dim vN As D3DVECTOR ReDim Preserve Vertices(StartIndex + 5) ''// Plain Koordinaten //////////////// ''// Dreieck 1 ''Oben Links Vertices(StartIndex) = CreateUnlitVertex(Vec1.X, Vec2.Y, Vec1.z, 0, 0, 0, 0, 0) ''Oben Rechts Vertices(StartIndex + 1) = CreateUnlitVertex(Vec2.X, Vec2.Y, Vec1.z, 0, 0, 0, 1, 0) ''Unten Links Vertices(StartIndex + 2) = CreateUnlitVertex(Vec1.X, Vec1.Y, Vec2.z, 0, 0, 0, 0, 1) ''Normalisieren vN = GetNormals(Vertices(0), Vertices(1), Vertices(2)) Vertices(StartIndex + 0).nx = vN.X: Vertices(StartIndex + 0).ny = vN.Y: Vertices(StartIndex + 0).nz = vN.z Vertices(StartIndex + 1).nx = vN.X: Vertices(StartIndex + 1).ny = vN.Y: Vertices(StartIndex + 1).nz = vN.z Vertices(StartIndex + 2).nx = vN.X: Vertices(StartIndex + 2).ny = vN.Y: Vertices(StartIndex + 2).nz = vN.z ''// Dreieck 2 ''Unten Links Vertices(StartIndex + 4) = CreateUnlitVertex(Vec1.X, Vec1.Y, Vec2.z, 0, 0, 0, 0, 1) ''Unten Rechts Vertices(StartIndex + 3) = CreateUnlitVertex(Vec2.X, Vec1.Y, Vec2.z, 0, 0, 0, 1, 1) ''Oben Rechts Vertices(StartIndex + 5) = CreateUnlitVertex(Vec2.X, Vec2.Y, Vec1.z, 0, 0, 0, 1, 0) ''Normalisieren vN = GetNormals(Vertices(4), Vertices(3), Vertices(5)) Vertices(StartIndex + 3).nx = vN.X: Vertices(StartIndex + 3).ny = vN.Y: Vertices(StartIndex + 3).nz = vN.z Vertices(StartIndex + 4).nx = vN.X: Vertices(StartIndex + 4).ny = vN.Y: Vertices(StartIndex + 4).nz = vN.z Vertices(StartIndex + 5).nx = vN.X: Vertices(StartIndex + 5).ny = vN.Y: Vertices(StartIndex + 5).nz = vN.z ''///////////////////////////////////// Exit Sub d3derror: D3DErr "Fehler in AddPlain()" End Sub Public Sub AddCube(ByRef Vertices() As UnlitVertex, X1 As Single, Z1 As Single, X2 As Single, Z2 As Single, H As Single, Optional StartIndex As Integer = 0) ''// Erzeugt Würfel ''////////////////// On Error GoTo d3derror Dim vN As D3DVECTOR ''ReDim Preserve Vertices(StartIndex + 35) ''// Vorne AddPlain Vertices(), MakeVector(X1, 0, Z1), MakeVector(X2, H, Z1), StartIndex ''// Hinten AddPlain Vertices(), MakeVector(X1, 0, Z2), MakeVector(X2, H, Z2), StartIndex + 6 ''// Unten AddPlain Vertices(), MakeVector(X1, 0, Z1), MakeVector(X2, 0, Z2), StartIndex + 12 ''// Oben AddPlain Vertices(), MakeVector(X1, H, Z1), MakeVector(X2, H, Z2), StartIndex + 18 ''// Links AddPlain Vertices(), MakeVector(X1, 0, Z1), MakeVector(X1, H, Z2), StartIndex + 24 ''// Rechts AddPlain Vertices(), MakeVector(X2, 0, Z1), MakeVector(X2, H, Z2), StartIndex + 30 Exit Sub d3derror: D3DErr "Fehler in AddCube()" End Sub The AddPlain() function works fine,but the AddCube function only dislays one plain correctly,the other vertices aren''t set correctly.But i don''t know why,please help

Share this post


Link to post
Share on other sites