Align to velocity vector using Quaternions

Started by
19 comments, last by nardove 14 years, 2 months ago
We got some motion! I change the line to

rotationQuat = rotationQuat.createFromAxisAngle(axis, angle);


Then

Matrix4x4 rotationMatrix = rotationQuat.getMatrix();


and as you can see here http://nardove.com/p5/misc/steering_3g

go nuts, I need to check the applyMatrix() values, the problem may be there

applyMatrix reference http://processing.org/reference/applyMatrix_.html


mat = quat.getMatrix();    //println(mat.matrix[0][0]);    Vec3D forward = new Vec3D((float)mat.matrix[0][2],                              (float)mat.matrix[1][2],                              (float)mat.matrix[2][2]);        Vec3D desired_forward = velocity.normalize();    Vec3D axis = forward.cross(desired_forward);    float leng = axis.magnitude();            if (leng > EPSILON) {      axis.scaleSelf(1 / leng);      float angle = atan2(leng, forward.dot(desired_forward));      rotationQuat = rotationQuat.createFromAxisAngle(axis, angle);            quat = quat.multiply(rotationQuat);      quat.normalize();            if (verbose) {        println("length:       " + leng);        println("angle:        " + angle);        println("axis:         " + axis);        println("rotationQuat: " + rotationQuat);        println("- - - - - - - - - - - - - - - - - - - - - - - -");      }    }            Matrix4x4 rotationMatrix = rotationQuat.getMatrix();    println(rotationMatrix);        //applyQuat2Matrix(rotationQuat);        pushMatrix();    // update location    translate(location.x, location.y, location.z);    // orientation to velocity    //rotate(rotationQuat.w, rotationQuat.x, rotationQuat.y, rotationQuat.z);    //rotate(res[0], res[1], res[2], res[3]);    applyMatrix((float)rotationMatrix.matrix[0][0], (float)rotationMatrix.matrix[0][1], (float)rotationMatrix.matrix[0][2], 0.0,                (float)rotationMatrix.matrix[1][0], (float)rotationMatrix.matrix[1][1], (float)rotationMatrix.matrix[1][2], 0.0,                (float)rotationMatrix.matrix[2][0], (float)rotationMatrix.matrix[2][1], (float)rotationMatrix.matrix[2][2], 0.0,                                        0.0,                         0.0,                         0.0, 1.0);         agent.display();        popMatrix();


... almost there :)

rS

This topic is closed to new replies.

Advertisement