Example #1
0
//--------------------------------------------------------------------------
void game::getMatrix( GLfloat * m, ofQuaternion quat ) {
	float x2 = quat.x() * quat.x();
	float y2 = quat.y() * quat.y();
	float z2 = quat.z() * quat.z();
	float xy = quat.x() * quat.y();
	float xz = quat.x() * quat.z();
	float yz = quat.y() * quat.z();
	float wx = quat.w() * quat.x();
	float wy = quat.w() * quat.y();
	float wz = quat.w() * quat.z();
	m[0] = 1.0f - 2.0f * (y2 + z2);
	m[1] = 2.0f * (xy - wz);
	m[2] = 2.0f * (xz + wy);
	m[3] = 0.0f;
	m[4] = 2.0f * (xy + wz);
	m[5] = 1.0f - 2.0f * (x2 + z2);
	m[6] = 2.0f * (yz - wx);
	m[7] = 0.0f;
	m[8] = 2.0f * (xz - wy);
	m[9] = 2.0f * (yz + wx);
	m[10] = 1.0f - 2.0f * (x2 + y2);
	m[11] = 0.0f;
	m[12] = 0.0f;
	m[13] = 0.0f;
	m[14] = 0.0f;
	m[15] = 1.0f;
}
Example #2
0
//------------------------------------------------------------
void Hammer::setRotation(ofQuaternion rotation){
    
    btTransform transform;
    btRigidBody* rigidBody = body.getRigidBody();
    rigidBody->getMotionState()->getWorldTransform( transform );
	
	btQuaternion originRot;
    originRot.setX(rotation.x());
    originRot.setY(rotation.y());
    originRot.setZ(rotation.z());
	originRot.setW(rotation.w());
    
	transform.setRotation(originRot);
	
    rigidBody->getMotionState()->setWorldTransform( transform );
    
}
Example #3
0
ofQuaternion testApp::lerpQuat(float t, ofQuaternion qa, ofQuaternion qb)
{
	ofQuaternion qm;

	//dot product
	float cosHalfTheta = qa.w() * qb.w() + qa.x() * qb.x() + qa.y() * qb.y() + qa.z() * qb.z();
    if (abs(cosHalfTheta) >= 1.0)
    {
        return qa;
    }
    else
    {
        // Calculate temporary values.
        float halfTheta = acos(cosHalfTheta);
        float sinHalfTheta = sqrt(1.0 - cosHalfTheta*cosHalfTheta);
        // if theta = 180 degrees then result is not fully defined
        // we could rotate around any axis normal to qa or qb
        if (fabs(sinHalfTheta) < 0.001){ // fabs is floating point absolute
        	qm.set(
        			(qa.x() * 0.5 + qb.x() * 0.5),
        			(qa.y() * 0.5 + qb.y() * 0.5),
        			(qa.z() * 0.5 + qb.z() * 0.5),
        			(qa.w() * 0.5 + qb.w() * 0.5)
        		);

            return qm;
        }

        float ratioA = sin((1 - t) * halfTheta) / sinHalfTheta;
        float ratioB = sin(t * halfTheta) / sinHalfTheta;

        //calculate Quaternion
    	qm.set(
    	        (qa.x() * ratioA + qb.x() * ratioB),
    	        (qa.y() * ratioA + qb.y() * ratioB),
    	        (qa.z() * ratioA + qb.z() * ratioB),
    	        (qa.w() * ratioA + qb.w() * ratioB)
    		);

        return qm;
    }
}
//--------------------------------------------------------------
void ofxBulletCapsule::create( btDiscreteDynamicsWorld* a_world, ofVec3f a_loc, ofQuaternion a_rot, float a_mass, float a_radius, float a_height ) {
	btTransform tr	= ofGetBtTransformFromVec3f( a_loc );
	tr.setRotation( btQuaternion(btVector3(a_rot.x(), a_rot.y(), a_rot.z()), a_rot.w()) );
	
	create( a_world, tr, a_mass, a_radius, a_height );
}
Example #5
0
string ofxToString(ofQuaternion q) {
    return ofToString(q.x()) + "," + ofToString(q.y()) + "," + ofToString(q.z()) + "," + ofToString(q.w());
}