# Visual Basic > Games and Graphics Programming > Game Demos >  draw 3D cube Direct3D

## Geemuse

Hi all,

I have a question. Does somebody knows a good tutorial to draw 3D with Direct3D and VB.NET.
I'm trying to draw a cube on the screen with Direct3D, and afterwards I want to draw cylinders and other 3D polygons.
Can somebody help me?

Thanks in advance.
Geemuse

----------


## Jenner

I got one for a cube.  It uses Managed Direct3D and isn't the prettiest in the world since the triangles that make up each vertexed side are hard coded, but the end result is nice.  You can spin the thing in 3D space with the mouse.  It's my only example of "drawing" a 3D object in DirectX, rather than just loading in a mesh.  

I tried to do a sphere generator as well but it suffered from vertex inversion that I couldn't quite figure out (half the triangles were drawn the wrong way and thus, appeared as holes in the sphere)

If this is what you're looking for, I can pack it up and post it.

----------


## Geemuse

What is the best way to do...create a mesh and draw every object in it and then put it on the screen, or just put everything right a way on the screen.

Yeah please, so I can look at it and see how it really works. I want to convert it into a dynamically created cube...with the points stored in databases.

Thanks
Geemuse

----------


## Jenner

Sorry it took a little while for me to post this.  Things got frantic suddenly.  

You need the Managed DirectX SDK installed to compile this.  You can get these files here direct from Microsoft.

Attached is the project; I included the compiled binary if you just want to check it out.   A picture of the program running is posted below.  Click and drag the cube to spin and rotate it.

RenderTest.zip

----------


## .paul.

> Sorry it took a little while for me to post this.  Things got frantic suddenly.  
> 
> You need the Managed DirectX SDK installed to compile this.  You can get these files here direct from Microsoft.
> 
> Attached is the project; I included the compiled binary if you just want to check it out.   A picture of the program running is posted below.  Click and drag the cube to spin and rotate it.
> 
> RenderTest.zip


interesting directX. how would i show an image on each side so i could make the cube a dice?

+ more complicated i know, how could i convert this cube into a rubiks cube?

any advice would be appreciated

----------


## Jenner

In this example, I'm just drawing the triangles of the cube object manually rather than load in a mesh, but since it's only a cube, it's easily done.  Now, drawing on the faces would be done by applying textures to them.  You would make a set of textures each representing the face of a dice and tell the engine to apply them to the appropriate face.   I have an example of this somewhere using a meshed object.  Let me see if I can adapt it to this generated object.

A Rubik's cube would be easiest done by generating multiple cube objects.  Make 26 individual cubes, and stack them into a 3x3x3 arrangement (you can skip the center-most cube).  This way, you can create rotation methods for rotating the various slices.

----------


## waddle1463

Well I made one in WPF which supports meshes and all kinds of things

----------


## Jenner

Easy enough and nothing new since WPF natively uses Direct3D and has plenty of support for simple 3D operations.  This example is more about setting up your own Direct3D environment using WinForms as a base and drawing to it.   You realize this thread is over a year and a half old too?    :Smilie:

----------

