Quantcast
Viewing all articles
Browse latest Browse all 40524

ofNode rotateAround() question

I'm looking into different ways to rotate a cube along one of his edges and came across the ofNode rotateAround function, which I tried to use in the following example. Now, something goes wrong and there's a duplication of the cube, due to very fast flipping back and forth... Can anyone shed some light on that function and what might cause this behaviour?

Also, any strategies for moving a cube around like this: https://www.youtube.com/watch?v=BZM9kTGFeko#t=3m33s
are very welcome.

.h
class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

        void eulerToQuats(ofVec3f);

    ofBoxPrimitive box;
    ofVec3f axis, euler;
    ofVec4f quat;
};

.cpp

//--------------------------------------------------------------
void ofApp::setup(){
    axis.set(-50.0, 0.0, -0.0);// Works fine
    //axis.set(-50.0, 50., -0.0);// Goes crazy
    quat.set (0.0, 0.0, 0.0, 0.0);
    box.set(100);
    box.setResolution(2);
    euler.set(0,0,0);
}

//--------------------------------------------------------------
void ofApp::update(){

    euler.z += 0.1;
    eulerToQuats(euler);
    box.rotate(quat);
    box.rotateAround(quat,axis);
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    box.drawAxes(100);
    box.drawWireframe();
}


//--------------------------------------------------------------
void ofApp::eulerToQuats(ofVec3f rotation){
    double c1 = cos(rotation.x/2);
    double s1 = sin(rotation.x/2);
    double c2 = cos(rotation.y/2);
    double s2 = sin(rotation.y/2);
    double c3 = cos(rotation.z/2);
    double s3 = sin(rotation.z/2);
    double c1c2 = c1*c2;
    double s1s2 = s1*s2;
    quat[0] =c1c2*c3 - s1s2*s3;
    quat[1] =c1c2*s3 + s1s2*c3;
    quat[2] =s1*c2*c3 + c1*s2*s3;
    quat[3] =c1*s2*c3 - s1*c2*s3;
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>