├── IK with DQ Report.docx ├── assets ├── electricfield.gif ├── electricfield2.gif ├── electricfieldmask.gif └── electricfield2mask.gif ├── main.cpp ├── DQ_Clickable_Object.h ├── IK-RobotArm.sln ├── README.md ├── ToDo.txt ├── DQ_Sphere.h ├── dualquat.h ├── DQ_Bone.h ├── IK-RobotArm.vcxproj ├── DQ_Skeleton.h ├── IKRobotArm.h └── LICENSE /IK with DQ Report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juanmihd/IK-RobotArm/HEAD/IK with DQ Report.docx -------------------------------------------------------------------------------- /assets/electricfield.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juanmihd/IK-RobotArm/HEAD/assets/electricfield.gif -------------------------------------------------------------------------------- /assets/electricfield2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juanmihd/IK-RobotArm/HEAD/assets/electricfield2.gif -------------------------------------------------------------------------------- /assets/electricfieldmask.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juanmihd/IK-RobotArm/HEAD/assets/electricfieldmask.gif -------------------------------------------------------------------------------- /assets/electricfield2mask.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juanmihd/IK-RobotArm/HEAD/assets/electricfield2mask.gif -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | /// @author Sam & Juanmi 4 | // 5 | // Modular Framework for OpenGLES2 rendering on multiple platforms. 6 | // 7 | // This is the Main for the project of the Robotic Arm 8 | // 9 | 10 | #define OCTET_BULLET 1 11 | 12 | #include "../../octet.h" 13 | #include "IKRobotArm.h" 14 | 15 | /// Create a box with octet 16 | int main(int argc, char **argv) { 17 | // set up the platform. 18 | octet::app::init_all(argc, argv); 19 | 20 | // our application. 21 | octet::IKRobotArm app(argc, argv); 22 | app.init(); 23 | 24 | // open windows 25 | octet::app::run_all_apps(); 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /DQ_Clickable_Object.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////// 2 | /// 3 | /// @author Sokol, Sam & Juanmi 4 | /// 5 | /// This class will form the base for all clickable objects 6 | /// 7 | 8 | #ifndef DQ_CLICKABLE_OBJ_H_INCLUDED 9 | #define DQ_CLICKABLE_OBJ_H_INCLUDED 10 | 11 | #include "dualquat.h" 12 | /// @brief Objects of this class will clickable, doing so shall return a pointer to this obejct 13 | /// Objects of this class will have the option to be bullet physics objects. 14 | namespace octet{ 15 | class ClickableObject : public resource{ 16 | private: 17 | DualQuat dual_quat; 18 | mesh _mesh; 19 | material *mat; 20 | bool is_dynamic; 21 | float mass; 22 | btRigidBody* rigidbody; 23 | ref app_scene; 24 | 25 | public: 26 | ClickableObject(){} 27 | ~ClickableObject(){} 28 | 29 | /// @brief initialise the clickable object given all parameters 30 | void init(visual_scene &app_scene_in, DualQuat dual_quat ){ 31 | 32 | } 33 | }; 34 | } 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /IK-RobotArm.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IK-RobotArm", "IK-RobotArm.vcxproj", "{6722CC8F-3FC9-4B11-B7AE-918054DD5ACA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6722CC8F-3FC9-4B11-B7AE-918054DD5ACA}.Debug|x64.ActiveCfg = Debug|x64 15 | {6722CC8F-3FC9-4B11-B7AE-918054DD5ACA}.Debug|x64.Build.0 = Debug|x64 16 | {6722CC8F-3FC9-4B11-B7AE-918054DD5ACA}.Release|x64.ActiveCfg = Release|x64 17 | {6722CC8F-3FC9-4B11-B7AE-918054DD5ACA}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IK-RobotArm 2 | OpenGL robotic arm controlled with Inverse Kinematics using Dual-Quaternions. 3 | 4 | This project it's done with https://github.com/Schmurst, and with https://github.com/sokol_murturi112 as our second assignment for the MATHEMATICS AND GRAPHICS module of the MSc in Computer Games & Entertainment at Goldsmiths, University of London. 5 | 6 | This project it's developed for OCTET Framework, using C++ with OpenGL. This is an educational project, but it can be easily exported and used for other purposes. 7 | 8 | How to use this 'game': 9 | 10 | - Mouse click -> The arm will go to the position clicked by the mouse. 11 | - Arrow keys -> To move the arm along the 'bar' 12 | - Ctrl+Arrow keys -> Teleports the arm to the middle position of each side of the table. 13 | - Spacebar -> Throw a magnetic charge 14 | - A -> Move the arm to a random position 15 | - S -> Activate the closest-neighbour algorithm to a random position 16 | - D -> Toggle party-mode. 17 | - R -> Move the arm to the top. 18 | - O -> Throw the balls again (to play again!) 19 | - Q -> Stops the current movement! 20 | - 1 -> Rotates the camera to the left 21 | - 2 -> Rotates the camera to the right 22 | - 3 -> Toggles top-view and side-view 23 | 24 | 25 | 26 | This project has been developed by: 27 | Sam Hayhurst, Juan Miguel Huertas Delgado and Sokol Murturi 28 | 29 | 30 | To use this application, put the images in the folder assets into the octet folder of octet/assets. And then... have fun!!! -------------------------------------------------------------------------------- /ToDo.txt: -------------------------------------------------------------------------------- 1 | INVERSE KINEMATICS WITH DUAL-QUATERNION 2 | WhWeWaToDo: 3 | 1st: Move a simple arm model, with two bones, one of them anchored. 4 | - Create the GIT repository. (Check) 5 | - Program the dual-quaternion (REF: Check Andy's class). (Check) 6 | - Program the bones-joints-arm structure -as a skeleton- (classes and so). (Partially checked) 7 | - Do it with a sphere+cylinder "bone". 8 | - Position of the arm (joint) - sphere. 9 | - Orientation of the arm (bone) - cylinder.orientation. 10 | 11 | 12 | >>>>IMPORTANT<<<< Rethink about the cylinder mesh. How do we want to represent the bone? We need a different mesh per bone? Or a dynamic mesh of a cylinder? 13 | 14 | 15 | - Length of the arm (bone) -cylinder.length. (position of the next arm sphere) 16 | - Program an 'interface' class for the skeletons(arms...) 17 | - "Build" the arm (three bones). (Checked) 18 | - Solve how to move the arm. 19 | 20 | 21 | >>>>IMPORTANT<<<< We need to add an animation process, that let us assign a new quaternion and a number of tics (time?) so it will animate the arm movement 22 | by interpolating between two different quaternions. To do this we need two methods, one to initialize the animation and another one to effectively animate 23 | the arm (only by increasing the "tic" of the current frame, and checking if the movement is done, and stopping the movement consequently) 24 | 25 | 26 | - Lazy random solution (incremental). 27 | - Program the inverse kinematics (mysterious box). 28 | - To do so, we will use the "Jacobian" matrix. 29 | 2nd: Add claw (and grab things?) and add other objects and table 30 | - Add the claw to the hand (not inverse kinematics). 31 | - Add objects to be grabbed. 32 | - Obtain the ray tracing thing. 33 | 3rd: Hanoi towers 34 | - Build the system. 35 | ---- dreaming starts here ---- 36 | 4th: AI for Hanoi towers 37 | 5th: Dynamically application for skeleton (turning it into a library) 38 | 6th: Make a dude walk 39 | 40 | Extra: 41 | 42 | ToDo: 43 | Understand dual-quaternions & inverse kinematics. 44 | Assemble it to do the 1st. 45 | 46 | Things that we need to do: 47 | - Dual-quaternion class 48 | - Ray-tracing 49 | 50 | Things to ask Andy: 51 | Why the code notation of quaternions is "(x,y,z),w" instead of like the mathematical rotation "w,(x,y,z)" 52 | Build the dual-quaternion class (based in Octet) -------------------------------------------------------------------------------- /DQ_Sphere.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////// 2 | /// 3 | /// @author Sam & Juanmi & Sokol 4 | /// 5 | /// Small classes that represents a quaternion and a dual-quaternion 6 | /// 7 | 8 | 9 | #ifndef DQ_SPHERE_H_INCLUDED 10 | #define DQ_SPHERE_H_INCLUDED 11 | 12 | #include "dualquat.h" 13 | namespace octet{ 14 | /// @brief This class represents a sphere which will have a charge, these 15 | /// sphere are design to be interacted upon by the robot arm. 16 | class DQ_Sphere : public resource{ 17 | private: 18 | // private data for the DQ_sphere. 19 | btRigidBody* rigid_body; // allow bt raycasting implementation plus physics sim. 20 | mat4t world_transform; 21 | ref node; 22 | float magnetism_power; 23 | mesh_instance* mesh_i; 24 | // pointer to visual scene used to add the shape to the world(s) 25 | visual_scene* app_scene; 26 | 27 | public: 28 | DQ_Sphere(){ 29 | mesh_i = nullptr; 30 | }; 31 | 32 | ~DQ_Sphere(){}; 33 | 34 | /// @brief initialse defaults for the sphere. 35 | void init(visual_scene* vs, vec3 pos = vec3(0), float radius = 1.0f, float n_magnetism_power = 40.0f){ 36 | material* my_material; 37 | app_scene = vs; 38 | magnetism_power = n_magnetism_power; 39 | if (n_magnetism_power < 0) 40 | my_material = new material(new image("assets/duckCM.gif")); 41 | else 42 | my_material = new material(new image("assets/grass.jpg")); 43 | world_transform[3] = vec4(pos, 1); 44 | mesh_instance* mesh_i = app_scene->add_shape(mat4t_in(world_transform), new mesh_sphere(vec3(0), radius), my_material, true); 45 | node = mesh_i->get_node(); 46 | rigid_body = node->get_rigid_body(); 47 | rigid_body->setActivationState(DISABLE_DEACTIVATION); 48 | } 49 | 50 | /// @brief This function is used to get the rigid body of the ball 51 | btRigidBody* get_rigidbody(){ 52 | return rigid_body; 53 | } 54 | 55 | /// @brief This function is used to get the position of the ball 56 | vec3 get_pos(){ 57 | return world_transform[3].xyz(); 58 | } 59 | 60 | scene_node* get_node(){ 61 | return node; 62 | } 63 | 64 | /// @brief this function gets the end position of the DQ_Skeleton and then 65 | /// produces an attuenated force on the rigidbody of this sphere inversely 66 | /// proportional to the square of the distance to the centre of the SPhere. 67 | void resolve_magnetic_force(vec3 wrist_pos){ 68 | // calculate vector between the wrist and this sphere 69 | vec3 force = node->get_nodeToParent()[3].xyz() - wrist_pos; 70 | force.get()[1] = 0.0f; 71 | float magnitude = force.lengthRecip(); 72 | force = force.normalize(); 73 | magnitude = magnetism_power * magnitude; 74 | btVector3 temp = get_btVector3(force * magnitude); 75 | this->get_rigidbody()->applyCentralImpulse(temp); 76 | } 77 | 78 | /// @brief This function is used to set the magentism power of the ball 79 | void set_magnetism_power(float n_magnetism_power){ 80 | magnetism_power = n_magnetism_power; 81 | } 82 | }; 83 | } 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /dualquat.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////// 2 | /// 3 | /// @author Sam & Juanmi 4 | /// 5 | /// Small classes that represents a quaternion and a dual-quaternion 6 | /// 7 | 8 | #ifndef DUALQUAT_H_INCLUDED 9 | #define DUALQUAT_H_INCLUDED 10 | 11 | /// @brief This is a copy of Andy's class quaternionwith some minor improvements 12 | namespace octet { 13 | class Quaternion : public vec4 14 | { 15 | public: 16 | /// @brief This is the constructor, initialize a quaternion with w = 1 and v = (0,0,0) 17 | Quaternion() : vec4(0, 0, 0, 1) {} 18 | /// @brief This will create a quaternion with a given set of values 19 | Quaternion(float x, float y, float z, float w) : vec4(x, y, z, w) {} 20 | /// @brief This is the copy constructor for the quaternion 21 | Quaternion(const vec4 &r) { *(vec4*)this = r; } 22 | /// @brief This is the product between quaternions 23 | Quaternion operator*(const Quaternion &r) const { return Quaternion(qmul(r)); } 24 | /// @brief This is the product of the quaternion with a scalar 25 | Quaternion operator*(float r) const { return Quaternion((vec4&)*this * r); } 26 | /// @brief This is to be able to concatenate different multiplications of quaternions 27 | Quaternion &operator*=(const Quaternion &r) { *(vec4*)this = qmul(r); return *this; } 28 | /// @brief This is the conjugate (uses vec4 conjugate) 29 | Quaternion conjugate() const { return qconj(); } 30 | /// @brief This is to rotate the quaternion along a vector (it will be rotate by the magnitudine) 31 | vec4 rotate(const vec4 &r) const { return (*this * r) * conjugate(); } 32 | /// @brief This is to be able to normalize the quaternion (uses the vector normalizer) 33 | void normalize(){ 34 | this->normalize(); 35 | } 36 | }; 37 | } 38 | 39 | /// @brief This is the class of the dual quaternion (consisting only in two quaternions together) 40 | namespace octet{ 41 | class DualQuat{ 42 | /// The real part of the dual-quaternion, represents the rotation 43 | Quaternion real_part; 44 | /// The dual part of the dual-quaternion, represents translation*rotation*0.5f 45 | Quaternion dual_part; 46 | public: 47 | /// @brief Constructor of the dual-quaternion. The default value is ((1,(0,0,0),(0,(0,0,0))) 48 | DualQuat(){ 49 | real_part = Quaternion(0, 0, 0, 1); 50 | dual_part = Quaternion(0, 0, 0, 0); 51 | } 52 | /// @brief This creates a dual-quaternion with a given real part and a given dual part (both quaternions) 53 | DualQuat(Quaternion n_real_part, Quaternion n_dual_part){ 54 | real_part = n_real_part; 55 | dual_part = n_dual_part; 56 | } 57 | /// @brief This is the dot product with another dual-quaternion 58 | /// This will receive another dual-quaternion and will return the float result 59 | float dot_product(DualQuat n_DualQuat){ 60 | return this->real_part.dot(n_DualQuat.real_part); 61 | } 62 | /// @brief Multiplicator with an scalar 63 | DualQuat operator*(float scalar){ 64 | DualQuat ret; 65 | ret.real_part = Quaternion(real_part * scalar); 66 | ret.dual_part = Quaternion(dual_part * scalar); 67 | return ret; 68 | } 69 | /// @brief This is to multiply quaternions 70 | DualQuat qMult(DualQuat n_DualQuat) const{ 71 | DualQuat ret; 72 | ret.real_part = real_part * n_DualQuat.real_part; 73 | ret.dual_part = dual_part * n_DualQuat.real_part + real_part * n_DualQuat.dual_part; 74 | return ret; 75 | } 76 | 77 | /// @brief This is to normalize a dual-quaternion 78 | void normalize(){ 79 | float magnitudine = real_part.get()[0] * real_part.get()[0] + 80 | real_part.get()[1] * real_part.get()[1] + 81 | real_part.get()[2] * real_part.get()[2] + 82 | real_part.get()[3] * real_part.get()[3]; 83 | magnitudine = sqrt(magnitudine); 84 | // This is to correct errors with the float point. If it's close to zero, it's zero! 85 | // And therefore, if it's zero, it has to "explode" 86 | if (magnitudine == 0) magnitudine = 0.0000001; 87 | real_part = real_part * (1.0f / magnitudine); 88 | dual_part = dual_part * (1.0f / magnitudine); 89 | } 90 | /// @brief This is to add quaternions 91 | DualQuat operator+(DualQuat n_DualQuat){ 92 | DualQuat ret; 93 | ret.real_part = real_part + n_DualQuat.real_part; 94 | ret.dual_part = dual_part + n_DualQuat.dual_part; 95 | return ret; 96 | } 97 | /// @brief This return a new dual-quaternion that is the conjugate of the current one 98 | DualQuat conjugate(){ 99 | return DualQuat(real_part.conjugate(), dual_part.conjugate()); 100 | } 101 | /// @brief This will return a quaternion representing the rotation of the dual-quaternion 102 | Quaternion get_rotation(){ 103 | return real_part; 104 | } 105 | /// @brief This will return a vec3 representing the translation of the dual-quaternion 106 | vec3 get_translation(){ 107 | Quaternion translation = (dual_part * 2.0f) * real_part.conjugate(); 108 | return vec3(translation.get()[0], translation.get()[1], translation.get()[2]); 109 | } 110 | 111 | /// @brief This will return a matrix valid for octet from the dual-quaternion 112 | /// As a side effect will normalize the current dual-quaternion 113 | mat4t get_matrix(){ 114 | mat4t n_matrix; 115 | // These are the elements of the quaternion that represent the rotation 116 | float r_x = real_part.get()[0]; 117 | float r_y = real_part.get()[1]; 118 | float r_z = real_part.get()[2]; 119 | float r_w = real_part.get()[3]; 120 | // This is the vector that represent the translation 121 | vec3 translation = get_translation(); 122 | // Now we combine that information and build the matrix that will represent the same information as the dual-quaternion 123 | n_matrix.init(vec4( r_w*r_w + r_x*r_x - r_y*r_y - r_z*r_z, 2*r_x*r_y + 2*r_w*r_z, 2*r_x*r_z - 2*r_w*r_y, 0 ), 124 | vec4( 2*r_x*r_y - 2*r_w*r_z, r_w*r_w + r_y*r_y - r_x*r_x - r_z*r_z, 2*r_y*r_z + 2*r_w*r_x, 0 ), 125 | vec4( 2*r_x*r_z + 2*r_w*r_y, 2*r_y*r_z - 2*r_w*r_x, r_w*r_w + r_z*r_z - r_x*r_x - r_y*r_y, 0 ), 126 | vec4( translation.get()[0], translation.get()[1], translation.get()[2] , 1 )); 127 | 128 | return n_matrix; 129 | } 130 | 131 | void print_me(){ 132 | printf("Real part: (%f, %f, %f, %f)\n", real_part.get()[0], real_part.get()[1], real_part.get()[2], real_part.get()[3]); 133 | printf("Dual part: (%f, %f, %f, %f)\n", dual_part.get()[0], dual_part.get()[1], dual_part.get()[2], dual_part.get()[3]); 134 | } 135 | }; 136 | } 137 | 138 | #endif -------------------------------------------------------------------------------- /DQ_Bone.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////// 2 | /// 3 | /// @author Sokol, Sam & Juanmi 4 | /// 5 | /// This class represents the bone (including the mesh and the dual-quaternion) 6 | /// 7 | 8 | #ifndef DQ_BONE_H_INCLUDED 9 | #define DQ_BONE_H_INCLUDED 10 | 11 | #include "dualquat.h" 12 | 13 | 14 | /// @brief This class represents a bone (sublcass of mesh, and containin the dual-quaternion) 15 | namespace octet{ 16 | class DQ_Bone : public resource{ 17 | // This is the dual-quaternion that contains the information of the curren transform 18 | DualQuat transform; //local 19 | DualQuat world_transform; // world 20 | DualQuat best_world_transform; // best_world 21 | float length; //length of the bone 22 | 23 | //Some info to interpolate! 24 | DualQuat prev_transform; // previous local 25 | DualQuat next_transform; // next local 26 | DualQuat best_transform; // best_solution 27 | float theta; 28 | float costheta; 29 | float sintheta; 30 | 31 | //Info to constraint movement and random generation 32 | //If (0,0,0) no constraints 33 | bool rotation_constraint; 34 | vec3 rotation_axis; 35 | // Minimum angle 36 | float angle_min; 37 | // Maximum angle 38 | float angle_max; 39 | // Incremention angle 40 | float angle_inc; 41 | 42 | //scene_nodes structure 43 | struct SceneNodes{ 44 | ref joint_node; 45 | ref bone_node; 46 | }; 47 | SceneNodes scene_nodes; 48 | 49 | // Adjacent bones 50 | ref parent; // The root bone will have a NULL parent 51 | dynarray children; //The leaf bone will have 0 children 52 | 53 | public: 54 | /// @brief Default constructor of the Bone 55 | DQ_Bone(){ 56 | //printf("DQ_Bone Contstructor call \n"); 57 | } 58 | 59 | /// @brief Constructor of the Bone from a Dual-Quaternion 60 | DQ_Bone(DualQuat n_transfom){ 61 | transform = n_transfom; 62 | init_values(); 63 | } 64 | 65 | /// @brief Constructor of the Bone by a given length 66 | DQ_Bone(float n_length){ 67 | length = n_length; 68 | init_values(); 69 | if (length < 0) length = -length; 70 | DualQuat translation = DualQuat(Quaternion(0, 0, 0, 1), Quaternion(0, length / 2.0f, 0, 0)); 71 | transform = translation; 72 | } 73 | 74 | void init_values(){ 75 | rotation_constraint = false; 76 | rotation_axis = (0.0f, 0.0f, 0.0f); 77 | angle_min = 0.0f; 78 | angle_max = 2 * 3.141592653f; 79 | angle_inc = 3.141592653f / 8.0f; 80 | } 81 | 82 | /// @brief This function will set the range of the random generation of next "jump" 83 | void set_range(float n_angle_inc, const vec3 &direction = (0.0f, 0.0f, 0.0f), float n_angle_min = 0.0f, float n_angle_max = 2 * 3.141592653f){ 84 | angle_inc = n_angle_inc; 85 | rotation_axis = direction; 86 | angle_min = n_angle_min; 87 | angle_max = n_angle_max; 88 | } 89 | 90 | /// @brief This function will set the range of the random generation of next "jump" 91 | void constraint_in_axis(float x, float y, float z){ 92 | rotation_axis = vec3(x, y, z); 93 | rotation_axis = rotation_axis.normalize(); 94 | rotation_constraint = true; 95 | } 96 | 97 | /// @brief This function will set the range of the random generation of next "jump" 98 | void constraint_in_angle(float n_angle_min, float n_angle_max){ 99 | angle_min = n_angle_min; 100 | angle_max = n_angle_max; 101 | } 102 | 103 | /// @brief Add the scene nodes for the joint and the bone 104 | void add_scene_nodes(scene_node* n_joint_node, scene_node* n_bone_node){ 105 | //printf("DQ_Bone add_scene_nodes call\n"); 106 | scene_nodes.joint_node = n_joint_node; 107 | scene_nodes.bone_node = n_bone_node; 108 | } 109 | 110 | /// @brief Adds a parent to this bone 111 | void set_parent(DQ_Bone* n_parent){ 112 | parent = n_parent; 113 | } 114 | 115 | /// @brief Adds a new child to the current bone 116 | void add_child(DQ_Bone* child){ 117 | //this bone is going to be the parent of the child bone 118 | child->set_parent(this); 119 | //add the children 120 | children.push_back(child); 121 | } 122 | 123 | /// @brief Update the w_positions information checking the parent and with the current dual-quaternion 124 | /// This function will be called by the skeleton before the draw process starts 125 | SceneNodes obtain_joints(){ 126 | //Obtain the joints real world position 127 | return scene_nodes; 128 | } 129 | 130 | /// @brief Returns the position of the bone 131 | vec3 get_position_bone(){ 132 | vec4 position = scene_nodes.bone_node->access_nodeToParent().z(); 133 | return vec3(position.get()[0], position.get()[1], position.get()[2]); 134 | } 135 | 136 | /// @brief Returns the estimated position of the bone 137 | vec3 get_best_position_bone(){ 138 | return best_world_transform.get_translation(); 139 | } 140 | 141 | /// @brief Returns the estimated position of the bone 142 | vec3 get_world_position_bone(){ 143 | return world_transform.get_translation(); 144 | } 145 | 146 | /// @brief Returns the matrix of the bone 147 | mat4t get_matrix_bone(){ 148 | return world_transform.get_matrix(); 149 | } 150 | 151 | /// @brief This function will fix his joints and will ask his children to fix themselves 152 | /// This function asumes that the current bone has a correct joint_node information (setted by the parent) 153 | /// This is a recursion. Careful. Sokol, we are talking to you. 154 | void fix_yourself(const DualQuat &n_transform){ 155 | //Fix yourself 156 | world_transform = n_transform.qMult(transform); 157 | world_transform.normalize(); 158 | 159 | //dual-quaternion-magically obtain bone node 160 | scene_nodes.bone_node->access_nodeToParent() = world_transform.get_matrix(); 161 | 162 | //Ask your children to fix themselves 163 | for (size_t i = 0; i < children.size(); ++i) 164 | { 165 | children[i]->set_joint_node(world_transform); 166 | children[i]->fix_yourself(world_transform); 167 | } 168 | } 169 | 170 | /// @brief This function will obtain the potential ending of the current solution 171 | /// This function asumes that the current bone has a correct joint_node information (setted by the parent) 172 | /// This is a recursion. Careful. Sokol, we are talking to you. 173 | void test_yourself(const DualQuat &n_transform){ 174 | //Fix yourself 175 | best_world_transform = n_transform.qMult(best_transform); 176 | best_world_transform.normalize(); 177 | 178 | //Ask your children to fix themselves 179 | for (size_t i = 0; i < children.size(); ++i) 180 | { 181 | children[i]->test_yourself(best_world_transform); 182 | } 183 | } 184 | 185 | /// @brief This will go through the whole set of arms, setting the next_position as the best_position 186 | void set_best_as_next(){ 187 | next_transform = best_transform; 188 | //Ask your children to fix themselves 189 | for (size_t i = 0; i < children.size(); ++i) 190 | { 191 | children[i]->set_best_as_next(); 192 | } 193 | } 194 | 195 | /// Set the joint node 196 | void set_joint_node(DualQuat &n_transform){ 197 | scene_nodes.joint_node->access_nodeToParent() = n_transform.get_matrix(); 198 | } 199 | 200 | /// returns the length 201 | float get_length(){ 202 | //printf("%f\n", length); 203 | return length; 204 | } 205 | 206 | /// @brief This function grants access to the children of the node 207 | dynarray get_children(){ 208 | return children; 209 | } 210 | 211 | /// @brief This function will set the next position that this bone has to go 212 | void set_next_position(DualQuat &n_position){ 213 | prev_transform = transform; 214 | next_transform = n_position; 215 | costheta = prev_transform.dot_product(next_transform); 216 | theta = acosf(costheta); 217 | sintheta = sinf(theta); 218 | } 219 | 220 | /// @brief This function will set the best position that this bone has to go 221 | void set_best_position(DualQuat &n_position){ 222 | best_transform = n_position; 223 | } 224 | 225 | /// @brief This function will interpolate the bone by the given information 226 | /// This function will receive a cur_tic and the total_tic. It will set the 227 | /// current world_transform getting into account the initial and the end 228 | /// position of the arm 229 | void animate_bone(int cur_tic, int total_tics){ 230 | float tic = 1.0f*cur_tic / total_tics; 231 | 232 | //printf("transform: %f\n", tic); 233 | //transform.print_me(); 234 | if (sintheta > 0.000001) 235 | transform = prev_transform * (sinf((1.0f - tic)*theta) / sintheta) + 236 | next_transform * (sinf(tic*theta) / sintheta); 237 | else 238 | transform = prev_transform + (next_transform + (prev_transform * -1.0f))*tic; 239 | transform.normalize(); 240 | //Tell all the children to animate themselves 241 | for (size_t i = 0; i < children.size(); i++) 242 | children[i]->animate_bone(cur_tic, total_tics); 243 | } 244 | 245 | /// @brief This function will be called to finish an animation 246 | /// This will set the prev_transform and the current transform as the next transform so far 247 | /// it will recursively call its children to finish the animation 248 | void finish_animation(bool force){ 249 | if (force){ 250 | prev_transform = transform; 251 | next_transform = transform; 252 | } 253 | else{ 254 | prev_transform = next_transform; 255 | transform = next_transform; 256 | } 257 | 258 | //Tell all the children to finish themselves 259 | for (size_t i = 0; i < children.size(); i++) 260 | children[i]->finish_animation(force); 261 | } 262 | 263 | /// @brief This function generates and return a new random position for this arm 264 | DualQuat generate_random_next(float new_angle, float x, float y, float z){ 265 | vec3 new_axis = vec3(x, y, z); 266 | //printf("Randomly rotating %f degrees along (%f, %f, %f)\n", new_angle, new_axis.get()[0], new_axis.get()[1], new_axis.get()[2]); 267 | new_axis = new_axis.normalize(); 268 | if (rotation_constraint) 269 | new_axis = rotation_axis; 270 | //printf("\n%f\n", angle_inc); 271 | new_angle = angle_inc * new_angle; 272 | //if (new_angle >= angle_max) new_angle = angle_max; 273 | //if (new_angle <= angle_min) new_angle = angle_min; 274 | float cos_half_angle = cos(new_angle / 2.0f); 275 | float sin_half_angle = sin(new_angle / 2.0f); 276 | //printf("Randomly rotating %f degrees along (%f, %f, %f)\n", new_angle, new_axis.get()[0], new_axis.get()[1], new_axis.get()[2]); 277 | //Creating the increment dualquat to add to the current dualquat 278 | DualQuat increment = DualQuat(Quaternion(new_axis.get()[0] * sin_half_angle, 279 | new_axis.get()[1] * sin_half_angle, 280 | new_axis.get()[2] * sin_half_angle, 281 | cos_half_angle), 282 | Quaternion(0, 0, 0, 0)); 283 | DualQuat temp = transform.qMult(increment); 284 | /* 285 | printf("Transform: \n"); 286 | transform.print_me(); 287 | printf("Increment: \n"); 288 | increment.print_me(); 289 | printf("Temp: \n"); 290 | temp.print_me(); 291 | printf("\n\n");*/ 292 | return temp; 293 | } 294 | }; 295 | } 296 | 297 | #endif -------------------------------------------------------------------------------- /IK-RobotArm.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {6722CC8F-3FC9-4B11-B7AE-918054DD5ACA} 15 | Win32Proj 16 | IK-RobotArm 17 | 18 | 19 | 20 | Application 21 | true 22 | Unicode 23 | v120 24 | 25 | 26 | Application 27 | false 28 | true 29 | Unicode 30 | v120 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | false 44 | $(SolutionDir)..\..\..\bin\ 45 | $(SolutionDir)..\..\..\bin\$(ProjectName)\$(Configuration)\ 46 | $(ProjectName)_debug 47 | 48 | 49 | false 50 | $(SolutionDir)..\..\..\bin\ 51 | $(SolutionDir)..\..\..\bin\$(ProjectName)\$(Configuration)\ 52 | $(ProjectName) 53 | 54 | 55 | 56 | 57 | 58 | Level3 59 | Disabled 60 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 61 | ProgramDatabase 62 | C:\Projects\Octet_IK_Robot\octet\octet; 63 | 64 | 65 | Console 66 | true 67 | 68 | 69 | 70 | 71 | Level3 72 | 73 | 74 | MaxSpeed 75 | true 76 | true 77 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 78 | 79 | 80 | Console 81 | true 82 | true 83 | true 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /DQ_Skeleton.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////// 2 | /// 3 | /// @author Sokol, Sam & Juanmi 4 | /// 5 | /// This class represents the skeleton (contains bones) 6 | /// 7 | 8 | #ifndef DQ_SKELETON_H_INCLUDED 9 | #define DQ_SKELETON_H_INCLUDED 10 | 11 | #include "DQ_Bone.h" 12 | 13 | /// @brief This class represent a skeleton made of dual-quaternions 14 | /// Contains a set of bones, anchored to the root bone 15 | namespace octet{ 16 | enum TypeSkeleton_Anim { _RANDOM_DANCE = -1, _RANDOM_ALG = 0, _IK_ALG = 1 }; 17 | enum StatusSkeleton { _STILL = -1, _ANIMATING = 0, _ALGORITHMING = 1 }; 18 | enum { _REAL_RANDOM = 1, _NUM_FAILED_ATTEMPTS = 10, _NUM_SOLUTIONS = 1000 }; 19 | class DQ_Skeleton : public resource{ 20 | //This bone is the root of the skeleton 21 | ref root_bone; 22 | ref wrist_bone; 23 | // This is the status of the current skeleton 24 | StatusSkeleton status; 25 | // This is for the stocastich algorithm 26 | vec3 dest_position; 27 | random rand_gen; 28 | float range; 29 | float best_distance; 30 | int total_tic; 31 | size_t num_failed_attemps; 32 | //This represent where the root bone is anchored 33 | DualQuat root_transform; 34 | //Info to draw the meshes 35 | ref app_scene; 36 | // sphere mesh set up 37 | ref mesh_joint; 38 | ref mesh_root; 39 | ref mesh_hand; 40 | ref hand_node; 41 | ref mat_joint; 42 | ref mat_hand; 43 | ref mat_bone; 44 | 45 | /// @brief This function will update all the joints of the bones (starting from the root) 46 | void update_joints(){ 47 | //printf("DQ_Skeleton update_joints call\n"); 48 | // update current bone's joints 49 | if (root_bone != nullptr){ 50 | //root_bone->animate_bone(); 51 | root_bone->set_joint_node(root_transform); 52 | root_bone->fix_yourself(root_transform); 53 | } 54 | } 55 | 56 | public: 57 | /// @brief Default constructor of the DQ_Skeleton 58 | DQ_Skeleton(){ 59 | range = 0; 60 | //For the stocastic algorithm 61 | if (_REAL_RANDOM) 62 | rand_gen.set_seed(time(NULL)); 63 | status = _STILL; 64 | num_failed_attemps = _NUM_FAILED_ATTEMPTS; 65 | //printf("DQ_Skeleton Contstructor call \n"); 66 | root_bone = nullptr; 67 | // Initialising the meshes and materials 68 | // create the sphere and cylinder meshes used to draw the skeleton 69 | mesh_joint = new mesh_sphere(vec3(0.0f, 0.0f, 0.0f), 0.6f); 70 | mesh_root = new mesh_sphere(vec3(0.0f, 0.0f, 0.0f), 1.0f); 71 | mesh_hand = new mesh_box(vec3(0.5f, 0.5f, 0.5f)); 72 | //set materials 73 | mat_joint = new material(vec4(1.0f, 0.0f, 0.0f, 1.0f)); 74 | mat_bone = new material(vec4(0.8f, 0.8f, 0.8f, 1.0f)); 75 | mat_hand = new material(vec4(0.0f, 0.0f, 1.0f, 1.0f)); 76 | } 77 | 78 | /// @brief This function will return the status of the skeleton 79 | StatusSkeleton get_status(){ return status; } 80 | 81 | /// @brief inits the DQ_SKeleton, it needs a position to where to anchor the root bone 82 | void init(const vec3 &position = vec3(0, 0, 0)){ 83 | //We obtain a pure translation with no rotation to represent the position of the anchor bone 84 | root_transform = DualQuat(Quaternion(0, 0, 0, 1), Quaternion(position.get()[0] / 2.0f, position.get()[1] / 2.0f, position.get()[2] / 2.0f, 0)); 85 | } 86 | 87 | /// @brief inits the DQ_SKeleton, it needs a position to where to anchor the root bone 88 | void translate(const vec3 &translation){ 89 | vec3 position = root_transform.get_translation(); 90 | position += translation; 91 | //We obtain a pure translation with no rotation to represent the position of the anchor bone 92 | root_transform = DualQuat(Quaternion(0, 0, 0, 1), Quaternion(position.get()[0] / 2.0f, position.get()[1] / 2.0f, position.get()[2] / 2.0f, 0)); 93 | } 94 | 95 | /// @brief Add the reference to the visual_scene 96 | void add_scene(visual_scene* scene){ 97 | //printf("DQ_Skeleton add_scene call\n"); 98 | app_scene = scene; 99 | } 100 | 101 | /// @brief Will add a new bone to a given parent 102 | /// If we give no information of the parent, we asume that the new bone is the root bone 103 | void add_bone(DQ_Bone* new_bone, DQ_Bone* parent = nullptr){ 104 | //funky code to obtain the lenght of the bone 105 | float bone_lenght = 5; 106 | 107 | //Create the scene nodes 108 | scene_node* joint_node = new scene_node(); 109 | scene_node* bone_node = new scene_node(); 110 | hand_node = new scene_node(); 111 | 112 | //Add the scene_nodes to the new bone 113 | new_bone->add_scene_nodes(joint_node, bone_node); 114 | 115 | // add the bones_meshes to the scene 116 | mat4t cylinder_matrix; 117 | mesh_cylinder* mesh_bone; 118 | cylinder_matrix.translate(0, new_bone->get_length() / 2.0f, 0); 119 | cylinder_matrix.rotate(90, 1, 0, 0); 120 | mesh_bone = new mesh_cylinder(zcylinder(vec3(0), 0.3f, new_bone->get_length() / 2.0f), cylinder_matrix); 121 | range += new_bone->get_length(); 122 | // we scale the bone mesh 123 | if (parent == nullptr) 124 | app_scene->add_mesh_instance(new mesh_instance(new_bone->obtain_joints().joint_node, mesh_root, mat_joint)); 125 | else 126 | app_scene->add_mesh_instance(new mesh_instance(new_bone->obtain_joints().joint_node, mesh_joint, mat_joint)); 127 | app_scene->add_mesh_instance(new mesh_instance(new_bone->obtain_joints().joint_node, mesh_bone, mat_bone)); 128 | 129 | // Add child to the parent (or sets the root to be the new bone) 130 | if (parent == nullptr){ 131 | root_bone = new_bone; 132 | root_bone->set_parent(nullptr); 133 | //fix root_bone world positions 134 | root_bone->set_joint_node(root_transform); 135 | } 136 | else 137 | parent->add_child(new_bone); 138 | wrist_bone = new_bone; 139 | } 140 | 141 | float get_range(){ return range; } 142 | 143 | /// @brief Draws the skeleton (to be called by the app) 144 | /// Internally, this function will update all the joints and THEN will draw all the bones 145 | void draw(){ 146 | //printf("DQ_Skeleton draw call\n"); 147 | // update all the joint positions of all the bones 148 | update_joints(); 149 | // Set position hand 150 | hand_node->access_nodeToParent() = wrist_bone->get_matrix_bone(); 151 | } 152 | 153 | /// @brief This function will generate a new animation 154 | /// It will return the num of tics expected to produce this animation 155 | int start_animation(TypeSkeleton_Anim anim_type = _RANDOM_DANCE, vec3 n_position = vec3(0,0,0)){ 156 | total_tic = 10; 157 | if (anim_type == _RANDOM_DANCE){ 158 | randomize(root_bone); 159 | status = _ANIMATING; 160 | } 161 | else if (anim_type == _RANDOM_ALG){ 162 | best_distance = ~0; 163 | num_failed_attemps = _NUM_FAILED_ATTEMPTS; 164 | dest_position = n_position; 165 | float distance = random_algorithm(dest_position); 166 | //obtain the number of tics depending the distance! 167 | //Get position of the bone 168 | vec3 next_bone_position = wrist_bone->get_best_position_bone(); 169 | vec3 bone_position = wrist_bone->get_position_bone(); 170 | //Obtain distance of the wirst bone with n_position 171 | vec3 v_distance = next_bone_position - bone_position; 172 | float local_distance = v_distance.length(); 173 | if (distance != 0) 174 | total_tic = (int) (2 * distance); 175 | else 176 | total_tic = 40; 177 | status = _ALGORITHMING; 178 | } 179 | 180 | //Update the total_tic (ToDo) by the distance of the movement 181 | 182 | return total_tic; 183 | } 184 | 185 | /// @brief This will animate the skeleton 186 | /// To operate this function, the app will send the "lenght" that the animation will take place 187 | /// Will give a total number of tics, and the cur tic 188 | void animate_skeleton(int cur_tic, int total_tics){ 189 | root_bone->animate_bone(cur_tic, total_tics); 190 | } 191 | 192 | /// @brief This will stop the animation 193 | int finish_animation(bool force = false){ 194 | root_bone->finish_animation(force); 195 | //Now it will check if it has to keep on animating or will go back to still 196 | if (force) 197 | status = _STILL; 198 | else if (status == _ALGORITHMING){ 199 | //check distance, if it's close enough, stop! if not, keep on doing that! 200 | vec3 bone_position = wrist_bone->get_world_position_bone(); 201 | //Obtain distance of the wirst bone with n_position 202 | vec3 v_distance = dest_position - bone_position; 203 | float current_distance = v_distance.length(); 204 | //Check the amounts of failed attempts, and stop if it has failed too much 205 | if (current_distance < best_distance) 206 | best_distance = current_distance; 207 | else 208 | --num_failed_attemps; 209 | 210 | // Debug info 211 | /*printf("Current distance between (%f, %f, %f) and (%f, %f, %f) is... %f\n", 212 | bone_position.get()[0], bone_position.get()[1], bone_position.get()[2], 213 | dest_position.get()[0], dest_position.get()[1], dest_position.get()[2], 214 | current_distance);*/ 215 | if (total_tic > 10) 216 | total_tic -= 2; 217 | //If it has arrived to the point, or it cannot improve more... 218 | if (current_distance < 0.5f || num_failed_attemps == 0) 219 | status = _STILL; 220 | else 221 | total_tic = (int) (2 * random_algorithm(dest_position)); 222 | } 223 | else 224 | status = _STILL; 225 | return total_tic; 226 | } 227 | 228 | //--- Now will start some functions to set the next position for the arm 229 | 230 | /// @brief It will obtain a completely Random position of the tree 231 | void randomize(DQ_Bone* bone){ 232 | //obtain random dual quaternion (only a small random rotation) 233 | DualQuat next_dualquat = bone->generate_random_next(rand_gen.get(-1.0f, 1.0f), rand_gen.get(-1.0f, 1.0f), rand_gen.get(-1.0f, 1.0f), rand_gen.get(-1.0f, 1.0f)); 234 | bone->set_next_position(next_dualquat); 235 | //set the next position of this arm 236 | for (size_t i = 0; i < bone->get_children().size(); ++i){ 237 | randomize(bone->get_children()[i]); 238 | } 239 | } 240 | 241 | /// @brief It will obtain a completely Random position of the tree (as a potential solution) 242 | void randomize_best(DQ_Bone* bone, float distance = 1){ 243 | //obtain random dual quaternion (only a small random rotation) 244 | DualQuat next_dualquat = bone->generate_random_next(rand_gen.get(-0.5f, 0.5f)*distance, rand_gen.get(-1.0f, 1.0f), rand_gen.get(-1.0f, 1.0f), rand_gen.get(-1.0f, 1.0f)); 245 | bone->set_best_position(next_dualquat); 246 | //set the next position of this arm 247 | for (int i = 0; i < bone->get_children().size(); ++i){ 248 | randomize_best(bone->get_children()[i]); 249 | } 250 | } 251 | 252 | /// @brief This will obtain a random position of the arm, but trying to get close to the position 253 | /// It will obtain 5 possible positions and will choose the one closer to the objective. 254 | float random_algorithm(vec3 position){ 255 | //Initialize values 256 | size_t num_tests = _NUM_SOLUTIONS; 257 | //Obtain distance of the wirst bone with n_position 258 | vec3 v_distance = position - wrist_bone->get_best_position_bone(); 259 | float distance_min = v_distance.length(); 260 | //Start testing things 261 | for (size_t i = 0; i < num_tests; i++) 262 | { 263 | //Generate solution (recursively) 264 | randomize_best(root_bone, distance_min); 265 | //Evaluate solution 266 | root_bone->test_yourself(root_transform); 267 | //Obtain distance of the wirst bone with n_position 268 | vec3 v_distance = position - wrist_bone->get_best_position_bone(); 269 | float current_distance = v_distance.length(); 270 | //Check solution 271 | if (current_distance < distance_min){ 272 | distance_min = current_distance; 273 | //Set best_solution as next_position 274 | root_bone->set_best_as_next(); 275 | } 276 | } 277 | return distance_min; 278 | } 279 | 280 | /// @brief Returns the wrist node from the skeleton (it's a DQ_Bone!) 281 | DQ_Bone* get_wrist_node(){ 282 | return wrist_bone; 283 | } 284 | 285 | 286 | }; 287 | } 288 | 289 | #endif -------------------------------------------------------------------------------- /IKRobotArm.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | /// @author Sam & Juanmi 4 | // 5 | // Modular Framework for OpenGLES2 rendering on multiple platforms. 6 | // 7 | 8 | #ifndef IKROBOTARM_H_DEFINED 9 | #define IKROBOTARM_H_DEFINED 10 | 11 | #include "DQ_Skeleton.h" 12 | #include "DQ_Sphere.h" 13 | 14 | namespace octet { 15 | /// Scene containing a box with octet. 16 | class IKRobotArm : public app { 17 | enum {_NUM_SPHERES = 8}; 18 | // scene for drawing box 19 | ref app_scene; 20 | ref camera_node; 21 | ref camera_tree_node; 22 | DQ_Sphere* test_sphere; 23 | DQ_Sphere* test_sphere2; 24 | dynarray> spheres; 25 | dynarray> table_mat; 26 | dynarray> table_instances; 27 | int index_mat; 28 | 29 | // for the raycasting 30 | btDiscreteDynamicsWorld *world; 31 | camera_instance* cam; 32 | mat4t starting_cam; 33 | vec3 dest_position; 34 | 35 | // skeleton declaration 36 | DQ_Skeleton* debug_skeleton; 37 | dynarray> arms; 38 | float top_bottom; 39 | float left_right; 40 | bool dancing_skeleton; 41 | bool moving_skeleton; 42 | bool moving_up_skeleton; 43 | int ball_grabbed; 44 | int magnetism; 45 | 46 | // Random destination 47 | random random_gen; 48 | mat4t old_cam_position; 49 | bool arm_fixed_cam; 50 | 51 | int cur_tic; 52 | int total_tic; 53 | public: 54 | /// this is called when we construct the class before everything is initialised. 55 | IKRobotArm(int argc, char **argv) : app(argc, argv) { 56 | } 57 | 58 | /// this is called once OpenGL is initialized 59 | void app_init() { 60 | moving_up_skeleton = false; 61 | ball_grabbed = -1; index_mat = 0; 62 | arm_fixed_cam = false; 63 | top_bottom = -9.5f; 64 | left_right = 0.0f; 65 | magnetism = 1; 66 | random_gen.set_seed(time(NULL)); 67 | app_scene = new visual_scene(); 68 | camera_tree_node = new scene_node(); 69 | app_scene->create_default_camera_and_lights(); 70 | cam = app_scene->get_camera_instance(0); 71 | camera_node = app_scene->get_camera_instance(0)->get_node(); 72 | camera_node->translate(vec3(0.0f, 25.0f, 0.0f)); 73 | camera_node->rotate(-40.0f, vec3(1.0f, 0.0f, 0.0f)); 74 | camera_tree_node->translate(vec3(0.0f, 0.0f, 30.0f)); 75 | camera_tree_node->add_child(camera_node); 76 | 77 | world = app_scene->get_bt_world(); 78 | 79 | // SH: Table construction 80 | mat4t transform; 81 | mat4t transform_wall_top; 82 | transform.translate(vec3(0, -2, 0)); 83 | transform.rotate(90, 1, 0, 0); 84 | image* jupiter = new image("assets/electricfield.gif"); 85 | image* jupiter_mask = new image("assets/electricfieldmask.gif"); 86 | image* jupiter2 = new image("assets/electricfield2.gif"); 87 | image* jupiter_mask2 = new image("assets/electricfield2mask.gif"); 88 | table_mat.resize(2); 89 | table_instances.resize(5); 90 | param_shader *shader = new param_shader("shaders/default.vs", "shaders/multitexture.fs"); 91 | table_mat[0] = new material(vec4(1, 1, 1, 1), shader); 92 | table_mat[1] = new material(vec4(1, 1, 1, 1), shader); 93 | table_mat[0]->add_sampler(0, app_utils::get_atom("jupiter"), jupiter, new sampler()); 94 | table_mat[0]->add_sampler(1, app_utils::get_atom("jupiter_mask"), jupiter_mask, new sampler()); //new material(vec4(0.6f, 0.81f, 0.2f, 1)); 95 | table_mat[1]->add_sampler(0, app_utils::get_atom("jupiter2"), jupiter2, new sampler()); 96 | table_mat[1]->add_sampler(1, app_utils::get_atom("jupiter_mask2"), jupiter_mask2, new sampler()); //new material(vec4(0.6f, 0.81f, 0.2f, 1)); 97 | material* orange = new material(vec4(0.81f, 0.3f, 0.2f, 1)); 98 | material* purple = new material(vec4(0.5f, 0.0f, 0.5f, 1)); 99 | material* cold_red = new material(vec4(0.2f, 0.2f, 0.2f, 1)); 100 | 101 | image* walls = new image("assets/Walls.gif"); 102 | image* walls_mask = new image("assets/Walls.gif"); table_mat[1]->add_sampler(0, app_utils::get_atom("jupiter2"), jupiter2, new sampler()); 103 | param_shader *shader2 = new param_shader("shaders/default.vs", "shaders/multitexture.fs"); 104 | material* transparent = new material(vec4(1, 1, 1, 1), shader2); 105 | transparent->add_sampler(0, app_utils::get_atom("walls"), walls, new sampler()); 106 | transparent->add_sampler(1, app_utils::get_atom("walls_mask"), walls_mask, new sampler()); 107 | 108 | app_scene->add_shape(transform, new mesh_box(vec3(21, 10, 0.5f)), table_mat[0], false); 109 | table_instances[0] = app_scene->get_mesh_instance(0); 110 | transform.loadIdentity(); 111 | transform.translate(0, 0, -11); 112 | app_scene->add_shape(transform, new mesh_box(vec3(20, 5, 1)), transparent, false); 113 | transform.loadIdentity(); 114 | transform.translate(0, 0, 11); 115 | app_scene->add_shape(transform, new mesh_box(vec3(20, 5, 1)), transparent, false); 116 | transform.loadIdentity(); 117 | transform.translate(-21, -2, -8); 118 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), transparent, false); 119 | transform.loadIdentity(); 120 | transform.translate(-21, -2, 8); 121 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), transparent, false); 122 | transform.loadIdentity(); 123 | transform.translate(21, -2, 8); 124 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), transparent, false); 125 | transform.loadIdentity(); 126 | transform.translate(21, -2, -8); 127 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), transparent, false); 128 | transform.loadIdentity(); 129 | transform.translate(0, -2, -11); 130 | app_scene->add_shape(transform, new mesh_box(vec3(20, 2, 1)), purple, false); 131 | transform.translate(0, 6.75, 1.5); 132 | app_scene->add_shape(transform, new mesh_box(vec3(22, 0.25, 0.25)), cold_red, false); 133 | transform.loadIdentity(); 134 | transform.translate(0, -2, 11); 135 | app_scene->add_shape(transform, new mesh_box(vec3(20, 2, 1)), purple, false); 136 | transform.translate(0, 6.75, -1.5); 137 | app_scene->add_shape(transform, new mesh_box(vec3(22, 0.25, 0.25)), cold_red, false); 138 | transform.loadIdentity(); 139 | transform.translate(21, -2, 8); 140 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), purple, false); 141 | transform.loadIdentity(); 142 | transform.translate(21, -2, -8); 143 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), purple, false); 144 | transform.loadIdentity(); 145 | transform.translate(21, -2, 0); 146 | transform.translate(-2, 6.75, 0); 147 | app_scene->add_shape(transform, new mesh_box(vec3(0.25, 0.25, 12)), cold_red, false); 148 | transform.loadIdentity(); 149 | transform.translate(-21, -2, -8); 150 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), purple, false); 151 | transform.loadIdentity(); 152 | transform.translate(-21, -2, 8); 153 | app_scene->add_shape(transform, new mesh_box(vec3(1, 2, 6)), purple, false); 154 | transform.loadIdentity(); 155 | transform.translate(-21, -2, 0); 156 | transform.translate(2, 6.75, 0); 157 | app_scene->add_shape(transform, new mesh_box(vec3(0.25, 0.25, 12)), cold_red, false); 158 | transform.loadIdentity(); 159 | transform.translate(-21, 3, 11); 160 | app_scene->add_shape(transform, new mesh_box(vec3(0.5, 6, 0.5)), cold_red, false); 161 | transform.translate(0, 1, 0); 162 | app_scene->add_shape(transform, new mesh_box(vec3(2.5, 0.25, 2.5)), cold_red, false); 163 | transform.loadIdentity(); 164 | transform.translate(21, 3, 11); 165 | app_scene->add_shape(transform, new mesh_box(vec3(0.5, 6, 0.5)), cold_red, false); 166 | transform.translate(0, 1, 0); 167 | app_scene->add_shape(transform, new mesh_box(vec3(2.5, 0.25, 2.5)), cold_red, false); 168 | transform.loadIdentity(); 169 | transform.translate(-21, 3, -11); 170 | app_scene->add_shape(transform, new mesh_box(vec3(0.5, 6, 0.5)), cold_red, false); 171 | transform.translate(0, 1, 0); 172 | app_scene->add_shape(transform, new mesh_box(vec3(2.5, 0.25, 2.5)), cold_red, false); 173 | transform.loadIdentity(); 174 | transform.translate(21, 3, -11); 175 | app_scene->add_shape(transform, new mesh_box(vec3(0.5, 6, 0.5)), cold_red, false); 176 | transform.translate(0, 1, 0); 177 | app_scene->add_shape(transform, new mesh_box(vec3(2.5, 0.25, 2.5)), cold_red, false); 178 | // end of table construction 179 | 180 | // Adding spheres 181 | for (size_t i = 0; i != _NUM_SPHERES; ++i){ 182 | DQ_Sphere* new_sphere = new DQ_Sphere(); 183 | //generate a random position for the ball 184 | vec3 position = vec3(random_gen.get(-15.0f, 15.0f), 185 | random_gen.get(2.0f, 7.0f) * i + 7.0f, 186 | random_gen.get(-8.0f, 8.0f) 187 | ); 188 | //obtain a random number between 0 and 1, and pic 189 | float magnetic_force = (random_gen.get(-1.0f, 1.0f)) < 0.0f ? 40.0f : -40.0f; 190 | //obtain 191 | float radius = random_gen.get(0.6f, 1.4f); 192 | new_sphere->init(app_scene, position, radius, magnetic_force); 193 | spheres.push_back(new_sphere); 194 | position.get()[0] = position.get()[0] * random_gen.get(0.0f, 0.2f); 195 | position.get()[1] = 0; 196 | position.get()[2] = position.get()[2] * random_gen.get(0.0f, 0.2f); 197 | btVector3 temp = get_btVector3(position * -0.5f); 198 | spheres[i]->get_rigidbody()->applyCentralImpulse(temp); 199 | } 200 | // End spheres 201 | 202 | //Creating the skeleton. The first thing is to link it to the scene 203 | debug_skeleton = new DQ_Skeleton(); 204 | debug_skeleton->add_scene(app_scene); 205 | //Init the skeleton (will set the initial position to the parameter given 206 | debug_skeleton->init(vec3(0, 0, 0)); 207 | dancing_skeleton = false; 208 | //Add the root bone 209 | DQ_Bone* root = new DQ_Bone(0.0001f); 210 | DQ_Bone* real_root = new DQ_Bone(2.5f); 211 | DQ_Bone* forearm = new DQ_Bone(1.5f); 212 | DQ_Bone* second_forearm = new DQ_Bone(1.5f); 213 | DQ_Bone* arm = new DQ_Bone(4.0f); 214 | real_root->constraint_in_axis(0.0f, 1.0f, 0.0f); 215 | forearm->constraint_in_axis(0.0f, 0.0f, 1.0f); 216 | debug_skeleton->add_bone(root); 217 | debug_skeleton->add_bone(real_root, root); 218 | debug_skeleton->add_bone(forearm, real_root); 219 | debug_skeleton->add_bone(second_forearm, forearm); 220 | debug_skeleton->add_bone(arm, second_forearm); 221 | skeleton_dance_once(debug_skeleton);//Creating the skeleton. The first thing is to link it to the scene 222 | 223 | debug_skeleton->init(vec3(0.0f, 5.0f, -9.5f)); 224 | } 225 | 226 | // @brief This function launchs the moving up movement 227 | void move_up_skeleton(){ 228 | if (!moving_up_skeleton){ 229 | moving_up_skeleton = true; 230 | debug_skeleton->finish_animation(true); 231 | if (debug_skeleton->get_status() == _STILL){ 232 | vec3 position = vec3(0.0f, 1.0f, 0.0f); 233 | position = position.normalize() * debug_skeleton->get_range(); 234 | position.get()[1] += 5; 235 | total_tic = debug_skeleton->start_animation(_RANDOM_ALG, position); 236 | cur_tic = 0; 237 | } 238 | } 239 | } 240 | 241 | // Reseting the game (rethrows the balls from the top) 242 | void reset_game(){ 243 | for (size_t i = 0; i != _NUM_SPHERES; ++i){ 244 | //generate a random position for the ball 245 | vec3 position = vec3(random_gen.get(-15.0f, 15.0f), 246 | random_gen.get(2.0f, 7.0f) * i + 7.0f, 247 | random_gen.get(-8.0f, 8.0f) 248 | ); 249 | spheres[i]->get_rigidbody()->clearForces(); 250 | spheres[i]->get_rigidbody()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); 251 | spheres[i]->get_rigidbody()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); 252 | btTransform reset_transform = btTransform(get_btMatrix3x3(mat4t(1)), get_btVector3(position)); 253 | spheres[i]->get_rigidbody()->setWorldTransform(reset_transform); 254 | position.get()[0] = position.get()[0] * random_gen.get(0.0f, 0.2f); 255 | position.get()[1] = 0; 256 | position.get()[2] = position.get()[2] * random_gen.get(0.0f, 0.2f); 257 | btVector3 temp = get_btVector3(position * -0.5f); 258 | spheres[i]->get_rigidbody()->applyCentralImpulse(temp); 259 | } 260 | } 261 | 262 | /// This will launch a random_dance_movenet 263 | void skeleton_dance_once(DQ_Skeleton *skeleton){ 264 | total_tic = skeleton->start_animation(); 265 | cur_tic = 0; 266 | } 267 | 268 | void rotate_camera(float angle){ 269 | camera_tree_node->translate(vec3(0.0f, 0.0f, -30.0f)); 270 | camera_tree_node->rotate(angle, vec3(0.0f, 1.0f, 0.0f)); 271 | camera_tree_node->translate(vec3(0.0f, 0.0f, 30.0f)); 272 | } 273 | 274 | /// This will define the actions of the user (mouse, keyboard...) 275 | void user_actions(){ 276 | //Move Camera Left 277 | if (is_key_down('1')){ 278 | if (!arm_fixed_cam) 279 | rotate_camera(-2.0f); 280 | } 281 | //Move Camera Down 282 | else if (is_key_down('2')){ 283 | if (!arm_fixed_cam) 284 | rotate_camera(2.0f); 285 | } 286 | else if (is_key_going_down('3')){ 287 | if (arm_fixed_cam){ 288 | arm_fixed_cam = false; 289 | camera_tree_node->access_nodeToParent().loadIdentity(); 290 | camera_tree_node->translate(vec3(0.0f, 0.0f, 30.0f)); 291 | camera_node->access_nodeToParent().loadIdentity(); 292 | camera_node->translate(vec3(0.0f, 25.0f, 0.0f)); 293 | camera_node->rotate(-40.0f, vec3(1.0f, 0.0f, 0.0f)); 294 | } 295 | else{ 296 | arm_fixed_cam = true; 297 | camera_tree_node->access_nodeToParent().loadIdentity(); 298 | camera_tree_node->translate(vec3(0.0f, 50.0f, 0.0f)); 299 | camera_node->access_nodeToParent().loadIdentity(); 300 | camera_node->rotate(-90.0f, vec3(1.0f, 0.0f, 0.0f)); 301 | } 302 | } 303 | if (is_key_down('A')){ 304 | debug_skeleton->finish_animation(true); 305 | if (debug_skeleton->get_status() == _STILL) 306 | skeleton_dance_once(debug_skeleton); 307 | } 308 | else if (is_key_going_down('D')){ 309 | dancing_skeleton = !dancing_skeleton; 310 | } 311 | else if (is_key_down(key_ctrl) && is_key_going_down(key_up)){ 312 | debug_skeleton->finish_animation(true); 313 | debug_skeleton->init(vec3(0.0f, 5.0f, -9.5f)); 314 | left_right = 0.0f; 315 | top_bottom = -9.5f; 316 | } 317 | else if (is_key_down(key_ctrl) && is_key_going_down(key_down)){ 318 | debug_skeleton->finish_animation(true); 319 | debug_skeleton->init(vec3(0.0f, 5.0f, 9.5f)); 320 | left_right = 0.0f; 321 | top_bottom = 9.5f; 322 | } 323 | else if (is_key_down(key_ctrl) && is_key_going_down(key_left)){ 324 | debug_skeleton->finish_animation(true); 325 | debug_skeleton->init(vec3(-19.0f, 5.0f, 0.0f)); 326 | left_right = -19.0f; 327 | top_bottom = 0.0f; 328 | } 329 | else if (is_key_down(key_ctrl) && is_key_going_down(key_right)){ 330 | debug_skeleton->finish_animation(true); 331 | debug_skeleton->init(vec3(19.0f, 5.0f, 0.0f)); 332 | left_right = 19.0f; 333 | top_bottom = 0.0f; 334 | } 335 | else if (is_key_down(key_up)){ 336 | move_up_skeleton(); 337 | if (left_right == -19.0f || left_right == 19.0f){ 338 | if (top_bottom > -9.5f){ 339 | debug_skeleton->translate(vec3(0.0f, 0.0f, -0.5f)); 340 | top_bottom -= 0.5f; 341 | } 342 | } 343 | } 344 | else if (is_key_down(key_down)){ 345 | move_up_skeleton(); 346 | if (left_right == -19.0f || left_right == 19.0f){ 347 | if (top_bottom < 9.5f){ 348 | debug_skeleton->translate(vec3(0.0f, 0.0f, 0.5f)); 349 | top_bottom += 0.5f; 350 | } 351 | } 352 | } 353 | else if (is_key_down(key_left)){ 354 | move_up_skeleton(); 355 | if (top_bottom == -9.5f || top_bottom == 9.5f){ 356 | if (left_right > -19.0f){ 357 | debug_skeleton->translate(vec3(-0.5f, 0.0f, 0.0f)); 358 | left_right -= 0.5f; 359 | } 360 | } 361 | } 362 | else if (is_key_down(key_right)){ 363 | move_up_skeleton(); 364 | if (top_bottom == -9.5f || top_bottom == 9.5f){ 365 | if (left_right < 19.0f){ 366 | debug_skeleton->translate(vec3(0.5f, 0.0f, 0.0f)); 367 | left_right += 0.5f; 368 | } 369 | } 370 | } 371 | else if (is_key_going_down('S')){ 372 | debug_skeleton->finish_animation(true); 373 | if (debug_skeleton->get_status() == _STILL){ 374 | dest_position = vec3(random_gen.get(-10, 10), random_gen.get(0, 10), random_gen.get(-10, 10)); 375 | dest_position = dest_position.normalize() * debug_skeleton->get_range(); 376 | //printf("Trying to get to %f, %f, %f\n", dest_position.get()[0], dest_position.get()[1], dest_position.get()[2]); 377 | total_tic = debug_skeleton->start_animation(_RANDOM_ALG, dest_position); 378 | cur_tic = 0; 379 | } 380 | } 381 | else if (is_key_going_down('R')){ 382 | debug_skeleton->finish_animation(true); 383 | if (debug_skeleton->get_status() == _STILL){ 384 | vec3 position = vec3(0.0f, 1.0f, 0.0f); 385 | position = position.normalize() * debug_skeleton->get_range(); 386 | position.get()[1] += 5; 387 | total_tic = debug_skeleton->start_animation(_RANDOM_ALG, position); 388 | cur_tic = 0; 389 | } 390 | } 391 | else if (is_key_going_down('O')){ 392 | reset_game(); 393 | } 394 | else if (is_key_going_down(key_lmb)){ 395 | debug_skeleton->finish_animation(true); 396 | if (debug_skeleton->get_status() == _STILL){ 397 | btVector3 start, end; 398 | cast_ray_from_mouse(start, end); 399 | btCollisionWorld::ClosestRayResultCallback rayCallBack(start, end); 400 | world->rayTest(start, end, rayCallBack); 401 | if (rayCallBack.hasHit()){ 402 | vec3 pos = get_vec3(rayCallBack.m_hitPointWorld); 403 | vec3 increment = vec3(0.0f, 1.0f, 0.0f); 404 | //printf("ray cast world pos: x: %f y: %f z: %f\n", rayCallBack.m_hitPointWorld.x(), rayCallBack.m_hitPointWorld.y(), rayCallBack.m_hitPointWorld.z()); 405 | total_tic = debug_skeleton->start_animation(_RANDOM_ALG, pos + increment); 406 | cur_tic = 0; 407 | } 408 | } 409 | } 410 | else if (is_key_going_down('Q')){ //Stop all animation 411 | debug_skeleton->finish_animation(true); 412 | } 413 | 414 | if (is_key_going_down(' ')){ //Magnetise! 415 | //printf("force is being called!\n"); 416 | vec3 wrist_pos = debug_skeleton->get_wrist_node()->get_world_position_bone(); 417 | for (size_t i = 0; i != _NUM_SPHERES; ++i){ 418 | if (i != ball_grabbed) 419 | spheres[i]->resolve_magnetic_force(wrist_pos); 420 | } 421 | } 422 | /* 423 | if (is_key_going_down('G')){ //grab the closest ball if is closer than x 424 | if (ball_grabbed == -1){ 425 | bool found_ball = false; 426 | vec3 wrist_pos = debug_skeleton->get_wrist_node()->get_world_position_bone(); 427 | for (size_t i = 0; i != _NUM_SPHERES && !found_ball; ++i){ 428 | //Check distance 429 | vec3 v_distance = spheres[i]->get_node()->get_nodeToParent()[3].xyz() - wrist_pos; 430 | float distance = v_distance.length(); 431 | //if closer than x, grab it, and out 432 | if (distance < 3.0f){ 433 | found_ball = true; 434 | ball_grabbed = i; 435 | spheres[ball_grabbed]->get_node()->access_nodeToParent() = mat4t(1); 436 | debug_skeleton->get_wrist_node()->obtain_joints().bone_node->add_child(spheres[ball_grabbed]->get_node()); 437 | } 438 | } 439 | } 440 | else{ 441 | spheres[ball_grabbed]->get_node()->remove_parent(); 442 | spheres[ball_grabbed]->get_node()->access_nodeToParent() = debug_skeleton->get_wrist_node()->obtain_joints().bone_node->get_nodeToParent(); 443 | 444 | ball_grabbed = -1; 445 | } 446 | }*/ 447 | } 448 | 449 | /// This function handles the raycasting of the 450 | void cast_ray_from_mouse(btVector3 &bt_start, btVector3 &bt_end){ 451 | int mx = 0, my = 0; 452 | int vx = 0, vy = 0; 453 | this->get_mouse_pos(mx, my); 454 | this->get_viewport_size(vx, vy); 455 | float x = (float)(mx - vx / 2) *2.0f / vx; 456 | float y = (float)(vy / 2 - my) *2.0f / vy; 457 | cam = app_scene->get_camera_instance(0); 458 | ray _ray = cam->get_ray(x, y); 459 | 460 | vec4 start = vec4(_ray.get_start(), 1); 461 | vec4 end = vec4(_ray.get_end(), 1); 462 | 463 | bt_start = get_btVector3(start.xyz()); 464 | bt_end = get_btVector3(end.xyz()); 465 | } 466 | 467 | /// this is called to draw the world 468 | void draw_world(int x, int y, int w, int h) { 469 | int vx = 0, vy = 0; 470 | get_viewport_size(vx, vy); 471 | app_scene->begin_render(vx, vy); 472 | btVector3 start, end; 473 | 474 | index_mat = (index_mat + 1) % 20; 475 | table_instances[0]->set_material(table_mat[index_mat / 10]); 476 | // draw the skeleton 477 | debug_skeleton->draw(); 478 | // controls the arm 479 | user_actions(); 480 | 481 | //// draw the skeleton 482 | if (debug_skeleton->get_status() != _STILL){ 483 | debug_skeleton->animate_skeleton(cur_tic, total_tic); 484 | // printf("Curr_frame: %i\n", cur_tic); 485 | ++cur_tic; 486 | if (cur_tic > total_tic){ 487 | moving_up_skeleton = false; 488 | cur_tic = 0; 489 | total_tic = debug_skeleton->finish_animation(); 490 | } 491 | } 492 | else{ 493 | if (dancing_skeleton){ 494 | skeleton_dance_once(debug_skeleton); 495 | } 496 | } 497 | 498 | //Add confetti when dancing 499 | if (dancing_skeleton) 500 | reset_game(); 501 | 502 | debug_skeleton->draw(); 503 | 504 | //// update matrices. assume 30 fps. 505 | app_scene->update(1.0f / 30); 506 | 507 | // draw the scene 508 | app_scene->render((float)vx / vy); 509 | } 510 | }; 511 | } 512 | 513 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------