PDA

View Full Version : when i rotate my model the lighting don't light the new part in front of its



airseb
04-26-2005, 07:54 AM
Hi !
my lighting works when i load my model but if i rotate the model the nex part in front of the light isn't lighted !
Do you know why ? what can i do ?

ce110ut
04-26-2005, 08:38 AM
hard to tell - could you post a code snippet?
:regards:

UrbanLegend
04-26-2005, 10:50 AM
What type of light

Does all you model have correct normals etc..

Are you rotating your light as well

Basically more information is needed

airseb
04-26-2005, 10:58 AM
in fact it works with some files(i am making a .3ds loader)and my model have at least some good normals (i have checked it), do you think it's possible that some others aren't right. I don't try to rotate the light, just the model.

ce110ut
04-26-2005, 11:51 AM
I apologize but I do not see where you have lighting involved. as far as the normals go, as long as they are "normalized" appropriately in your myLoader->myObjects[i].perVertexNormals data object. also, what if you have a model that encompasses the light source? could that be possible?

:regards:

airseb
04-26-2005, 12:09 PM
sorry i didn't pay attention :
this is normals computation (the function "multiplyMatrix" multiply normals by the rotation part of the tranformation matrix of the .3ds in which i read)
void loader3ds::loadIndices()
{
float resultDp ;
ofstream oFile2("sortie3ds2.txt");

file.read((char*) &(myObjects[counterObj].nbPoly), sizeof (unsigned short int));

for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbPoly ; polyCounter++)
{

file.read((char*) &amp;(myObjects[counterObj].myIndices[polyCounter][0]), sizeof (unsigned short int));
file.read((char*) &amp;(myObjects[counterObj].myIndices[polyCounter][1]), sizeof (unsigned short int));
file.read((char*) &amp;(myObjects[counterObj].myIndices[polyCounter][2]), sizeof (unsigned short int));
file.read((char*) &amp;(faceInfo), sizeof (short int));
// cout<<"face info "<<faceInfo<<endl ;

int Va = myObjects[counterObj].myIndices[polyCounter][0] ;
int Vb = myObjects[counterObj].myIndices[polyCounter][1] ;
int Vc = myObjects[counterObj].myIndices[polyCounter][2] ;

//on se sert de ab et ca pour le produit vectoriel, ça et le reste servent uniquement pour la normal weight
float Vab[] = {(myObjects[counterObj].myVertices[Vb][0] - myObjects[counterObj].myVertices[Va][0]),
(myObjects[counterObj].myVertices[Vb][1] - myObjects[counterObj].myVertices[Va][1]),
(myObjects[counterObj].myVertices[Vb][2] - myObjects[counterObj].myVertices[Va][2])};

float Vac[] = {(myObjects[counterObj].myVertices[Vc][0] - myObjects[counterObj].myVertices[Va][0]),
(myObjects[counterObj].myVertices[Vc][1] - myObjects[counterObj].myVertices[Va][1]),
(myObjects[counterObj].myVertices[Vc][2] - myObjects[counterObj].myVertices[Va][2])};

float Vba[] = {(myObjects[counterObj].myVertices[Va][0] - myObjects[counterObj].myVertices[Vb][0]),
(myObjects[counterObj].myVertices[Va][1] - myObjects[counterObj].myVertices[Vb][1]),
(myObjects[counterObj].myVertices[Va][2] - myObjects[counterObj].myVertices[Vb][2])};

float Vbc[] = {(myObjects[counterObj].myVertices[Vc][0] - myObjects[counterObj].myVertices[Vb][0]),
(myObjects[counterObj].myVertices[Vc][1] - myObjects[counterObj].myVertices[Vb][1]),
(myObjects[counterObj].myVertices[Vc][2] - myObjects[counterObj].myVertices[Vb][2])};

float Vca[] = {(myObjects[counterObj].myVertices[Va][0] - myObjects[counterObj].myVertices[Vc][0]),
(myObjects[counterObj].myVertices[Va][1] - myObjects[counterObj].myVertices[Vc][1]),
(myObjects[counterObj].myVertices[Va][2] - myObjects[counterObj].myVertices[Vc][2])};

float Vcb[] = {(myObjects[counterObj].myVertices[Vb][0] - myObjects[counterObj].myVertices[Vc][0]),
(myObjects[counterObj].myVertices[Vb][1] - myObjects[counterObj].myVertices[Vc][1]),
(myObjects[counterObj].myVertices[Vb][2] - myObjects[counterObj].myVertices[Vc][2])};

normalize(Vab) ;
normalize(Vac) ;
dotProduct(Vab, Vac, &amp;resultDp) ;
//oFile2<<dec<<"resultDp "<<resultDp<<endl ;
angle[polyCounter][0]=acosf(resultDp) ;
//oFile2<<"angle "<<dec<<angle[polyCounter][0]<<endl ;

normalize(Vba) ;
normalize(Vbc) ;
dotProduct(Vba, Vbc, &amp;resultDp) ;
//cout<<"resultDp "<<resultDp<<endl ;
angle[polyCounter][1]=acosf(resultDp) ;

normalize(Vca) ;
normalize(Vcb) ;
dotProduct(Vca, Vcb, &amp;resultDp) ;
angle[polyCounter][2]=acosf(resultDp) ;
//oFile2<<"angle "<<dec<<angle[polyCounter][0]<<" "<<angle[polyCounter][1]<<" "<<angle[polyCounter][2]<<endl ;
switch (faceInfo)
{
case 0x3 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vbc) ;
break ;
case 0x7 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vbc) ;
break ;
case 0x6 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vbc) ;
break ;
case 0x5 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vab) ;
break ;
case 0x4 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vab, Vcb) ;
break ;
case 0x2 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vca, Vbc) ;
break ;
case 0x1 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vac, Vcb) ;
break ;
case 0x0 :crossProduct(&amp;myObjects[counterObj].perFaceNormals[polyCounter], Vba, Vcb) ;
break ;
}
normalize(&amp;myObjects[counterObj].perFaceNormals[polyCounter]) ;

