-3

I started to program a 3D game using XNA, and I want to make a function that will create a 3D cube by height, width and depth properties. I couldn't find anything like that on Google, and that's why I'm asking here.

I want the function to return a Model type variable (the 3D box).

mcmonkey4eva
  • 1,359
  • 7
  • 19
user2466186
  • 11
  • 1
  • 2
  • When I google for `xna 3d cube` I get many results. Have you been using the wrong google? – Klaus Byskov Pedersen Jun 08 '13 at 11:54
  • i didn't tried too much because i haven't seen any built-in function that could help me, i've been searching on google but i haven't find anything good. and i searched already for "xna 3d cube" but no result realy answerd my question. – user2466186 Jun 08 '13 at 12:15

2 Answers2

1

First: I'm assuming you want a cuboid not a cube. A cube has the same height, width, and depth - always. A cuboid is a rectangular prism.

Second: XNA doesn't let you dynamically create the "Model" class (Or, at least, not easily). So you have two choices here:

Option A: (The easy fix) Create a perfect 1x1x1 cube model, use that for everything, but, when drawing, scale it with a Vector3 set to your height / width / depth choice.

Option B: (The pointlessly hard way) Forget everything you know about 3D models in XNA (Specifically the sections about the Model and ModelMesh classes), and build VertexPositionNormalTexture[] VertexArray and int[] IndexArray and render it using a BasicEffect object and device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, ... )

If you choose option B, note that a proper cuboid has 8 Vertexes, and 12 triangles (36 indices)

mcmonkey4eva
  • 1,359
  • 7
  • 19
-1

Read the first 3 tutorials in here :

http://rbwhitaker.wikidot.com/3d-tutorials

OopsUser
  • 4,642
  • 7
  • 46
  • 71
  • i already know all of this actualy, I mean i got something pretty cool already but the thing is that i want to create the cubes by code and not using 3Ds Max as i did. – user2466186 Jun 08 '13 at 12:12