Problem with DirectX scene-graph

  • Problem with DirectX scene-graph Alex

    I'm trying to implement a basic scene graph in DirectX using C++. I am using a left child-right sibling binary tree to do this. I'm having trouble updating each node's world transformation relative to its parent (and its parent's parent etc.). I'm struggling to get it to work recursively, though I can get it to work like this:

    for(int i = 0; i < NUM_OBJECTS; i++)
        // Initialize to identity matrix.
        int k = i;
        while( k != -1 )
            mObject[i].toWorldXForm *= mObject[k].toParentXForm;
            k = mObject[k].parent;

    toWorldXForm is the object's world transform and toParentXForm is the object's transform relative to the parent. I want to do this using a method within my object class (the code above is in my main class). This is what I've tried but it doesn't work (only works with nodes 1 generation away from the root)

    if (this->sibling != NULL)
    this->toWorldXForm *= this->toParentXForm;
    this->toWorldXForm *= toParentXForm;    
    toParentXForm *= this->toParentXForm;
    if (this->child != NULL)

    Sorry if I've not been clear, please tell me if there's anything else you need to know. I've no doubt it's merely a silly mistake on my part, hopefully an outside view will be able to spot the problem.

  • I believe what you are trying to do is simply stack the matrix of each child to generate the toWorldMatrix from a set of toParentMatrices?


    class Object
       void GenerateWorldMats();
       cMatrix toWorld;
       cMatrix toParent;
       Object* mParent;
       Object** mChildren;
       uint32 mNumChildren;

    You can...

    void Object::GenerateWorldMats()  
       if(mParent == NULL)
          toWorld = mParent.toWorld * toParent;  //Or Swapped order depending on pre or post mult
       for(int i = 0; i < mNumChildren; ++i)

c++ directx matrix scene-graph
Related questions and answers
  • every frame to handle input and render etc I call an UpdatePhysics method to update the physics simulation. void GameState::UpdatePhysics(unsigned int TDeltaTime) { World-&gt;stepSimulation(TDeltaTime... code shows the changes I made to get accurate physics. void GameState::createScene() { m_pSceneMgr-&gt;createLight("Light")-&gt;setPosition(75,75,75); // Physics // As a test we want a floor plane... the rigid body object btRigidBody *RigidBody = new btRigidBody(0, MotionState, Shape, LocalInertia); // Store a pointer to the Ogre Node so we can update it later RigidBody-&gt;setUserPointer((void

  • i think i just found the solution. 1) the problem is that backbuffer surface and source surface are of different formats - that is why exception was thrown. 2) the image path needed double slash "C...: return DefWindowProc(hWnd, message, wParam, lParam); } } bool initDirect3D(void) { pD3D = NULL; pd3dDevice = NULL; // create the DirectX object if(NULL == (pD3D = Direct3DCreate9..., Info.Format, D3DPOOL_SYSTEMMEM, &amp;Surface, NULL); D3DXLoadSurfaceFromFile(Surface, NULL, NULL, wsPath.c_str(), NULL, D3DX_FILTER_NONE, 0, NULL); pd3dDevice -&gt; GetBackBuffer(0, 0

  • ]; // nx, ny, nz; float colour[4]; // r, g, b, a float padding[20]; // padded for performance }; I've already written a working VertexBufferObject class that creates a vertex buffer... ); glDisableClientState( GL_COLOR_ARRAY ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); } Back to the Vertex Array Object though. My code for creating the Vertex... in the shader code) for( int n = 0; n < vShaderArgs.size(); n ++) glBindAttribLocation( m_nProgramId, n, vShaderArgs[n].sFieldName.c_str() ); // Create and bind to a vertex array object, which

  • but when I press the X button on the PSP I see no bullet being drawn or updated on the screen. I know the problem doesn't lie with the pad because I press start and it exits my game so I do not think it is the pad that is causing the problem. Maybe the bullet is being drawn out of the screen already. But I am not sure since I cannot debug maybe somebody can see the flaw in my code. main.cpp class... = (WIDTH / 2) - 64; allegro_message("Initialzing ship class"); s-&gt;Init(x); int frame = 0; BITMAP* buffer = NULL; BITMAP* background = NULL; BITMAP* ship = NULL; SceCtrlData

  • (pBackBuffer, NULL, &amp;rtv); pBackBuffer-&gt;Release(); // set the back buffer as the render target device-&gt;OMSetRenderTargets(1, &amp;rtv, dsv); D3D10_VIEWPORT viewport; // create a struct to hold... be on the depth buffer is 0.0 viewport.MaxDepth = 1; // the farthest an object can be on the depth buffer is 1.0 device-&gt;RSSetViewports(1, &amp;viewport); // set the viewport...(&amp;PassDesc); // get the Transform effect variable pTransform = pEffect-&gt;GetVariableByName("Transform")-&gt;AsMatrix(); // create the input element descriptions D3D10_INPUT_ELEMENT_DESC Layout

  • ; for(char i= '0'; i!= ' ';swall++) i= buff[buff.size()-1][swall+1]; int sspace= 0; int I= swall+1; for(char i= '0'; i!= 'X';sspace++, I++) i= buff[buff.size()-1][I..., coll); if(coll== 'X'){ if(player.Alive()== false){} // do something about it // if there is life else{ for(int I= 0... in the main function * not Finally.. but i believe that te numb_coll problem has something to do with the time and framrate. When running full speed i quickly die upon entering a wall as numb_coll

  • I'm writing a simple class to draw all the debugging lines I have in my scene at once. The code in the draw loop is this so far: (If I put for example, 2 instead of temporary2DVerts.size() where I...; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device-&gt;CreateBuffer(&amp;bd, NULL, &amp;pBuffer); void* pVoid; pBuffer-&gt;Map(D3D10_MAP_WRITE_DISCARD, 0, &amp;pVoid); //HERE memcpy(pVoid...(D3D10_PRIMITIVE_TOPOLOGY_LINELIST); UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); screenPass-&gt;Apply(0

  • with different types of objects in the same scene. I was also thinking about making a MeshNode class and then make a Mesh object that contains them, but then I have some conflict on where to store some data... know if my speculations are ok, as I don't have much experience with 3d animations yet. I want to make a well decision as any option I choose would require a lot of work to get it to render and I... for my needs. Ah and I forgot to mention that nodes can have hierarchy, but this is not a problem if the frame data is reduced. The structure instances don't get duplicated unless any value changes. When

  • I want to create an object than only moves along the the X and Z axes, while keeping the Y-axis disabled (it's like movement in 2D, and the object wont fall down). I'm currently using a 6 dof constraint to restrict movement in the Y-axis, but it's not working: btRigidBody* zeroBody = new btRigidBody(0, NULL, NULL); // Create the body that we attach things to btRigidBody* robot = mCarChassis-&gt...;setLinearLowerLimit( btVector3( 1, 1, 1)); constrict-&gt;setLinearUpperLimit( btVector3(-1, 1,-1)); constrict-&gt;setAngularLowerLimit( btVector3( 1, 1, 1) ); constrict-&gt;setAngularUpperLimit( btVector3(-1

Data information