Results 1 to 3 of 3

Thread: Problem with "rotate"

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    5

    Problem with "rotate"

    Hi,

    I'm currently implementing Collada import for "Render Studio", you can see the c# source code at : http://rs.codeplex.com/

    But I have a problem when loading the "BikeFromXSI" from :
    http://collada.org/owl/browse.php?sess= ... rtname=ASC

    When I remove the rotation, the bike sounds correct, but when I add it, I got a very strange result, where some parts of the bike are not at the correct position and the correct orientation.

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: Problem with "rotate"

    You have to concatenate the transforms in the order they occur within the node element.

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    5

    Re: Problem with "rotate"

    Thanks a lot Marcus,

    It is what I do, here is my code :

    Code :
    it = navigator.Select("child::*", NSManager);
                while (it.MoveNext())
                {
                    switch (it.Current.Name)
                    {
                        case "lookat":
                            LookAt(it.Current);
                            break;
                        case "matrix":
                            Matrix(it.Current);
                            break;
                        case "rotate":
                            Rotate(it.Current);
                            break;
                        case "scale":
                            Scale(it.Current);
                            break;
                        case "skew":
                            Skew(it.Current);
                            break;
                        case "translate":
                            Translate(it.Current);
                            break;
                        case "instance_geometry":
                            InstanceGeometry(it.Current);
                            break;
                    }
                }

    Code :
            public void Translate(XPathNavigator navigator)
            {
                Node node = _nodes.Peek();
     
                float[] translation = ConvertString2FloatArray(navigator.Value);
                Vector3 transVector = new Vector3(translation[0], translation[1], translation[2]);
     
                // Apply all the transformations to the same matrix
                node.Rotation.Translation = node.Rotation.Translation + transVector;
            }

    Code :
            public void Rotate(XPathNavigator navigator)
            {
                Node node = _nodes.Peek();
     
                string sid = navigator.GetAttribute("sid", "");
                float[] rotation = ConvertString2FloatArray(navigator.Value);
     
                double angle = rotation[3] / 180 * System.Math.PI;
                double theta = System.Math.Cos(angle / 2);
     
                Quaternion q = new Quaternion(theta, rotation[0], rotation[1], rotation[2]);
     
                // Apply all the transformations to the same matrix
                node.Rotation = node.Rotation * q.ToRotationMatrix();
            }

Posting Permissions

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