Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3706 in orxonox.OLD for orxonox/branches/shadows/src/shadow.cc


Ignore:
Timestamp:
Mar 31, 2005, 11:29:47 PM (19 years ago)
Author:
dave
Message:

branches/shadows: Ok, das Abbild vom Raumschiff funktioniert schon mal, sieht recht cool aus:)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/shadows/src/shadow.cc

    r3680 r3706  
    3939*/
    4040
    41 Shadow::Shadow(Model* player,float* groundVertexes)
     41Shadow::Shadow(OBJModel* player,Player* playerangle,float groundVertexes[])
    4242{
    4343    this->player=player;
     44    this->playerangle=playerangle;
    4445}
    4546
     
    8889    glNewList(this->player_id,GL_COMPILE);
    8990   
    90     //blabla
     91    this->player->draw();
    9192   
    9293    glEndList();   
     
    9495    this->image=(unsigned char*)malloc(SIZE*SIZE*4);
    9596   
    96     //this->player_id=newList {glNormalefv;glVertex3fv}
    97     //this->ground_id=newList {glTexCoord2fv;glNormal3fv;glVertex3fv}
    98    
    99    
    100     //lightPos[] blabla
     97
    10198}
    10299
     
    117114    glLoadIdentity();
    118115   
    119     //gluLookAt(light0,light1,light2,player0,player1,player2,0,0,1);
     116    gluLookAt(this->lightPos[0],this->lightPos[1],this->lightPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
    120117   
    121118    glColor3f(.4,.4,.4);
    122     //glTranslatef(player0,player1,player2);
     119    glTranslatef(this->playerPos[0],this->playerPos[1],this->playerPos[2]);
     120    glRotatef(this->playerangle->angle,1.0,0.0,0.0);
     121   
     122   
    123123    glCallList(this->player_id);
    124124    glColor3f(1,1,1);
     
    134134}
    135135
     136
     137/**
     138    brief updatePosition is used in the same kind as for skysphere, because
     139    the light has got a static orientation(parallel light), we have to always
     140    add the same relative coordinates being 0,10,19 to the players position
     141    in order to receive the lightPosition. This is needed to calculate the Shadow!!
     142
     143*/
     144
     145void Shadow::updatePosition(float x,float y,float z)
     146{
     147    this->playerPos[0]=x;
     148    this->playerPos[1]=y;
     149    this->playerPos[2]=z;
     150   
     151    this->lightPos[0]=this->playerPos[0];
     152    this->lightPos[1]=this->playerPos[1]+10;
     153    this->lightPos[2]=this->playerPos[2]+19;
     154
     155   
     156}
     157/**
     158
     159    brief m_inverse simply inverses the *m matrix and stores the result back
     160    to *out. This is needed further down in the draw() method
     161
     162
     163*/
     164
    136165void Shadow::m_inverse(const float *m,float *out)
    137166{
    138167    float det;
    139     det=m[0]*m[5]*m[10];
     168    det=  m[0]*m[5]*m[10];
    140169    det+= m[4]*m[9]*m[2];
    141170    det+= m[8]*m[1]*m[6];
     
    143172    det-= m[4]*m[1]*m[10];
    144173    det-= m[0]*m[9]*m[6];
    145 }
    146 
     174   
     175    if(det!= 0.0)
     176        det=1.0/det;
     177    out[0]=  (m[5]*m[10]-m[9]*m[6])*det;
     178    out[1]= -(m[1]*m[10]-m[9]*m[2])*det;
     179    out[2]=  (m[1]*m[6]-m[5]*m[2])*det;
     180    out[3]= 0.0;
     181    out[4]= -(m[4]*m[10]-m[8]*m[6])*det;
     182    out[5]=  (m[0]*m[10]-m[8]*m[2])*det;
     183    out[6]= -(m[0]*m[6]-m[4]*m[2])*det;
     184    out[7]= 0.0;
     185    out[8]=  (m[4]*m[9]-m[8]*m[5])*det;
     186    out[9]= -(m[0]*m[9]-m[8]*m[1])*det;
     187    out[10]= (m[0]*m[5]-m[4]*m[1])*det;
     188    out[11]= 0.0;
     189    out[12]=- (m[12]*out[0]+m[13]*out[4]+m[14]*out[8]);
     190    out[13]=- (m[12]*out[1]+m[13]*out[5]+m[14]*out[9]);
     191    out[14]=- (m[12]*out[2]+m[13]*out[6]+m[14]*out[10]);
     192    out[15]= 1.0;
     193
     194
     195}
     196
     197/**
     198    brief Method draw() is called after each tick() from the world.cc class
     199*/
    147200
    148201void Shadow::draw()
     
    151204    createShadow();
    152205   
    153     glClearColor(0,0,0,0);
     206    /*glClearColor(0,0,0,0);
    154207    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    155208    glMatrixMode(GL_PROJECTION);
     
    159212    glLoadIdentity();
    160213   
    161     //gluLookAt(camera0,camera1,camera2,player0,player1,player2,0,0,1);
    162    
     214    gluLookAt(this->cameraPos[0],this->cameraPos[1],this->cameraPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
     215    */
    163216    glEnable(GL_TEXTURE_GEN_S);
    164217    glEnable(GL_TEXTURE_GEN_T);
     
    166219    glEnable(GL_TEXTURE_GEN_Q);
    167220    glGetFloatv(GL_MODELVIEW_MATRIX,m);
     221    m_inverse(m,im);
     222    glMatrixMode(GL_TEXTURE);
     223    glLoadIdentity();
     224    glTranslatef(0.5,0.5,1.0);
     225    glOrtho(-1,1,-1,1,-1,1);
     226   
     227    gluLookAt(this->lightPos[0],this->lightPos[1],this->lightPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
     228   
     229    glMultMatrixf(im);
     230    glEnable(GL_TEXTURE_2D),
     231    glBindTexture(GL_TEXTURE_2D,this->shadow_id);
     232    glEnable(GL_BLEND);
     233    glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
     234    glCallList(ground_id);
     235    glDisable(GL_BLEND);
     236   
     237    glLoadIdentity();
     238    glMatrixMode(GL_MODELVIEW);
     239    glDisable(GL_TEXTURE_GEN_S);
     240    glDisable(GL_TEXTURE_GEN_T);
     241    glDisable(GL_TEXTURE_GEN_R);
     242    glDisable(GL_TEXTURE_GEN_Q);
     243   
     244   
    168245   
    169246}
Note: See TracChangeset for help on using the changeset viewer.