View Full Version : Boringly enough, I've templated my Vector classes.
Robbo
07-26-2002, 12:31 AM
ie. CVector3D<double> MyVector or CVector3D<float> MyVector etc.
Still looking for that elusive vector randomizer!
www.orbsoftware.com (http://www.orbsoftware.com)
(the nurd zone).
Questions Burner
07-26-2002, 12:48 AM
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).]
Jambolo
07-26-2002, 11:18 PM
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).]
Robbo
07-27-2002, 12:01 AM
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!
Robbo
07-27-2002, 12:28 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
}
void convert_to_polar_coords ( vec3 vector, float &azim, float &elev, float &radius)
{
// I hope you know coordinate transformations http://www.opengl.org/discussion_boards/ubb/smile.gif
}
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 );
return;
}
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.