diff --git a/CMakeLists.txt b/CMakeLists.txt index 75059ded..827b81d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET(POLYVOX_VERSION_MINOR "1") SET(POLYVOX_VERSION_PATCH "0") SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}") -ADD_SUBDIRECTORY(examples/OpenGL) +#ADD_SUBDIRECTORY(examples/OpenGL) #Projects source files SET(SRC_FILES @@ -86,4 +86,6 @@ INSTALL(TARGETS PolyVox ARCHIVE DESTINATION lib ) -INSTALL(FILES ${INC_FILES} DESTINATION include/PolyVox) \ No newline at end of file +INSTALL(FILES ${INC_FILES} DESTINATION include/PolyVox) + +ADD_SUBDIRECTORY(examples/OpenGL) \ No newline at end of file diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index 3eee064c..1cd244d4 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -16,6 +16,7 @@ SET(CMAKE_DEBUG_POSTFIX "_d") SOURCE_GROUP("Sources" FILES ${SRC_FILES}) #SOURCE_GROUP("Headers" FILES ${INC_FILES}) +FIND_PACKAGE(Boost REQUIRED) FIND_PACKAGE(OpenGL REQUIRED) IF (WIN32) @@ -24,10 +25,12 @@ IF (WIN32) #This means glut.h and glut32.lib go in the 'include' and 'lib' folders within Microsoft Visual Studio 8\VC\PlatformSDK\ #Also, glut32.dll goes in C:\Windows\System. Using C:\Windows\System32 doesn't seem to work - #Tell CMake the paths - INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR}) + #Tell CMake the paths for OpenGL and for PolyVox ()which is just relative to our current location + INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} "../../include") + #No idea why we have to look three levels up for build and only two for include. They should be the same level?! + LINK_DIRECTORIES("../../../build") #Build ADD_EXECUTABLE(OpenGLExample ${SRC_FILES}) - TARGET_LINK_LIBRARIES(OpenGLExample glut32.lib ${OPENGL_gl_LIBRARY}) + TARGET_LINK_LIBRARIES(OpenGLExample glut32.lib ${OPENGL_gl_LIBRARY} debug PolyVox_d.lib optimized PolyVox.lib) ENDIF (WIN32) \ No newline at end of file diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 86016318..9255f4c0 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -1,15 +1,46 @@ -/* -When creating your project, uncheck OWL, -uncheck Class Library, select Static -instead of Dynamic and change the target -model to Console from GUI. -Also link glut.lib to your project once its done. -*/ +#include "BlockVolume.h" +#include "BlockVolumeIterator.h" +#include "Utility.h" #include // Standard Header For Most Programs #include // The GL Header File #include // The GL Utility Toolkit (Glut) Header +//Some namespaces we need +using namespace boost; +using namespace PolyVox; +using namespace std; + +//Global variables are easier for demonstration purposes, especially +//as I'm not sure if I can pass variables to the GLUT functions. +const uint16_t g_uVolumeSideLength = 128; +BlockVolume g_volData(logBase2(g_uVolumeSideLength)); //Creates a volume 128x128x128 + +void createSphereInVolume(void) +{ + //Create an iterator to access data in the volume + BlockVolumeIterator volIter(g_volData); + + //A region corresponding to the whole volume + const Region& regWholeVolume = g_volData.getEnclosingRegion(); + + //This iterator will iterate over the whole volume + volIter.setValidRegion(regWholeVolume); + + //Start at the begining + volIter.setPosition(static_cast(regWholeVolume.getLowerCorner())); + do + { + //Get our current position + const uint16_t uX = volIter.getPosX(); + const uint16_t uY = volIter.getPosY(); + const uint16_t uZ = volIter.getPosZ(); + + //The centre of the volume + const uint16_t uVolCenterX = g_uVolumeSideLength / 2; + }while (volIter.isValidForRegion()); //In our case this covers the whole volume +} + void init ( GLvoid ) // Create Some Everyday Functions { @@ -26,18 +57,12 @@ void display ( void ) // Create The Display Function { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix - glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 - glBegin(GL_TRIANGLES); // Drawing Using Triangles - glVertex3f( 0.0f, 1.0f, 0.0f); // Top - glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left - glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right - glEnd(); // Finished Drawing The Triangle - glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units + glTranslatef(0.0f,0.0f,-200.0f); // Move Right 3 Units glBegin(GL_QUADS); // Draw A Quad - glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left - glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right - glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right - glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left + glVertex3f(0.0f, 0.0f, 0.0f); // Top Left + glVertex3f( 128.0f, 0.0f, 0.0f); // Top Right + glVertex3f( 128.0f, 128.0f, 0.0f); // Bottom Right + glVertex3f(0.0f, 128.0f, 0.0f); // Bottom Left glEnd(); diff --git a/include/BlockVolumeIterator.h b/include/BlockVolumeIterator.h index d82e938e..6c3af7df 100644 --- a/include/BlockVolumeIterator.h +++ b/include/BlockVolumeIterator.h @@ -49,6 +49,7 @@ namespace PolyVox boost::uint16_t getPosZ(void) const; VoxelType getVoxel(void) const; + void setPosition(const Vector3DInt16& v3dNewPos); void setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos); void setValidRegion(const Region& region); void setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast); diff --git a/include/BlockVolumeIterator.inl b/include/BlockVolumeIterator.inl index b1fc729b..cabdaa5a 100644 --- a/include/BlockVolumeIterator.inl +++ b/include/BlockVolumeIterator.inl @@ -162,6 +162,12 @@ namespace PolyVox #pragma endregion #pragma region Setters + template + void BlockVolumeIterator::setPosition(const Vector3DInt16& v3dNewPos) + { + setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ()); + } + template void BlockVolumeIterator::setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos) {