Jump to content
  • Advertisement

dev578

Member
  • Content Count

    221
  • Joined

  • Last visited

Community Reputation

128 Neutral

About dev578

  • Rank
    Member
  1. dev578

    Parsing an OpenType Font File

    I was expecting a response like this:) I guess there is just a certain satisfaction that comes from rendering a font myself. If I don't get anything else from it, it's nice to learn the mechanics of how fonts work. Since I'm developing cross platform ( Windows, Mac, Linux ), this reduces the amount of OS specific code in my engine. I'd much rather maintain one set of generic code than three sets of OS specific code that do the same thing. Dealing with OTF at such a low level also gives me the opportunity to have performance configuration options to optimize based on the needs of the game. For now I'll just not support the features I can't test due to not having a font that uses those features. -Dev578
  2. Greetings! I'm trying to add OpenType font support to my game engine. I am aware of FreeType, but have decided to write the parsing code myself. The OpenType font specification is a monstrosity, but I've learned a lot about fonts in the process... Anyway, I'm trying to test my character map ( "cmap" ) table parsing code. So far, I haven't been able to find a font that uses a character map with format 8.0 ( mixed 16-bit and 32-bit coverage ), 10.0 ( trimmed array ), or 13.0 ( many-to-one range mappings ). Does anyone know of a font I can download that uses these character map formats? Or a tool that can generate a font file with those character encodings? Thanks, -Dev578
  3. For the transformation order, I would think the same thing. However, with .x, I guess you are supposed to do rotation * scale * translation. Again, I got this from "Loading and displaying .x files without DirectX," which seems to be a credible source. The order I mention does appear to be correct, as I was able to get the animation to work. There were some bones that did not have keyframes, and I needed to set their local transformations to the frame transformation matrices. Without setting them, they were identity, and the combined matrices would obviously not be correct. Rating++ for your help. Thank you, Dev578
  4. Thank you for the reply. After further examination, I can see that the mesh is in fact lining up with the combined (flattened / world space) interpolated keyframe matrices. It wasn't before because another module in my application was changing the world matrix before the mesh rendered. Now, it is apparent that the interpolated keyframe matrices are incorrect. They are what is causing the mesh to twist in wierd ways, The mesh is going where the keyframes are telling it to go. When combining interpolated keyframes, I multiply in the order of rotation, scaling, and translation. I got this order from "Loading and displaying .x files without DirectX." As for the right handed matrix suggestion, there is an option in the exporter to convert to a left handed system. Maybe this just transforms the vertices? Also, if this were the case, wouldn't the DirectX viewer screw up? Any ideas? Thank you for your time, Dev578
  5. Thank you for the response. I believe I see how it works now. However, I am still having a problem with the models exported from Maya. As I said in the original post, tiny.x works and animates. So I decided to print spheres at the locations of the two sets of matrices. I printed green spheres at the locations of the inverse bone offset matrices. I printed red spheres at the locations of the combined (flattened / world space) interpolated keyframe matrices. In the tiny.x model, the red set was translated above the green set. The model rendered directly over the red set. This is what I would expect to happen. I essentially ignored the frame transformation matrices stored in each frame. Although the red set differed from the green set, when the inverse green set was applied to the red set, the transformation difference showed through the translation of the mesh vertices. As I understand it, this is correct (let me know if it's not). I wouldn't even know there was a problem until trying to load an exported model. The exported model plays perfectly in the DirectX mesh viewing application, so I think I can assume the export was valid. The exported mesh does not display over the red set of matrices, it displays in some odd position in very painful looking poses. I'm out of ideas as to why this would work this way. Does anyone have any idea as to why this would happen? Has anyone ever worked with this before and run into this problem? As a side note, sorry about calling the matrices red and green sets, it was just easier to type and keep my thoughts straight:) Thank you for your time, Dev578
  6. I am loading in an animated .x file using data objects. I was successfully able to load and render tiny.x with animations. However, when I try to render a .x file exported from maya, the model gets transformed in odd ways. I think it has something to do with the relationship between the bone offset matrices from the skin info, and the transformation matrices stored in the frame objects. The way I understand it, the bone offset matrices are matrices that, when applied to a bone, transform the bone to the root frame. As I understand it, this is the inverse bind pose matrix to be used in the skinning algorithm. The transformation matrix is a local matrix that offsets a child frame from its parent. Therefore, if we were to flatten the transformation matrices into world space through recursion, we would have a matrix that could transform a frame from the root to where it belongs. So if we were to take the inverse of said matrix, it should match the bone offset matrix. This, however, is not the case. Right now, I am ignoring the transformation matrices from the frames. This worked for tiny.x, but does not work for a .x file exported from maya. Does anyone have any idea how these bone offset matrices and frame transformation matrices need to be used to render a skinned mesh? Thank you for your time, -Dev578
  7. dev578

    Manually loading in .X files

    That was it! Apparently, you cannot pass NULL for adjacency information. However, you can for materials, number of materials, and effect instances. This is kind of dumb, but you are correct in saying the documentation never says you can pass NULL. It's a little annoying that D3DXLoadMeshFromX will allow you to pass NULL for everything, but D3DXLoadMeshFromXof requires adjacency information. Thank you, -Dev578
  8. dev578

    Manually loading in .X files

    Thanks for the reply. Yes, I have run the code with the debug runtimes. It doesn't tell me anything about why it failed. It actually crashes somewhere in the D3DXLoadMeshFromXof function. I was using the August 2007 SDK, but I just upgraded to November 2007. The crash is the same with both of them. If the debugger is working correctly, it is crashing in this function from guiddef.h: __inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) { return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } rguid2 appears to be invalid, as it has ???'s throughout the data fields. This is the same behavior with both the SDK versions I have used. Any ideas? -Dev578 [EDIT] Oh, and what do you mean by data format?
  9. I am trying to manually load in a .X file so I can eventually parse my own custom data. I am also trying to load skeletal animation information, and I want to use the information independently of the DirectX API. As in, I just want to use DirectX to load in the information from a .X file, because I don't want to write a parser dealing with low level file I/O. I want to use the loaded information in my own systems, independent of the DirectX API. So I came across D3DXLoadMeshFromXof, and it seems to be what I want. However, the call to D3DXLoadMeshFromXof crashes, giving me an access violation reading location 0x0. I wrote an equivalent D3DXLoadMeshFromX function, and it works. I hate asking questions like this, but the documentation on this function is very limited at best. Does anyone have any experience with this, or have any idea why this would be happening? #include "MainGame.h" #include <rmxftmpl.h> #include <rmxfguid.h> #pragma comment (lib, "dxguid.lib") #include "D3DRenderer.h" #include "RendererGeneral.h" #define MANUAL_LOADING CMainGame::CMainGame() { m_bFocus = false; m_pMesh = 0; } CMainGame::~CMainGame() { } bool CMainGame::Initialize(HWND hWnd, HINSTANCE hInstance, BOOL bWindowed) { if (CD3DRenderer::GetInstance()->Init(hWnd, bWindowed) == FALSE) { MessageBox(NULL, "Failed to initialize renderer", "Error", MB_OK); return false; } // Set the world matrix D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); CD3DRenderer::GetInstance()->SetWorld(matWorld); // Set the camera back so we can view the mesh D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f, 0.0f, -5.0f); D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); CD3DRenderer::GetInstance()->SetView(matView); // Set the projection matrix D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f, 4.0f / 3.0f, 1.0f, 1000.0f); CD3DRenderer::GetInstance()->SetProj(matProj); // Set the clear color tColor3f clrColor(0.0f, 0.0f, 1.0f); CD3DRenderer::GetInstance()->SetClearColor(clrColor); #ifdef MANUAL_LOADING // Try to parse our .X file manually ID3DXFile* pDXFile = NULL; ID3DXFileEnumObject* pDXEnum = NULL; ID3DXFileData* pDXData = NULL; SIZE_T nChildren, i; GUID id; // Create the file object if (FAILED(D3DXFileCreate(&pDXFile))) return false; // Register the common templates if (FAILED(pDXFile->RegisterTemplates((LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES))) { pDXFile->Release(); return false; } // Create an enumeration object if (FAILED(pDXFile->CreateEnumObject("tiger.x", D3DXF_FILELOAD_FROMFILE, &pDXEnum))) { pDXFile->Release(); return false; } if (SUCCEEDED(pDXEnum->GetChildren(&nChildren))) { for (i = 0; i < nChildren; ++i) { if (FAILED(pDXEnum->GetChild(i, &pDXData))) break; if (FAILED(pDXData->GetType(&id))) { pDXData->Release(); break; } if (id == TID_D3DRMMesh) { if (SUCCEEDED(D3DXLoadMeshFromXof(pDXData, 0, CD3DRenderer::GetInstance()->GetDevice(), 0, 0, 0, 0, &m_pMesh))) { pDXData->Release(); break; } } pDXData->Release(); } } // Release used COM objects pDXEnum->Release(); pDXFile->Release(); #else if (FAILED(D3DXLoadMeshFromX("tiger.x", 0, CD3DRenderer::GetInstance()->GetDevice(), 0, 0, 0, 0, &m_pMesh))) { MessageBox(NULL, "Failed to load mesh", "Error", MB_OK); return false; } #endif return true; } bool CMainGame::GameLoop() { if (CD3DRenderer::GetInstance()->RenderBegin(TRUE, TRUE, TRUE) == FALSE) { MessageBox(NULL, "Failed to begin rendering", "Error", MB_OK); return false; } if (m_pMesh) m_pMesh->DrawSubset(0); CD3DRenderer::GetInstance()->RenderEnd(); return true; } void CMainGame::Shutdown() { if (m_pMesh) m_pMesh->Release(); m_pMesh = 0; CD3DRenderer::GetInstance()->Shutdown(); CD3DRenderer::DeleteInstance(); } Thank you for your time, Dev578
  10. Excellent, this is the kind of solution I was looking for. Thank you very much. Rating++. -Dev578
  11. Hmm, no replies. Maybe this never comes up in practice, I just have a bad design? It seems like there should be an elegant solution to this problem, maybe not. Thanks anyway. -Dev578
  12. This is a bit hard for me to put in words, but I'll give it my best shot. I have a registry object where you register with it to create certain objects. It instantiates a creation function for the requested object, and then you can create it with a string representing that object. As in, there is a map between strings and instantiated creation functions. The problem I am having is how you actually register derived types with the registry. You could do it in the registry itself, but then the registry would have to know about all of the types it creates. You could do it in "main," but then main would have to keep changing. Ideally, I would like this to happen somehow in the derived objects. As in, the derived objects would notify the registry how to create them. At first, you might think this can be done in the derived classes constructors. But then, the registry would try to create the objects, and they haven't been created yet (hence, their constructors haven't been called). This problem has come up in several projects I have worked on now, and I would really like an elegant solution once and for all. I took the time to write a sample application demonstrating what I am talking about. In the sample, I get it working the incorrect way by registering the objects in main. If anyone could offer a solution to this problem, it would be greatly appreciated. Thank you for your time, Dev578 #include <iostream> using std::cout; using std::cin; #include <map> #include <string> template <typename BaseType> class CRegistry { // Define our object creator type typedef BaseType* (*ObjectCreator)(); // Our map of strings to creation functions // the derived classes register in this map std::map<std::string, ObjectCreator> m_ObjectCreators; // Create a new object of a given type template <typename DerivedType> static BaseType* ConstructObject() { return new DerivedType; } public: // Constructor CRegistry(){} // Destructor ~CRegistry(){} // Register a derived class type template <typename DerivedType> void RegisterClassType(std::string sID) { m_ObjectCreators[sID] = ConstructObject<DerivedType>; } // Create an object BaseType* CreateObject(std::string sID) { std::map<std::string, ObjectCreator>::iterator mIter; mIter = m_ObjectCreators.find(sID); return mIter == m_ObjectCreators.end() ? 0 : mIter->second(); } }; class CBase { public: // Constructor CBase(){} // Destructor virtual ~CBase(){} }; class CDerivedOne : public CBase { public: // Constructor CDerivedOne(){} // Destructor virtual ~CDerivedOne(){} }; class CDerivedTwo : public CBase { public: // Constructor CDerivedTwo(){} // Destructor virtual ~CDerivedTwo(){} }; int main() { // Create our registry CRegistry<CBase> registry; // Register derived types: this is the problem I'm talking about // I DONT WANT THIS HERE: //////////////////////////////////////////////////////////////// registry.RegisterClassType<CDerivedOne>("DerivedOne"); registry.RegisterClassType<CDerivedTwo>("DerivedTwo"); //////////////////////////////////////////////////////////////// CBase* pOne = registry.CreateObject("DerivedOne"); CBase* pTwo = registry.CreateObject("DerivedTwo"); delete pTwo; delete pOne; return 0; }
  13. dev578

    Circle Math

    I have a weird problem I have encountered, and I am unfamiliar with the math in how to solve it. I have a vehicle and I can change its forward speed and turn speed to move it. For example, if I set the forward speed to 10m/sec and the turn speed to -20deg/sec, after one second the vehicle will have travelled an arc of length 10 meters, and the forward vector will have rotated by 20 degrees to the left. What I need to be able to do is tweak these two values to produce a circle of radius r. I looked up arc length equations and some geometry identities, but was unable to find a solution to the problem. Any ideas on how to handle this? Thank you, -Dev578
  14. dev578

    Trouble with some geometry

    Oh, that was easy. Sorry, sometimes I overcomplicate things without seeing a simple solution. Thank you for your time. -dev578
  15. I have two points, p1 and p2, and I know both of their coordinates. P2 is the center of a circle with radius x. Two tangent lines from the circle formed by p2 intersect at p1. I need to know the angle these two lines make. To clarify, if I made an arrow from p1 to p2, it would cross through the center of the angle I am looking for. I really do hate asking questions, but I don't really know how to research this one. Any help would be appreciated. Thank you, -dev578
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!