menubutton option: screenshot, infobox, nothing

bondscaling (useful for gas phase, etc)
Only calculate bonds if needed
Render transparent markers
parent 9402e3a4
......@@ -77,6 +77,8 @@ float ** markercolours;
float animationspeed;
float movementspeed;
menubutton_t menubutton;
std::vector<information> info;
const char * loadConfigFileErrors[] =
......@@ -233,6 +235,10 @@ void initState()
infolinecolour[1] = 1.0f;
infolinecolour[2] = 0.0f;
infolinecolour[3] = 1.0f;
menubutton = Record;
bondscaling = 0.7f;
}
int loadConfigFile(const char * f)
......@@ -636,10 +642,25 @@ int loadConfigFile(const char * f)
r=fscanf (F, "%f %f %f", infolinecolour, infolinecolour+1, infolinecolour+2);
if (r<3)
eprintf ("Error reading atomtrajectorycolour value");
} else if (!strcmp (s, "animationspeed")) {
r=fscanf (F, "%f", &animationspeed);
}
else if (!strcmp(s, "animationspeed")) {
r = fscanf(F, "%f", &animationspeed);
if (r < 1)
eprintf("Error reading animationspeed");
}
else if (!strcmp(s, "")) {
r = fscanf(F, "%f", &bondscaling);
if (r<1)
eprintf ("Error reading animationspeed");
eprintf("Error reading bondscaling");
bondscaling = sqrt(bondscaling);
} else if (!strcmp(s, "menubutton")) {
r = fscanf(F, "%s", s);
if (!strcmp(s, "Record"))
menubutton = Record;
else if (!strcmp(s, "Infobox"))
menubutton = Infobox;
else if (!strcmp (s, "Nothing"))
menubutton = Nothing;
} else if (!strcmp (s, "movementspeed")) {
r=fscanf (F, "%f", &movementspeed);
if (r<1)
......
......@@ -89,6 +89,15 @@ struct information {
GLuint tex;
};
typedef enum {
Record,
Infobox,
Nothing
} menubutton_t;
extern menubutton_t menubutton;
extern std::vector<information> info;
#endif //__CONFIGFILE_H
......@@ -25,3 +25,5 @@ float cubetrans[3];
float supercell[3];
int voxelSize[3];
float bondscaling;
\ No newline at end of file
......@@ -29,4 +29,6 @@ extern int voxelSize[3];
extern float supercell[3];
extern float bondscaling;
#endif //CONFIGFILEATOMS_H
......@@ -280,69 +280,76 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLu
float *current=tmp;
const int atomlimit=30;
const float bondscaling=0.7f;
numBonds=new int[getAtomTimesteps() ];
for (int p=0;p<getAtomTimesteps() ;p++) {
for (int a = 0; a < numAtoms[p]; a++) {
for (int k = 0; k < 4; k++) {
*current++ = atoms[p][4 * a + k];
}
} //a
}
for (int a = 0; a < numAtoms[p]; a++) {
for (int k = 0; k < 4; k++) {
*current++ = atoms[p][4 * a + k];
}
} //a
if (numAtoms[0]<atomlimit) {
//eprintf ("searching bonds basic");
//bonds FIXME quadractic complexity
for (int a1=0; a1 < numAtoms[p]; a1++) {
for (int a2=a1+1; a2 < numAtoms[p]; a2++) {
float d=0, r;
for (int k=0;k<3;k++) {
float dif=atoms[p][4 * a1 + k]-atoms[p][4 * a2 + k];
d+=dif*dif;
}
r=atomRadius(static_cast<int>(atoms[p][4 * a1 + 3]))+
atomRadius(static_cast<int>(atoms[p][4 * a2 + 3]));
if (d*bondscaling<r*r) {// bond
bonds.push_back(a1+(p==0?0:numAtoms[p-1]));
bonds.push_back(a2+(p==0?0:numAtoms[p-1]));
if (!displaybonds) {
numBonds=nullptr;
for (int p=1; p<getAtomTimesteps() ;p++)
numAtoms[p]+=numAtoms[p-1];
} else {
numBonds=new int[getAtomTimesteps() ];
//can be slow, add loading screen here if Vive
for (int p=0;p<getAtomTimesteps() ;p++) {
if (numAtoms[p]<atomlimit) {
//eprintf ("searching bonds basic");
//bonds FIXME quadractic complexity
for (int a1=0; a1 < numAtoms[p]; a1++) {
for (int a2=a1+1; a2 < numAtoms[p]; a2++){
float d=0, r;
for (int k=0;k<3;k++) {
float dif=atoms[p][4 * a1 + k]-atoms[p][4 * a2 + k];
d+=dif*dif;
}
r=atomRadius(static_cast<int>(atoms[p][4 * a1 + 3]))+
atomRadius(static_cast<int>(atoms[p][4 * a2 + 3]));
if (d*bondscaling<r*r) {// bond
bonds.push_back(a1+(p==0?0:numAtoms[p-1]));
bonds.push_back(a2+(p==0?0:numAtoms[p-1]));
}
}
}
}
} else { //more than 30 atoms, try grid optimization
//eprintf ("searching bonds grid");
} else { //more than 30 atoms, try grid optimization
//eprintf ("searching bonds grid");
float m[3];
float M[3];
for (int k=0; k<3;k++) {
m[k]=M[k]=atoms[p][k];
}
for (int a = 1; a < numAtoms[p]; a++) {
float m[3];
float M[3];
for (int k=0; k<3;k++) {
if (m[k]>atoms[p][4*a+k])
m[k]=atoms[p][4*a+k];
if (M[k]<atoms[p][4*a+k])
M[k]=atoms[p][4*a+k];
m[k]=M[k]=atoms[p][k];
}
}
grid g(m, M, pow(numAtoms[p], 1.0f/3.0f), bondscaling);
for (int a = 1; a < numAtoms[p]; a++)
g.add(atoms[p]+4*a);
for (int a = 0; a < numAtoms[p]; a++) {
std::vector<float*> found=g.find(atoms[p]+4*a);
for (int b=0;b<found.size();b++) {
//if (found[b] < tmp+4*a) // already got this bound
// continue;
bonds.push_back(a+(p==0?0:numAtoms[p-1]));
bonds.push_back(((found[b]-atoms[p])/4)+(p==0?0:numAtoms[p-1]));
for (int a = 1; a < numAtoms[p]; a++) {
for (int k=0; k<3;k++) {
if (m[k]>atoms[p][4*a+k])
m[k]=atoms[p][4*a+k];
if (M[k]<atoms[p][4*a+k])
M[k]=atoms[p][4*a+k];
}
}
grid g(m, M, pow(numAtoms[p], 1.0f/3.0f), bondscaling);
for (int a = 1; a < numAtoms[p]; a++)
g.add(atoms[p]+4*a);
for (int a = 0; a < numAtoms[p]; a++) {
std::vector<float*> found=g.find(atoms[p]+4*a);
for (int b=0;b<found.size();b++) {
//if (found[b] < tmp+4*a) // already got this bound
// continue;
bonds.push_back(a+(p==0?0:numAtoms[p-1]));
bonds.push_back(((found[b]-atoms[p])/4)+(p==0?0:numAtoms[p-1]));
}
}
}
}
numBonds[p]=bonds.size();
if (p!=0)
numAtoms[p]+=numAtoms[p-1];
} //p
numBonds[p]=bonds.size();
if (p!=0)
numAtoms[p]+=numAtoms[p-1];
} //p
} // showbonds
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const void *)(0));
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const void *)(3 * sizeof(float)));
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * totalatoms * 4 , tmp,
......@@ -354,7 +361,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLu
if ((e = glGetError()) != GL_NO_ERROR)
eprintf( "opengl error %d, end of SetupAtoms, l %d\n", e, __LINE__);
if (showTrajectories) {
//fill the restart buffer
//use abc for measuring
......@@ -405,18 +412,19 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLu
}
delete[] tmp;
//bonds
glBindVertexArray((*AtomVAO)[2]);
glBindBuffer(GL_ARRAY_BUFFER, (*AtomVertBuffer)[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *BondIndices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*bonds.size(), bonds.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const void *)(0));
glEnableVertexAttribArray(0);
glBindVertexArray(0);
e=glGetError();
if ((e = glGetError()) != GL_NO_ERROR)
eprintf( "opengl error %d, creating chemical bonds, l %d\n", e, __LINE__);
if (displaybonds) {
glBindVertexArray((*AtomVAO)[2]);
glBindBuffer(GL_ARRAY_BUFFER, (*AtomVertBuffer)[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *BondIndices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*bonds.size(), bonds.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const void *)(0));
glEnableVertexAttribArray(0);
glBindVertexArray(0);
e=glGetError();
if ((e = glGetError()) != GL_NO_ERROR)
eprintf( "opengl error %d, creating chemical bonds, l %d\n", e, __LINE__);
}
//now clones
if (basisvectorreps ||!clonedAtoms) //do not replicate
return e;
......
......@@ -577,7 +577,7 @@ bool CMainApplication::BInit()
if( m_bDebugOpenGL )
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
m_pWindow = SDL_CreateWindow( "Geophysics OpenVR SDL", nWindowPosX, nWindowPosY, m_nWindowWidth, m_nWindowHeight, unWindowFlags );
m_pWindow = SDL_CreateWindow( "NOMAD OpenVR", nWindowPosX, nWindowPosY, m_nWindowWidth, m_nWindowHeight, unWindowFlags );
if (m_pWindow == NULL)
{
printf( "%s - Window could not be created! SDL Error: %s\n", __FUNCTION__, SDL_GetError() );
......@@ -2129,7 +2129,7 @@ void CMainApplication::RenderStereoTargets()
char name[100];
#ifndef NOSAVINGSCREENSHOTS
if (savetodisk) {
if (menubutton==Record && savetodisk) {
sprintf(name, "%sL%05d.bmp", SCREENSHOT, framecounter);
SaveScreenshot(name);
}
......@@ -2156,7 +2156,7 @@ void CMainApplication::RenderStereoTargets()
RenderScene( vr::Eye_Right );
#ifndef NOSAVINGSCREENSHOTS
if (savetodisk && saveStereo) {
if (menubutton == Record &&savetodisk && saveStereo) {
sprintf(name, "%sR%05d.bmp", SCREENSHOT, framecounter);
SaveScreenshot(name);
}
......@@ -2175,7 +2175,7 @@ void CMainApplication::RenderStereoTargets()
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0 );
#ifndef NOSAVINGSCREENSHOTS
if (savetodisk) {
if (menubutton == Record && savetodisk) {
framecounter++;
}
#endif
......@@ -2492,11 +2492,20 @@ void CMainApplication::RenderScene(vr::Hmd_Eye nEye)
glEnable(GL_DEPTH_TEST);
if (ISOS==0) {
RenderInfo(nEye);
//simple transparency model for markers
if (showAtoms) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
if (menubutton==Infobox && savetodisk)
RenderInfo(nEye);
RenderAtoms(nEye);
RenderUnitCell(nEye);
if (showcontrollers)
RenderAllTrackedRenderModels(nEye);
if (showAtoms) {
glDisable(GL_BLEND);
}
return;
}
......@@ -2529,7 +2538,8 @@ void CMainApplication::RenderScene(vr::Hmd_Eye nEye)
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after paintgrid: %d, %s\n", e, gluErrorString(e));
if (numAtoms!=0) {
RenderInfo(nEye);
if (menubutton == Infobox && savetodisk)
RenderInfo(nEye);
RenderAtoms(nEye);
RenderUnitCell(nEye);
}
......@@ -2629,7 +2639,8 @@ void CMainApplication::RenderScene(vr::Hmd_Eye nEye)
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(m_unSceneProgramID);
PaintGrid(nEye, currentiso);
RenderInfo(nEye);
if (menubutton == Infobox && savetodisk)
RenderInfo(nEye);
if (showcontrollers)
RenderAllTrackedRenderModels(nEye);
} //else currentiso =isos
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment