Boringly enough, I've templated my Vector classes.

ie. CVector3D<double> MyVector or CVector3D<float> MyVector etc.

Still looking for that elusive vector randomizer!

(the nurd zone).

Just “Vector” will do, you don’t have to use template class for vector in OpenGL. OpenGL uses GLfloat

glVertex3dv, for example, takes a pointer to three GLdoubles.

There are other types than float and double that makes sense in a vector class. For example, to represent a pixel in an image you can use a vector of chars (or any other integer type, depending on required precision). To add two pixels, just add the two vectors representing the pixels.

[This message has been edited by Bob (edited 07-26-2002).]

that elusive vector randomizer:

// Set up the rotation and translation

glTranslate( ... );
glRotate( ... );

// Create a random unit vector within a specified angle of the -Z axis.

a1 = rand( 0., TWOPI );
a2 = rand( 0., limit );

x = cos( a1 ) * sin( a2 );
y = sin( a1 ) * sin( a2 );
z = -cos( a2 );

Now, what was so hard about that?

[This message has been edited by Jambolo (edited 07-27-2002).]

No. That isn’t quite right. Firstly, I don’t think your spread will be even over the area concerned.

Secondly, glTranslate\glRotate are no-nos. This is purely theoretical - for the vector class - nothing to do with gl.

Thanks anyway!

Actually, daveperman wrote over on flipcode:

float float_rand()
//return a random number between [-1.0f, 1.0f]

void convert_to_cartesian_coords ( float azim, float elev, float radius, vec3* output )
// I hope you know coordinate transformations

void convert_to_polar_coords ( vec3 vector, float &azim, float &elev, float &radius)
// I hope you know coordinate transformations

randomize ( vec3 input, float variance, vec3 *output )
float azim, elev, radius;
convert_to_polar_coords ( input, azim, elev, radius );
azim += float_rand()*variance;
elev += float_rand()*variance;
radius = radius; //keep the radius same
convert_to_cartesian_coords ( azim, elev, radius, output );