Radioactive-Software Radioactive-Software
Forum to discuss Radioactive-Software Products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting Started
Goto page Previous  1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Radioactive-Software Forum Index -> Programming
View previous topic :: View next topic  
Author Message
kingIZZZY
Newbie


Joined: 31 Aug 2007
Posts: 4

PostPosted: Fri Aug 31, 2007 5:43 am    Post subject: Uh, programming Reply with quote

Hey you're my dream man, I wish one day to do at least as good as you.
'm just starting out at directX, after having covered most basics of c++.

Several questions;

1) (what all those "experts" out there ask) why reinvent the wheel? if there are so many game engines out there why not just make a game with one of them? (who ever needs to learn programming game-engines etc. anymore for that matter?) those other game engines (doom3, farcry, quake, etc) have been designed and implemented by seasoned experienced programmers who definately implemented the stuff to be as efficient as possible, what makes you think your engine is as good / better?
2) do you use the fixed-function-pipeline or you implemented your own? (i heard the FFP is completely dropped in dx10)
3) hey cut me some slack- do you know of some good website etc that might offer some absolute-n00b help for the math part of 3d? such as "the source-code equations needed for a first-person camera rotation is ....... and here is a short explanation of how and why it works...." without needing to learn all this endless math? Sofar i did manage to do many matrix operations just by copying some code and playing around with'em, maybe its possible to survive programming anything in direct3d skipping the gory math details.... or isnt it?

I would really have wanted to join the beta testing, but im not at all online enough... sux for me.
_________________
d3dDevice->BeginScene();
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Fri Aug 31, 2007 10:02 am    Post subject: Re: Uh, programming Reply with quote

kingIZZZY wrote:
Hey you're my dream man, I wish one day to do at least as good as you.
'm just starting out at directX, after having covered most basics of c++.

Several questions;

1) (what all those "experts" out there ask) why reinvent the wheel? if there are so many game engines out there why not just make a game with one of them? (who ever needs to learn programming game-engines etc. anymore for that matter?) those other game engines (doom3, farcry, quake, etc) have been designed and implemented by seasoned experienced programmers who definately implemented the stuff to be as efficient as possible, what makes you think your engine is as good / better?

2) do you use the fixed-function-pipeline or you implemented your own? (i heard the FFP is completely dropped in dx10)

3) hey cut me some slack- do you know of some good website etc that might offer some absolute-n00b help for the math part of 3d? such as "the source-code equations needed for a first-person camera rotation is ....... and here is a short explanation of how and why it works...." without needing to learn all this endless math? Sofar i did manage to do many matrix operations just by copying some code and playing around with'em, maybe its possible to survive programming anything in direct3d skipping the gory math details.... or isnt it?

I would really have wanted to join the beta testing, but im not at all online enough... sux for me.


1- For the learning experience lol, and because my game is so specific there isn't really one enigne out there that would meet all my needs. Plus I enjoy coding game engines. Also you have to pay money to license a game engine. It costs 750,000 to license the unreal engine, I spent 100k on the whole game, and now have a 150,000 line code base to build my next engine/game off.

2 - I do not used the fixed function pipeline, I require shader model 2.0 [pixel and vertex].

3 - You'll have to sit down and learn the math, or learn it slowly over the years through a lot of trial / error. You'll gain experience and knowledge by just messing with the samples. Where it really picks up is when you are motivated to do something...think of your dream game then try to make it. The only site I ever use is gamedev.net the forums there are full of the best people to ask for anything.

Lemme know if you have any more questions.

- Danny
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
kingIZZZY
Newbie


Joined: 31 Aug 2007
Posts: 4

PostPosted: Fri Aug 31, 2007 10:28 am    Post subject: Reply with quote

if theres anything in the world i want- its to see source code from your engine. specifically;

- what mesh files do you use and how do you load them (and with what do you model them for that matter- dont tell me you made your own modeling program too), "how" as in when is the best time to load what where etc

- what your render() function looks like

- whats your take on the OO design of the engine, how did you encapsulate what where, what contains what etc.

- are you using ANY external libraries at all for stuff like loading files, windows handling, d3d modes (resolutin etc) handling, or anything else (you got no D3DX in there at all?) (my personal gut feeling is to do everything myself, 1st of all, as you said, for the learning experience. 2nd of all (again, just a gut feeling) i just hate extra layers of abstraction, its already bad enough that theres binary/machine-code/assembly/c-c++, why add more abstraction like sdl or other libraries. scr€w the layers and deal with the core!)

