Jump to content

  • Log In with Google      Sign In   
  • Create Account

Eric Lengyel

Member Since 25 Nov 2003
Offline Last Active Yesterday, 09:20 PM

#5148021 Writing model 3D Model data to a new file as a new format

Posted by Eric Lengyel on 18 April 2014 - 06:18 PM

There is also the new OpenGEX format:



#5127125 About 3dMax export Skeleton

Posted by Eric Lengyel on 28 January 2014 - 10:34 PM

I use IGame to export the skeleton, but have some questions. I want to calculate the binding position with the skeleton. The function with


IGameSkin->GetInitBoneTM(IGameNode * boneNode, GMatrix &intMat)


can get the bone TM when skin was added. But it will return false the the param is root bone. There is another function 


GetInitSkinTM(GMatrix & intMat)


in IGameSkin. But it always return a Identity matrix. So how can I get the binding position with root bone?


If GetInitBoneTM() returns false, then it suggests that the bone is not actually used by the skinned mesh.


The GetInitSkinTM() function returns the transform that was applied to the skin geometry at the time that it was bound to the skeleton, and not the transform of any particular bone.


If you'd like to see an example of skin/skeleton exporting from Max (but without using the IGame interface), take a look at the source for the OpenGEX exporter:




The skin and bone bind transforms are exported at the top of the OpenGexExport::ExportSkin() function.

#5091113 Collision of plane and sphere

Posted by Eric Lengyel on 02 September 2013 - 03:18 PM

Not sure what L*P is supposed to mean.


It means the dot product between the four-dimensional plane L = (Nx, Ny, Nz, D) and the homogeneous point P = (Px, Py, Pz, 1). The plus sign in the book is correct. If you're familiar with my more recent talks on Grassmann Algebra, then this is more accurately stated as the wedge product between the antivector (Nx, Ny, Nz, D) and the vector (Px, Py, Pz, 1).

#5059353 normals in tangent space question

Posted by Eric Lengyel on 04 May 2013 - 11:32 PM

The tangent and bitangent are derived using a calculation like this:



#5055934 A C++ code to smooth (and fix cracks in) meshes generated by the standard, or...

Posted by Eric Lengyel on 22 April 2013 - 11:51 PM

another alternative is the transvoxel algorithm by E. Lengyel, though I am not sure if it's patented, it is iirc


The Transvoxel algorithm is not patented. More information here:




In general, a correctly implemented Marching Cubes algorithm generating a mesh with a single LOD will only produce cracks if it doesn't have a consistent way of choosing polarity for the so-called "ambiguous cases". This can be solved by using a fixed polarity based on corner states or some face-level choice function as used in the MC33 algorithm. See Section 3.1.2 of my dissertation at the above link for some discussion of these. Using fixed polarity is easy, and it never generates any holes in the resulting mesh.


A good MC implementation will generate a smooth mesh to begin with if the data at each voxel location has a range of values instead of just a binary in or out state. The ugly stair-stepping only shows up if you're forced to put each vertex right in middle of each isosurface-crossing edge because you don't have enough information to do anything more intelligent.

#5026889 C++ how to avoid calling destructor

Posted by Eric Lengyel on 29 January 2013 - 01:44 PM

You could do this, but I don't recommend it:

void pushback_function()
    char storage[sizeof(some_class)];
    some_class *temp = new(storage) some_class;

#5023723 Texture coordinate scaling + TBN calculation

Posted by Eric Lengyel on 20 January 2013 - 08:00 PM

Are you scaling after the rotation, so as to cause a skew? This would cause the tangent and bitangent to no longer be perpendicular, so calculating the bitangent as the cross product between the normal and tangent won't quite work. Instead, if you calculate the bitangent in terms of tan1 just like you calculated the tangent in terms of tan0, you'll get the right vector. But then you can no longer assume that the inverse of the TBN matrix is just its transpose when you do your shading.

#5021634 Game engine slection for a game programming course

