animationspeed, movementspeed, newatom options.

Check for bom mark
add sphere config option
parent 70d13df1
...@@ -1079,7 +1079,7 @@ glBindVertexArray(AtomTVAO[0]); ...@@ -1079,7 +1079,7 @@ glBindVertexArray(AtomTVAO[0]);
eprintf("1 Gl error RenderAtomTrajectoriesUnitCell: %d\n", e); eprintf("1 Gl error RenderAtomTrajectoriesUnitCell: %d\n", e);
//glUseProgram(UnitCellP); //glUseProgram(UnitCellP);
//glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, matrix); //glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, matrix);
glUniform4fv(UnitCellColourLoc, 1, atomtrajectorycoluor); glUniform4fv(UnitCellColourLoc, 1, atomtrajectorycolour);
if ((e = glGetError()) != GL_NO_ERROR) if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error after glUniform4fv 2 RenderAtomTrajectoriesUnitCell: %d\n", e); eprintf("Gl error after glUniform4fv 2 RenderAtomTrajectoriesUnitCell: %d\n", e);
//glEnableVertexAttribArray(0); //glEnableVertexAttribArray(0);
......
...@@ -57,12 +57,13 @@ bool gazenavigation; ...@@ -57,12 +57,13 @@ bool gazenavigation;
int transparencyquality; int transparencyquality;
float nearclip, farclip; float nearclip, farclip;
//markers such as hole positions and electron positions //markers such as hole positions and electron positions
float ** markers; float ** markers;
float ** markercolours; float ** markercolours;
float cubetrans[3]; float cubetrans[3];
float animationspeed;
float movementspeed;
const char * loadConfigFileErrors[] = const char * loadConfigFileErrors[] =
{ {
...@@ -86,6 +87,7 @@ const char * loadConfigFileErrors[] = ...@@ -86,6 +87,7 @@ const char * loadConfigFileErrors[] =
"markers with no previous correct timesteps parameter", //-17 "markers with no previous correct timesteps parameter", //-17
"markercolours with no previous correct timesteps parameter", //-18 "markercolours with no previous correct timesteps parameter", //-18
"Error reading atomcolour", // -19 "Error reading atomcolour", // -19
"Error reading newatom", //-20
"Error loading xyz file, add 100 to see the error",//<-100 "Error loading xyz file, add 100 to see the error",//<-100
"Error loading cube file, add 200 to see the error",//<-200 "Error loading cube file, add 200 to see the error",//<-200
"Error loading encyclopedia json file, add 300 to see the error",//<-300 "Error loading encyclopedia json file, add 300 to see the error",//<-300
...@@ -146,7 +148,7 @@ while (*file!='\0') { ...@@ -146,7 +148,7 @@ while (*file!='\0') {
void initState() void initState()
{ {
BACKGROUND[0] = 0.95f; BACKGROUND[0] = 0.95f;
BACKGROUND[1] = 0.95f; BACKGROUND[1] = 0.95f;
BACKGROUND[2] = 0.95f; BACKGROUND[2] = 0.95f;
SCREENSHOT="C:\\temp\\frame"; SCREENSHOT="C:\\temp\\frame";
...@@ -209,6 +211,9 @@ void initState() ...@@ -209,6 +211,9 @@ void initState()
atomtrajectorycolour[1]=0.0f; atomtrajectorycolour[1]=0.0f;
atomtrajectorycolour[2]=0.0f; atomtrajectorycolour[2]=0.0f;
atomtrajectorycolour[3]=1.0f; atomtrajectorycolour[3]=1.0f;
animationspeed=1.0f;
movementspeed=1.0f;
} }
int loadConfigFile(const char * f) int loadConfigFile(const char * f)
...@@ -221,7 +226,6 @@ int loadConfigFile(const char * f) ...@@ -221,7 +226,6 @@ int loadConfigFile(const char * f)
initState(); initState();
char *token=0; char *token=0;
//
FILE *F = fopen(f, "r"); FILE *F = fopen(f, "r");
if (F == 0) if (F == 0)
{ {
...@@ -235,6 +239,8 @@ int loadConfigFile(const char * f) ...@@ -235,6 +239,8 @@ int loadConfigFile(const char * f)
r=fscanf(F, "%99s", s); r=fscanf(F, "%99s", s);
if (r <= 0) if (r <= 0)
continue; continue;
if ((unsigned char)s[0]==0xef && (unsigned char)s[1]==0xbb && (unsigned char)s[2]==0xbf) //utf bom
strcpy (s, s+3);
if (s[0] == '#') {//comment if (s[0] == '#') {//comment
discardline(F); discardline(F);
continue; continue;
...@@ -452,6 +458,11 @@ int loadConfigFile(const char * f) ...@@ -452,6 +458,11 @@ int loadConfigFile(const char * f)
solid=new Solid(Solid::Type::Octahedron); solid=new Solid(Solid::Type::Octahedron);
else if(!strcmp(s, "tetrahedron")) else if(!strcmp(s, "tetrahedron"))
solid=new Solid(Solid::Type::Tetrahedron); solid=new Solid(Solid::Type::Tetrahedron);
else if(!strcmp(s, "sphere")) {
int subd;
r=fscanf (F, "%d", &subd);
solid=new Solid(Solid::Type::Sphere, subd);
}
else else
return -15; return -15;
} else if (!strcmp (s, "token")) { } else if (!strcmp (s, "token")) {
...@@ -481,9 +492,11 @@ int loadConfigFile(const char * f) ...@@ -481,9 +492,11 @@ int loadConfigFile(const char * f)
//for (int s=0;s<3;s++) //for (int s=0;s<3;s++)
// tmp[s]-=translations[0][s]; //using translation of iso 0 // tmp[s]-=translations[0][s]; //using translation of iso 0
//check if coordinates are outside of cell //check if coordinates are outside of cell
for (int s=0;s<3;s++) { if (translations) {
while (tmp[s]<-translations[0][s]) for (int s=0;s<3;s++) {
tmp[s]+=supercell[2-s]; while (tmp[s]<-translations[0][s])
tmp[s]+=supercell[2-s];
}
} }
for (int s=0;s<3;s++) { for (int s=0;s<3;s++) {
markers[i][s]=tmp[2]*abc[0][s]+tmp[1]*abc[1][s]+tmp[0]*abc[2][s]; //hole positions seem to be in zyx markers[i][s]=tmp[2]*abc[0][s]+tmp[1]*abc[1][s]+tmp[0]*abc[2][s]; //hole positions seem to be in zyx
...@@ -524,6 +537,34 @@ int loadConfigFile(const char * f) ...@@ -524,6 +537,34 @@ int loadConfigFile(const char * f)
} }
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
atomColours[a][i]=rgb[i]; atomColours[a][i]=rgb[i];
} else if (!strcmp (s, "newatom")) {
char atom [100];
float rgb[3];
float size;
r = fscanf(F, "%s %f %f %f %f", atom, rgb, rgb + 1, rgb + 2, &size);
if (r!=5) {
eprintf ("Error loading newatom");
return -20;
}
int a=findAtom(atom);
if (a!=-1) {
if (a<atomsInPeriodicTable) {
for (int i=0;i<3;i++)
atomColours[a][i]=rgb[i];
atomColours[a][3]=size;
} else {
for (int i=0;i<3;i++)
extraAtomData[a-atomsInPeriodicTable][i]=rgb[i];
extraAtomData[a-atomsInPeriodicTable][3]=size;
}
} else { //new
extraAtomNames.push_back(strdup(atom));
extraAtomData.push_back(new float[4]);
float *e=extraAtomData.back();
for (int i=0;i<3;i++)
e[i]=rgb[i];
e[3]=size;
}
} else if (!strcmp (s, "markerscaling")) { } else if (!strcmp (s, "markerscaling")) {
r = fscanf(F, "%f", &markerscaling); r = fscanf(F, "%f", &markerscaling);
} else if (!strcmp (s, "displayunitcell")) { } else if (!strcmp (s, "displayunitcell")) {
...@@ -544,8 +585,6 @@ int loadConfigFile(const char * f) ...@@ -544,8 +585,6 @@ int loadConfigFile(const char * f)
showcontrollers=true; showcontrollers=true;
} else if (!strcmp (s, "gazenavigation")) { } else if (!strcmp (s, "gazenavigation")) {
gazenavigation=true; gazenavigation=true;
}else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!)
continue;
} else if (!strcmp (s, "transparencyquality")) { } else if (!strcmp (s, "transparencyquality")) {
r=fscanf (F, "%d", &transparencyquality); r=fscanf (F, "%d", &transparencyquality);
if (r<1) if (r<1)
...@@ -570,7 +609,17 @@ int loadConfigFile(const char * f) ...@@ -570,7 +609,17 @@ int loadConfigFile(const char * f)
r=fscanf (F, "%f %f %f", atomtrajectorycolour, atomtrajectorycolour+1, atomtrajectorycolour+2); r=fscanf (F, "%f %f %f", atomtrajectorycolour, atomtrajectorycolour+1, atomtrajectorycolour+2);
if (r<3) if (r<3)
eprintf ("Error reading atomtrajectorycolour value"); eprintf ("Error reading atomtrajectorycolour value");
}else { } else if (!strcmp (s, "animationspeed")) {
r=fscanf (F, "%f", &animationspeed);
if (r<1)
eprintf ("Error reading animationspeed");
} else if (!strcmp (s, "movementspeed")) {
r=fscanf (F, "%f", &movementspeed);
if (r<1)
eprintf ("Error reading movementspeed");
} else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!)
continue;
} else {
eprintf( "Unrecognized parameter %s\n", s); eprintf( "Unrecognized parameter %s\n", s);
for (int i=0;i<strlen(s);i++) for (int i=0;i<strlen(s);i++)
eprintf ("<%d>", s[i]); eprintf ("<%d>", s[i]);
......
...@@ -54,6 +54,9 @@ extern bool gazenavigation; ...@@ -54,6 +54,9 @@ extern bool gazenavigation;
extern int transparencyquality; extern int transparencyquality;
extern float nearclip, farclip; extern float nearclip, farclip;
extern float animationspeed; //how fast to change to next timestep
extern float movementspeed; //how fast to move the user
//markers such as hole positions and electron positions //markers such as hole positions and electron positions
extern float ** markers; extern float ** markers;
extern float ** markercolours; extern float ** markercolours;
......
...@@ -16,6 +16,7 @@ const char * const AtomShaders [] = { ...@@ -16,6 +16,7 @@ const char * const AtomShaders [] = {
"#version 300 es\n" "#version 300 es\n"
#endif #endif
"uniform sampler2D atomData;\n" "uniform sampler2D atomData;\n"
"uniform float totalatoms=118.0;\n" //(float)atomsInPeriodicTable
"layout(location = 0) in vec3 center;\n" "layout(location = 0) in vec3 center;\n"
"layout(location = 1) in float atomIn;\n" "layout(location = 1) in float atomIn;\n"
"out vec4 vcolor;\n" //color , radius "out vec4 vcolor;\n" //color , radius
...@@ -23,7 +24,7 @@ const char * const AtomShaders [] = { ...@@ -23,7 +24,7 @@ const char * const AtomShaders [] = {
"void main()\n" "void main()\n"
"{\n" "{\n"
//"gl_Position = matrix * vec4(position+center, 1);\n" //"gl_Position = matrix * vec4(position+center, 1);\n"
"float coord=atomIn/118.0+0.5/118.0;\n" "float coord=atomIn/totalatoms+0.5/totalatoms;\n"
"vcolor=vec4(texture(atomData, vec2(coord, 0)));\n" "vcolor=vec4(texture(atomData, vec2(coord, 0)));\n"
"vcen=center;\n" "vcen=center;\n"
//"color.a=1;\n" //"color.a=1;\n"
...@@ -96,6 +97,7 @@ const char * const AtomShadersNoTess [] = { ...@@ -96,6 +97,7 @@ const char * const AtomShadersNoTess [] = {
#endif #endif
"uniform sampler2D atomData;\n" "uniform sampler2D atomData;\n"
"uniform mat4 matrix;\n" "uniform mat4 matrix;\n"
"uniform float totalatoms=118.0;\n" //(float)atomsInPeriodicTable
"layout(location = 0) in vec3 pos;\n" "layout(location = 0) in vec3 pos;\n"
"layout(location = 1) in vec3 normalIn;\n" "layout(location = 1) in vec3 normalIn;\n"
"layout(location = 2) in float atomIn;\n" "layout(location = 2) in float atomIn;\n"
...@@ -106,7 +108,7 @@ const char * const AtomShadersNoTess [] = { ...@@ -106,7 +108,7 @@ const char * const AtomShadersNoTess [] = {
"{\n" "{\n"
"gl_Position = matrix * vec4(pos, 1);\n" "gl_Position = matrix * vec4(pos, 1);\n"
"normal=normalIn;\n" "normal=normalIn;\n"
"float coord=atomIn/118.0+0.5/118.0;\n" "float coord=atomIn/totalatoms+0.5/totalatoms;\n"
"color=vec4(texture(atomData, vec2(coord, 0)));\n" "color=vec4(texture(atomData, vec2(coord, 0)));\n"
"color.a=1.0;\n" "color.a=1.0;\n"
"vertex=pos;\n" "vertex=pos;\n"
......
...@@ -28,7 +28,8 @@ const char * TMPDIR;//filled by main ...@@ -28,7 +28,8 @@ const char * TMPDIR;//filled by main
bool inv_abc_init=false; bool inv_abc_init=false;
float inv_abc[3][3]; float inv_abc[3][3];
std::vector<const char*> extraAtomNames;
std::vector<float*> extraAtomData;
const char * const atomNames[] = const char * const atomNames[] =
...@@ -176,7 +177,10 @@ float atomColours[][4] = ...@@ -176,7 +177,10 @@ float atomColours[][4] =
float atomRadius (int i) float atomRadius (int i)
{ {
return atomColours[i][3]; if (i<atomsInPeriodicTable)
return atomColours[i][3];
else
return extraAtomData[i-atomsInPeriodicTable][3];
} }
void discardline (FILE *F) void discardline (FILE *F)
...@@ -190,7 +194,19 @@ do { ...@@ -190,7 +194,19 @@ do {
int findAtom(const char *const s) int findAtom(const char *const s)
{ {
//discard number at end //discard number at end
//rgh: I have C1A, so better to go from the end to avoid this being confused with C
char x[10]; char x[10];
strcpy (x, s);
char *p=x+strlen(x);
p--;
while (*p > '0' && *p <= '9') {
*p='\0';
*p--;
if (p==x)
break;
}
/*
char *p=x; char *p=x;
const char *q=s; const char *q=s;
while (*q!=0) { while (*q!=0) {
...@@ -199,10 +215,15 @@ int findAtom(const char *const s) ...@@ -199,10 +215,15 @@ int findAtom(const char *const s)
*p++=*q++; *p++=*q++;
} }
*p=0; *p=0;
*/
//rgh FIXME, add caching //rgh FIXME, add caching
for (unsigned int i=0;i<sizeof(atomNames)/sizeof(const char *);i++) for (unsigned int i=0;i<sizeof(atomNames)/sizeof(const char *);i++)
if (!strcmp(x, atomNames[i])) if (!strcmp(x, atomNames[i]))
return i; return i;
//now check extra atoms, starting at atomsInPeriodicTable
for (unsigned int i=0;i<extraAtomNames.size();i++)
if (!strcmp(x, extraAtomNames[i]))
return i+atomsInPeriodicTable;
return -1; return -1;
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
extern float atomColours[][4]; extern float atomColours[][4];
const int atomsInPeriodicTable=118;
extern const char * TMPDIR; extern const char * TMPDIR;
int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float ***pos); int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float ***pos);
...@@ -44,4 +46,7 @@ void TransformAtoms(std::vector<float>* clonedAtoms, const float abc[3][3]); ...@@ -44,4 +46,7 @@ void TransformAtoms(std::vector<float>* clonedAtoms, const float abc[3][3]);
extern bool inv_abc_init; extern bool inv_abc_init;
extern float inv_abc[3][3]; extern float inv_abc[3][3];
extern std::vector<const char*> extraAtomNames;
extern std::vector<float*> extraAtomData;
#endif //__ATOMS_H #endif //__ATOMS_H
...@@ -22,21 +22,28 @@ int getAtomTimesteps() ...@@ -22,21 +22,28 @@ int getAtomTimesteps()
GLenum atomTexture(GLuint t) GLenum atomTexture(GLuint t)
{ {
GLenum e; GLenum e;
int finalatoms=getTotalAtomsInTexture();
//rgh: scale atoms here //rgh: scale atoms here
//in google cardboard, this is called again if the program is running, so leave original or atoms get progresivelly smaller! //in google cardboard, this is called again if the program is running, so leave original or atoms get progresivelly smaller!
float *a=new float[118*4]; float *a=new float[finalatoms*4];
for (int i = 0; i < 118; i++) { for (int i = 0; i < atomsInPeriodicTable; i++) {
a[i*4+0]=atomColours[i][0]; a[i*4+0]=atomColours[i][0];
a[i*4+1]=atomColours[i][1]; a[i*4+1]=atomColours[i][1];
a[i*4+2]=atomColours[i][2]; a[i*4+2]=atomColours[i][2];
a[i*4+3]=atomColours[i][3] * atomScaling; a[i*4+3]=atomColours[i][3] * atomScaling;
} }
for (int i=0;i<extraAtomNames.size();i++) {
a[(i+atomsInPeriodicTable)*4+0]=extraAtomData[i][0];
a[(i+atomsInPeriodicTable)*4+1]=extraAtomData[i][1];
a[(i+atomsInPeriodicTable)*4+2]=extraAtomData[i][2];
a[(i+atomsInPeriodicTable)*4+3]=extraAtomData[i][3]*atomScaling;
}
glBindTexture(GL_TEXTURE_2D, t); //atom texture glBindTexture(GL_TEXTURE_2D, t); //atom texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 118, 1, 0, GL_RGBA, GL_FLOAT, a); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a);
glBindTexture( GL_TEXTURE_2D, 0 ); glBindTexture( GL_TEXTURE_2D, 0 );
if ((e = glGetError()) != GL_NO_ERROR) { if ((e = glGetError()) != GL_NO_ERROR) {
...@@ -301,7 +308,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLu ...@@ -301,7 +308,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[4]*/, GLuint **AtomVertBuffer /*[3]*/, GLu
M[k]=atoms[p][4*a+k]; M[k]=atoms[p][4*a+k];
} }
} }
grid g(m, M, pow(numAtoms[p], 1.0/3), bondscaling); grid g(m, M, pow(numAtoms[p], 1.0f/3.0f), bondscaling);
for (int a = 1; a < numAtoms[p]; a++) for (int a = 1; a < numAtoms[p]; a++)
g.add(atoms[p]+4*a); g.add(atoms[p]+4*a);
for (int a = 0; a < numAtoms[p]; a++) { for (int a = 0; a < numAtoms[p]; a++) {
...@@ -546,8 +553,8 @@ GLenum SetupUnitCell(GLuint *UnitCellVAO, GLuint *UnitCellVertBuffer, GLuint *Un ...@@ -546,8 +553,8 @@ GLenum SetupUnitCell(GLuint *UnitCellVAO, GLuint *UnitCellVertBuffer, GLuint *Un
bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP, bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP,
GLint *AtomMatrixLocation, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation, GLint *AtomMatrixLocation, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation,
GLint *MarkerMatrixLocation){ GLint *MarkerMatrixLocation, GLint *totalatomsLocation){
if (!PrepareAtomShader(AtomP, AtomMatrixLocation)) if (!PrepareAtomShader(AtomP, AtomMatrixLocation, totalatomsLocation))
return false; return false;
if (!PrepareUnitCellShader(cellP, UnitCellMatrixLocation, UnitCellColourLocation)) if (!PrepareUnitCellShader(cellP, UnitCellMatrixLocation, UnitCellColourLocation))
...@@ -559,7 +566,7 @@ bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP, ...@@ -559,7 +566,7 @@ bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP,
return true; return true;
} }
bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation){ bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation, GLint *totalatomsLocation){
//https://www.gamedev.net/topic/591110-geometry-shader-point-sprites-to-spheres/ //https://www.gamedev.net/topic/591110-geometry-shader-point-sprites-to-spheres/
//no rotation, only translations means we can do directional lighting in the shader. //no rotation, only translations means we can do directional lighting in the shader.
//FIXME //FIXME
...@@ -576,6 +583,13 @@ bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation){ ...@@ -576,6 +583,13 @@ bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation){
eprintf( "Unable to find matrix uniform in atom shader\n" ); eprintf( "Unable to find matrix uniform in atom shader\n" );
return false; return false;
} }
*totalatomsLocation=glGetUniformLocation(*AtomP, "totalatoms");
if( *totalatomsLocation == -1 )
{
eprintf( "Unable to find matrix uniform in atom shader\n" );
return false;
}
return true; return true;
} }
...@@ -599,7 +613,7 @@ bool PrepareMarkerShader (GLuint *MP, GLint *MMatrixLocation){ ...@@ -599,7 +613,7 @@ bool PrepareMarkerShader (GLuint *MP, GLint *MMatrixLocation){
return true; return true;
} }
bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation){ bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation, GLint *totalatomsLocation){
//https://www.gamedev.net/topic/591110-geometry-shader-point-sprites-to-spheres/ //https://www.gamedev.net/topic/591110-geometry-shader-point-sprites-to-spheres/
//no rotation, only translations means we can do directional lighting in the shader. //no rotation, only translations means we can do directional lighting in the shader.
//FIXME //FIXME
...@@ -616,6 +630,12 @@ bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation){ ...@@ -616,6 +630,12 @@ bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation){
eprintf( "Unable to find matrix uniform in atom shader no tess\n" ); eprintf( "Unable to find matrix uniform in atom shader no tess\n" );
return false; return false;
} }
*totalatomsLocation=glGetUniformLocation(*AtomP, "totalatoms");
if( *totalatomsLocation == -1 )
{
eprintf( "Unable to find matrix uniform in atom shader\n" );
return false;
}
return true; return true;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define __ATOMSGL_H #define __ATOMSGL_H
#include "MyGL.h" #include "MyGL.h"
#include "atoms.hpp"
GLenum atomTexture(GLuint t); GLenum atomTexture(GLuint t);
GLenum SetupAtoms(GLuint **AtomVAO, GLuint **AtomVertBuffer, GLuint *BondIndices); GLenum SetupAtoms(GLuint **AtomVAO, GLuint **AtomVertBuffer, GLuint *BondIndices);
...@@ -11,14 +12,18 @@ GLenum SetupMarker(GLuint *MarkerVAO, GLuint *MarkerVertBuffer); ...@@ -11,14 +12,18 @@ GLenum SetupMarker(GLuint *MarkerVAO, GLuint *MarkerVertBuffer);
bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP, bool PrepareUnitCellAtomShader (GLuint *AtomP, GLuint *cellP, GLuint *MarkerP,
GLint *AtomMatrixLocation, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation, GLint *AtomMatrixLocation, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation,
GLint *MarkerMatrixLocation); GLint *MarkerMatrixLocation, GLint *totalatomsLocation);
bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation); bool PrepareAtomShader (GLuint *AtomP, GLint *AtomMatrixLocation, GLint *totalatomsLocation);
bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation); bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation, GLint *totalatomsLocation);
bool PrepareUnitCellShader (GLuint *cellP, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation); bool PrepareUnitCellShader (GLuint *cellP, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation);
bool PrepareMarkerShader (GLuint *MP, GLint *MMatrixLocation); bool PrepareMarkerShader (GLuint *MP, GLint *MMatrixLocation);
void GetDisplacement(int p[3], float f[3]); void GetDisplacement(int p[3], float f[3]);
int getAtomTimesteps(); int getAtomTimesteps();
inline int getTotalAtomsInTexture()
{
return atomsInPeriodicTable+extraAtomNames.size();
}
#endif //__ATOMSGL_H #endif //__ATOMSGL_H
...@@ -63,8 +63,8 @@ public: ...@@ -63,8 +63,8 @@ public:
for (int i=0;i<SphereFacets;i++) for (int i=0;i<SphereFacets;i++)
for (int j=0;j<SphereFacets;j++) { for (int j=0;j<SphereFacets;j++) {
float t, f; float t, f;
t=i*2*M_PI/(float)(SphereFacets-1); t=i*2.0f*(float)M_PI/(float)(SphereFacets-1);
f=j*M_PI/(float)(SphereFacets-1); f=j*(float)M_PI/(float)(SphereFacets-1);
tVerts[i*SphereFacets*3 + j*3]=sin(f)*sin(t); tVerts[i*SphereFacets*3 + j*3]=sin(f)*sin(t);
tVerts[i*SphereFacets*3 + j*3+1]=sin(f)*cos(t); tVerts[i*SphereFacets*3 + j*3+1]=sin(f)*cos(t);
......
...@@ -287,6 +287,7 @@ private: // OpenGL bookkeeping ...@@ -287,6 +287,7 @@ private: // OpenGL bookkeeping
GLint m_nAtomMVLocation; GLint m_nAtomMVLocation;
GLint m_nUnitCellMatrixLocation, m_nUnitCellColourLocation; GLint m_nUnitCellMatrixLocation, m_nUnitCellColourLocation;
GLint m_nMarkerMatrixLocation; GLint m_nMarkerMatrixLocation;
GLint m_nTotalatomsLocation;
struct FramebufferDesc struct FramebufferDesc
{ {
...@@ -869,7 +870,7 @@ bool CMainApplication::HandleInput() ...@@ -869,7 +870,7 @@ bool CMainApplication::HandleInput()
SDL_Event sdlEvent; SDL_Event sdlEvent;
bool bRet = false; bool bRet = false;
float speed = 0.02f; float speed = 0.02f*movementspeed;
while (SDL_PollEvent(&sdlEvent) != 0) while (SDL_PollEvent(&sdlEvent) != 0)
{ {
...@@ -1002,8 +1003,8 @@ bool CMainApplication::HandleInput() ...@@ -1002,8 +1003,8 @@ bool CMainApplication::HandleInput()
} }
} }
else { else {
float newtime = videospeed*float(SDL_GetTicks());; float newtime = videospeed*float(SDL_GetTicks());
if (newtime-elapsedtime > 1) { if (newtime-elapsedtime > 1.0f/animationspeed) {
elapsedtime = newtime; elapsedtime = newtime;
currentset++; currentset++;
if (currentset >= TIMESTEPS) if (currentset >= TIMESTEPS)
...@@ -1300,7 +1301,7 @@ bool CMainApplication::CreateAllShaders() ...@@ -1300,7 +1301,7 @@ bool CMainApplication::CreateAllShaders()
} }
if (!PrepareUnitCellAtomShader (&m_unAtomsProgramID, &m_unUnitCellProgramID, &m_unMarkerProgramID, if (!PrepareUnitCellAtomShader (&m_unAtomsProgramID, &m_unUnitCellProgramID, &m_unMarkerProgramID,
&m_nAtomMatrixLocation, &m_nUnitCellMatrixLocation, &m_nUnitCellColourLocation, &m_nMarkerMatrixLocation)) &m_nAtomMatrixLocation, &m_nUnitCellMatrixLocation, &m_nUnitCellColourLocation, &m_nMarkerMatrixLocation, &m_nTotalatomsLocation))
return false; return false;
...@@ -2196,6 +2197,7 @@ float delta[3]; ...@@ -2196,6 +2197,7 @@ float delta[3];
::GetDisplacement(p, delta); ::GetDisplacement(p, delta);
Vector3 iPos(delta[0], delta[1], delta[2]); Vector3 iPos(delta[0], delta[1], delta[2]);
glUseProgram(m_unAtomsProgramID); glUseProgram(m_unAtomsProgramID);
glUniform1f(m_nTotalatomsLocation, (float)getTotalAtomsInTexture());
float levelso[4] = { TESSSUB, TESSSUB, TESSSUB, TESSSUB }; float levelso[4] = { TESSSUB, TESSSUB, TESSSUB, TESSSUB };
float levelsi[2] = { TESSSUB, TESSSUB}; float levelsi[2] = { TESSSUB, TESSSUB};
......
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