- math math and more math; what does your first (or third) person camera rotation and displacment code look like; other object rotation etc;


got any excerpts to enlighten me?

or, would you know of any game engines (or other direct3d 9 engines) out there that show the engine's own source code?


thanx alot for your time btw
_________________
d3dDevice->BeginScene();
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Fri Aug 31, 2007 11:23 am    Post subject: Reply with quote

Lol, that would take me forever to explain all that to you...hmmm I'll try to keep it basic.

-Mesh files are a bitch, base your code off the SDK sample.
-I think I've posted my render callback in a previous thread, it's nothing too complex, I don't use a scene graph.
-I use a hybrid of c/c++ I have classes like CGameEngine, CActor, CVehicle, CWeapon, CParticleSystem, etc. there are 100s of classes I've written.
-I use lots of external libraries - Ageia PhysX, FMOD, RakNet, CURL, DirectX, hmmmm I think that's it.
-The math for a freelook camera is pretty basic you can use the D3DXLookAt function to build a matrix from whatever point you want, just generate a normalized vector from the viewer to the viewpoint and scale it. There are lots of examples out there I think.

No source code sorry. It's not pretty I didn't plan on anyone else looking at it Smile

- Danny
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
kingIZZZY
Newbie


Joined: 31 Aug 2007
Posts: 4

PostPosted: Sat Sep 01, 2007 10:02 pm    Post subject: Reply with quote

so you opt for "dirty but might be faster (efficient)" code over "neat but might be slightly less efficient" code? and by the way if you dont mind, i definately wouldnt mind having a peek at some dirty code of yours...

btw i just saw a bunch of anti-microsoft windows clips out there, especially anti vista (im sure you heard some of that before), and im having doubts again about going for directX...

i mean, with openGL you have both windows and the rest of the OSs out there, but directx is windows only...going for directx is like saying "i beleive microsoft rules and will rule" and nowdays you have to wonder if its true...

wouldnt you want you're game to be cross platform? if every developpers target is a large market, who would opt for direct3d if opengl is for all platforms?

im googling for some sort of statistics of the percentage of windows customers out there...
_________________
d3dDevice->BeginScene();
Back to top
View user's profile Send private message
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Sun Sep 02, 2007 2:09 pm    Post subject: Reply with quote

kingIZZZY wrote:
so you opt for "dirty but might be faster (efficient)" code over "neat but might be slightly less efficient" code? and by the way if you dont mind, i definately wouldnt mind having a peek at some dirty code of yours...

btw i just saw a bunch of anti-microsoft windows clips out there, especially anti vista (im sure you heard some of that before), and im having doubts again about going for directX...

i mean, with openGL you have both windows and the rest of the OSs out there, but directx is windows only...going for directx is like saying "i beleive microsoft rules and will rule" and nowdays you have to wonder if its true...

wouldnt you want you're game to be cross platform? if every developpers target is a large market, who would opt for direct3d if opengl is for all platforms?

im googling for some sort of statistics of the percentage of windows customers out there...


Right it's all about weighing the amount of work it would take to make things cross platform. There are a number of reasons I use DirectX[ it's probably used in 90% of commerical games btw] mostly because of the D3DX library.

I've learned OpenGL and it was great to work with for a few years/small projects but for a commercial project I think DirectX is better.

Also I'm not sure if any of the other libraries I'm using are crossplatform [Ageia PhysX?]

Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at Smile

Lots of work to do today...HDR lighting mergeing the animations, getting some new/better of shadow mapping going on...arg.

- Danny
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
rappen
Mini-Me


Joined: 22 Apr 2007
Posts: 6633
Location: Spijkenisse, Netherlands

PostPosted: Sun Sep 02, 2007 2:40 pm    Post subject: Reply with quote

dgreen wrote:
kingIZZZY wrote:
so you opt for "dirty but might be faster (efficient)" code over "neat but might be slightly less efficient" code? and by the way if you dont mind, i definately wouldnt mind having a peek at some dirty code of yours...

btw i just saw a bunch of anti-microsoft windows clips out there, especially anti vista (im sure you heard some of that before), and im having doubts again about going for directX...

i mean, with openGL you have both windows and the rest of the OSs out there, but directx is windows only...going for directx is like saying "i beleive microsoft rules and will rule" and nowdays you have to wonder if its true...

wouldnt you want you're game to be cross platform? if every developpers target is a large market, who would opt for direct3d if opengl is for all platforms?

im googling for some sort of statistics of the percentage of windows customers out there...


Right it's all about weighing the amount of work it would take to make things cross platform. There are a number of reasons I use DirectX[ it's probably used in 90% of commerical games btw] mostly because of the D3DX library.

I've learned OpenGL and it was great to work with for a few years/small projects but for a commercial project I think DirectX is better.

Also I'm not sure if any of the other libraries I'm using are crossplatform [Ageia PhysX?]

Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at Smile

Lots of work to do today...HDR lighting mergeing the animations, getting some new/better of shadow mapping going on...arg.

- Danny


Good, work is good
_________________
Rappen Fo'shizzle my nizzle oh fo dizzle Razz

Back to top
View user's profile Send private message AIM Address MSN Messenger
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Tue Sep 04, 2007 12:35 am    Post subject: Reply with quote

rappen wrote:
dgreen wrote:
kingIZZZY wrote:
so you opt for "dirty but might be faster (efficient)" code over "neat but might be slightly less efficient" code? and by the way if you dont mind, i definately wouldnt mind having a peek at some dirty code of yours...

btw i just saw a bunch of anti-microsoft windows clips out there, especially anti vista (im sure you heard some of that before), and im having doubts again about going for directX...

i mean, with openGL you have both windows and the rest of the OSs out there, but directx is windows only...going for directx is like saying "i beleive microsoft rules and will rule" and nowdays you have to wonder if its true...

wouldnt you want you're game to be cross platform? if every developpers target is a large market, who would opt for direct3d if opengl is for all platforms?

im googling for some sort of statistics of the percentage of windows customers out there...


Right it's all about weighing the amount of work it would take to make things cross platform. There are a number of reasons I use DirectX[ it's probably used in 90% of commerical games btw] mostly because of the D3DX library.

I've learned OpenGL and it was great to work with for a few years/small projects but for a commercial project I think DirectX is better.

Also I'm not sure if any of the other libraries I'm using are crossplatform [Ageia PhysX?]

Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at Smile

Lots of work to do today...HDR lighting mergeing the animations, getting some new/better of shadow mapping going on...arg.

- Danny


Good, work is good


You're a post whore.

But I like it. You have no comments on the ratio of comments per lines of code, or if a solo coder should maintain comments even though nobody else will see the code? eh? Any idea if it's a better to use OpenGL or DirectX or to write your own software rasterizer? Rappen...!1111111111111 you dutch whore.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
rappen
Mini-Me


Joined: 22 Apr 2007
Posts: 6633
Location: Spijkenisse, Netherlands

PostPosted: Tue Sep 04, 2007 9:02 am    Post subject: Reply with quote

Sad
_________________
Rappen Fo'shizzle my nizzle oh fo dizzle Razz

Back to top
View user's profile Send private message AIM Address MSN Messenger
kingIZZZY
Newbie


Joined: 31 Aug 2007
Posts: 4

PostPosted: Tue Sep 04, 2007 5:53 pm    Post subject: Reply with quote

dgreen wrote:
Quote:
Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at


Hey i really dont care, i think im good at seeing rotten code and actually figuring out what is it trying to do... just let me see some code... please?
_________________
d3dDevice->BeginScene();
Back to top
View user's profile Send private message
rappen
Mini-Me


Joined: 22 Apr 2007
Posts: 6633
Location: Spijkenisse, Netherlands

PostPosted: Wed Sep 05, 2007 6:51 am    Post subject: Reply with quote

kingIZZZY wrote:
dgreen wrote:
Quote:
Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at


Hey i really dont care, i think im good at seeing rotten code and actually figuring out what is it trying to do... just let me see some code... please?


Ok you now know how it works, go and help danny a little hand
_________________
Rappen Fo'shizzle my nizzle oh fo dizzle Razz

Back to top
View user's profile Send private message AIM Address MSN Messenger
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Wed Sep 05, 2007 2:33 pm    Post subject: Reply with quote

