Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi there!

This may to many of you seem like a stupid question. But my objects seem to be transparent to the objects to the right. I must have misunderstood something here. I'm using VB.NET, and I'm using PositionNormalColored() to create the triangles.

 

I use DirectX9c dec.04 and the DirectX object is named D3Ddev in this program. I use no lights (so far). I would very much appreciate if someone could tell me why the cubes to the right "shines through" the ones to the left.

 

Do I create the triangles the wrong way? Like counter clockwise instead of clockwise? I really have no idea at all. I have programmed "normal" applications for quite a while, but I am very(!) new to DirectX programming.

 

Here is some code (not complete...too much to post :-\ ):

 

' Some variables I use
Private buffer(5) As VertexBuffer
Private vertex(5) As Integer
Private numObj As Integer

'---------------------'
' CREATING THE CUBE '
'---------------------'
' This function returns the number of vertices that is used in this object
Private Function CreateCube(ByRef aBuffer As VertexBuffer, ByVal posX As Single, ByVal posY As Single, ByVal posZ As Single, ByVal x As Single, ByVal y As Single, ByVal z As Single, ByVal col As Integer) As Integer
       Dim Vertices() As CustomVertex.PositionNormalColored
       Const antVertices = 36

       aBuffer = New VertexBuffer(GetType(CustomVertex.PositionNormalColored), antVertices, D3Ddev, Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default)
       Vertices = aBuffer.Lock(0, LockFlags.None)

       ' Front face
       Vertices(0) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ), New Vector3(0.0F, 0.0F, -1.0F), col)
       Vertices(1) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ), New Vector3(0.0F, 0.0F, -1.0F), col)
       Vertices(2) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ), New Vector3(0.0F, 0.0F, -1.0F), col)
       Vertices(3) = Vertices(1)
       Vertices(4) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ), New Vector3(0.0F, 0.0F, -1.0F), col)
       Vertices(5) = Vertices(2)

       ' Back face
       Vertices(6) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ + z), New Vector3(0.0F, 0.0F, 1.0F), col)
       Vertices(7) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ + z), New Vector3(0.0F, 0.0F, 1.0F), col)
       Vertices(8) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ + z), New Vector3(0.0F, 0.0F, 1.0F), col)
       Vertices(9) = Vertices(7)
       Vertices(10) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ + z), New Vector3(0.0F, 0.0F, 1.0F), col)
       Vertices(11) = Vertices(8)

       ' Left face
       Vertices(12) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ + z), New Vector3(-1.0F, 0.0F, 0.0F), col)
       Vertices(13) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ), New Vector3(-1.0F, 0.0F, 0.0F), col)
       Vertices(14) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ + z), New Vector3(-1.0F, 0.0F, 0.0F), col)
       Vertices(15) = Vertices(13)
       Vertices(16) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ), New Vector3(-1.0F, 0.0F, 0.0F), col)
       Vertices(17) = Vertices(14)

       ' Right face
       Vertices(18) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ), New Vector3(1.0F, 0.0F, 0.0F), col)
       Vertices(19) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ + z), New Vector3(1.0F, 0.0F, 0.0F), col)
       Vertices(20) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ), New Vector3(1.0F, 0.0F, 0.0F), col)
       Vertices(21) = Vertices(19)
       Vertices(22) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ + z), New Vector3(1.0F, 0.0F, 0.0F), col)
       Vertices(23) = Vertices(20)

       ' Bottom face
       Vertices(24) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ), New Vector3(0.0F, -1.0F, 0.0F), col)
       Vertices(25) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ), New Vector3(0.0F, -1.0F, 0.0F), col)
       Vertices(26) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY, posZ + z), New Vector3(0.0F, -1.0F, 0.0F), col)
       Vertices(27) = Vertices(25)
       Vertices(28) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY, posZ + z), New Vector3(0.0F, -1.0F, 0.0F), col)
       Vertices(29) = Vertices(26)

       ' Top face
       Vertices(30) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ + z), New Vector3(0.0F, 1.0F, 0.0F), col)
       Vertices(31) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ + z), New Vector3(0.0F, 1.0F, 0.0F), col)
       Vertices(32) = New CustomVertex.PositionNormalColored(New Vector3(posX, posY + y, posZ), New Vector3(0.0F, 1.0F, 0.0F), col)
       Vertices(33) = Vertices(31)
       Vertices(34) = New CustomVertex.PositionNormalColored(New Vector3(posX + x, posY + y, posZ), New Vector3(0.0F, 1.0F, 0.0F), col)
       Vertices(35) = Vertices(32)

       'aBuffer.SetData(Vertices, 0, LockFlags.None)
       aBuffer.Unlock()

       CreateCube = antVertices
   End Function

' Drawing the objects (this goes on a loop)
numObj = 3
vertex(0) = CreateCube(buffer(0), -0.5F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F, Color.Red.ToArgb)
vertex(1) = CreateCube(buffer(1), 0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F, Color.Yellow.ToArgb)
vertex(2) = CreateCube(buffer(2), 0.5F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F, Color.Yellow.ToArgb)

D3Ddev.Clear(ClearFlags.Target, Color.FromArgb(255, 255, 255), 0, 0)
D3Ddev.BeginScene()

D3Ddev.Transform.View = Matrix.LookAtLH(New Vector3(0.0F, 0.0F, -3.0F), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 1.0F, 0.0F))
D3Ddev.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 3.0F, 1.0F, 1.0F, 10.0F)

' Drawing the number of objects that is set in numObj
For i = 0 To numObj - 1
 D3Ddev.SetStreamSource(0, buffer(i), 0)
 D3Ddev.DrawPrimitives(PrimitiveType.TriangleList, 0, vertex(i) / 3)
Next

D3Ddev.EndScene()
D3Ddev.Present()

 

Any tips, hints would be appreciated!

 

//theHollow

Posted

I haven't had the time to check all the vertices yet, but plot them on a peice of paper and be sure you're drawing the triangles in teh cube clockwise.

 

Turn off Culling if you don't feel like doing that. (I beleive its' d3ddev.renderstate.cullmode = cullmode.none).

 

Also, if that doesn't work, a screenshot might help :).

 

-The Pentium Guy

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...