Add following code to matrix4.h in class defination.
Code: Select all
//! Returns Front Vector
vector3df getFrontVector() const;
//! Returns Up Vector
vector3df getUpVector() const;
//! Returns Right Vector
vector3df getRightVector() const;
//! Set Front Vector
void setFrontVector(const vector3df& V);
//! Set Up Vector
void setUpVector(const vector3df& V);
//! Set Right Vector
void setRightVector(const vector3df& V);
//! Builds GrammSchmidt - Tree orthonormal axes with front vector aligned to the given vector
void buildGrammSchmidt(const vector3df& Front);
//! Builds a matrix from axes vectors
void buildFromAxes(const vector3df& Front, const vector3df& Up, const vector3df& Right);
Code: Select all
//! Returns Front Vector
inline vector3df matrix4::getFrontVector() const{
return vector3df(M[0], M[1], M[2]);
}
//! Returns Up Vector
inline vector3df matrix4::getUpVector() const{
return vector3df(M[4], M[5], M[6]);
}
//! Returns Right Vector
inline vector3df matrix4::getRightVector() const{
return vector3df(M[8], M[9], M[10]);
}
//! Set Front Vector
inline void matrix4::setFrontVector(const vector3df& V){
M[0] = V.X; M[1] = V.Y; M[2] = V.Z;
}
//! Set Up Vector
inline void matrix4::setUpVector(const vector3df& V){
M[4] = V.X; M[5] = V.Y; M[6] = V.Z;
}
//! Set Right Vector
inline void matrix4::setRightVector(const vector3df& V){
M[8] = V.X; M[9] = V.Y; M[10] = V.Z;
}
//! Builds GrammSchmidt - Tree orthonormal axes with front vector aligned to the given vector
inline void matrix4::buildGrammSchmidt(const vector3df& Dir){
vector3df Front, Up, Right;
Front = Dir;
Front.normalize();
if(abs_<f32>(Front.Z) > 0.577f)
Right = Front.crossProduct(vector3df(-Front.Y, Front.Z, 0.0f));
else
Right = Front.crossProduct(vector3df(-Front.Y, Front.X, 0.0f));
Right.normalize();
Up = Right.crossProduct( Front );
setFrontVector( Front );
setUpVector( Up );
setRightVector( Right );
}
//! Builds a matrix from axes vectors
inline void matrix4::buildFromAxes(const vector3df& Front, const vector3df& Up, const vector3df& Right){
setFrontVector( Front );
setUpVector( Up );
setRightVector( Right );
}
And two function for vector3d:
add this into defination of vector3d class in vector3d.h
Code: Select all
//! Returns scaled vector
vector3d<T> getScaled(T Scale){return vector3d<T>(*this *= Scale);};
vector3d<T> getScaled(vector3d<T> Scale){return vector3d<T>(X * Scale.X, Y * Scale.Y, Z * Scale.Z);}
//! Returns inverted vector
vector3d<T> getInverted(){
return vector3df(X *= -1.0f, Y *= -1.0f, Z *= -1.0f);
}