kingIZZZY wrote:
dgreen wrote:
Quote:
Also regarding the source code...by not pretty I mean't 'comment less', I'm quite pedantic when it comes to maintaining the same style / format throughout all my code. It's just setup so I'll understand it, some people might not like my style...or the lack of comments would be a problem...I dunno, eitherway I say the source is not worth looking at


Hey i really dont care, i think im good at seeing rotten code and actually figuring out what is it trying to do... just let me see some code... please?


How to generate tangents by hand for a skinned and animated mesh...I only store the tangent in the mesh, and calcualate the binormal inside the shader.

This code was made obsolete by D3DXGenerateTangentsEx()...

But in-case you can't get it to work...this will always work.

The margins are fux0red. Oh well, have fun....might want to copy paste into an IDE of your choice.
Code:

void CSkinnedMesh::GenerateTangents(LPD3DXFRAME pFrameBase)
{
 //DWORD NewFVF = (pMeshContainer->MeshData.pMesh->GetFVF() & D3DFVF_POSITION_MASK) | D3DFVF_NORMAL | D3DFVF_TEX2 | D3DFVF_LASTBETA_UBYTE4 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE4(1);
 D3DXFRAME_DERIVED *pFrame = (D3DXFRAME_DERIVED*)pFrameBase;
 D3DXMESHCONTAINER_DERIVED *pMeshContainer;
 pMeshContainer = (D3DXMESHCONTAINER_DERIVED *)pFrame->pMeshContainer;
 
 while(pMeshContainer != NULL)
 {
  int NumVerts = pMeshContainer->MeshData.pMesh->GetNumVertices();
  int NumFaces = pMeshContainer->MeshData.pMesh->GetNumFaces();
  int NumBytesPerVertex = pMeshContainer->MeshData.pMesh->GetNumBytesPerVertex();
  bool MeshUses32BitIndices = (pMeshContainer->MeshData.pMesh->GetOptions() & D3DXMESH_32BIT);
  int NumBytesPerIndex = (MeshUses32BitIndices ? 4:2);

  //Output mesh information
  GameEngine.LogEntry("Generating Tangents %s - [NumFaces %d | NumBytesPerVert %d | NumBytesPerIndex %d | NumVerts %d | sizeof(MeshVertex) = %d]", pFrame->Name, NumFaces, NumBytesPerVertex, NumBytesPerIndex, NumVerts, sizeof(SkinnedMeshVertex));

  //Check to make sure sizes of verts match up
  if(sizeof(SkinnedMeshVertex) != NumBytesPerVertex)
  {
   GameEngine.LogEntry("WARNING! In GenerateTangents() [MeshVertex size (%d) != NumBytesPerVertex (%d)]", sizeof(SkinnedMeshVertex), NumBytesPerVertex);
  } //end of if   
  if(sizeof(SkinnedMeshVertex) < NumBytesPerVertex) return;

  BYTE* pVertices = NULL;
  WORD* pIndices = NULL;
  long int ReadPosition = 0;

  //Allocate arrays to hold verts + faces
  SkinnedMeshVertex *pMeshVerts = new SkinnedMeshVertex[NumVerts];
  SkinnedMeshTangentTriangle *pTangentTris = new SkinnedMeshTangentTriangle[NumFaces];

  //Lock the mesh's VB
  HRESULT hr = pMeshContainer->MeshData.pMesh->LockVertexBuffer(/*D3DLOCK_READONLY*/0, (LPVOID*)&pVertices);

  if(!FAILED(hr))
  {
   //Copy the meshs' vertex data into the temp array using one memcpy
   //memcpy(pMeshVerts, pVertices, NumBytesPerVertex*NumVerts);

   //Loop through each vertex moving it into the temp array, and output it as well...
   for(int i = 0; i < NumVerts; i++) 
   {
    //Copy the vertex from mesh to temp memory...
   memcpy(&pMeshVerts[i], pVertices+ReadPosition, NumBytesPerVertex);

    //Output vertex for debugging purposes...
/*    GameEngine.LogEntry("        Vert %d - [Position %0.3f %0.3f %0.3f] [Normal %0.3f %0.3f %0.3f] [TexCoord %0.2f %0.2f] [Tangent %0.2f %0.2f %0.2f %0.2f] [BlendWeights %0.2f %0.2f %0.2f] [BlendIndices %d %d %d %d]", i,
                          pMeshVerts[i].Position.x, pMeshVerts[i].Position.y, pMeshVerts[i].Position.z,
                          pMeshVerts[i].Normal.x, pMeshVerts[i].Normal.y, pMeshVerts[i].Normal.z,
                          pMeshVerts[i].TexCoord.x, pMeshVerts[i].TexCoord.y,
                          pMeshVerts[i].Tangent.x, pMeshVerts[i].Tangent.y, pMeshVerts[i].Tangent.z, pMeshVerts[i].Tangent.w,                        
                          pMeshVerts[i].BlendWeights.x, pMeshVerts[i].BlendWeights.y, pMeshVerts[i].BlendWeights.z,
                          pMeshVerts[i].BlendIndices[0], pMeshVerts[i].BlendIndices[1], pMeshVerts[i].BlendIndices[2], pMeshVerts[i].BlendIndices[3]);
*/
    ReadPosition+=NumBytesPerVertex;
   } //end of for loop
   
   //Now generate triangle array from the mesh's index buffer...
   //First lock the index buffer
   pMeshContainer->MeshData.pMesh->LockIndexBuffer(0, (LPVOID*)&pIndices);

   //For each face get the indices of the 3 verts that make up that face.
   for(i = 0; i < NumFaces; i++) 
   {   
    for(int j = 0; j < 3; j++)
   {   
     if(MeshUses32BitIndices)
    {
      //32-bit indices     
    } //end of if
    else
    {
     //16-bit indices
      WORD tempIndex;
     memcpy(&tempIndex, pIndices, NumBytesPerIndex);
     pTangentTris[i].Index[j] = tempIndex;
    } //end of else
    pIndices++;
   } //end of for loop
   //GameEngine.LogEntry("Tri %d - [%d %d %d]", i, pTangentTris[i].Index[0], pTangentTris[i].Index[1], pTangentTris[i].Index[2]);
   } //end of for loop

   //Unlock index buffer
   pMeshContainer->MeshData.pMesh->UnlockVertexBuffer();

   //Actually compute tangents inside this function.
   //The array of verts will be filled with correct tangent data after this fucntion.
   CalculateTangentArrayMeshVerts(NumVerts, NumFaces, pMeshVerts, pTangentTris);

   //Loop through each vertex and move the data [including the tangents] back into the mesh...
   //Could use one memcpy call, but doing it this way allows other per-vertex calculations to be done here.
   ReadPosition = 0;
   for(i = 0; i < NumVerts; i++) 
   {   
    //pMeshVerts[i].TexCoord.x = 0;
   //pMeshVerts[i].TexCoord.y = 0;

   //Output vertex for debugging purposes...
   /* GameEngine.LogEntry("        Vert %d - [Position %0.3f %0.3f %0.3f] [Normal %0.3f %0.3f %0.3f] [TexCoord %0.2f %0.2f] [Tangent %0.2f %0.2f %0.2f %0.2f] [BlendWeights %0.2f %0.2f %0.2f] [BlendIndices %d %d %d %d]", i,
                          pMeshVerts[i].Position.x, pMeshVerts[i].Position.y, pMeshVerts[i].Position.z,
                          pMeshVerts[i].Normal.x, pMeshVerts[i].Normal.y, pMeshVerts[i].Normal.z,
                          pMeshVerts[i].TexCoord.x, pMeshVerts[i].TexCoord.y,
                          pMeshVerts[i].Tangent.x, pMeshVerts[i].Tangent.y, pMeshVerts[i].Tangent.z, pMeshVerts[i].Tangent.w,                        
                          pMeshVerts[i].BlendWeights.x, pMeshVerts[i].BlendWeights.y, pMeshVerts[i].BlendWeights.z,
                          pMeshVerts[i].BlendIndices[0], pMeshVerts[i].BlendIndices[1], pMeshVerts[i].BlendIndices[2], pMeshVerts[i].BlendIndices[3]);*/

   //Copy vertex data back into mesh...
    memcpy(pVertices+ReadPosition, &pMeshVerts[i], NumBytesPerVertex);

    ReadPosition+=NumBytesPerVertex;
   } //end of for loop

   // Finished so unlock VBs
   pMeshContainer->MeshData.pMesh->UnlockVertexBuffer();

   //Delete memory used to store verts/faces
   delete[] pMeshVerts;
   delete[] pTangentTris;
  } //end of if
  else 
  {
   GameEngine.LogEntry("LockVertexBuffer() #1 FAILED!");
  } //end of else

  pMeshContainer = (D3DXMESHCONTAINER_DERIVED *)pMeshContainer->pNextMeshContainer;
 } //end of while loop

 if(pFrame->pFrameSibling != NULL)
 {
  GenerateTangents(pFrame->pFrameSibling);
 } //end of if

 if(pFrame->pFrameFirstChild != NULL)
 {
  GenerateTangents(pFrame->pFrameFirstChild);
 } //end of if
} //end of GenerateTangents function