//oFile2<<dec<<"angle "<<angle[polyCounter*3]<<" "<<angle[polyCounter*3+1]<<" "<<angle[polyCounter*3+2]<<endl ;

}//fin de la boucle for

cout<<"face info "<<hex<<faceInfo<<endl ;
//éventuellement supprimer l'initialisation, vu que (peut etre) tout les sommets y passent
for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbVertices ; polyCounter++)
{
myObjects[counterObj].perVertexNormals[polyCounter][0] = 0 ;
myObjects[counterObj].perVertexNormals[polyCounter][1] = 0 ;
myObjects[counterObj].perVertexNormals[polyCounter][2] = 0 ;
}

for(nIndice=0 ; nIndice < myObjects[counterObj].nbVertices ; nIndice++)
{
for(i=0 ; i < myObjects[counterObj].nbPoly ; i++)
{
for(j=0 ; j< 3; j++)
{
if(myObjects[counterObj].myIndices[i][j]==nIndice)
{
myObjects[counterObj].perVertexNormals[nIndice][0] += myObjects[counterObj].perFaceNormals[i].x*angle[i][j] ;
myObjects[counterObj].perVertexNormals[nIndice][1] += myObjects[counterObj].perFaceNormals[i].y*angle[i][j] ;
myObjects[counterObj].perVertexNormals[nIndice][2] += myObjects[counterObj].perFaceNormals[i].z*angle[i][j] ;
}
}
}
}

/*multiplyMatrix(myObjects[counterObj].localAxisMatrix,
&amp;myObjects[counterObj].myVertices[0][0],
&amp;myObjects[counterObj].nbVertices) ;*/

multiplyMatrix(myObjects[counterObj].localAxisMatrix,
&amp;myObjects[counterObj].perVertexNormals[0][0],
&amp;myObjects[counterObj].nbVertices) ;

/* float tempSwap, tempSwap2 ;

for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)
{
tempSwap = myObjects[counterObj].myVertices[counter][1] ;
myObjects[counterObj].myVertices[counter][1]= myObjects[counterObj].myVertices[counter][2] ;
myObjects[counterObj].myVertices[counter][2]= -tempSwap ;

tempSwap2 = myObjects[counterObj].perVertexNormals[counter][1] ;
myObjects[counterObj].perVertexNormals[counter][1]= myObjects[counterObj].perVertexNormals[counter][2] ;
myObjects[counterObj].perVertexNormals[counter][2]= -tempSwap2 ;
}*/

//on normalise
for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)
{
normalize(&amp;myObjects[counterObj].perVertexNormals[counter][0],
&amp;myObjects[counterObj].perVertexNormals[counter][1],
&amp;myObjects[counterObj].perVertexNormals[counter][2]) ;
}

ofstream oFile("sortie3ds.txt");
for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)
{
oFile<<"par vertex "<<myObjects[counterObj].perVertexNormals[counter][0] <<" "
<<myObjects[counterObj].perVertexNormals[counter][1] <<" "
<<myObjects[counterObj].perVertexNormals[counter][2] <<endl ;
}
/*for(counter=0 ; counter < myObjects[counterObj].nbVertices ; counter++)
{
for(i=0 ; i<100 ; i++)
{
oFile2<<dec<<tableIndices[counter][i]<<" " ;
}
}*/
cout.flush() ;
}

UrbanLegend
04-26-2005, 03:57 PM
Are you using a

Omni-directional light source ?

or

Directional light source ?

or

Spot Light source ?