Changeset 3706 in orxonox.OLD for orxonox/branches/shadows/src/shadow.cc
- Timestamp:
- Mar 31, 2005, 11:29:47 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/shadows/src/shadow.cc
r3680 r3706 39 39 */ 40 40 41 Shadow::Shadow( Model* player,float* groundVertexes)41 Shadow::Shadow(OBJModel* player,Player* playerangle,float groundVertexes[]) 42 42 { 43 43 this->player=player; 44 this->playerangle=playerangle; 44 45 } 45 46 … … 88 89 glNewList(this->player_id,GL_COMPILE); 89 90 90 //blabla91 this->player->draw(); 91 92 92 93 glEndList(); … … 94 95 this->image=(unsigned char*)malloc(SIZE*SIZE*4); 95 96 96 //this->player_id=newList {glNormalefv;glVertex3fv} 97 //this->ground_id=newList {glTexCoord2fv;glNormal3fv;glVertex3fv} 98 99 100 //lightPos[] blabla 97 101 98 } 102 99 … … 117 114 glLoadIdentity(); 118 115 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); 120 117 121 118 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 123 123 glCallList(this->player_id); 124 124 glColor3f(1,1,1); … … 134 134 } 135 135 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 145 void 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 136 165 void Shadow::m_inverse(const float *m,float *out) 137 166 { 138 167 float det; 139 det= m[0]*m[5]*m[10];168 det= m[0]*m[5]*m[10]; 140 169 det+= m[4]*m[9]*m[2]; 141 170 det+= m[8]*m[1]*m[6]; … … 143 172 det-= m[4]*m[1]*m[10]; 144 173 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 */ 147 200 148 201 void Shadow::draw() … … 151 204 createShadow(); 152 205 153 glClearColor(0,0,0,0);206 /*glClearColor(0,0,0,0); 154 207 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 155 208 glMatrixMode(GL_PROJECTION); … … 159 212 glLoadIdentity(); 160 213 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 */ 163 216 glEnable(GL_TEXTURE_GEN_S); 164 217 glEnable(GL_TEXTURE_GEN_T); … … 166 219 glEnable(GL_TEXTURE_GEN_Q); 167 220 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 168 245 169 246 }
Note: See TracChangeset
for help on using the changeset viewer.