//This function is a slight modification of the one found @ http://www.terathon.com/code/tangent.php [ by Eric Lengyel ]
//Now uses D3DXVECTOR3 & and the SkinnedMeshVertex / SkinnedMeshTangentTriangle structs which represent
//the FVF / Decl of the mesh.  Also checks for divide by zero & other error checking.
void CalculateTangentArrayMeshVerts(unsigned long VertexCount, unsigned long TriangleCount, SkinnedMeshVertex *pVerts, const SkinnedMeshTangentTriangle *pTriangles)
{
 //The code generates a four-component tangent T in which the handedness of
 //the local coordinate system is stored as ±1 in the w-coordinate. The bitangent
 //vector B is then given by B = (N × T)Tw.

 //For mathematical details, see http://www.terathon.com/books/mathgames2.html

 D3DXVECTOR3 *tan1 = new D3DXVECTOR3[VertexCount * 2];
 D3DXVECTOR3 *tan2 = tan1 + VertexCount;

 //Clear the memory
 memset(tan1, 0, sizeof(D3DXVECTOR3) * VertexCount * 2);
   
 for(long a = 0; a < TriangleCount; a++)
 {
  unsigned short i1 = pTriangles->Index[0];
  unsigned short i2 = pTriangles->Index[1];
  unsigned short i3 = pTriangles->Index[2];

  //Do bounds checking making sure each index is between 0 & VertexCount.
  if(i1 >= VertexCount || i1 < 0 || i2 >= VertexCount || i2 < 0 || i3 >= VertexCount || i3 < 0)
  {
   GameEngine.LogEntry("CalculateTangentArrayMeshVerts() ERROR! Bounds Exceeded! [%d %d %d]", i1, i2, i3);
   return;
  } //end of if
     
  const D3DXVECTOR3& v1 = pVerts[i1].Position;
  const D3DXVECTOR3& v2 = pVerts[i2].Position;
  const D3DXVECTOR3& v3 = pVerts[i3].Position;
       
  const D3DXVECTOR2& w1 = pVerts[i1].TexCoord;
  const D3DXVECTOR2& w2 = pVerts[i2].TexCoord;
  const D3DXVECTOR2& w3 = pVerts[i3].TexCoord;
       
  double x1 = v2.x - v1.x;
  double x2 = v3.x - v1.x;
  double y1 = v2.y - v1.y;
  double y2 = v3.y - v1.y;
  double z1 = v2.z - v1.z;
  double z2 = v3.z - v1.z;
       
  double s1 = w2.x - w1.x;
  double s2 = w3.x - w1.x;
  double t1 = w2.y - w1.y;
  double t2 = w3.y - w1.y;

  double DivValue = (s1 * t2 - s2 * t1);

  //Check for divide by zero...
  if(DivValue == 0.0f)
  {
   GameEngine.LogEntry("CalculateTangentArrayMeshVerts() WARNING! Divide by 0 detected! Indices = [%d %d %d] TexCoords = [%f %f] [%f %f] [%f %f]", i1, i2, i3, w1.x, w1.y, w2.x, w2.y, w3.x, w3.y);      
   DivValue = 1.0F;
  } //end of if

  double r = 1.0F / DivValue;
  D3DXVECTOR3 sdir = D3DXVECTOR3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
  D3DXVECTOR3 tdir = D3DXVECTOR3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
       
  tan1[i1] += sdir;
  tan1[i2] += sdir;
  tan1[i3] += sdir;
       
  tan2[i1] += tdir;
  tan2[i2] += tdir;
  tan2[i3] += tdir;
       
  pTriangles++;
 } //end of for loop
   
 for(long a = 0; a < VertexCount; a++)
 {
  const D3DXVECTOR3& n = pVerts[a].Normal;
  const D3DXVECTOR3& t = tan1[a];
       
  // Gram-Schmidt orthogonalize
  D3DXVECTOR3 TempTangent = (t - n * D3DXVec3Dot(&n, &t));
  D3DXVec3Normalize(&TempTangent, &TempTangent);
   
  // Calculate handedness & set final tangent
  pVerts[a].Tangent.x = TempTangent.x;
  pVerts[a].Tangent.y = TempTangent.y;
  pVerts[a].Tangent.z = TempTangent.z;
  pVerts[a].Tangent.w = (D3DXVec3Dot(D3DXVec3Cross(&TempTangent, &n, &t), &tan2[a]) < 0.0F) ? -1.0F : 1.0F; 
 // GameEngine.LogEntry("%d = %f %f %f %f", a, pVerts[a].Tangent.x, pVerts[a].Tangent.y, pVerts[a].Tangent.z, pVerts[a].Tangent.w);
 } //end of for loop
   
 delete[] tan1;
} //end of CalculateTangentArrayMeshVerts function



