Work on new OpenGL example.
This commit is contained in:
parent
e32d840c50
commit
a50bb8413e
@ -6,6 +6,7 @@ PROJECT(OpenGLExample)
|
||||
SET(SRC_FILES
|
||||
glew/glew.c
|
||||
main.cpp
|
||||
shapes.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
@ -13,6 +14,7 @@ SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
shapes.h
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
|
46
examples/OpenGL/Shapes.cpp
Normal file
46
examples/OpenGL/Shapes.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "Shapes.h"
|
||||
|
||||
using namespace PolyVox;
|
||||
|
||||
void createSphereInVolume(BlockVolume<uint8>& volData, float fRadius, uint8 uValue)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(volData.getSideLength() / 2, volData.getSideLength() / 2, volData.getSideLength() / 2);
|
||||
|
||||
//This three-level for loop iterates over every voxel in the volume
|
||||
for (int z = 0; z < volData.getSideLength(); z++)
|
||||
{
|
||||
for (int y = 0; y < volData.getSideLength(); y++)
|
||||
{
|
||||
for (int x = 0; x < volData.getSideLength(); x++)
|
||||
{
|
||||
//Store our current position as a vector...
|
||||
Vector3DFloat v3dCurrentPos(x,y,z);
|
||||
//And compute how far the current position is from the center of the volume
|
||||
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||
|
||||
//If the current voxel is less than 'radius' units from the center
|
||||
//then we make it solid, otherwise we make it empty space.
|
||||
if(fDistToCenter <= fRadius)
|
||||
{
|
||||
volData.setVoxelAt(x,y,z, uValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createCubeInVolume(BlockVolume<uint8>& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8 uValue)
|
||||
{
|
||||
//This three-level for loop iterates over every voxel between the specified corners
|
||||
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
|
||||
{
|
||||
for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++)
|
||||
{
|
||||
for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++)
|
||||
{
|
||||
volData.setVoxelAt(x,y,z, uValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
examples/OpenGL/Shapes.h
Normal file
9
examples/OpenGL/Shapes.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef __OpenGLExample_Shapes_H__
|
||||
#define __OpenGLExample_Shapes_H__
|
||||
|
||||
#include "PolyVoxCore/BlockVolume.h"
|
||||
|
||||
void createSphereInVolume(PolyVox::BlockVolume<PolyVox::uint8>& volData, float fRadius, PolyVox::uint8 uValue);
|
||||
void createCubeInVolume(PolyVox::BlockVolume<PolyVox::uint8>& volData, PolyVox::Vector3DUint16 lowerCorner, PolyVox::Vector3DUint16 upperCorner, PolyVox::uint8 uValue);
|
||||
|
||||
#endif //__OpenGLExample_Shapes_H__
|
@ -3,9 +3,11 @@
|
||||
#include "PolyVoxCore/SurfaceExtractors.h"
|
||||
#include "PolyVoxCore/Utility.h"
|
||||
|
||||
#include "Shapes.h"
|
||||
|
||||
#include <windows.h> // Standard Header For Most Programs
|
||||
|
||||
//#define USE_OPENGL_VERTEX_BUFFERS_OBJECTS
|
||||
#define USE_OPENGL_VERTEX_BUFFERS_OBJECTS
|
||||
|
||||
#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS
|
||||
#ifdef WIN32
|
||||
@ -154,48 +156,7 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(IndexedSurfacePatch& isp)
|
||||
}
|
||||
#endif
|
||||
|
||||
void createSphere(float fRadius, uint8 uValue)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(g_volData.getSideLength() / 2, g_volData.getSideLength() / 2, g_volData.getSideLength() / 2);
|
||||
|
||||
//This three-level for loop iterates over every voxel in the volume
|
||||
for (int z = 0; z < g_volData.getSideLength(); z++)
|
||||
{
|
||||
for (int y = 0; y < g_volData.getSideLength(); y++)
|
||||
{
|
||||
for (int x = 0; x < g_volData.getSideLength(); x++)
|
||||
{
|
||||
//Store our current position as a vector...
|
||||
Vector3DFloat v3dCurrentPos(x,y,z);
|
||||
//And compute how far the current position is from the center of the volume
|
||||
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||
|
||||
//If the current voxel is less than 'radius' units from the center
|
||||
//then we make it solid, otherwise we make it empty space.
|
||||
if(fDistToCenter <= fRadius)
|
||||
{
|
||||
g_volData.setVoxelAt(x,y,z, uValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createCube(Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8 uValue)
|
||||
{
|
||||
//This three-level for loop iterates over every voxel between the specified corners
|
||||
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
|
||||
{
|
||||
for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++)
|
||||
{
|
||||
for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++)
|
||||
{
|
||||
g_volData.setVoxelAt(x,y,z, uValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void timerFunc(int value)
|
||||
{
|
||||
@ -428,18 +389,18 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al
|
||||
uint16 minPos = 0;
|
||||
uint16 midPos = g_volData.getSideLength() / 2;
|
||||
uint16 maxPos = g_volData.getSideLength() - 1;
|
||||
createCube(Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(maxPos, maxPos, maxPos), 0);
|
||||
createCubeInVolume(g_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(maxPos, maxPos, maxPos), 0);
|
||||
|
||||
createSphere(50.0f, 5);
|
||||
createSphere(40.0f, 4);
|
||||
createSphere(30.0f, 3);
|
||||
createSphere(20.0f, 2);
|
||||
createSphere(10.0f, 1);
|
||||
createSphereInVolume(g_volData, 50.0f, 5);
|
||||
createSphereInVolume(g_volData, 40.0f, 4);
|
||||
createSphereInVolume(g_volData, 30.0f, 3);
|
||||
createSphereInVolume(g_volData, 20.0f, 2);
|
||||
createSphereInVolume(g_volData, 10.0f, 1);
|
||||
|
||||
createCube(Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0);
|
||||
createCube(Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0);
|
||||
createCube(Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0);
|
||||
createCube(Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0);
|
||||
createCubeInVolume(g_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0);
|
||||
createCubeInVolume(g_volData, Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0);
|
||||
createCubeInVolume(g_volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0);
|
||||
createCubeInVolume(g_volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0);
|
||||
|
||||
//Our volume is broken down into cuboid regions, and we create one mesh for each region.
|
||||
//This three-level for loop iterates over each region.
|
||||
@ -483,5 +444,4 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al
|
||||
init ();
|
||||
|
||||
glutMainLoop ( ); // Initialize The Main Loop
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user