School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,015 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,059 people online right now. Registration is fast and FREE... Join Now!




Simple Question

 

Simple Question, About Matrices

grnEyeDvl

28 Oct, 2009 - 09:38 AM
Post #1

New D.I.C Head
*

Joined: 28 Oct, 2009
Posts: 10

Hi

I have a question about matrices and 3d cubes (using directx and c++) when aptemping to create a 3d cube is there a Matrice which i can use that takes a plane and creates the other sides? or do i have create my own algorithms which calculates the vertors.

Thanks

This post has been edited by grnEyeDvl: 28 Oct, 2009 - 09:55 AM

User is offlineProfile CardPM
+Quote Post


Aeternalis

RE: Simple Question

28 Oct, 2009 - 01:15 PM
Post #2

D.I.C Regular
***

Joined: 13 Jul, 2009
Posts: 273



Thanked: 25 times
My Contributions
As far as I know there is no DirectX function that will take a plane and create a cube from it.

My Direct3D programming bible states that for a cube (if your hard coding it) will contain eight vertices, 24 vertex normals, and the face data for the cube must refer to each of the six faces.

CODE


// a cube has six planar faces defined by 8 vertices
D3DVECTOR vertices[] = {-0.5f, -0.5f, -0.5f,  // first vertex
                                       -0.5f, -0.5f,  0.5f,  // second vertex etc...
                                       -0.5f, 0.5f,  -0.5f,
                                       -0.5f, 0.5f,  0.5f,
                                       0.5f, -0.5f,  -0.5f,
                                       0.5f, -0.5f,  0.5f,
                                       0.5f,  0.5f,  -0.5f,
                                       0.5f, 0.5f,  0.5f};  //last vertex

// each of the cubes 6 faces has 4 vertex normals for a total of 24
D3DVECTOR normals[] = { 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 1.0f,
                                        0.0f, 1.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f,
                                        1.0f, 0.0f , 0.0f,
                                        1.0f, 0.0f , 0.0f,
                                        1.0f, 0.0f , 0.0f,
                                        1.0f, 0.0f , 0.0f,
                                        0.0f, 0.0f, -1.0f,
                                        0.0f, 0.0f, -1.0f,
                                        0.0f, 0.0f, -1.0f,
                                        0.0f, 0.0f, -1.0f,
                                        0.0f, -1.0f, 0.0f,
                                        0.0f, -1.0f, 0.0f,
                                        0.0f, -1.0f, 0.0f,
                                        0.0f, -1.0f, 0.0f,
                                        -1.0f, 0.0f , 0.0f,
                                        -1.0f, 0.0f , 0.0f,
                                        -1.0f, 0.0f , 0.0f,
                                        -1.0f, 0.0f , 0.0f,};

// face data refers to each face of the cube

DWORD faceData[] = { 4, 1, 0, 5, 1, 7, 2, 3 ,3,
                                   4, 2, 4, 3, 5, 7, 6, 6, 7,
                                   4, 5, 8, 4, 9, 6, 10, 7, 11,
                                   4, 0, 12, 2, 13, 6, 10, 7, 11,
                                   4, 0, 16, 4, 17, 5, 18, 1, 19,
                                   4, 0, 20, 1, 21, 3, 22, 2, 23, 0};

LPDIRECT3DRMMESHBUILDER3     pMeshBuilder;
pMeshBuilder->AddFaces( 8,                       // number of vertices
                                                  vertices,  // vertex array
                                                  24,          // number of normals
                                                  normals,  // normals array
                                                  faceData, //data for each face
                                                  NULL);




Hope that helps.. if you are going to be building them dynamically, you can dynamically fill the arrays before calling AddFaces();

Aet


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:27AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month