Strucuts used in the code above...
Code:

struct SkinnedMeshVertex
{
 D3DXVECTOR3 Position;
 D3DXVECTOR3 BlendWeights;
 unsigned char BlendIndices[4];
 D3DXVECTOR3 Normal;
 D3DXVECTOR2 TexCoord;
 D3DXVECTOR4 Tangent;
};

struct SkinnedMeshTangentTriangle
{
 unsigned short Index[3];
};



Here is the code needed to make space for the tangents in the mesh's vertex declaration.
Code:

void CSkinnedMesh::ForceDeclRecursive(LPD3DXFRAME pFrameBase)
{
 D3DXFRAME_DERIVED *pFrame = (D3DXFRAME_DERIVED*)pFrameBase;
 D3DXMESHCONTAINER_DERIVED *pMeshContainer;
 HRESULT hr;

 pMeshContainer = (D3DXMESHCONTAINER_DERIVED *)pFrame->pMeshContainer;

 while(pMeshContainer != NULL)
 {
  //Force Decl...
  //NumBytesPerVert = 64
  //Element #0 - D3DDECLUSAGE_POSITION | Offset 0 | Type 2 | Usage Index 0
  //Element #1 - D3DDECLUSAGE_BLENDWEIGHT | Offset 12 | Type 2 | Usage Index 0
  //Element #2 - D3DDECLUSAGE_BLENDINDICES | Offset 24 | Type 4 | Usage Index 0
  //Element #3 - D3DDECLUSAGE_NORMAL | Offset 28 | Type 2 | Usage Index 0
  //Element #4 - D3DDECLUSAGE_TEXCOORD | Offset 40 | Type 1 | Usage Index 0
  //Element #5 - D3DDECLUSAGE_TEXCOORD | Offset 48 | Type 3 | Usage Index 1

  D3DVERTEXELEMENT9 NewVertexDecl[] =
  {
   { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
   { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT,   0 },
   { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES,  0 },
   { 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
   { 0, 40, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
   { 0, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },

   D3DDECL_END()
  };

  LPD3DXMESH pMesh2;
  hr = pMeshContainer->MeshData.pMesh->CloneMesh(pMeshContainer->MeshData.pMesh->GetOptions(), NewVertexDecl, D3DDEVICE, &pMesh2);
  if(!FAILED(hr))
  {
   pMeshContainer->MeshData.pMesh->Release();
   pMeshContainer->MeshData.pMesh = pMesh2;
   pMesh2 = NULL;
  } //end of if
  else
  {
   GameEngine.LogEntry("CSkinnedMesh::[CloneMesh() failed in ForceDeclRecursive()]");
   return;
  } //end of eles

  hr = pMeshContainer->MeshData.pMesh->UpdateSemantics(NewVertexDecl);
  if(FAILED(hr))
  {
   GameEngine.LogEntry("CSkinnedMesh::[ERROR: UpdateSemantics() failed in ForceDeclRecursive() %d]", hr);
   return;
  } //end of if

  pMeshContainer = (D3DXMESHCONTAINER_DERIVED *)pMeshContainer->pNextMeshContainer;
 } //end of while loop

 if(pFrame->pFrameSibling != NULL)
 {
  ForceDeclRecursive(pFrame->pFrameSibling);
 } //end of if

 if(pFrame->pFrameFirstChild != NULL)
 {
  ForceDeclRecursive(pFrame->pFrameFirstChild);
 } //end of if
} //end of ForceDeclRecursive function


Some debug code to output the vertex declaration of a skinned mesh.
Code:

void OutputDecl(LPD3DXMESH pMesh)
{
 HRESULT hr;
 if(pMesh == NULL)
 {
  GameEngine.LogEntry("CSkinnedMesh::[ERROR in OutputDecl() pMesh == NULL");
  return;
 } //end of if

 D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
 hr = pMesh->GetDeclaration(elems);
 if(SUCCEEDED(hr))
 {
  GameEngine.LogEntry("      Outputting Vertex Declaration...");
  GameEngine.LogEntry("      ----------------------------------------");
  GameEngine.LogEntry("      NumBytesPerVert = %d", pMesh->GetNumBytesPerVertex());
  for(int i = 0; i < MAX_FVF_DECL_SIZE; ++i)
  {
   // Did we reach D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}?
   if(elems[i].Stream == 0xff)
    break;

   if(elems[i].Usage == D3DDECLUSAGE_POSITION)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_POSITION | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if
   else if(elems[i].Usage == D3DDECLUSAGE_NORMAL)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_NORMAL | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if
   else if(elems[i].Usage == D3DDECLUSAGE_TEXCOORD)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_TEXCOORD | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if
   else if(elems[i].Usage == D3DDECLUSAGE_BLENDWEIGHT)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_BLENDWEIGHT | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if
   else if(elems[i].Usage == D3DDECLUSAGE_TANGENT)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_TANGENT | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if
   else if(elems[i].Usage == D3DDECLUSAGE_BLENDINDICES)
   {
   GameEngine.LogEntry("      Element #%d - D3DDECLUSAGE_BLENDINDICES | Offset %d | Type %d | Usage Index %d", i, elems[i].Offset, elems[i].Type, elems[i].UsageIndex);
   } //end of if   
   else
   {
   GameEngine.LogEntry("      Element #%d contains unsupported usage...%d", i, elems[i].Usage);
   } //end of else
  }   //end of for loop   
 } //end of if
 else
 {      
  GameEngine.LogEntry("CSkinnedMesh::[Failed to load vertex declaration]");
 }//end of else
} //end of if


Hope that's enough for you...I've got about 150,000 more lol.

- Danny
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
MyGFHasNoTeeth
Rockstar


Joined: 07 Aug 2007
Posts: 170
Location: Cary, NC

PostPosted: Thu Sep 06, 2007 2:19 pm    Post subject: Reply with quote

hahaha... you failed to load vertex declaration. you suck.
_________________
Roses are red, violets are blue, I'll fuck you with a rake.
Back to top
View user's profile Send private message Visit poster's website AIM Address
dgreen
The One


Joined: 24 Sep 2005
Posts: 6811
Location: Raleigh, NC

PostPosted: Thu Sep 06, 2007 11:06 pm    Post subject: Reply with quote

MyGFHasNoTeeth wrote:
hahaha... you failed to load vertex declaration. you suck.


lol. That's not a very nice error message.
_________________
I run this place.
"Some muckety-muck architecture magazine was interviewing Will Wright about SimCity, and they asked
him a question something like "which ontological urban paridigm most influenced your design of the simulator,
the Exo-Hamiltonian Pattern Language Movement, or the Intra-Urban Deconstructionist Sub-Culture Hypothesis?"
He replied, "I just kind of optimized for game play."

Back to top
View user's profile Send private message Visit poster's website AIM Address
MyGFHasNoTeeth
Rockstar


Joined: 07 Aug 2007
Posts: 170
Location: Cary, NC

PostPosted: Fri Sep 07, 2007 7:19 am    Post subject: Reply with quote

No error message is nice, because by default they tell you there is an error therefore it means you failed and most likely so did your program. So the error message might as well insult you while its at it, at least it would be entertaining.
_________________
Roses are red, violets are blue, I'll fuck you with a rake.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Radioactive-Software Forum Index -> Programming All times are GMT - 5 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group