0

i am trying to loop through my scene graph with a draw function, this function is meant to take the world matrix and multiples it by the local matrix. i believe that i need to call the function recursively so that it work through the tree.

so far my function looks like so

draw(pContext, pWorldTransformMatrix)
{
    var newTransformMatrix = new Matrix()
    newTransformMatrix = pWorldTransformMatrix.multiply(this.mMatrix);
    newTransformMatrix.setTransform(pContext);
    // var child = new sceneGraph();
    for (var x =0; x<this.getNumberOfChildren(); x+=1)
    {
        var child = this.getChildAt(x);
        // child = this.getChildAt(x);
        child.draw(pContext, newTransformMatrix);
    }

}

i am getting the error

TypeError: Cannot read property 'draw' of undefined at sceneGraph.draw (\adir.hull.ac.uk\home\528\528986\Desktop\500085 2DCGAS\lab\js\sceneGraph.js:39:20)

the at sceneGraph.draw is repeated 7 times which i believe to be each node within the tree.

is this error coming from my function? and if so how would i think the error?

Bhoomi Patel
  • 777
  • 10
  • 32
RCHudspeth
  • 27
  • 1
  • 7
  • it means `sceneGraph` is undefined somewhere else. Probably you can check why it is undefined. – Kevin He Dec 12 '18 at 07:54
  • when looking at the variables with the debugger, i can see that the all the `sceneGraphs` are defined except for the bottom nodes which are my `draw` functions. is my issue due to these being undefined? or are they meant to be like that? – RCHudspeth Dec 12 '18 at 08:39

0 Answers0