Reorganising some code...

This commit is contained in:
David Williams 2008-06-08 17:51:36 +00:00
parent f6f5cb524d
commit f75805999d
5 changed files with 60 additions and 23 deletions

View File

@ -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)
INSTALL(FILES ${INC_FILES} DESTINATION include/PolyVox)
ADD_SUBDIRECTORY(examples/OpenGL)

View File

@ -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)

View File

@ -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 <windows.h> // Standard Header For Most Programs
#include <gl/gl.h> // The GL Header File
#include <gl/glut.h> // 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<uint8_t> g_volData(logBase2(g_uVolumeSideLength)); //Creates a volume 128x128x128
void createSphereInVolume(void)
{
//Create an iterator to access data in the volume
BlockVolumeIterator<uint8_t> 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<Vector3DInt16>(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();

View File

@ -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);

View File

@ -162,6 +162,12 @@ namespace PolyVox
#pragma endregion
#pragma region Setters
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setPosition(const Vector3DInt16& v3dNewPos)
{
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos)
{