Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------------------------------------------
- Filename: VoxTestApplication.cpp
- -----------------------------------------------------------------------------
- This source file is generated by the
- ___ _ __ __ _ _
- /___\__ _ _ __ ___ /_\ _ __ _ __/ / /\ \ (_)______ _ _ __ __| |
- // // _` | '__/ _ \ //_\\| '_ \| '_ \ \/ \/ / |_ / _` | '__/ _` |
- / \_// (_| | | | __/ / _ \ |_) | |_) \ /\ /| |/ / (_| | | | (_| |
- \___/ \__, |_| \___| \_/ \_/ .__/| .__/ \/ \/ |_/___\__,_|_| \__,_|
- |___/ |_| |_|
- Ogre 1.8.x Application Wizard for Code::Blocks (May 2012)
- https://bitbucket.org/jacmoe/ogreappwizards
- -----------------------------------------------------------------------------
- */
- #include "VoxTestApplication.h"
- //-------------------------------------------------------------------------------------
- VoxTestApplication::VoxTestApplication(void)
- {
- }
- //-------------------------------------------------------------------------------------
- VoxTestApplication::~VoxTestApplication(void)
- {
- }
- void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius)
- {
- //This vector hold the position of the center of the volume
- Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
- //This three-level for loop iterates over every voxel in the volume
- for (int z = 0; z < volData.getDepth(); z++)
- {
- for (int y = 0; y < volData.getHeight(); y++)
- {
- for (int x = 0; x < volData.getWidth(); 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();
- uint8_t uVoxelValue = 0;
- //If the current voxel is less than 'radius' units from the center then we make it solid.
- if(fDistToCenter <= fRadius)
- {
- //Our new voxel value
- uVoxelValue = 255;
- }
- //Wrte the voxel value into the volume
- volData.setVoxelAt(x, y, z, uVoxelValue);
- }
- }
- }
- }
- //-------------------------------------------------------------------------------------
- void VoxTestApplication::createScene(void)
- {
- SimpleVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
- createSphereInVolume(volData, 30);
- SurfaceMesh<PositionMaterialNormal> mesh;
- //MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
- CubicSurfaceExtractorWithNormals< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
- surfaceExtractor.execute();
- cerr << mesh.getNoOfIndices() << ' ' << mesh.getNoOfVertices() << endl;
- // Set the scene's ambient light
- mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
- //Create a ManualObject
- Ogre::ManualObject* manual = mSceneMgr->createManualObject("manual");
- //Begin a section of the ManualObject (we're only using one section)
- manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
- //Iterate through all the vertices in the mesh produced by the surface extractor
- //and add them to the ManualObject section.
- for(vector<PositionMaterialNormal>::const_iterator it = mesh.getVertices().begin(); it != mesh.getVertices().end(); ++it)
- {
- const Vector3DFloat& vertexPos = it->getPosition();
- const Vector3DFloat& vertexNorm = it->getNormal();
- manual->position(vertexPos.getX(),vertexPos.getY(),vertexPos.getZ());
- manual->normal(vertexNorm.getX(),vertexNorm.getY(),vertexNorm.getZ());
- manual->colour(abs(vertexNorm.getX()),abs(vertexNorm.getY()),abs(vertexNorm.getZ()));
- }
- //Now we iterate through all the indices from the mesh and also add them to the ManualObject section
- for(vector<uint32_t>::const_iterator it = mesh.getIndices().begin(); it != mesh.getIndices().end(); ++it)
- {
- manual->index(*it);
- }
- //End the section then add the ManualObject to the scenegraph
- manual->end();
- mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
- // Create a Light and set its position
- Ogre::Light* light = mSceneMgr->createLight("MainLight");
- light->setPosition(20.0f, 80.0f, 50.0f);
- }
- #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
- #define WIN32_LEAN_AND_MEAN
- #include "windows.h"
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
- INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
- #else
- int main(int argc, char *argv[])
- #endif
- {
- // Create application object
- VoxTestApplication app;
- try {
- app.go();
- } catch( Ogre::Exception& e ) {
- #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
- MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
- #else
- std::cerr << "An exception has occured: " <<
- e.getFullDescription().c_str() << std::endl;
- #endif
- }
- return 0;
- }
- #ifdef __cplusplus
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment