Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 CreateFlags.TriangleStrip
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

The Pentium Guy
Squire

12 Posts

Posted - Mar 21 2004 :  12:35:33 PM  Show Profile  Visit The Pentium Guy's Homepage  Send The Pentium Guy an AOL message  Click to see The Pentium Guy's MSN Messenger address  Send The Pentium Guy a Yahoo! Message  Reply with Quote
hey, i tried making a function that creates a cube easily, unfortunately, the compiler doesnt like the number of primitaves i provided(a cube has 6 faces, thus 12 vertices..)

here's my function

[vb]

Public Function CreateCube(ByVal TopLeftPos As Vector3, ByVal Width As Integer, ByVal Height As Integer, ByVal Depth As Integer, ByVal ImageLocation As String) As CustomVertex.PositionTextured


Dim vertices() As CustomVertex.PositionTextured
Dim ColorKeyVal As Color = Color.FromArgb(255, 0, 255, 0) 'LimeGreen

Try

SprTexture = TextureLoader.FromFile(d3ddev, ImageLocation)

VertBuffer = New VertexBuffer(GetType(CustomVertex.PositionTextured), 8, d3ddev, Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default)


vertices = VertBuffer.Lock(0, 0)

'-----------------------------
' Front face - The Z's are the same
'Top Left
vertices(0) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y, TopLeftPos.Z, 0, 0)
'Bottom Left
vertices(1) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y + Height, TopLeftPos.Z, 0, 1)
'Top Right
vertices(2) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y, TopLeftPos.Z, 1, 0)
'Bottom Right
vertices(3) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y + Height, TopLeftPos.Z, 1, 1)
'------------------------------



'-----------------------------
' Top face - The Y's are the same
'***Note: The Front Face's Top Left and Top Right are shared by the Top Face's Bottom Left and Bottom Right, so we don't need them
'
'Top Left(Prentend you're looking at this face from the top)
vertices(4) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y, TopLeftPos.Z + Depth, 0, 0)
'Top Right
vertices(5) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y, TopLeftPos.Z + Depth, 1, 0)
'------------------------------



'-----------------------------
' Bottom face - The Y's are the same
'***Note: The Front Face's Bottom Left and Bottom Right are shared by the Bottom Face's Top Left and Top Right
'
'Bottom Left(Prentend you're "underneath" this face)
vertices(6) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y + Height, TopLeftPos.Z + Depth, 0, 0)
'Bottom Right
vertices(7) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y + Height, TopLeftPos.Z + Depth, 1, 0)
'------------------------------


'-----------------------------
' Left face - The X's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------

'-----------------------------
' Right face - The X's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------

'-----------------------------
' Back face - The Z's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------


VertBuffer.Unlock()

Catch de As Exception
MessageBox.Show("Something stupid happened while creating your cube... so yeah. Error: " & de.Message, "3D Initialization.", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Function

[/vb]

and here's the render sub(where the problem is)
[vb]
Public Sub Render()

d3ddev.VertexFormat = CustomVertex.PositionTextured.Format
d3ddev.SetStreamSource(0, VertBuffer, 0)
d3ddev.SetTexture(0, SprTexture)
d3ddev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 12) '<-- right here
End Sub

[/vb]

does anyone know waht im doing wrong here?,
thanks,
-Pent-

VBBR
Moderator

Brazil
617 Posts

Posted - Mar 21 2004 :  1:52:50 PM  Show Profile  Reply with Quote
I think you did something wrong when creating the buffer. Look in www.directx4vb.com for a good tutorial on D3D9.


Whatever. Who knows...
Go to Top of Page

The Pentium Guy
Squire

12 Posts

Posted - Mar 22 2004 :  12:47:36 PM  Show Profile  Visit The Pentium Guy's Homepage  Send The Pentium Guy an AOL message  Click to see The Pentium Guy's MSN Messenger address  Send The Pentium Guy a Yahoo! Message  Reply with Quote
oh, no, it's right,

i realized what i did wrong,
TriangleStrip reads the vertices this order:
012, 123, 234, 345, 456.. etc

and the order that i have them in, it doesnt like :p
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Mar 22 2004 :  12:57:55 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
I think you have the logic wrong in creating your cube. A cube face is comprised of 2 triangles. That translates to 6 vertices per "square" face. With 6 faces that's a total of 36 vertices, not 12. You can reduce this if you use indexed primitives, but from what you're doing, you're not indexing them, so I won't explain that.
Go to Top of Page

The Pentium Guy
Squire

12 Posts

Posted - Mar 23 2004 :  5:22:41 PM  Show Profile  Visit The Pentium Guy's Homepage  Send The Pentium Guy an AOL message  Click to see The Pentium Guy's MSN Messenger address  Send The Pentium Guy a Yahoo! Message  Reply with Quote
yeah ur right, i did have the logic wrong -
what i jsut did was created a Triangle class, and then created a Rectangle Class which inherited from the triangle class, and then created a CUBE class which inherited from the RECTANGLE class and put it all together and it worked o_O,
its a much bigger releif doing that then just creating a cube class..
and plus its a little bit more organized :)
thanks,
pent
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Mar 23 2004 :  5:33:20 PM  Show Profile  Reply with Quote
One more thing, the primitive count of DrawPrimitives is the number of TRIANGLES and not number of vertices.

Whatever. Who knows...
Go to Top of Page

The Pentium Guy
Squire

12 Posts

Posted - Mar 24 2004 :  4:44:44 PM  Show Profile  Visit The Pentium Guy's Homepage  Send The Pentium Guy an AOL message  Click to see The Pentium Guy's MSN Messenger address  Send The Pentium Guy a Yahoo! Message  Reply with Quote
oh yeah, sorry that's what i meant :)

Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Mar 25 2004 :  09:39:15 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
A triangle as a class seems a bit overboard IMHO.
Go to Top of Page

Peter
Administrator

Canada
67 Posts

Posted - Mar 25 2004 :  7:48:53 PM  Show Profile  Visit Peter's Homepage  Reply with Quote
Yeah, thats oop taken to an insane level

And it cant be fast ;)

Talos Studios - VoodooVB - VB Gamer

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.