Quad Pang
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QVector.c
Go to the documentation of this file.
00001 
00002 #include "Internal.h"
00003 
00004 #include <string.h>
00005 #include "math.h"
00006 #include "QVector.h"
00007 
00008 double* vec_mul(double vec[3], double k)
00009 {
00010     int i;
00011     for (i = 0; i < 3; i++)
00012         vec[i] *=k;
00013 
00014     return vec;
00015 }
00016 
00017 double vec_magnitude(double vec[3])
00018 {
00019     double magnitude = 0;
00020     int i;
00021     for (i = 0; i < 3; i++)
00022         magnitude += vec[i] * vec[i];
00023 
00024     return pow(magnitude, 0.5);
00025 }
00026 
00027 double* vec_once(double vec[3])
00028 {
00029     int i;
00030     double magnitude = vec_magnitude(vec);
00031 
00032     for (i = 0; i != 3; i++)
00033         vec[i] /= magnitude;
00034 
00035     return vec;
00036 }
00037 
00038 double* vec_ofpow(double vec[3], double power)
00039 {
00040     int i;
00041     double magnitude = power/vec_magnitude(vec);
00042 
00043     for (i = 0; i < 3; i++)
00044         vec[i] *= magnitude;
00045 
00046     return vec;
00047 }
00048 
00049 
00050 double* vec_rotateY(double vec[3], double angle)
00051 {
00052     double 
00053         a = cos(angle),
00054         b = sin(angle),
00055         tx = vec[0] * a  + vec[2] * b,
00056         ty = -vec[0] * b + vec[2] * a;
00057 
00058     vec[0] = tx;
00059     vec[2] = ty;
00060 
00061     return  vec;
00062 }
00063 double* vec_add(double vec1[3], const double vec2[3])
00064 {
00065     int i;
00066     for (i=0; i<3; i++)
00067         vec1[i] += vec2[i];
00068 
00069     return vec1;
00070 }
00071 double* vec_adddiff(double vec1[3], const double vec2[3], const double vec3[3])
00072 {
00073     int i;
00074     for (i=0; i<3; i++)
00075         vec1[i] += vec3[i] - vec2[i];
00076 
00077     return vec1;
00078 }
00079 
00080 int vec_eq(const double vec1[3], const double vec2[3])
00081 {
00082     int i;
00083     for (i = 0; i < 3; i++)
00084     {
00085         if (vec1[i] != vec2[i])
00086             return 0;
00087     }
00088     return 1;
00089 }
00090 
00091 void draw_circle(double rad, int severity)
00092 {
00093     int i;
00094     double vec[] = { rad, 0.0, 0.0 };
00095     double pove[3];
00096     GLfloat normal[] = { 0.0, -1.0, 0.0 }; 
00097   
00098 
00099     glBegin(GL_POLYGON);
00100     
00101     glNormal3fv(normal);   
00102     glVertex3f(vec[0], vec[1], vec[2]);
00103     for (i = 1; i < severity; i++)
00104     {
00105         memcpy(pove, vec, sizeof(vec) );
00106         vec_rotateY(pove, -2 * i * M_PI / severity);
00107         glNormal3fv(normal);
00108         glVertex3f(pove[0], pove[1], pove[2]);
00109     }
00110     glEnd();
00111 }
00112 
00113 const double VZERO[3] = { 0.0, 0.0, 0.0 };