Results 1 to 5 of 5

Thread: node transforms

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    20

    node transforms

    can anybody tell me how to get the transform of a node? i know this sounds simple, but all i see in some of the nodes is info for (and some of this data is missing for certain nodes, mostly translational data):
    getRotate_array
    getTranslate_array

    getMatrix_array doesn't have an data for all of my nodes.
    Matt

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    You can use the domNode::getContents method to iterate over the elements in the <node> and concatenate all the transforms. The getContents method returns the elements in the order they appeared in the file, which is important for applying the transforms in the right order.
    Code :
    daeElementRefArray& elements = node->getContents();
    Matrix resultMatrix = identity;
     
    for (size_t i = 0; i < elements.getCount(); i++) {
      if (elements[i]->getElementType() == COLLADA_TYPE::TRANSLATE) {
        // We have a <translate> element. Convert it to a matrix and concatenate it with the result transform
        resultMatrix = convertToMatrix(elements[i])*resultMatrix;
      } else if (elements[i]->getElementType() == COLLADA_TYPE::ROTATE) {
        // Handle <rotate> element
      } else if ...

  3. #3
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Also, you might want to check here or here for more info.

  4. #4
    Junior Member
    Join Date
    Jun 2007
    Posts
    20
    Thanks for the help.

    I'm getting closer, but can't seem to get the data from the "TRANSLATE" element.

    In your code, where it says ...
    "// We have a <translate> element. Convert it to a matrix"

    I'm translating this to mean:

    domTranslate* domTrans = daeSafeCast<domTranslate>(elements[i]);
    domFloat3 trans = domTrans->getValue ();

    but trans contains invalid data.
    Can you tell me what I'm doing wrong?
    Matt

  5. #5
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Not sure. This works for me:
    Code :
    void testTranslate() {
    	DAE dae;
    	char* docUri = "file:///home/sthomas/models/Seymour.dae";
    	if (dae.load(docUri) != DAE_OK)
    		return;
     
    	// Get a random <translate> from the model
    	daeElement* element = 0;
    	dae.getDatabase()->getElement(&element, 0, 0, "translate");
    	domTranslate* translate = daeSafeCast<domTranslate>(element);
    	domFloat3& v = translate->getValue();
    	cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
    }
    It prints the value of the first <translate> element in the model, which in my case is 0 4.3 -1.0. This doesn't work for you? In my code I'm getting the value by reference (domFloat3&) instead of copying it, but it should work the same either way (and does for me).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •