mathmod.cpp (mathmod-11.0-source) | : | mathmod.cpp (mathmod-11.1-source) | ||
---|---|---|---|---|
skipping to change at line 180 | skipping to change at line 180 | |||
LocalScene.ArrayNorVer_localPt[i*10 ] = float(ValCol[j+1]); | LocalScene.ArrayNorVer_localPt[i*10 ] = float(ValCol[j+1]); | |||
LocalScene.ArrayNorVer_localPt[i*10+1] = float(ValCol[j+2]); | LocalScene.ArrayNorVer_localPt[i*10+1] = float(ValCol[j+2]); | |||
LocalScene.ArrayNorVer_localPt[i*10+2] = float(ValCol[j+3]); | LocalScene.ArrayNorVer_localPt[i*10+2] = float(ValCol[j+3]); | |||
LocalScene.ArrayNorVer_localPt[i*10+3] = float(ValCol[j+4]); | LocalScene.ArrayNorVer_localPt[i*10+3] = float(ValCol[j+4]); | |||
j = 100; | j = 100; | |||
} | } | |||
} | } | |||
} | } | |||
int MathMod::memoryallocation(uint nbthreads, | int MathMod::memoryallocation(uint nbthreads, | |||
uint initparGrid, uint initisoGrid, | uint initparGrid, uint initisoGrid, | |||
uint FactX, uint FactY, uint FactZ) | uint FactX, uint FactY, uint FactZ) | |||
{ | { | |||
try | try | |||
{ | { | |||
IsoObjet = new Iso3D(nbthreads, initisoGrid, FactX, FactY, FactZ); | IsoObjet = new Iso3D(nbthreads, initisoGrid, FactX, FactY, FactZ); | |||
ParObjet = new Par3D(nbthreads, initparGrid); | ParObjet = new Par3D(nbthreads, initparGrid); | |||
return 1; | return 1; | |||
} | } | |||
catch (std::bad_alloc &) | catch (std::bad_alloc &) | |||
{ | { | |||
message.setText("Not enough memory available to complete this operation" ); | message.setText("Not enough memory available to complete this operation" ); | |||
skipping to change at line 207 | skipping to change at line 207 | |||
void MathMod::SaveSceneAsObjPoly(int type) | void MathMod::SaveSceneAsObjPoly(int type) | |||
{ | { | |||
int startpl = 0; | int startpl = 0; | |||
uint actualpointindice; | uint actualpointindice; | |||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), " ", | QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), " ", | |||
tr("OBJ Files (*.obj)")); | tr("OBJ Files (*.obj)")); | |||
QFile data(fileName); | QFile data(fileName); | |||
if (data.open(QFile::ReadWrite | QFile::Truncate)) | if (data.open(QFile::ReadWrite | QFile::Truncate)) | |||
{ | { | |||
uint i; | ||||
QTextStream stream(&data); | QTextStream stream(&data); | |||
stream.setRealNumberNotation(QTextStream::FixedNotation); | stream.setRealNumberNotation(QTextStream::FixedNotation); | |||
stream.setRealNumberPrecision(3); | stream.setRealNumberPrecision(3); | |||
// save vertices: | // save vertices: | |||
if (type == 1) | if (type == 1) | |||
{ | { | |||
for (i = 0; i < LocalScene.VertxNumber; i++) | for (uint i = 0; i < LocalScene.VertxNumber; i++) | |||
{ | { | |||
(stream) << "v " | (stream) << "v " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) * | |||
(difMaximum*factx/ hauteur_fenetre) - decalage _xo) | (difMaximum*factx/ hauteur_fenetre) - decalage _xo) | |||
<< " " | << " " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) * | |||
(difMaximum*facty / hauteur_fenetre) - decalag e_yo) | (difMaximum*facty / hauteur_fenetre) - decalag e_yo) | |||
<< " " | << " " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) * | |||
(difMaximum*factz / hauteur_fenetre) - decalag e_zo) | (difMaximum*factz / hauteur_fenetre) - decalag e_zo) | |||
<< " " << LocalScene.ArrayNorVer_localPt[10 * i] << " " | << " " << LocalScene.ArrayNorVer_localPt[10 * i] << " " | |||
<< LocalScene.ArrayNorVer_localPt[10 * i + 1] << " " | << LocalScene.ArrayNorVer_localPt[10 * i + 1] << " " | |||
<< LocalScene.ArrayNorVer_localPt[10 * i + 2] << "\n"; | << LocalScene.ArrayNorVer_localPt[10 * i + 2] << "\n"; | |||
} | } | |||
} | } | |||
else | else | |||
{ | { | |||
for (i = 0; i < LocalScene.VertxNumber; i++) | for (uint i = 0; i < LocalScene.VertxNumber; i++) | |||
{ | { | |||
(stream) << "v " | (stream) << "v " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 7]) * | |||
(difMaximum*factx / hauteur_fenetre) - decalag e_xo) | (difMaximum*factx / hauteur_fenetre) - decalag e_xo) | |||
<< " " | << " " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 8]) * | |||
(difMaximum*facty / hauteur_fenetre) - decalag e_yo) | (difMaximum*facty / hauteur_fenetre) - decalag e_yo) | |||
<< " " | << " " | |||
<< float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) * | << float(double(LocalScene.ArrayNorVer_localPt[10 * i + 9]) * | |||
(difMaximum*factz / hauteur_fenetre) - decalag e_zo) | (difMaximum*factz / hauteur_fenetre) - decalag e_zo) | |||
<< "\n"; | << "\n"; | |||
} | } | |||
} | } | |||
// save faces: | // save faces: | |||
startpl = LocalScene.PolyNumber; | uint paramcomp= LocalScene.componentsinfos.ParametricGrid.size(); | |||
for (i = 0; i < LocalScene.NbPolygnNbVertexPtMin; i++) | if(LocalScene.typedrawing == 1) | |||
{ | ||||
startpl = LocalScene.PolyNumber; | ||||
for (uint i = 0; i < LocalScene.NbPolygnNbVertexPtMin; i++) | ||||
{ | ||||
uint polysize = LocalScene.PolyIndices_localPtMin[i]; | ||||
(stream) << "f"; | ||||
for (uint j = 0; j < polysize; j++) | ||||
{ | ||||
actualpointindice = LocalScene.PolyIndices_localPt[startpl++ | ||||
]+1; | ||||
(stream) << " " << actualpointindice; | ||||
} | ||||
(stream) << "\n"; | ||||
} | ||||
} | ||||
else if(LocalScene.typedrawing == -1) | ||||
{ | ||||
//**** Parametrics components ***/ | ||||
uint ugrid=0; | ||||
uint vgrid =0; | ||||
uint index=0; | ||||
for (uint p = 0; p < paramcomp; p += 2) | ||||
{ | ||||
ugrid=LocalScene.componentsinfos.ParametricGrid[p]; | ||||
vgrid=LocalScene.componentsinfos.ParametricGrid[p+1]; | ||||
for (uint i = 0; i < ugrid-1; i ++) | ||||
for (uint j = 0; j < vgrid-1; j ++) | ||||
{ | ||||
(stream) << "f " | ||||
<< " " << (i*vgrid + j+index) +1<< " " | ||||
<< ((i+1)*vgrid + j +index) +1<< " " | ||||
<< ((i+1)*vgrid + (j+1)+index) +1<< " " | ||||
<< (i*vgrid + (j+1)+index) +1<< "\n"; | ||||
} | ||||
index += ugrid*vgrid; | ||||
} | ||||
} | ||||
else | ||||
{ | { | |||
uint polysize = LocalScene.PolyIndices_localPtMin[i]; | //**** Parametrics components ***/ | |||
(stream) << "f"; | ||||
for (uint j = 0; j < polysize; j++) | uint ugrid=0; | |||
uint vgrid =0; | ||||
uint index=0; | ||||
for (uint p = 0; p < paramcomp; p += 2) | ||||
{ | { | |||
actualpointindice = LocalScene.PolyIndices_localPt[startpl++]+1; | ugrid=LocalScene.componentsinfos.ParametricGrid[p]; | |||
(stream) << " " << actualpointindice; | vgrid=LocalScene.componentsinfos.ParametricGrid[p+1]; | |||
for (uint i = 0; i < ugrid-1; i ++) | ||||
for (uint j = 0; j < vgrid-1; j ++) | ||||
{ | ||||
(stream) << "f " | ||||
<< " " << (i*vgrid + j+index) +1<< " " | ||||
<< ((i+1)*vgrid + j +index) +1<< " " | ||||
<< ((i+1)*vgrid + (j+1)+index) +1<< " " | ||||
<< (i*vgrid + (j+1)+index) +1<< "\n"; | ||||
} | ||||
index += ugrid*vgrid; | ||||
} | } | |||
(stream) << "\n"; | ||||
// Isosurfaces components | ||||
startpl = LocalScene.PolyNumber+LocalScene.componentsinfos.MinParamet | ||||
ricMeshLines; | ||||
uint kl= LocalScene.componentsinfos.NbParametricMeshLines; | ||||
for (uint i = kl; i < LocalScene.NbPolygnNbVertexPtMin; i++) | ||||
{ | ||||
uint polysize = LocalScene.PolyIndices_localPtMin[i]; | ||||
(stream) << "f"; | ||||
for (uint j = 0; j < polysize; j++) | ||||
{ | ||||
actualpointindice = LocalScene.PolyIndices_localPt[startpl++] | ||||
+1; | ||||
(stream) << " " << actualpointindice; | ||||
} | ||||
(stream) << "\n"; | ||||
} | ||||
} | } | |||
} | } | |||
} | } | |||
void MathMod::SaveSceneAsObjTrian(int type) | void MathMod::SaveSceneAsObjTrian(int type) | |||
{ | { | |||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), " ", | QString fileName = QFileDialog::getSaveFileName(this, tr("Save OBJ file"), " ", | |||
tr("OBJ Files (*.obj)")); | tr("OBJ Files (*.obj)")); | |||
QFile data(fileName); | QFile data(fileName); | |||
if (data.open(QFile::ReadWrite | QFile::Truncate)) | if (data.open(QFile::ReadWrite | QFile::Truncate)) | |||
skipping to change at line 554 | skipping to change at line 618 | |||
for(uint id=0; id<4; id++) | for(uint id=0; id<4; id++) | |||
{ | { | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+0] = 0.0; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+0] = 0.0; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+1] = 0.0; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+1] = 0.0; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+2] = 2.0; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+2] = 2.0; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+3] = 1.0f; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+3] = 1.0f; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+7] = AxeArray[3*( id+32) ]; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+7] = AxeArray[3*( id+32) ]; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+8] = AxeArray[3*( id+32)+1]; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+8] = AxeArray[3*( id+32)+1]; | |||
LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+9] = AxeArray[3*( id+32)+2]; | LocalScene.ArrayNorVer_localPt[10*(NbVert+12+60+32+id)+9] = AxeArray[3*( id+32)+2]; | |||
} | } | |||
uint polynb=0; | ||||
if(LocalScene.typedrawing == -1) | ||||
{ | ||||
uint sz = LocalScene.componentsinfos.ParametricGrid.size(); | ||||
for (uint p = 0; p < sz; p += 2) | ||||
{ | ||||
polynb += (LocalScene.componentsinfos.ParametricGrid[p]-1) * | ||||
(LocalScene.componentsinfos.ParametricGrid[p+1]-1); | ||||
} | ||||
} | ||||
else | ||||
polynb = LocalScene.NbPolygnNbVertexPtMin; | ||||
labelinfos = " \n Grid : "; | labelinfos = " \n Grid : "; | |||
(LocalScene.typedrawing == 1) | (LocalScene.typedrawing == 1) | |||
? labelinfos += QString::number(Xgrid - CutX) + "x" + | ? labelinfos += QString::number(Xgrid - CutX) + "x" + | |||
QString::number(Ygrid - CutY) + "x" + | QString::number(Ygrid - CutY) + "x" + | |||
QString::number(Zgrid - CutZ) +" \n" | QString::number(Zgrid - CutZ) +" \n" | |||
: labelinfos += QString::number(Ugrid - CutU) + "x" + | : labelinfos += QString::number(Ugrid - CutU) + "x" + | |||
QString::number(Vgrid - CutV) +" \n"; | QString::number(Vgrid - CutV) +" \n"; | |||
labelinfos+=" Vertices : "+QString::number(LocalScene.VertxNumber)+" \n"+ | labelinfos+=" Vertices : "+QString::number(LocalScene.VertxNumber)+" \n"+ | |||
" Triangles: "+QString::number(LocalScene.PolyNumber/ 3)+" \n" | " Triangles: "+QString::number(LocalScene.PolyNumber/ 3)+" \n" | |||
" Polygons : "+QString::number(LocalScene.NbPolygnNbV ertexPtMin)+" \n"; | " Polygons : "+QString::number(polynb)+" \n"; | |||
if(LocalScene.morph==-1) | if(LocalScene.morph==-1) | |||
labelinfos+=" X["+QString::number(minx,'g',3)+","+QString::number(maxx,'g ',3)+"]\n\ | labelinfos+=" X["+QString::number(minx,'g',3)+","+QString::number(maxx,'g ',3)+"]\n\ | |||
Y["+QString::number(miny,'g',3)+","+QString::number(maxy,'g',3)+"]\n\ | Y["+QString::number(miny,'g',3)+","+QString::number(maxy,'g',3)+"]\n\ | |||
Z["+QString::number(minz,'g',3)+","+QString::number(maxz,'g',3)+"]\n"; | Z["+QString::number(minz,'g',3)+","+QString::number(maxz,'g',3)+"]\n"; | |||
else | else | |||
labelinfos+=" X["+QString::number(oldminx,'g',3)+","+QString::number(oldm axx,'g',3)+"]\n\ | labelinfos+=" X["+QString::number(oldminx,'g',3)+","+QString::number(oldm axx,'g',3)+"]\n\ | |||
Y["+QString::number(oldminy,'g',3)+","+QString::number(oldmaxy,'g',3)+"]\n\ | Y["+QString::number(oldminy,'g',3)+","+QString::number(oldmaxy,'g',3)+"]\n\ | |||
Z["+QString::number(oldminz,'g',3)+","+QString::number(oldmaxz,'g',3)+"]\n"; | Z["+QString::number(oldminz,'g',3)+","+QString::number(oldmaxz,'g',3)+"]\n"; | |||
if(LocalScene.morph==1) | if(LocalScene.morph==1) | |||
skipping to change at line 702 | skipping to change at line 778 | |||
update(); | update(); | |||
} | } | |||
void MathMod::transDiff(int cl) | void MathMod::transDiff(int cl) | |||
{ | { | |||
lightDiffuse[3] = (cl/ 100.0f); | lightDiffuse[3] = (cl/ 100.0f); | |||
LocalScene.DiffuseValUpdated=true; | LocalScene.DiffuseValUpdated=true; | |||
update(); | update(); | |||
} | } | |||
void MathMod::glfrontfacesupp(int val) | ||||
{ | ||||
LocalScene.glFrontFacingSupport = val; | ||||
LocalScene.FrontSurfValUpdated=true; | ||||
update(); | ||||
} | ||||
void MathMod::drawCube() | void MathMod::drawCube() | |||
{ | { | |||
glLineWidth(1.0); | glLineWidth(1.0); | |||
glUniform1i(uniformThereisRGBA, 0); | glUniform1i(uniformThereisRGBA, 0); | |||
glDrawArrays(GL_LINE_STRIP,CubeStartIndex, 12); | glDrawArrays(GL_LINE_STRIP,CubeStartIndex, 12); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::DrawPariso(ObjectProperties *scene, uint ParisoTypeIndex) | void MathMod::DrawPariso(ObjectProperties *scene, uint ParisoTypeIndex) | |||
{ | { | |||
uint idx = 0; | uint idx = 0; | |||
for (uint i = 0; i < ParisoTypeIndex; i++) | for (uint i = 0; i < ParisoTypeIndex; i++) | |||
idx += scene->componentsinfos.NbComponentsType[i]; | idx += scene->componentsinfos.NbComponentsType[i]; | |||
int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx]; | int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx]; | |||
float frontcl[4], backcl[4]; | float frontcl[4], backcl[4]; | |||
glEnable(GL_POLYGON_OFFSET_FILL); | glEnable(GL_POLYGON_OFFSET_FILL); | |||
glPolygonOffset(scene->polyfactor, scene->polyunits); | glPolygonOffset(scene->polyfactor, scene->polyunits); | |||
if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex]) | if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex]) | |||
{ | { | |||
for (uint j = 0; j < 4; j++) | for (uint j = 0; j < 4; j++) | |||
{ | { | |||
frontcl[j] = scene->frontcols[j]; | frontcl[j] = scene->frontcols[j]; | |||
backcl[j] = scene->backcols[j]; | backcl[j] = scene->backcols[j]; | |||
} | } | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
glUniform1i(uniformHSVactive, 0); | ||||
glUniform4fv(uniformFrontColor, 1, frontcl); | glUniform4fv(uniformFrontColor, 1, frontcl); | |||
glUniform4fv(uniformBackColor, 1, backcl); | glUniform4fv(uniformBackColor, 1, backcl); | |||
glUniform1i(uniformThereisRGBA, 1); | } | |||
else | ||||
{ | ||||
glUniform1i(uniformHSVactive, scene->componentsinfos.hsv[ParisoTypeIndex | ||||
]?1:0); | ||||
glUniform1i(uniformThereisRGBA, 0); | ||||
} | } | |||
if (scene->componentsinfos.ThereisCND[ParisoTypeIndex]) | if (scene->componentsinfos.ThereisCND[ParisoTypeIndex]) | |||
{ | { | |||
size_t Offset0 = start_triangle*sizeof( GL_FLOAT); | size_t Offset0 = start_triangle*sizeof( GL_FLOAT); | |||
glDrawElements( | glDrawElements( | |||
GL_TRIANGLES, | GL_TRIANGLES, | |||
int(3 * (scene->componentsinfos.NbTrianglesNoCND[ParisoTypeIndex])), | int(3 * (scene->componentsinfos.NbTrianglesNoCND[ParisoTypeIndex])), | |||
GL_UNSIGNED_INT, (void *)(Offset0)); | GL_UNSIGNED_INT, (void *)(Offset0)); | |||
skipping to change at line 773 | skipping to change at line 863 | |||
uint cmpIndex = (ParisoTypeIndex==1) ? (scene->componentsinfos.NbCom ponentsType[0]+i):i; | uint cmpIndex = (ParisoTypeIndex==1) ? (scene->componentsinfos.NbCom ponentsType[0]+i):i; | |||
if (scene->componentsinfos.ShowParIsoCmp[cmpIndex]) | if (scene->componentsinfos.ShowParIsoCmp[cmpIndex]) | |||
{ | { | |||
if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex]) | if (!scene->componentsinfos.ThereisRGBA[ParisoTypeIndex]) | |||
{ | { | |||
for (uint j = 0; j < 4; j++) | for (uint j = 0; j < 4; j++) | |||
{ | { | |||
frontcl[j] = scene->frontcols[4 * (i % 10) + j]; | frontcl[j] = scene->frontcols[4 * (i % 10) + j]; | |||
backcl[j] = scene->backcols[4 * (i % 10) + j]; | backcl[j] = scene->backcols[4 * (i % 10) + j]; | |||
} | } | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
glUniform4fv(uniformFrontColor, 1, frontcl); | glUniform4fv(uniformFrontColor, 1, frontcl); | |||
glUniform4fv(uniformBackColor, 1, backcl); | glUniform4fv(uniformBackColor, 1, backcl); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
else | else | |||
{ | ||||
glUniform1i(uniformThereisRGBA, 0); | glUniform1i(uniformThereisRGBA, 0); | |||
} | ||||
{ | { | |||
size_t Offset = scene->componentsinfos.ParisoTriangle[2*(i+i dx)]*sizeof( GL_FLOAT); | size_t Offset = scene->componentsinfos.ParisoTriangle[2*(i+i dx)]*sizeof( GL_FLOAT); | |||
glDrawElements( | glDrawElements( | |||
GL_TRIANGLES, | GL_TRIANGLES, | |||
int(3 * scene->componentsinfos.ParisoTriangle[2 * (i + i dx) + 1]),GL_UNSIGNED_INT,(void *)(Offset)); | int(3 * scene->componentsinfos.ParisoTriangle[2 * (i + i dx) + 1]),GL_UNSIGNED_INT,(void *)(Offset)); | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
glDisable(GL_POLYGON_OFFSET_FILL); | glDisable(GL_POLYGON_OFFSET_FILL); | |||
glUniform1i(uniformThereisRGBA, 0); | //glUniform1i(uniformThereisRGBA, 0); | |||
} | } | |||
void MathMod::normOk() | void MathMod::normOk() | |||
{ | { | |||
LocalScene.norm *= -1; | LocalScene.norm *= -1; | |||
update(); | update(); | |||
} | } | |||
void MathMod::boundingboxOk() | void MathMod::boundingboxOk() | |||
{ | { | |||
skipping to change at line 845 | skipping to change at line 937 | |||
int IsCompiled_VS, IsCompiled_FS; | int IsCompiled_VS, IsCompiled_FS; | |||
GLuint vertexshader, fragmentshader; | GLuint vertexshader, fragmentshader; | |||
char *vertexInfoLog; | char *vertexInfoLog; | |||
char *fragmentInfoLog; | char *fragmentInfoLog; | |||
char *shaderProgramInfoLog; | char *shaderProgramInfoLog; | |||
int IsLinked; | int IsLinked; | |||
int maxLength; | int maxLength; | |||
const int MAX_LENGTH = 2048; | const int MAX_LENGTH = 2048; | |||
char log[MAX_LENGTH]; | char log[MAX_LENGTH]; | |||
int logLength = 0; | int logLength = 0; | |||
bool shaderValid; | ||||
shaderprogramId = glCreateProgram(); | ||||
//+++++++++++++++++++++++++++++++// | ||||
//++++++++ Vertex shader ++++++++// | ||||
//+++++++++++++++++++++++++++++++// | ||||
vertexshader = glCreateShader(GL_VERTEX_SHADER); | vertexshader = glCreateShader(GL_VERTEX_SHADER); | |||
bool shaderValid = glIsShader(vertexshader); | shaderValid = glIsShader(vertexshader); | |||
if (!shaderValid) | if (!shaderValid) | |||
{ | { | |||
std::cout << "Could not create Vertex Shader!"; | std::cout << "Could not create Vertex Shader!"; | |||
} | } | |||
fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); | ||||
static const char *c_str_vertex = | static const char *c_str_vertex = | |||
R"( | R"( | |||
// GLSL version | // GLSL version | |||
//#version 120 | //#version 120 | |||
#ifdef GL_ES | #ifdef GL_ES | |||
precision mediump float; | precision mediump float; | |||
#endif | #endif | |||
// uniforms | // uniforms | |||
uniform mat4 matrixModelView; | uniform mat4 matrixModelView; | |||
uniform mat4 matrixNormal; | uniform mat4 matrixNormal; | |||
uniform mat4 matrixModelViewProjection; | uniform mat4 matrixModelViewProjection; | |||
uniform int glFrontFacing_1; | ||||
// vertex attribs (input) | // vertex attribs (input) | |||
attribute vec3 vertexPosition; | attribute vec3 vertexPosition; | |||
attribute vec3 vertexNormal; | attribute vec3 vertexNormal; | |||
attribute vec4 vertexColor; | attribute vec4 vertexColor; | |||
//attribute vec2 vertexTexCoord; | ||||
// varyings (output) | // varyings (output) | |||
varying vec3 esVertex, esNormal; | varying vec3 esVertex, esNormal; | |||
varying vec4 color; | varying vec4 color; | |||
varying vec4 v_position; | ||||
void main() | void main() | |||
{ | { | |||
esVertex = vec3(matrixModelView * vec4(vertexPosition, 1.0)); | esVertex = vec3(matrixModelView * vec4(vertexPosition, 1.0)); | |||
esNormal = vec3(matrixNormal * vec4(vertexNormal, 1.0)); | esNormal = vec3(matrixNormal * vec4(vertexNormal, 1.0)); | |||
color = vertexColor; | color = vertexColor; | |||
gl_Position = matrixModelViewProjection * vec4(vertexPosition, 1 | if(glFrontFacing_1 == 0) | |||
.0); | { | |||
v_position = -matrixModelView * vec4 (vertexPosition, 1.0); | ||||
} | ||||
gl_Position = matrixModelViewProjection * vec4(vertexPosition, | ||||
1.0); | ||||
} | } | |||
)"; | )"; | |||
glShaderSource(vertexshader, 1, &c_str_vertex, NULL); | ||||
glCompileShader(vertexshader); | ||||
glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &IsCompiled_VS); | ||||
if(IsCompiled_VS==GL_FALSE) | ||||
{ | ||||
QMessageBox msgBox; | ||||
glGetShaderiv(vertexshader, GL_INFO_LOG_LENGTH, &maxLength); | ||||
vertexInfoLog = (char *)malloc(maxLength); | ||||
glGetShaderInfoLog(vertexshader, maxLength, &maxLength, vertexInfoLog); | ||||
std::string vertexInfoLogString = std::string(vertexInfoLog); | ||||
msgBox.setText("Error : " +QString::fromStdString(std::string(vertexInfoL | ||||
og))); | ||||
msgBox.adjustSize(); | ||||
msgBox.exec(); | ||||
} | ||||
//++++++++++++++++++++++++++// | ||||
//++++++ Fragment shader +++// | ||||
//++++++++++++++++++++++++++// | ||||
fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); | ||||
shaderValid = glIsShader(fragmentshader); | ||||
if (!shaderValid) | ||||
{ | ||||
std::cout << "Could not create Fragment Shader!"; | ||||
} | ||||
static const char *c_str_fragment = | static const char *c_str_fragment = | |||
R"( | R"( | |||
// GLSL version | // GLSL version | |||
//#version 120 | //#version 120 | |||
#ifdef GL_ES | #ifdef GL_ES | |||
precision mediump float; | precision mediump float; | |||
#endif | #endif | |||
// uniforms | // uniforms | |||
uniform vec4 frontColor; | uniform vec4 frontColor; | |||
uniform vec4 backColor; | uniform vec4 backColor; | |||
uniform vec4 gridColor; | uniform vec4 gridColor; | |||
uniform vec4 lightPosition; | uniform vec4 lightPosition; | |||
uniform vec4 lightAmbient; | uniform vec4 lightAmbient; | |||
uniform vec4 lightDiffuse; | uniform vec4 lightDiffuse; | |||
uniform vec4 lightSpecular; | uniform vec4 lightSpecular; | |||
uniform int hsvactive; | ||||
uniform int thereisRGBA; | uniform int thereisRGBA; | |||
uniform int drawgridColor; | uniform int drawgridColor; | |||
uniform float shininess; | uniform float shininess; | |||
uniform int glFrontFacing_2; | ||||
// varyings | // varyings | |||
varying vec3 esVertex, esNormal; | varying vec3 esVertex, esNormal; | |||
varying vec4 color; | varying vec4 color; | |||
varying vec4 v_position; | ||||
// All components are in the range [0…1], including hue. | ||||
vec3 hsv2rgb(vec3 c) | ||||
{ | ||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | ||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | ||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | ||||
} | ||||
void main() | void main() | |||
{ | { | |||
vec4 color1=color; | vec4 color1=color; | |||
vec3 normal = normalize(esNormal); | vec3 normal = normalize(esNormal); | |||
if(!gl_FrontFacing) | if(glFrontFacing_2 == 1) | |||
{ | { | |||
normal *= -1.0; | if(gl_FrontFacing == false) | |||
} | { | |||
normal *= -1.0; | ||||
if(thereisRGBA ==1) | ||||
{ | ||||
color1=backColor; | ||||
} | ||||
if(drawgridColor == 1) | } | |||
{ | else | |||
color1=gridColor; | { | |||
if(!gl_FrontFacing) | if(thereisRGBA ==1) | |||
{ | { | |||
normal *= -1.0; | color1=frontColor; | |||
} | } | |||
} | ||||
} | } | |||
if(thereisRGBA ==1) | else | |||
{ | { | |||
if(!gl_FrontFacing) | if(dot(normal, v_position.xyz) <= 0.0) | |||
{ | { | |||
color1=backColor; | normal *= -1.0; | |||
if(thereisRGBA ==1) | ||||
{ | ||||
color1=backColor; | ||||
} | ||||
} | } | |||
else | else | |||
color1=frontColor; | { | |||
if(thereisRGBA ==1) | ||||
{ | ||||
color1=frontColor; | ||||
} | ||||
} | ||||
} | ||||
if(drawgridColor == 1) | ||||
{ | ||||
color1=gridColor; | ||||
} | } | |||
vec3 light; | vec3 light; | |||
if(lightPosition.w == 0.0) | if(lightPosition.w == 0.0) | |||
{ | { | |||
light = normalize(lightPosition.xyz); | light = normalize(lightPosition.xyz); | |||
} | } | |||
else | else | |||
{ | { | |||
light = normalize(lightPosition.xyz - esVertex); | light = normalize(lightPosition.xyz - esVertex); | |||
} | } | |||
if(hsvactive == 1) | ||||
color1 = vec4(hsv2rgb(color1.xyz), color1.w); | ||||
vec3 view = normalize(-esVertex); | vec3 view = normalize(-esVertex); | |||
vec3 halfv = normalize(light + view); | vec3 halfv = normalize(light + view); | |||
vec4 fragColor = lightAmbient * color1; | ||||
vec4 fragColor = lightAmbient * color1; // begin wi | ||||
th ambient | ||||
float dotNL = max(dot(normal, light), 0.0); | float dotNL = max(dot(normal, light), 0.0); | |||
fragColor += lightDiffuse* color1 * dotNL; // add d iffuse | fragColor += lightDiffuse* color1 * dotNL; // add diffu se | |||
float dotNH = max(dot(normal, halfv), 0.0); | float dotNH = max(dot(normal, halfv), 0.0); | |||
fragColor += (pow(dotNH, shininess) * lightSpecular) * color1; / / add specular | fragColor += (pow(dotNH, shininess) * lightSpecular) * color1; / / add specular | |||
// set frag color | // set frag color | |||
//gl_FragColor = (hsvactive == 1)? vec4(hsv2rgb(fragColor.xyz), fragColor.w) : fragColor; | ||||
gl_FragColor = fragColor; | gl_FragColor = fragColor; | |||
} | } | |||
)"; | )"; | |||
glShaderSource(vertexshader, 1, &c_str_vertex, NULL); | ||||
glCompileShader(vertexshader); | ||||
glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &IsCompiled_VS); | ||||
if(IsCompiled_VS==GL_FALSE) | ||||
{ | ||||
QMessageBox msgBox; | ||||
glGetShaderiv(vertexshader, GL_INFO_LOG_LENGTH, &maxLength); | ||||
vertexInfoLog = (char *)malloc(maxLength); | ||||
glGetShaderInfoLog(vertexshader, maxLength, &maxLength, vertexInfoLog); | ||||
std::string vertexInfoLogString = std::string(vertexInfoLog); | ||||
msgBox.setText("Error : " +QString::fromStdString(std::string(vertexInfoL | ||||
og))); | ||||
msgBox.adjustSize(); | ||||
msgBox.exec(); | ||||
} | ||||
glShaderSource(fragmentshader, 1, &c_str_fragment, NULL); | glShaderSource(fragmentshader, 1, &c_str_fragment, NULL); | |||
glCompileShader(fragmentshader); | glCompileShader(fragmentshader); | |||
glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &IsCompiled_FS); | glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &IsCompiled_FS); | |||
if(IsCompiled_FS==GL_FALSE) | if(IsCompiled_FS==GL_FALSE) | |||
{ | { | |||
QMessageBox msgBox; | QMessageBox msgBox; | |||
glGetShaderiv(fragmentshader, GL_INFO_LOG_LENGTH, &maxLength); | glGetShaderiv(fragmentshader, GL_INFO_LOG_LENGTH, &maxLength); | |||
fragmentInfoLog = (char *)malloc(maxLength); | fragmentInfoLog = (char *)malloc(maxLength); | |||
glGetShaderInfoLog(fragmentshader, maxLength, &maxLength, fragmentInfoLog ); | glGetShaderInfoLog(fragmentshader, maxLength, &maxLength, fragmentInfoLog ); | |||
std::string vertexInfoLogString = std::string(fragmentInfoLog); | std::string vertexInfoLogString = std::string(fragmentInfoLog); | |||
msgBox.setText("Error : " +QString::fromStdString(std::string(fragmentInf oLog))); | msgBox.setText("Error : " +QString::fromStdString(std::string(fragmentInf oLog))); | |||
msgBox.adjustSize(); | msgBox.adjustSize(); | |||
msgBox.exec(); | msgBox.exec(); | |||
//return; | ||||
} | } | |||
shaderprogramId = glCreateProgram(); | ||||
glAttachShader(shaderprogramId, vertexshader); | glAttachShader(shaderprogramId, vertexshader); | |||
glAttachShader(shaderprogramId, fragmentshader); | glAttachShader(shaderprogramId, fragmentshader); | |||
glBindAttribLocation(shaderprogramId, 0, "in_Position"); | glBindAttribLocation(shaderprogramId, 0, "in_Position"); | |||
glBindAttribLocation(shaderprogramId, 1, "in_Color"); | glBindAttribLocation(shaderprogramId, 1, "in_Color"); | |||
glLinkProgram(shaderprogramId); | glLinkProgram(shaderprogramId); | |||
glGetProgramiv(shaderprogramId, GL_LINK_STATUS, (int *)&IsLinked); | glGetProgramiv(shaderprogramId, GL_LINK_STATUS, (int *)&IsLinked); | |||
if(!IsLinked) | if(!IsLinked) | |||
{ | { | |||
glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &maxLength); | glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &maxLength); | |||
shaderProgramInfoLog = (char *)malloc(maxLength); | shaderProgramInfoLog = (char *)malloc(maxLength); | |||
skipping to change at line 1004 | skipping to change at line 1146 | |||
uniformMatrixModelViewProjection = glGetUniformLocation(shaderprogramId, "ma trixModelViewProjection"); | uniformMatrixModelViewProjection = glGetUniformLocation(shaderprogramId, "ma trixModelViewProjection"); | |||
uniformMatrixNormal = glGetUniformLocation(shaderprogramId, "ma trixNormal"); | uniformMatrixNormal = glGetUniformLocation(shaderprogramId, "ma trixNormal"); | |||
uniformLightPosition = glGetUniformLocation(shaderprogramId, "li ghtPosition"); | uniformLightPosition = glGetUniformLocation(shaderprogramId, "li ghtPosition"); | |||
uniformLightAmbient = glGetUniformLocation(shaderprogramId, "li ghtAmbient"); | uniformLightAmbient = glGetUniformLocation(shaderprogramId, "li ghtAmbient"); | |||
uniformLightDiffuse = glGetUniformLocation(shaderprogramId, "li ghtDiffuse"); | uniformLightDiffuse = glGetUniformLocation(shaderprogramId, "li ghtDiffuse"); | |||
uniformLightSpecular = glGetUniformLocation(shaderprogramId, "li ghtSpecular"); | uniformLightSpecular = glGetUniformLocation(shaderprogramId, "li ghtSpecular"); | |||
uniformFrontColor = glGetUniformLocation(shaderprogramId, "fr ontColor"); | uniformFrontColor = glGetUniformLocation(shaderprogramId, "fr ontColor"); | |||
uniformBackColor = glGetUniformLocation(shaderprogramId, "ba ckColor"); | uniformBackColor = glGetUniformLocation(shaderprogramId, "ba ckColor"); | |||
uniformGridColor = glGetUniformLocation(shaderprogramId, "gr idColor"); | uniformGridColor = glGetUniformLocation(shaderprogramId, "gr idColor"); | |||
uniformThereisRGBA = glGetUniformLocation(shaderprogramId, "th ereisRGBA"); | uniformThereisRGBA = glGetUniformLocation(shaderprogramId, "th ereisRGBA"); | |||
uniformHSVactive = glGetUniformLocation(shaderprogramId, "hs vactive"); | ||||
uniformShininess = glGetUniformLocation(shaderprogramId, "sh ininess"); | uniformShininess = glGetUniformLocation(shaderprogramId, "sh ininess"); | |||
uniformglFrontFacing_1 = glGetUniformLocation(shaderprogramId, "gl | ||||
FrontFacing_1"); | ||||
uniformglFrontFacing_2 = glGetUniformLocation(shaderprogramId, "gl | ||||
FrontFacing_2"); | ||||
uniformdrawgridColor = glGetUniformLocation(shaderprogramId, "dr awgridColor"); | uniformdrawgridColor = glGetUniformLocation(shaderprogramId, "dr awgridColor"); | |||
attribVertexPosition = glGetAttribLocation(shaderprogramId, "ver texPosition"); | attribVertexPosition = glGetAttribLocation(shaderprogramId, "ver texPosition"); | |||
attribVertexNormal = glGetAttribLocation(shaderprogramId, "ver texNormal"); | attribVertexNormal = glGetAttribLocation(shaderprogramId, "ver texNormal"); | |||
attribVertexColor = glGetAttribLocation(shaderprogramId, "ver texColor"); | attribVertexColor = glGetAttribLocation(shaderprogramId, "ver texColor"); | |||
glUniform4fv(uniformLightPosition, 1, lightPosition); | glUniform4fv(uniformLightPosition, 1, lightPosition); | |||
glUniform4fv(uniformLightAmbient, 1, lightAmbient); | glUniform4fv(uniformLightAmbient, 1, lightAmbient); | |||
glUniform4fv(uniformLightDiffuse, 1, lightDiffuse); | glUniform4fv(uniformLightDiffuse, 1, lightDiffuse); | |||
glUniform4fv(uniformLightSpecular, 1, lightSpecular); | glUniform4fv(uniformLightSpecular, 1, lightSpecular); | |||
glUniform4fv(uniformFrontColor, 1, frontColor); | glUniform4fv(uniformFrontColor, 1, frontColor); | |||
glUniform4fv(uniformBackColor, 1, backColor); | glUniform4fv(uniformBackColor, 1, backColor); | |||
glUniform4fv(uniformGridColor, 1, gridcol); | glUniform4fv(uniformGridColor, 1, gridcol); | |||
glUniform1f(uniformShininess, shininessVal); | glUniform1f(uniformShininess, shininessVal); | |||
glUniform1i(uniformThereisRGBA, 1); | glUniform1i(uniformglFrontFacing_1, LocalScene.glFrontFacingSupport); | |||
glUniform1i(uniformglFrontFacing_2, LocalScene.glFrontFacingSupport); | ||||
glUniform1i(uniformThereisRGBA, 0); | ||||
glUniform1i(uniformHSVactive, 0); | ||||
glUniform1i(uniformdrawgridColor, 0); | glUniform1i(uniformdrawgridColor, 0); | |||
int linkStatus; | int linkStatus; | |||
glGetProgramiv(shaderprogramId, GL_LINK_STATUS, &linkStatus); | glGetProgramiv(shaderprogramId, GL_LINK_STATUS, &linkStatus); | |||
if(linkStatus == GL_FALSE) | if(linkStatus == GL_FALSE) | |||
{ | { | |||
glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &logLength); | glGetProgramiv(shaderprogramId, GL_INFO_LOG_LENGTH, &logLength); | |||
glGetProgramInfoLog(shaderprogramId, MAX_LENGTH, &logLength, log); | glGetProgramInfoLog(shaderprogramId, MAX_LENGTH, &logLength, log); | |||
std::cout << "===== GLSL Program Log =====\n" << log << std::endl; | std::cout << "===== GLSL Program Log =====\n" << log << std::endl; | |||
return; | return; | |||
} | } | |||
else | else | |||
skipping to change at line 1056 | skipping to change at line 1203 | |||
} | } | |||
void MathMod::initializeGL() | void MathMod::initializeGL() | |||
{ | { | |||
initializeOpenGLFunctions(); | initializeOpenGLFunctions(); | |||
glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | |||
glEnable(GL_BLEND); | glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
glFrontFace(GL_CCW); | glFrontFace(GL_CCW); | |||
glClearColor(0, 0, 0, 0); | glClearColor(0, 0, 0, 0); | |||
//initCamera(); | ||||
proj(); | proj(); | |||
} | } | |||
void MathMod::resizeGL(int newwidth, int newheight) | void MathMod::resizeGL(int newwidth, int newheight) | |||
{ | { | |||
screenWidth = newwidth; | screenWidth = newwidth; | |||
screenHeight = newheight; | screenHeight = newheight; | |||
proj(); | proj(); | |||
} | } | |||
skipping to change at line 1155 | skipping to change at line 1301 | |||
{ | { | |||
int key = e->key(); | int key = e->key(); | |||
switch (key) | switch (key) | |||
{ | { | |||
case Qt::CTRL+Qt::Key_A: | case Qt::CTRL+Qt::Key_A: | |||
anim(); | anim(); | |||
break; | break; | |||
case Qt::CTRL+Qt::Key_P: | case Qt::CTRL+Qt::Key_P: | |||
morph(); | morph(); | |||
break; | break; | |||
case Qt::CTRL+Qt::Key_C: | case Qt::Key_C: | |||
Parent->show(); | Parent->show(); | |||
break; | break; | |||
} | } | |||
update(); | update(); | |||
} | } | |||
void MathMod::FillOk() | void MathMod::FillOk() | |||
{ | { | |||
LocalScene.fill *= -1; | LocalScene.fill *= -1; | |||
update(); | update(); | |||
} | } | |||
void MathMod::DrawAxe() | void MathMod::DrawAxe() | |||
{ | { | |||
glLineWidth(1.0); | glLineWidth(1.0); | |||
glUniform1i(uniformThereisRGBA, 0); | glUniform1i(uniformThereisRGBA, 0); | |||
glUniform1i(uniformHSVactive, 0); | ||||
// Draw the three axes (lines without head) | // Draw the three axes (lines without head) | |||
glDrawArrays(GL_LINES,AxesStartIndex,6); | glDrawArrays(GL_LINES,AxesStartIndex,6); | |||
// Head of the X Axe: | // Head of the X Axe: | |||
glDrawArrays(GL_TRIANGLE_FAN,XStartIndex,6); | glDrawArrays(GL_TRIANGLE_FAN,XStartIndex,6); | |||
// Head of the Y Axe: | // Head of the Y Axe: | |||
glDrawArrays(GL_TRIANGLE_FAN,YStartIndex,6); | glDrawArrays(GL_TRIANGLE_FAN,YStartIndex,6); | |||
// Head of the Z Axe: | // Head of the Z Axe: | |||
glDrawArrays(GL_TRIANGLE_FAN,ZStartIndex,6); | glDrawArrays(GL_TRIANGLE_FAN,ZStartIndex,6); | |||
glLineWidth(3.0); | glLineWidth(3.0); | |||
// Draw the X axe | // Draw the X axe | |||
glDrawArrays(GL_LINES,XletterIndex,4); | glDrawArrays(GL_LINES,XletterIndex,4); | |||
// Draw the Y axe | // Draw the Y axe | |||
glDrawArrays(GL_LINES,YletterIndex,4); | glDrawArrays(GL_LINES,YletterIndex,4); | |||
// Draw the Z axe | // Draw the Z axe | |||
glDrawArrays(GL_LINE_STRIP,ZletterIndex,4); | glDrawArrays(GL_LINE_STRIP,ZletterIndex,4); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::DrawNormals(ObjectProperties *) | void MathMod::DrawNormals(ObjectProperties *) | |||
{ | { | |||
/* | ||||
uint j = 0; | ||||
glColor4f(0.8f, 0., 0.7f, 1.0); | ||||
for (uint i = 0; i < scene->PolyNumber; i += 4) | ||||
{ | ||||
j = 10 * scene->PolyIndices_localPt[i]; | ||||
glBegin(GL_LINES); | ||||
glVertex3f(scene->ArrayNorVer_localPt[j + 7], | ||||
scene->ArrayNorVer_localPt[j + 8], | ||||
scene->ArrayNorVer_localPt[j + 9]); | ||||
glVertex3f(scene->ArrayNorVer_localPt[j + 7] + | ||||
40 * scene->ArrayNorVer_localPt[j + 4], | ||||
scene->ArrayNorVer_localPt[j + 8] + | ||||
40 * scene->ArrayNorVer_localPt[j + 5], | ||||
scene->ArrayNorVer_localPt[j + 9] + | ||||
40 * scene->ArrayNorVer_localPt[j + 6]); | ||||
glEnd(); | ||||
} | ||||
*/ | ||||
} | } | |||
void MathMod::Winitialize_GL() | void MathMod::Winitialize_GL() | |||
{ | { | |||
if (LocalScene.componentsinfos.updateviewer) | if (LocalScene.componentsinfos.updateviewer) | |||
{ | { | |||
PutObjectInsideCube(); | PutObjectInsideCube(); | |||
PutObjectInsideCubeOk=true; | PutObjectInsideCubeOk=true; | |||
} | } | |||
} | } | |||
skipping to change at line 1237 | skipping to change at line 1366 | |||
else | else | |||
LocalScene.updategl = true; | LocalScene.updategl = true; | |||
} | } | |||
void MathMod::DrawParisoCND(ObjectProperties *scene, uint compindex) | void MathMod::DrawParisoCND(ObjectProperties *scene, uint compindex) | |||
{ | { | |||
uint idx = 0; | uint idx = 0; | |||
for (uint i = 0; i < compindex; i++) | for (uint i = 0; i < compindex; i++) | |||
idx += scene->componentsinfos.NbComponentsType[i]; | idx += scene->componentsinfos.NbComponentsType[i]; | |||
int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx]; | int start_triangle = scene->componentsinfos.ParisoTriangle[2 * idx]; | |||
glUniform1i(uniformThereisRGBA, 0); | ||||
glUniform1i(uniformHSVactive, 0); | ||||
if (scene->cndoptions[3]) | if (scene->cndoptions[3]) | |||
{ | { | |||
size_t Offset0 = (3 * scene->componentsinfos.NbTrianglesNoCND[compindex] + start_triangle)*sizeof( GL_FLOAT); | size_t Offset0 = (3 * scene->componentsinfos.NbTrianglesNoCND[compindex] + start_triangle)*sizeof( GL_FLOAT); | |||
glLineWidth(0.3); | glLineWidth(0.3); | |||
for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesVerifyCND[co mpindex]); i += 3) | for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesVerifyCND[co mpindex]); i += 3) | |||
{ | { | |||
glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset0)); | glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset0)); | |||
Offset0+=(3*sizeof( GL_FLOAT)); | Offset0+=(3*sizeof( GL_FLOAT)); | |||
} | } | |||
} | } | |||
skipping to change at line 1272 | skipping to change at line 1403 | |||
{ | { | |||
size_t Offset2 = (3*scene->componentsinfos.NbTrianglesNoCND[compindex]+3 *(scene->componentsinfos.NbTrianglesVerifyCND[compindex] + | size_t Offset2 = (3*scene->componentsinfos.NbTrianglesNoCND[compindex]+3 *(scene->componentsinfos.NbTrianglesVerifyCND[compindex] + | |||
scene->componentsinfos.NbTrianglesNotVerifyCND[compind ex])+start_triangle)*sizeof( GL_FLOAT); | scene->componentsinfos.NbTrianglesNotVerifyCND[compind ex])+start_triangle)*sizeof( GL_FLOAT); | |||
glLineWidth(4.0); | glLineWidth(4.0); | |||
for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesBorderCND[co mpindex]); i += 3) | for (uint i = 0; i < (3 * scene->componentsinfos.NbTrianglesBorderCND[co mpindex]); i += 3) | |||
{ | { | |||
glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset2)); | glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset2)); | |||
Offset2+=(3*sizeof( GL_FLOAT)); | Offset2+=(3*sizeof( GL_FLOAT)); | |||
} | } | |||
} | } | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::DrawMeshIso(ObjectProperties *scene) | void MathMod::DrawTrianglMesh(ObjectProperties *scene) | |||
{ | { | |||
size_t Offset = 0; | size_t Offset = 0; | |||
uint st = 0; | uint st = 0; | |||
glUniform4fv(uniformGridColor, 1, scene->gridcol); | glUniform4fv(uniformGridColor, 1, scene->gridcol); | |||
glUniform1i(uniformdrawgridColor, 1); | glUniform1i(uniformdrawgridColor, 1); | |||
glUniform1i(uniformThereisRGBA, 0); | ||||
glUniform1i(uniformHSVactive, 0); | ||||
glLineWidth(0.3); | glLineWidth(0.3); | |||
for (uint i = 0; i < scene->PolyNumber; i += 3) | for (uint i = 0; i < scene->PolyNumber; i += 3) | |||
{ | { | |||
Offset = st*sizeof( GL_FLOAT); | Offset = st*sizeof( GL_FLOAT); | |||
glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset)); | glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, (void *)(Offset)); | |||
st+=3; | st+=3; | |||
} | } | |||
glUniform1i(uniformdrawgridColor, 0); | glUniform1i(uniformdrawgridColor, 0); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::DrawMinimalTopology(ObjectProperties *scene) | void MathMod::DrawMinimalTopology(ObjectProperties *scene) | |||
{ | { | |||
glUniform4fv(uniformGridColor, 1,scene->gridcol); | glUniform4fv(uniformGridColor, 1,scene->gridcol); | |||
glUniform1i(uniformdrawgridColor, 1); | glUniform1i(uniformdrawgridColor, 1); | |||
glUniform1i(uniformThereisRGBA, 0); | ||||
glUniform1i(uniformHSVactive, 0); | ||||
glLineWidth(0.4); | glLineWidth(0.4); | |||
uint st = scene->PolyNumber; | uint st = scene->PolyNumber; | |||
uint polysize=0; | uint polysize=0; | |||
size_t Offset; | size_t Offset; | |||
for (uint i = 0; i < scene->NbPolygnNbVertexPtMin; i++) | if(scene->typedrawing == -1) | |||
for (uint i = 0; i < (scene->NbPolygnNbVertexPtMin); i++) | ||||
{ | { | |||
polysize = scene->PolyIndices_localPtMin[i]; | polysize = scene->PolyIndices_localPtMin[i]; | |||
Offset = st*sizeof( GL_FLOAT); | Offset = st*sizeof( GL_FLOAT); | |||
glDrawElements( | glDrawElements( | |||
GL_LINE_LOOP, | GL_LINE_STRIP, | |||
polysize, | polysize, | |||
GL_UNSIGNED_INT, | GL_UNSIGNED_INT, | |||
(void *)(Offset)); | (void *)(Offset)); | |||
st+=(polysize); | st+=(polysize); | |||
} | } | |||
else | ||||
if(scene->typedrawing == 1) | ||||
for (uint i = 0; i < (scene->NbPolygnNbVertexPtMin); i++) | ||||
{ | ||||
polysize = scene->PolyIndices_localPtMin[i]; | ||||
Offset = st*sizeof( GL_FLOAT); | ||||
glDrawElements( | ||||
GL_LINE_LOOP, | ||||
polysize, | ||||
GL_UNSIGNED_INT, | ||||
(void *)(Offset)); | ||||
st+=(polysize); | ||||
} | ||||
else | ||||
{ | ||||
uint kl= scene->componentsinfos.NbParametricMeshLines; | ||||
for (uint i = 0; i < (scene->NbPolygnNbVertexPtMin); i++) | ||||
{ | ||||
polysize = scene->PolyIndices_localPtMin[i]; | ||||
Offset = st*sizeof( GL_FLOAT); | ||||
glDrawElements( | ||||
(i<kl)? GL_LINE_STRIP:GL_LINE_LOOP, | ||||
polysize, | ||||
GL_UNSIGNED_INT, | ||||
(void *)(Offset)); | ||||
st+=(polysize); | ||||
} | ||||
} | ||||
glUniform1i(uniformdrawgridColor, 0); | glUniform1i(uniformdrawgridColor, 0); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::plan() | void MathMod::plan() | |||
{ | { | |||
glUniform1i(uniformThereisRGBA, 0); | glUniform1i(uniformThereisRGBA, 0); | |||
glUniform1i(uniformHSVactive, 0); | ||||
glLineWidth(0.3); | glLineWidth(0.3); | |||
glDrawArrays(GL_LINES,PlanStartIndex,60); | glDrawArrays(GL_LINES,PlanStartIndex,60); | |||
glUniform1i(uniformThereisRGBA, 1); | ||||
} | } | |||
void MathMod::CopyData(ObjectProperties *scene) | void MathMod::CopyData(ObjectProperties *scene) | |||
{ | { | |||
static int firstaction=0; | static int firstaction=0; | |||
static uint previousVertxNumber=0; | static uint previousVertxNumber=0; | |||
static uint previousPolyNumberNbPolygnNbVertexPtMin=0; | static uint previousPolyNumberNbPolygnNbVertexPtMin=0; | |||
if(firstaction==0) | if(firstaction==0) | |||
{ | { | |||
vbo[0]=vbo[1]=0; | vbo[0]=vbo[1]=0; | |||
skipping to change at line 1411 | skipping to change at line 1580 | |||
if(LocalScene.AmbientValUpdated) | if(LocalScene.AmbientValUpdated) | |||
{ | { | |||
glUniform4fv(uniformLightAmbient, 1, lightAmbient); | glUniform4fv(uniformLightAmbient, 1, lightAmbient); | |||
LocalScene.AmbientValUpdated =false; | LocalScene.AmbientValUpdated =false; | |||
} | } | |||
if(LocalScene.DiffuseValUpdated) | if(LocalScene.DiffuseValUpdated) | |||
{ | { | |||
glUniform4fv(uniformLightDiffuse, 1, lightDiffuse); | glUniform4fv(uniformLightDiffuse, 1, lightDiffuse); | |||
LocalScene.DiffuseValUpdated =false; | LocalScene.DiffuseValUpdated =false; | |||
} | } | |||
if(LocalScene.FrontSurfValUpdated) | ||||
{ | ||||
glUniform1i(uniformglFrontFacing_1 , LocalScene.glFrontFacingSupport); | ||||
glUniform1i(uniformglFrontFacing_2 , LocalScene.glFrontFacingSupport); | ||||
LocalScene.FrontSurfValUpdated = false; | ||||
} | ||||
// We draw the Plan first because we don't want it to spin around X,Y and Z axes | // We draw the Plan first because we don't want it to spin around X,Y and Z axes | |||
if (scene->plan == 1) | if (scene->plan == 1) | |||
plan(); | plan(); | |||
if(LocalScene.animx==1) | if(LocalScene.animx==1) | |||
matrixViewx.rotate(rotationx); | matrixViewx.rotate(rotationx); | |||
if(LocalScene.animy==1) | if(LocalScene.animy==1) | |||
matrixViewx.rotate(rotationy); | matrixViewx.rotate(rotationy); | |||
if(LocalScene.animz==1) | if(LocalScene.animz==1) | |||
matrixViewx.rotate(rotationz); | matrixViewx.rotate(rotationz); | |||
if(LocalScene.animx==1 || LocalScene.animy==1 || LocalScene.animz==1) | if(LocalScene.animx==1 || LocalScene.animy==1 || LocalScene.animz==1) | |||
skipping to change at line 1443 | skipping to change at line 1618 | |||
// Axe : | // Axe : | |||
if (scene->axe == 1) | if (scene->axe == 1) | |||
DrawAxe(); | DrawAxe(); | |||
if (scene->fill == 1 && scene->componentsinfos.updateviewer) | if (scene->fill == 1 && scene->componentsinfos.updateviewer) | |||
for (uint i = 0; i < scene->componentsinfos.NbComponentsType.size(); i++ ) | for (uint i = 0; i < scene->componentsinfos.NbComponentsType.size(); i++ ) | |||
DrawPariso(scene, i); | DrawPariso(scene, i); | |||
// Draw Mesh Object: | // Draw Mesh Object: | |||
if (scene->triangles == 1 && scene->componentsinfos.updateviewer) | if (scene->triangles == 1 && scene->componentsinfos.updateviewer) | |||
DrawMeshIso(scene); | DrawTrianglMesh(scene); | |||
// Bounding Box: | // Bounding Box: | |||
if (scene->boundingbox == 1) | if (scene->boundingbox == 1) | |||
drawCube(); | drawCube(); | |||
// Draw Minimal topology for isosurfaces: | // Draw Minimal topology for isosurfaces: | |||
if (scene->mesh == 1 && scene->componentsinfos.updateviewer) | if (scene->mesh == 1 && scene->componentsinfos.updateviewer) | |||
DrawMinimalTopology(scene); | DrawMinimalTopology(scene); | |||
if (scene->activarecnd && scene->componentsinfos.updateviewer) | if (scene->activarecnd && scene->componentsinfos.updateviewer) | |||
skipping to change at line 1579 | skipping to change at line 1754 | |||
else | else | |||
btmilieu = 0; | btmilieu = 0; | |||
mouseY = e->y()/2; | mouseY = e->y()/2; | |||
} | } | |||
void MathMod::mouseMoveEvent(QMouseEvent *e) | void MathMod::mouseMoveEvent(QMouseEvent *e) | |||
{ | { | |||
static int oldx=0, oldy=0; | static int oldx=0, oldy=0; | |||
static QVector3D oldn=QVector3D(0,0,1); | static QVector3D oldn=QVector3D(0,0,1); | |||
static qreal oldacc; | ||||
if(mouseLeftDown) | if(mouseLeftDown) | |||
{ | { | |||
QVector2D diff = QVector2D(e->localPos()) - mousePressPosition; | QVector2D diff = QVector2D(e->localPos()) - mousePressPosition; | |||
// Rotation axis is perpendicular to the mouse position difference | // Rotation axis is perpendicular to the mouse position difference | |||
n = QVector3D(diff.y(), diff.x(), 0.0).normalized(); | n = QVector3D(diff.y(), diff.x(), 0.0).normalized(); | |||
// Accelerate angular speed relative to the length of the mouse sweep | // Accelerate angular speed relative to the length of the mouse sweep | |||
acc =std::sqrt((diff.y()-oldy)*(diff.y()-oldy)+ float(diff.x()-oldx)*(di ff.x()-oldx))/ /*(double)(LocalScene.viewport[2]+1)*/3.0; | acc =std::sqrt((diff.y()-oldy)*(diff.y()-oldy)+ float(diff.x()-oldx)*(di ff.x()-oldx))/ /*(double)(LocalScene.viewport[2]+1)*/3.0; | |||
// Calculate new rotation axis | // Calculate new rotation axis | |||
rotation = QQuaternion::fromAxisAndAngle(n, acc)*oldRotation; | rotation = QQuaternion::fromAxisAndAngle(n, acc)*oldRotation; | |||
oldacc= acc; | ||||
oldn = n; | oldn = n; | |||
} | } | |||
if(mouseRightDown) | if(mouseRightDown) | |||
{ | { | |||
cameraDistance -= (e->y()/2 - mouseY) * 0.02f; | cameraDistance -= (e->y()/2 - mouseY) * 0.02f; | |||
mouseY = e->y()/2; | mouseY = e->y()/2; | |||
} | } | |||
update(); | update(); | |||
} | } | |||
skipping to change at line 1753 | skipping to change at line 1926 | |||
{ | { | |||
glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | |||
glFrontFace(GL_CCW); | glFrontFace(GL_CCW); | |||
update(); | update(); | |||
} | } | |||
MathMod::MathMod(QWidget *parent, uint nbthreads, | MathMod::MathMod(QWidget *parent, uint nbthreads, | |||
uint initparGrid, uint initisoGrid, uint FactX, uint FactY, | uint initparGrid, uint initisoGrid, uint FactX, uint FactY, | |||
uint FactZ) :QOpenGLWidget(parent) | uint FactZ) :QOpenGLWidget(parent) | |||
{ | { | |||
//MathMod::context(); | ||||
//makeCurrent(); | ||||
PerlinNoise = new ImprovedNoise(4., 4., 4.); | PerlinNoise = new ImprovedNoise(4., 4., 4.); | |||
latence = 10; | latence = 10; | |||
Vgrid = Ugrid = 64; | Vgrid = Ugrid = 64; | |||
CutV = CutU = 0; | CutV = CutU = 0; | |||
Xgrid = Ygrid = Zgrid = 64; | Xgrid = Ygrid = Zgrid = 64; | |||
CutX = CutY = CutZ = 0; | CutX = CutY = CutZ = 0; | |||
LocalScene.VertxNumber = 0; | LocalScene.VertxNumber = 0; | |||
LabelInfos.setWindowFlags(Qt::WindowStaysOnTopHint| Qt::FramelessWindowHint) ; | LabelInfos.setWindowFlags(Qt::WindowStaysOnTopHint| Qt::FramelessWindowHint) ; | |||
LabelInfos.setAttribute(Qt::WA_TranslucentBackground); | LabelInfos.setAttribute(Qt::WA_TranslucentBackground); | |||
LabelInfos.setAttribute(Qt::WA_NoSystemBackground); | LabelInfos.setAttribute(Qt::WA_NoSystemBackground); | |||
skipping to change at line 1990 | skipping to change at line 2161 | |||
} | } | |||
void MathMod::ParametricSurfaceProcess(int type) | void MathMod::ParametricSurfaceProcess(int type) | |||
{ | { | |||
if (!ParObjet->isRunning()) | if (!ParObjet->isRunning()) | |||
{ | { | |||
if (type == 3) | if (type == 3) | |||
{ | { | |||
ParObjet->masterthread->param4D = 1; | ParObjet->masterthread->param4D = 1; | |||
ParObjet->param4D = 1; | ParObjet->param4D = 1; | |||
ParObjet->masterthread->param3d_C = false; | ||||
} | } | |||
else | else | |||
{ | { | |||
ParObjet->masterthread->param4D = -1; | ParObjet->masterthread->param4D = -1; | |||
ParObjet->param4D = -1; | ParObjet->param4D = -1; | |||
ParObjet->masterthread->param4d_C = false; | ||||
} | } | |||
int result = ParsePar(); | int result = ParsePar(); | |||
if (result == -1) | if (result == -1) | |||
return; | return; | |||
LocalScene.typedrawing = -1; | LocalScene.typedrawing = -1; | |||
ParObjet->localScene = &(LocalScene); | ParObjet->localScene = &(LocalScene); | |||
ParObjet->start(QThread::LowPriority); | ParObjet->start(QThread::LowPriority); | |||
} | } | |||
} | } | |||
void MathMod::ParisoObjectProcess() | void MathMod::ParisoObjectProcess() | |||
{ | { | |||
LocalScene.typedrawing = 0; | LocalScene.typedrawing = 0; | |||
LocalScene.updategl = false; | LocalScene.updategl = false; | |||
LocalScene.componentsinfos.pariso = true; | LocalScene.componentsinfos.pariso = true; | |||
if (!ParObjet->isRunning()) | if (!ParObjet->isRunning()) | |||
{ | { | |||
ParObjet->masterthread->param4D = | ParObjet->masterthread->param4D = | |||
ParObjet->param4D = -1; | ParObjet->param4D = -1; | |||
ParObjet->masterthread->param4d_C = | ||||
ParObjet->masterthread->param3d_C = false; | ||||
int result = ParsePar(); | int result = ParsePar(); | |||
if (result == -1) | if (result == -1) | |||
return; | return; | |||
ParObjet->localScene = &(LocalScene); | ParObjet->localScene = &(LocalScene); | |||
ParObjet->start(QThread::LowPriority); | ParObjet->start(QThread::LowPriority); | |||
ParObjet->wait(); | ParObjet->wait(); | |||
} | } | |||
if (!IsoObjet->isRunning()) | if (!IsoObjet->isRunning()) | |||
{ | { | |||
int result = ParseIso(); | int result = ParseIso(); | |||
End of changes. 75 change blocks. | ||||
95 lines changed or deleted | 274 lines changed or added |