// Persistence of Vision Ray Tracer Scene Description File // File: QSample1.pov // Vers: 3.5 // Desc: Very basic introduction sample for using quaternions for rotation // Date: 2003.10.07 // Auth: Alain Ducharme // Run as animation (ex.: use command line option +kff50) #version 3.5; global_settings { assumed_gamma 1.0 } #default { texture { pigment { color rgb 1 } finish { specular 0.9 roughness 0.02 } } } camera { location <0.0, 0.5, -4.0> angle 53 right x*image_width/image_height look_at <0.0, 0.0, 0.0> } light_source { <0, 0, 0> color rgb <1, 1, 1> translate <-30, 30, -30> } #include "quaternions.inc" // Quaternion can be used to rotate a vector or an entire object using // a transfomation matrix. Set UseVector to true to demonstrate rotation of // a vector. Set it to false to rotate the entire object using a matrix // In this example the end result should be the same #declare UseVector = false; //Different ways to create a quaternion #declare qa = <0,0,0,1>; // Directly, not easy (no rotation, in this case) #declare qb = QRotate(z,pi/2); // Rotation around arbitrary axis #declare qc = EulerToQ(<0,0,-pi/2>); // As a regular xyz rotate #declare qd = QRotate(<10,2,2>,pi); // Rotation about arbitrary axis // You can also create a quaternion from an existing Povray transformation matrix // using ABX's Transform_To_Array() macro in combination with QFromMatrix() // Bezier rotation from qa to qb using qc & qd // Last parameter is 0 to 1 (qa to qb) // (sin used here for smooth acceleration and deceleration) #declare qr = QBezier(qa,qc,qd,qb,sin(pi*clock/2)); // Or Rotate from qa to qb using tangents qc & qd //#declare qr = QHermite(qa,qb,qc,qd,sin(pi*clock/2)); // Could also do linear interpolation with qr = QLinear(qa,qb,clock), but because // qa has no rotation in this example, you could simply use qr = QRotate(z,(pi/2)*clock) // You can also use qr = QMultiply(qr,qb) to add two rotations together, suppose you // store qr in between frames, or use it in a loop, this is an easy way to // rotate an entire object in any arbitrary angular direction. // Show the current axis of rotation from origin using red cylinder // (could be used to see the single axis of rotation for any standard Pov rotations) #declare angl = 0; #declare axe = QAxAn(qr,angl); cylinder { 0,axe, 0.01 texture { pigment { color rgb <1,0,0> } } } #declare Vec = <0,1,0>; #if (UseVector) // Rotate the vector using the quaternion #declare Vec = VQRotate(Vec,qr); #else // Or, use a transformation matrix to rotate the object #declare M = QToMatrix(qr); #end union { cylinder { <0,0,0>, Vec, 0.1 } cone { <0,0,0>, 0.2, Vec/4, 0 translate Vec } #if (!UseVector) matrix #end }