GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


A Paste by Anonymous
template <class T> view<T> &view<T>::LookAt(T eX,T eY,T eZ,
                                            T cX,T cY,T cZ,
                                        T uX,T uY,T uZ){
    Unit();
    V3D F,UP,s,u;    
    UP.set(uX,uY,uZ);
    F.set(eX-cX,eY-cY,eZ-cZ);
    F.normal();
    
    s.CrossProduct(UP,F);
    u.CrossProduct(F,s);
    s.normal();
    u.normal();

    this->arrMat[0]=s.x;
    this->arrMat[1]=s.y;
    this->arrMat[2]=s.z;
    this->arrMat[4]=u.x;
    this->arrMat[5]=u.y;
    this->arrMat[6]=u.z;
    this->arrMat[8]=F.x;
    this->arrMat[9]=F.y;
    this->arrMat[10]=F.z;
    this->MultMatrix();
    this->Translate(-eX,-eY,-eZ);
    this->MultMatrix();

    return *this;


}
template <class T> view<T> &view<T>::Frustum(T Left,T Right,T Down,T Up,T Near,T Far){

    this->arrMat[0]=2*Near/(Right-Left);
    this->arrMat[1]=0;
    this->arrMat[2]=(Right+Left)/(Right-Left);
    this->arrMat[3]=0;
    this->arrMat[4]=0;
    this->arrMat[5]=2*Near/(Up-Down);
    this->arrMat[6]=(Up+Down)/(Up-Down);
    this->arrMat[7]=0;
    this->arrMat[8]=this->arrMat[9]=0;
    this->arrMat[10]=(Far+Near)/(Far-Near);
    this->arrMat[11]=2*Near*Far/(Far-Near);;
    this->arrMat[12]=0;
    this->arrMat[13]=0;
    this->arrMat[14]=-1;
    this->arrMat[15]=0;
    glMultMatrixf(this->arrMat);
    return *this;
}