1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 234 235 236 237 238 239 240 241 242 243 244 245
|
/*
* Modification History
*
* 2000-December-13 Jason Rohrer
* Created.
*
* 2000-December-14 Jason Rohrer
* Added data members and constructors.
*
* 2001-January-10 Jason Rohrer
* Made class serializable.
*
* 2001-January-15 Jason Rohrer
* Added a print() function.
*
* 2001-February-10 Jason Rohrer
* Added a linear sum function.
*
* 2001-March-11 Jason Rohrer
* Added a scale function.
*
* 2004-February-13 Jason Rohrer
* Added setComponents functions.
*
* 2006-September-3 Jason Rohrer
* Added zero-angle constructor.
*/
#ifndef ANGLE_3D_INCLUDED
#define ANGLE_3D_INCLUDED
#include <stdio.h>
#include "minorGems/io/Serializable.h"
/**
* Angle in 3-space.
*
* @author Jason Rohrer
*/
class Angle3D : public Serializable {
public:
// rotations in radians around x, y, and z axis
double mX, mY, mZ;
/**
* Constructs an Angle3D.
*/
Angle3D( double inX, double inY, double inZ );
/**
* Constructs a zero angle.
*/
Angle3D();
/**
* Constructs an Angle3D by copying the parameters from
* another Angle3D.
*
* @param inOther angle to copy parameters from.
*/
Angle3D( Angle3D *inOther );
/**
* Sets the components of this angle.
*/
void setComponents( double inX, double inY, double inZ );
/**
* Sets components by copying the parameters from
* another Angle3D.
*
* @param inOther vector to copy parameters from.
* Must be destroyed by caller.
*/
void setComponents( Angle3D *inOther );
/**
* Sums another angle with this angle.
*
* @param inOther angle to add to this angle.
*/
void add( Angle3D *inOther );
/**
* Subtracts a angle from this angle.
*
* @param inOther angle to subtract from this angle.
*/
void subtract( Angle3D *inOther );
/**
* Multiplies this angle by a scalar.
*
* @param inScalar scalar to multiply this angle by.
*/
void scale( double inScalar );
/**
* Computes the linear weighted sum of two angles.
*
* @param inFirst the first angle.
* @param inSecond the second angle.
* @param inFirstWeight the weight given to the first angle in the
* sum. The second angle is weighted (1-inFirstWeight).
*
* @return the sum angle. Must be destroyed by caller.
*/
static Angle3D *linearSum( Angle3D *inFirst, Angle3D *inSecond,
double inFirstWeight );
/**
* Prints this angle to standard out.
*/
void print();
// implement the Serializable interface
virtual int serialize( OutputStream *inOutputStream );
virtual int deserialize( InputStream *inInputStream );
};
inline Angle3D::Angle3D( double inX, double inY, double inZ )
: mX( inX ), mY( inY ), mZ( inZ ) {
}
inline Angle3D::Angle3D()
: mX( 0 ), mY( 0 ), mZ( 0 ) {
}
inline Angle3D::Angle3D( Angle3D *inOther )
: mX( inOther->mX ), mY( inOther->mY ), mZ( inOther->mZ ) {
}
inline void Angle3D::setComponents( double inX, double inY, double inZ ) {
mX = inX;
mY = inY;
mZ = inZ;
}
inline void Angle3D::setComponents( Angle3D *inOther ) {
setComponents( inOther->mX,
inOther->mY,
inOther->mZ );
}
inline void Angle3D::add( Angle3D *inOther ) {
mX += inOther->mX;
mY += inOther->mY;
mZ += inOther->mZ;
}
inline void Angle3D::subtract( Angle3D *inOther ) {
mX -= inOther->mX;
mY -= inOther->mY;
mZ -= inOther->mZ;
}
inline void Angle3D::scale( double inScalar ) {
mX *= inScalar;
mY *= inScalar;
mZ *= inScalar;
}
inline Angle3D *Angle3D::linearSum( Angle3D *inFirst, Angle3D *inSecond,
double inFirstWeight ) {
double secondWeight = 1 - inFirstWeight;
double x = inFirstWeight * inFirst->mX + secondWeight * inSecond->mX;
double y = inFirstWeight * inFirst->mY + secondWeight * inSecond->mY;
double z = inFirstWeight * inFirst->mZ + secondWeight * inSecond->mZ;
return new Angle3D( x, y, z );
}
inline int Angle3D::serialize( OutputStream *inOutputStream ) {
int numBytes = 0;
numBytes += inOutputStream->writeDouble( mX );
numBytes += inOutputStream->writeDouble( mY );
numBytes += inOutputStream->writeDouble( mZ );
return numBytes;
}
inline int Angle3D::deserialize( InputStream *inInputStream ) {
int numBytes = 0;
numBytes += inInputStream->readDouble( &( mX ) );
numBytes += inInputStream->readDouble( &( mY ) );
numBytes += inInputStream->readDouble( &( mZ ) );
return numBytes;
}
inline void Angle3D::print() {
printf( "(%f, %f, %f)", mX, mY, mZ );
}
#endif
|