Quad Pang
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Functions | Variables
QVector.c File Reference
#include "Internal.h"
#include <string.h>
#include "math.h"
#include "QVector.h"

Go to the source code of this file.

Functions

double * vec_mul (double vec[3], double k)
 Multiply vector with scalar.
double vec_magnitude (double vec[3])
double * vec_once (double vec[3])
 Calculate Vector Intensity.
double * vec_ofpow (double vec[3], double power)
 Vector of the same direction and power magnitude.
double * vec_rotateY (double vec[3], double angle)
 Rotate around Y access vec[1].
double * vec_add (double vec1[3], const double vec2[3])
 Add vec2 to vec1.
double * vec_adddiff (double vec1[3], const double vec2[3], const double vec3[3])
 add difference of vec2 and vec3 to vec1
int vec_eq (const double vec1[3], const double vec2[3])
 Whether two vectors are equal.
void draw_circle (double rad, int severity)
 Draw circle as OpenGL Polygon.

Variables

const double VZERO [3] = { 0.0, 0.0, 0.0 }
 Zero vector.

Function Documentation

void draw_circle ( double  rad,
int  severity 
)

Draw circle as OpenGL Polygon.

This method is different then others declared in this file because it is using OpenGL routines to draw poligon in shape of circle.

Parameters:
radCircle radius
severityNumber of vertices of the poligon.

Definition at line 91 of file QVector.c.

Referenced by Hitti::Display().

{
    int i;
    double vec[] = { rad, 0.0, 0.0 };
    double pove[3];
    GLfloat normal[] = { 0.0, -1.0, 0.0 }; 
  

    glBegin(GL_POLYGON);
    
    glNormal3fv(normal);   
    glVertex3f(vec[0], vec[1], vec[2]);
    for (i = 1; i < severity; i++)
    {
        memcpy(pove, vec, sizeof(vec) );
        vec_rotateY(pove, -2 * i * M_PI / severity);
        glNormal3fv(normal);
        glVertex3f(pove[0], pove[1], pove[2]);
    }
    glEnd();
}
double* vec_add ( double  vec1[3],
const double  vec2[3] 
)

Add vec2 to vec1.

 vec1 += vec2;
Returns:
sum, ie vec1

Definition at line 63 of file QVector.c.

Referenced by ViewBongoFollower::Move(), BongoOrthoMover::ProcessKey(), and ViewBongoFollower::QuadEvent().

{
    int i;
    for (i=0; i<3; i++)
        vec1[i] += vec2[i];

    return vec1;
}
double* vec_adddiff ( double  vec1[3],
const double  vec2[3],
const double  vec3[3] 
)

add difference of vec2 and vec3 to vec1

 vec1 = vec1 + vec2 - vec3

Definition at line 71 of file QVector.c.

{
    int i;
    for (i=0; i<3; i++)
        vec1[i] += vec3[i] - vec2[i];

    return vec1;
}
int vec_eq ( const double  vec1[3],
const double  vec2[3] 
)

Whether two vectors are equal.

Returns:
1 if equal , 0 if not

Definition at line 80 of file QVector.c.

{
    int i;
    for (i = 0; i < 3; i++)
    {
        if (vec1[i] != vec2[i])
            return 0;
    }
    return 1;
}
double vec_magnitude ( double  vec[3])

Definition at line 17 of file QVector.c.

Referenced by ViewBongoFollower::QuadEvent(), vec_ofpow(), and vec_once().

{
    double magnitude = 0;
    int i;
    for (i = 0; i < 3; i++)
        magnitude += vec[i] * vec[i];

    return pow(magnitude, 0.5);
}
double* vec_mul ( double  vec[3],
double  k 
)

Multiply vector with scalar.

 vec = vec * k
Parameters:
vecVector
kScalar
Returns:
For simiplicity it returns vec argument

Definition at line 8 of file QVector.c.

Referenced by ViewBongoFollower::Move(), BongoRealMover::ProcessKey(), and ViewBongoFollower::QuadEvent().

{
    int i;
    for (i = 0; i < 3; i++)
        vec[i] *=k;

    return vec;
}
double* vec_ofpow ( double  vec[3],
double  power 
)

Vector of the same direction and power magnitude.

 vec = vec * power/vec_magnitude(vec)
Parameters:
vecVector
powerScalar value
Returns:
vec argument

Definition at line 38 of file QVector.c.

Referenced by BongoRealMover::BongoRealMover(), and Ball::Init().

{
    int i;
    double magnitude = power/vec_magnitude(vec);

    for (i = 0; i < 3; i++)
        vec[i] *= magnitude;

    return vec;
}
double* vec_once ( double  vec[3])

Calculate Vector Intensity.

 sqrt(vec[0]^2 + vec[1]^2 + vec[2]^2)
 \codend

 \param vec
 Vector

 \returns
 vector intensity

double  vec_magnitude(double vec[3]);

 \brief Divide vector by its magnitude
 
 \code
 vec = vec * 1/vec_magnitude(vec)
Parameters:
vecVector
Returns:
vec argument

Definition at line 27 of file QVector.c.

{
    int i;
    double magnitude = vec_magnitude(vec);

    for (i = 0; i != 3; i++)
        vec[i] /= magnitude;

    return vec;
}
double* vec_rotateY ( double  vec[3],
double  angle 
)

Rotate around Y access vec[1].

Parameters:
vecVector
angleRotation angle
Returns:
vec argument

Definition at line 50 of file QVector.c.

Referenced by CollisionMaster::Collision(), draw_circle(), and BongoRealMover::ProcessKey().

{
    double 
        a = cos(angle),
        b = sin(angle),
        tx = vec[0] * a  + vec[2] * b,
        ty = -vec[0] * b + vec[2] * a;

    vec[0] = tx;
    vec[2] = ty;

    return  vec;
}

Variable Documentation

const double VZERO[3] = { 0.0, 0.0, 0.0 }

Zero vector.

Definition at line 113 of file QVector.c.

Referenced by CollisionMaster::Collision(), and Quad_impl::SetActive().