Commit d2ee02e6 authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
Browse files

Latest changes regarding separation of nomad vr lib

parent 99c5d0b0
......@@ -82,6 +82,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\..\bin\win64</OutDir>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -108,14 +109,14 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;../thirdparty/sdl2-2.0.3/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;../thirdparty/sdl2-2.0.3/include;Y:\v2t\software\rapidjson\include;Y:\v2t\software\curl\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>openvr_api.lib;glew32.lib;SDL2.lib;SDL2main.lib;glu32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\thirdparty\glew\glew-1.11.0\lib\Release\x64;..\thirdparty\sdl2-2.0.3\bin\win64;..\..\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>openvr_api.lib;glew32.lib;SDL2.lib;SDL2main.lib;glu32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\thirdparty\glew\glew-1.11.0\lib\Release\x64;..\thirdparty\sdl2-2.0.3\bin\win64;..\..\lib\win64;Y:\v2t\software\curl\lib\.libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LargeAddressAware>true</LargeAddressAware>
</Link>
</ItemDefinitionGroup>
......@@ -149,16 +150,17 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;..\thirdparty\sdl2-2.0.3\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;..\thirdparty\sdl2-2.0.3\include;Y:\v2t\software\rapidjson\include</AdditionalIncludeDirectories>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>openvr_api.lib;glew32.lib;SDL2.lib;SDL2main.lib;glu32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>openvr_api.lib;glew32.lib;SDL2.lib;SDL2main.lib;glu32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\thirdparty\glew\glew-1.11.0\lib\Release\x64;H:\Temp\SDL2-2.0.3-vs2013-64\Release;..\..\lib\win64;..\thirdparty\sdl2-2.0.3\bin\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LargeAddressAware>true</LargeAddressAware>
</Link>
......@@ -167,23 +169,16 @@
<ClCompile Include="..\shared\lodepng.cpp" />
<ClCompile Include="..\shared\Matrices.cpp" />
<ClCompile Include="..\shared\pathtools.cpp" />
<ClCompile Include="atoms.cpp" />
<ClCompile Include="hellovr_opengl_main.cpp" />
<ClCompile Include="hsv.c" />
<ClCompile Include="polyhedron.cpp" />
<ClCompile Include="rply.c" />
<ClCompile Include="TessShaders.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\shared\lodepng.h" />
<ClInclude Include="..\shared\Matrices.h" />
<ClInclude Include="..\shared\pathtools.h" />
<ClInclude Include="..\shared\Vectors.h" />
<ClInclude Include="atoms.hpp" />
<ClInclude Include="hsv.h" />
<ClInclude Include="NOMADViveT.h" />
<ClInclude Include="polyhedron.h" />
<ClInclude Include="TessShaders.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="NOMADViveT.rc" />
......
......@@ -33,7 +33,7 @@
<ClCompile Include="..\shared\pathtools.cpp">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="rply.c">
<ClCompile Include="hsv.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
......@@ -50,6 +50,12 @@
<ClInclude Include="..\shared\pathtools.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="hsv.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NOMADViveT.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="NOMADViveT.rc">
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>C:\Users\mobile\Desktop\openvrDemos\win64\CO2-CaO-Rel.txt</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\temp\39409.ncfg</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>Y:\v2t\software\openvr\NOMAD-bin\CO2-CaO.txt</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>Y:\v2t\software\openvr\NOMAD-bin\shell.txt</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -27,13 +27,16 @@
#include "shared/Matrices.h"
#include "shared/pathtools.h"
#include "rply.h"
//#include "hsv.h"
#include "atoms.hpp"
#include "polyhedron.h"
#include "rply/rply.h"
#include "TessShaders.h"
#include "UnitCellShaders.h"
#include "NOMADVRLib/ConfigFile.h"
#include "NOMADVRLib/atoms.hpp"
#include "NOMADVRLib/atomsGL.h"
#include "NOMADVRLib/TessShaders.h"
#include "NOMADVRLib/UnitCellShaders.h"
#include "NOMADVRLib/CompileGLShader.h"
static int vertex_cb(p_ply_argument argument);
static int face_cb(p_ply_argument argument);
......@@ -44,36 +47,8 @@ static int CurrentVertex;
static int CurrentIndex;
//#define SOLID Tetrahedron //not nicely uniform distribution
#define SOLID Icosahedron
//#define SOLID Icosahedron
#define TESSSUB 16
//#define SOLID Octahedron
static float BACKGROUND[3];
static const char * PATH;
static const char * SCREENSHOT;
static int ISOS;
static int TIMESTEPS;
static float **isocolours; // [ISOS][4];
const char **plyfiles;
static float **translations;
static float userpos[3];
static int* numAtoms; //[timesteps]
static float **atoms; //[timesteps][numAtoms[i]*4] //xyzu, u=atom number
static float atomScaling;
static std::vector<float> *clonedAtoms;
static int numClonedAtoms;
static int *basisvectorreps;
static bool showTrajectories;
static std::vector<int> atomtrajectories;
static std::vector<std::vector<int>> atomtrajectoryrestarts;
static float abc[3][3]; //basis vectors
static bool has_abc = false;
int repetitions[3];
//TTF_Font* font;
......@@ -177,7 +152,7 @@ public:
void RenderAtomsUnitCell(const vr::Hmd_Eye &nEye, int p[3]);
void RenderUnitCell(const vr::Hmd_Eye &nEye);
Vector3 GetDisplacement(int p[3]);
//Vector3 GetDisplacement(int p[3]);
Matrix4 GetHMDMatrixProjectionEye(vr::Hmd_Eye nEye);
Matrix4 GetHMDMatrixPoseEye(vr::Hmd_Eye nEye);
......@@ -187,8 +162,6 @@ public:
Matrix4 ConvertSteamVRMatrixToMatrix4(const vr::HmdMatrix34_t &matPose);
GLuint CompileGLShader(const char *pchShaderName, const char *pchVertexShader, const char *pchFragmentShader,
const char *pchTessEvalShader=nullptr);
bool CreateAllShaders();
void SetupRenderModelForTrackedDevice(vr::TrackedDeviceIndex_t unTrackedDeviceIndex);
......@@ -366,6 +339,23 @@ void dprintf( const char *fmt, ... )
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buffer, 0);
}
//pure windows, no sdl
void eprintf( const char *fmt, ... )
{
va_list args;
char buffer[ 2048 ];
va_start( args, fmt );
vsprintf_s( buffer, fmt, args );
va_end( args );
if ( g_bPrintf )
printf( "%s", buffer );
MessageBoxA(0, buffer, "Warning", 0);
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
......@@ -1108,97 +1098,7 @@ void CMainApplication::RenderFrame()
}
//-----------------------------------------------------------------------------
// Purpose: Compiles a GL shader program and returns the handle. Returns 0 if
// the shader couldn't be compiled for some reason.
//-----------------------------------------------------------------------------
GLuint CMainApplication::CompileGLShader( const char *pchShaderName, const char *pchVertexShader, const char *pchFragmentShader,
const char *pchTessEvalShader /*= nullptr*/)
{
GLuint unProgramID = glCreateProgram();
GLuint nSceneVertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource( nSceneVertexShader, 1, &pchVertexShader, NULL);
glCompileShader( nSceneVertexShader );
GLint vShaderCompiled = GL_FALSE;
glGetShaderiv( nSceneVertexShader, GL_COMPILE_STATUS, &vShaderCompiled);
if ( vShaderCompiled != GL_TRUE)
{
dprintf("%s - Unable to compile vertex shader %d!\n", pchShaderName, nSceneVertexShader);
GLchar mess[3000];
GLsizei le;
glGetShaderInfoLog(nSceneVertexShader, 3000, &le, mess);
dprintf("error messages: %s", mess);
glDeleteProgram( unProgramID );
glDeleteShader( nSceneVertexShader );
return 0;
}
glAttachShader( unProgramID, nSceneVertexShader);
glDeleteShader( nSceneVertexShader ); // the program hangs onto this once it's attached
GLuint nSceneFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource( nSceneFragmentShader, 1, &pchFragmentShader, NULL);
glCompileShader( nSceneFragmentShader );
GLint fShaderCompiled = GL_FALSE;
glGetShaderiv( nSceneFragmentShader, GL_COMPILE_STATUS, &fShaderCompiled);
if (fShaderCompiled != GL_TRUE)
{
dprintf("%s - Unable to compile fragment shader %d!\n", pchShaderName, nSceneFragmentShader );
GLchar mess[3000];
GLsizei le;
glGetShaderInfoLog(nSceneFragmentShader, 3000, &le, mess);
dprintf("error messages: %s", mess);
glDeleteProgram( unProgramID );
glDeleteShader( nSceneFragmentShader );
return 0;
}
glAttachShader( unProgramID, nSceneFragmentShader );
glDeleteShader( nSceneFragmentShader ); // the program hangs onto this once it's attached
//tess
if (pchTessEvalShader) {
GLuint nSceneTessShader = glCreateShader(GL_TESS_EVALUATION_SHADER);
glShaderSource(nSceneTessShader, 1, &pchTessEvalShader, NULL);
glCompileShader(nSceneTessShader);
GLint tShaderCompiled = GL_FALSE;
glGetShaderiv(nSceneTessShader, GL_COMPILE_STATUS, &tShaderCompiled);
if (tShaderCompiled != GL_TRUE)
{
dprintf("%s - Unable to compile tess eval shader %d!\n", pchShaderName, nSceneTessShader);
GLchar mess[3000];
GLsizei le;
glGetShaderInfoLog(nSceneTessShader, 3000, &le, mess);
dprintf("error messages: %s", mess);
glDeleteProgram(unProgramID);
glDeleteShader(nSceneTessShader);
return 0;
}
glAttachShader(unProgramID, nSceneTessShader);
glDeleteShader(nSceneTessShader); // the program hangs onto this once it's attached
}
glLinkProgram( unProgramID );
GLint programSuccess = GL_TRUE;
glGetProgramiv( unProgramID, GL_LINK_STATUS, &programSuccess);
if ( programSuccess != GL_TRUE )
{
dprintf("%s - Error linking program %d!\n", pchShaderName, unProgramID);
glDeleteProgram( unProgramID );
return 0;
}
glUseProgram( unProgramID );
glUseProgram( 0 );
return unProgramID;
}
//-----------------------------------------------------------------------------
......@@ -1333,47 +1233,12 @@ bool CMainApplication::CreateAllShaders()
dprintf( "Unable to find matrix uniform in render model shader\n" );
return false;
}
//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.
//FIXME
//http://stackoverflow.com/questions/40101023/flat-shading-in-webgl
m_unAtomsProgramID = CompileGLShader(
AtomShaders[SHADERNAME],
AtomShaders[SHADERVERTEX],
AtomShaders[SHADERFRAGMENT],
AtomShaders[SHADERTESSEVAL]
);
m_nAtomMatrixLocation=glGetUniformLocation(m_unAtomsProgramID, "matrix");
if( m_nAtomMatrixLocation == -1 )
{
dprintf( "Unable to find matrix uniform in atom shader\n" );
return false;
}
m_unUnitCellProgramID= CompileGLShader(
UnitCellShaders[SHADERNAME],
UnitCellShaders[SHADERVERTEX],
UnitCellShaders[SHADERFRAGMENT],
UnitCellShaders[SHADERTESSEVAL]
);
m_nUnitCellMatrixLocation=glGetUniformLocation(m_unUnitCellProgramID, "matrix");
if( m_nUnitCellMatrixLocation == -1 )
{
dprintf( "Unable to find matrix uniform in UnitCell shader\n" );
return false;
}
m_nUnitCellColourLocation=glGetUniformLocation(m_unUnitCellProgramID, "color");
if( m_nUnitCellColourLocation == -1 )
{
dprintf( "Unable to find color uniform in UnitCell shader\n" );
return false;
}
// m_nAtomMVLocation=glGetUniformLocation(m_unAtomsProgramID, "mv");
/*if( m_nAtomMVLocation == -1 )
{
dprintf( "Unable to find mv uniform in atom shader\n" );
if (!PrepareUnitCellAtomShader (&m_unAtomsProgramID, &m_unUnitCellProgramID, &m_nAtomMatrixLocation,
&m_nUnitCellMatrixLocation, &m_nUnitCellColourLocation))
return false;
}*/
m_unLensProgramID = CompileGLShader(
"Distortion",
......@@ -1455,16 +1320,7 @@ bool CMainApplication::SetupTexturemaps()
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, SetupTextureMaps 1\n", e);
//rgh: scale atoms here
for (int i = 0; i < 118; i++)
atomColours[i][3] *= atomScaling;
glBindTexture(GL_TEXTURE_2D, m_iTexture[3+ZLAYERS]); //atom texture
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_WRAP_S, 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, atomColours);
e=atomTexture( m_iTexture[3+ZLAYERS]);
glBindTexture( GL_TEXTURE_2D, 0 );
......@@ -1551,6 +1407,8 @@ void CMainApplication::SetupScene()
{
SetupIsosurfaces();
SetupAtoms();
delete[] clonedAtoms;
clonedAtoms=0;
SetupUnitCell();
}
......@@ -1559,161 +1417,24 @@ void CMainApplication::SetupScene()
//-----------------------------------------------------------------------------
void CMainApplication::SetupUnitCell()
{
if (!has_abc)
return;
int e;
glGenVertexArrays(1, &m_unUnitCellVAO);
glGenBuffers(1, &m_glUnitCellVertBuffer);
glGenBuffers(1, &m_glUnitCellIndexBuffer);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, glGenBuffers, l %d\n", e, __LINE__);
glBindVertexArray(m_unUnitCellVAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_glUnitCellIndexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_glUnitCellVertBuffer);
glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
float *tmp = new float[3*8];
//0, a, b, c, a+b+c, b+c, a+c, a+b
for (int i=0;i<3;i++) {
tmp[0+i]=0;
for (int j=0;j<3;j++)
tmp[3*(j+1)+i]=abc[j][i];
tmp[3*4+i]=abc[0][i]+abc[1][i]+abc[2][i];
tmp[3*5+i]= abc[1][i]+abc[2][i];
tmp[3*6+i]=abc[0][i]+ abc[2][i];
tmp[3*7+i]=abc[0][i]+abc[1][i];
}
int tmpi[12*2]={ //lines
0,1,
1,6,
6,3,
3,0,
2,7,
7,4,
4,5,
5,2,
0,2,
1,7,
6,4,
3,5
};
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3*8 , tmp,
GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (const void *)(0));
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(tmpi), tmpi, GL_STATIC_DRAW);
GLenum e;
e=::SetupUnitCell(&m_unUnitCellVAO, &m_glUnitCellVertBuffer, &m_glUnitCellIndexBuffer);
if (e!=GL_NO_ERROR)
dprintf("opengl error %d, SetupUnitCell, l %d\n", e, __LINE__);
}
void CMainApplication::SetupAtoms()
{
if (!numAtoms)
return;
//rgh FIXME: put this all in the same vao
//http://prideout.net/blog/?p=48 //public domain code
//xyz u=atom type ; 4 floats
int e;
int totalatoms=0;
for (int i=0;i<TIMESTEPS;i++) {
totalatoms += numAtoms[i];
}
m_unAtomVAO = new GLuint[2]; //atoms, cloned atoms
m_glAtomVertBuffer = new GLuint[2];
glGenVertexArrays(2, m_unAtomVAO);
glGenBuffers(2, m_glAtomVertBuffer);
glBindVertexArray(m_unAtomVAO[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_glAtomVertBuffer[0]);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
float *tmp = new float[4 * totalatoms];
float *current=tmp;
for (int p=0;p<TIMESTEPS;p++) {
for (int a = 0; a < numAtoms[p]; a++) {
for (int k = 0; k < 4; k++) {
*current++ = atoms[p][4 * a + k];
}
} //a
if (p!=0)
numAtoms[p]+=numAtoms[p-1];
}
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,
GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__);
if (glGetError() != GL_NO_ERROR)
dprintf("opengl error attrib pointer 0\n");
glBindVertexArray(0);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, end of SetupAtoms, l %d\n", e, __LINE__);
if (showTrajectories) {
//fill the restart buffer
//use abc for measuring
float max=0;
if (has_abc) {
for (int i=0;i<3;i++)
for (int j=0;j<3;j++)
max+=abc[i][j];
max /=9*2;
}
for (int t=0;t<atomtrajectories.size();t++) {
atomtrajectoryrestarts.push_back(std::vector<int>());
atomtrajectoryrestarts[t].push_back(0);
for (int p=1;p<TIMESTEPS;p++) {
int a=atomtrajectories[t];
if (fabs(atoms[p][a*4+0]-atoms[p-1][a*4+0])+
fabs(atoms[p][a*4+1]-atoms[p-1][a*4+1])+
fabs(atoms[p][a*4+2]-atoms[p-1][a*4+2])>max)
atomtrajectoryrestarts[t].push_back(p);
}
atomtrajectoryrestarts[t].push_back(TIMESTEPS);
}
}
delete[] tmp;
//now clones
if (basisvectorreps ||!clonedAtoms) //do not replicate
return;
glBindVertexArray(m_unAtomVAO[1]); //rgh FIXME, only works for TIMESTEPS=1
glBindBuffer(GL_ARRAY_BUFFER, m_glAtomVertBuffer[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * clonedAtoms[0].size(), clonedAtoms[0].data(),
GL_STATIC_DRAW);
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)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("opengl error %d, end of Setup cloned Atoms, l %d\n", e, __LINE__);
delete[] clonedAtoms;
clonedAtoms=0;
GLenum e;
e=::SetupAtoms(&m_unAtomVAO, &m_glAtomVertBuffer);
// GLuint *vao, *buffer, *index;
// e=::SetupAtomsNoTess(&vao, &buffer, &index);
if (e!=GL_NO_ERROR)
dprintf("opengl error %d, SetupAtoms, l %d\n", e, __LINE__);
}
//-----------------------------------------------------------------------------
// Purpose: Load the isosurfaces into OpenGL
//-----------------------------------------------------------------------------
......@@ -2494,30 +2215,32 @@ void CMainApplication::RenderUnitCell(const vr::Hmd_Eye &nEye)
dprintf("Gl error after glBindVertexArray RenderUnitCell: %d, %s\n", e, gluErrorString(e));
Matrix4 trans;
int p[3];
int p[3];
for (p[0]=0;p[0]<repetitions[0];(p[0])++)
for (p[1]=0;p[1]<repetitions[1];(p[1])++)
for (p[2]=0;p[2]<repetitions[2];(p[2])++)
{
Vector3 iPos = GetDisplacement(p);
trans.identity();
{
float delta[3];
::GetDisplacement(p, delta);
Vector3 iPos(delta[0], delta[1], delta[2]);
trans.identity();
trans.translate(iPos).rotateX(-90).translate(UserPosition);
Matrix4 transform = GetCurrentViewProjectionMatrix(nEye)*trans;
glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, transform.get());
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after glUniform4fv 1 RenderUnitCell: %d, %s\n", e, gluErrorString(e));
float color[4]={1,1,1,1};
glUniform4fv(m_nUnitCellColourLocation, 1, color);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after glUniform4fv 2 RenderUnitCell: %d, %s\n", e, gluErrorString(e));
glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0);
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after RenderUnitCell: %d, %s\n", e, gluErrorString(e));
}
trans.translate(iPos).rotateX(-90).translate(UserPosition);
Matrix4 transform = GetCurrentViewProjectionMatrix(nEye)*trans;
glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, transform.get());
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after glUniform4fv 1 RenderUnitCell: %d, %s\n", e, gluErrorString(e));
float color[4]={1,1,1,1};
glUniform4fv(m_nUnitCellColourLocation, 1, color);
if ((e = glGetError()) != GL_NO_ERROR)