Posted by Eric Lengyel on 14 January 2013 - 07:48 PM

If you're looking for an engine that teaches the proper techniques and general theory of game programming, then you'll probably want an engine that includes source code, and that eliminates Unity and UDK.


Please check out the C4 Engine, which has been used in game programming classes at many universities for several years. Here is an example of a specific course that uses the C4 Engine:





You can see the feature list here:




If you have any questions, please feel free to post in the C4 Engine forums:



#5016191 How do I create a vector tangent to each point in a non-function defined surf...

Posted by Eric Lengyel on 31 December 2012 - 04:59 PM

The answer to the thread title can be found here:



#5007293 Question about glGenTextures

Posted by Eric Lengyel on 04 December 2012 - 09:33 PM

The GL driver also keeps a copy of the texture image in RAM. The contents of the VRAM accessible to the GPU can be dumped at any time (for example, if the screen resolution is changed), and the driver needs to be able to restore your textures from its copy in RAM without you having to do anything.

#4941663 Intersection of two line segment in 3 dimensions

Posted by Eric Lengyel on 20 May 2012 - 10:19 AM

Aren't those both line-line tests and not line segment-line segment tests?

Yes, you're right. I must have been to sleepy to see the word "segment".

#4941645 Intersection of two line segment in 3 dimensions

Posted by Eric Lengyel on 20 May 2012 - 08:46 AM

Calculate the following values, where x means cross product:

T1 = B - A
M1 = A x B
T2 = D - C
M2 = C x D

Then the two lines intersect if and only if

T1 * M2 + T2 * M1 = 0

where * means the dot product.

Of course, in floating-point calculations, you're unlikely to see a value of exactly zero, so you'd want to instead check for values very close to zero.

If you'd like to know more about where the above stuff comes from, look into Grassmann algebra and homogeneous coordinates. Here's a presentation:


#4927286 Video Game Architecture

Posted by Eric Lengyel on 01 April 2012 - 03:40 PM

I provided a link to the C4 diagram just because I thought the OP might have been interested in seeing how one example of a professional game engine is put together. Nothing more. I'm not telling people that's the only way to do things, and I'm not saying that other solutions are wrong. The diagram itself is just a big picture of how a bunch of different systems are related, and there is nothing exact about it. The green/orange boxes represent large collections of code, and the gray boxes represent features. The green arrows loosely represent dependencies, and the little black arrows simply show where in the engine specific features are handled. Red arrows are the same as green arrows, but come from plugin modules as opposed to the main engine. Arrows that are not connected to anything mean that a collection of code is used throughout the engine and that it would be silly to connect arrows from that box to almost all the other boxes.

flodihn, some of your comments are way out of line, and you've shown a complete lack of respect for people (not just me) who clearly know a lot more than you. I have a Ph.D. in computer science, I've written or contributed to 9 books on the topics of game programming and computer graphics (and my game math book has been a bestseller for over a decade), I designed the graphics driver architecture for the PlayStation 3 (see patent #20090002380), I've worked in the industry for 16 years at companies including Sierra, Apple, and Naughty Dog, I regularly speak at the Game Developers Conference, and I've been running a successful game engine company for the past 7 years where I am the sole programmer for the C4 Engine. The C4 Engine architecture and source code are widely regarded by professional game programmers as some of the cleanest design in existence. Now tell me, exactly what qualifies you to say I don't have a clue about software engineering?

#4926986 Video Game Architecture

Posted by Eric Lengyel on 31 March 2012 - 12:36 PM

This diagram of the C4 Engine architecture might interest you:


#4922713 Using normal mapping with triplanar texture projection

Posted by Eric Lengyel on 16 March 2012 - 06:51 PM

You would probably find "Voxel-Based Terrain for Real-Time Virtual Simulations" to be very interesting. It thoroughly addresses the problem of tangent-space normal mapping for triplanar projections in Section 5.5. You can find the paper here: