Results 1 to 6 of 6

Thread: Converting world coordinate orientation angles to roll, pitch, and yaw

  1. #1

    Default Converting world coordinate orientation angles to roll, pitch, and yaw

    For my current project, I'm receiving positional and orientation data from a DIS interface (Distributed Interactive Simulation). DIS provides world coordinate system X, Y, Z positional and psi, phi, theta orientation angles. From this information I'm attempting to render 3D models in their proper position and orientation. My code requires the position and the yaw, pitch, and roll of the 3D model to properly render. I quickly found out that DIS and WorldWind use a different X Y Z axis convention, but that was solved easily. I'm now trying to properly orientate the 3D models, but I'm having a heck of a time since my math skills aren't as strong as they need be.

    What I need to be able to do is take the world coordinate system phi, psi, and theta rotations and translate them into the roll, pitch, and yaw respective to the 3D model I'm rendering. I tried using quaternions (which I really don't even understand) as follows:

    Code:
            Quaternion quat = Quaternion.fromRotationXYZ(theta, psi, phi);
            double yaw = quat.getRotationX().degrees;
            double pitch = quat.getRotationY().degrees;
            double roll = quat.getRotationZ().degrees;
    Since I don't know how psi, phi, and theta relates between DIS and Worldwind, I tried reorienting them all (and yaw, pitch, and roll too). Long story short, I think I've tried all the possiblities and still can't figure it out and render my 3D models correctly. Is this even close to being correct? Or perhaps a better question, is there a simple way to convert world coordinate sytem psi, phi, theta orientations into a 3D model's respective roll, pitch and yaw?

    Thank you

  2. #2
    Senior Member
    Join Date
    Jun 2007
    Location
    Huntsville, AL
    Posts
    101

    Default

    Orienting models can be tricky. Make sure that you are orienting your models correctly by lat/lon rotations before adding roll/pitch/yaw to the mix.

  3. #3
    WWJ Consultant patmurris's Avatar
    Join Date
    Jun 2005
    Location
    Saint-Paul de Vence, Alpes Maritimes, France
    Posts
    3,383

    Default

    slade is right, getting a model to be properly orientated is often a source of confusion. Try first to get it 'standing' properly in any place on the globe before trying to apply yaw pitch or roll angles.

    Have a look at Globe.computeTransformToPosition().
    My World Wind Java Blog & WW.net Plugins page

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    22

    Default

    Did you end up having success with this??? I'm trying something similar with 3D models and I'm having a lot of trouble with the orientation of the model.

  5. #5

    Default Converting world coordinate orientation

    Yes, after a while I finally figured it out. So now my app will accept either DIS orientation info (phi, psi, and theta) or the more common roll, pitch, and yaw. Either way it will render it correctly.

    Code:
        protected void draw(DrawContext dc, WWModel3D model) {
            GL gl = dc.getGL();
            Position pos = model.getPosition();
            Vec4 loc = dc.getGlobe().computePointFromPosition(pos);
            double computedSize = this.computeSize(dc, loc);
    
            if (dc.getView().getFrustumInModelCoordinates().contains(loc)) {
    
                dc.getView().pushReferenceCenter(dc, loc);
    
                if (model.isDisDataUsed()){ // uses DIS coordinates
    
                    gl.glRotated(model.getPsi()  ,  0, 1, 0);    // psi is around z-axis (north pole) in DIS (Yaw)
                    gl.glRotated(model.getTheta(),  1, 0, 0);    // theta is around the y-axis in DIS (Pitch)
                    gl.glRotated(model.getPhi()  ,  0, 0, 1);    // phi is around the x-axis in DIS (Roll)
    
                } else {  // uses normal WW/OpenGL data coordinates--model's x-axis is front, its y-axis is right, and its z-axis is down
    
                    gl.glRotated(pos.getLongitude().degrees, 0, 1, 0);  // orient model with respect to world longitude
                    gl.glRotated(-pos.getLatitude().degrees, 1, 0, 0);  // orient model with respect to world latitude
    
                    double roll  = model.getRoll();
                    double pitch = model.getPitch();
                    double yaw   = model.getOrientation();
    
                    double cosPitch  = Math.cos(Math.toRadians(pitch));
                    double sinPitch  = Math.sin(Math.toRadians(pitch));
                    double cosRoll   = Math.cos(Math.toRadians(roll));
                    double sinRoll   = Math.sin(Math.toRadians(roll));
    
                    // 1st rotate pitch (around the x-axis)
                    gl.glRotated(pitch, 1, 0, 0);  // x-axis vector = [1 0 0]
                        // y' axis vector is now [ 0    cos(pitch)   -sin(pitch) ]
                        // z' axis vector is now [ 0    sin(pitch)    cos(pitch) ]
                        //  note: to pitch in the other direction, switch the - on the two "sin(pitch)" factors
    
                    // 2nd rotate roll around the y' axis
                    gl.glRotated(roll,   0, cosPitch, -sinPitch);
                        // z" axis vector is now [ -sin(roll)    sin(pitch)*cos(roll)  cos(pitch)*cos(roll) ]
    
                    // 3rd rotate yaw around z" axis
                    gl.glRotated(-yaw, -sinRoll, sinPitch*cosRoll, cosPitch*cosRoll);
    
                    // Last step: Orient 3D model to correct coordinate system
                    gl.glRotated(-90, 1, 0, 0);
                    
                }
                gl.glScaled(computedSize, computedSize, computedSize);
                gl.glCallList(Model3DisplayListFactory.getModel(gl, model.getPath(), model.getLightingEnabled()));
                dc.getView().popReferenceCenter(dc);
            }
        }

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    22

    Default

    Thanks, that helped! I'm new to jogl so a point of confusion for me was whenever glRotated(...) is called it pushes something on a stack so the rotations actually get executed in reverse order. Just something I needed to keep in mind when visualizing a series of rotations. Also, rotating by lat/lon to align the model to the ground assumes a spherical earth so it might be a tiny bit off depending on latitude.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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