How to pick blocks in minecraft?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: How to pick blocks in minecraft?

Post by Radikalizm »

804 wrote:Is there an Example of Blocky terrains? I don't Know where to start...
Why don't you just take the advice given to you in the beginning of this thread?

If you're already at a roadblock when you haven't even started out yet, how are you going to deal with the more massive problems you'll encounter while doing a project like this?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: How to pick blocks in minecraft?

Post by serengeor »

804 wrote:Is there an Example of Blocky terrains? I don't Know where to start...
The best way to start is searching and gathering information on that subject you're interested in. Open polyvox site look trough samples, try to understand how it works, figure out a way you could connect it to irrlicht.
Working on game: Marrbles (Currently stopped).
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: How to pick blocks in minecraft?

Post by Cube_ »

but first (I repeat myself)
Make something simpler....
you can always revisit this project after ^^

And look at the documentation before asking, because I managed to (as far as I got to reading the dox (this includes the examples) it shouldn't be to much of a problem.
"this is not the bottleneck you are looking for"
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: How to pick blocks in minecraft?

Post by Virror »

As everyone said over and over again, read the docs, try to make the simple tutorial they have. Search the PolyVox forum for Irrlicht integration, there are good examples there.
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

OK, here I am...
I spend some time in read some tutorials and look into the examples and produced some lines of code:

Code: Select all

#include <PolyVoxCore\MaterialDensityPair.h>
#include <PolyVoxCore\CubicSurfaceExtractorWithNormals.h>
//#include <PolyVoxCore\irrsurfaceextractor.h>
#include <PolyVoxCore\SurfaceMesh.h>
#include <PolyVoxCore\simpleVolume.h>
#include <irrlicht.h>
 
using namespace PolyVox;
using namespace irr;
 
irr::scene::IMeshBuffer* ConvertMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh)
{
    const std::vector<uint32_t>& indices = mesh.getIndices();
    const std::vector<PolyVox::PositionMaterialNormal>& vertices = mesh.getVertices();
 
    irr::scene::IDynamicMeshBuffer *mb = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_32BIT);
    mb->getVertexBuffer().set_used(vertices.size());
    for (size_t i = 0; i < vertices.size(); ++i)
    {
        const PolyVox::Vector3DFloat& position = vertices[i].getPosition();
        const PolyVox::Vector3DFloat& normal = vertices[i].getNormal();
        mb->getVertexBuffer()[i].Pos.X = position.getX();
        mb->getVertexBuffer()[i].Pos.Y = position.getY();
        mb->getVertexBuffer()[i].Pos.Z = position.getZ();
        mb->getVertexBuffer()[i].Normal.X = normal.getX();
        mb->getVertexBuffer()[i].Normal.Y = normal.getY();
        mb->getVertexBuffer()[i].Normal.Z = normal.getZ();
        mb->getVertexBuffer()[i].Color = irr::video::SColor(255,0,200,200);
    }
    mb->getIndexBuffer().set_used(indices.size());
    for (size_t i = 0; i < indices.size(); ++i)
    {
        mb->getIndexBuffer().setValue(i, indices[i]);
    }
    mb->recalculateBoundingBox();
    return mb;
}
void createSphereInVolume(PolyVox::SimpleVolume<MaterialDensityPair44>& 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.getWidth(); z++)
        {
                for (int y = 0; y < volData.getHeight(); y++)
                {
                        for (int x = 0; x < volData.getDepth(); 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.
                                if(fDistToCenter <= fRadius)
                                {
                                        //Our new density value
                                        uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
 
                                        //Get the old voxel
                                        MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
 
                                        //Modify the density
                                        voxel.setDensity(uDensity);
 
                                        //Wrte the voxel value into the volume  
                                        volData.setVoxelAt(x, y, z, voxel);
                                }
                        }
                }
        }
}
 
int main()
{
        IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 768), 16);
    if (device == 0)
        return 1; // could not create selected driver.
    gui::IGUIEnvironment* gui = device->getGUIEnvironment();
    video::IVideoDriver* driver = device->getVideoDriver();
        irr::scene::ISceneManager* smgr = device->getSceneManager();
 
        //Create an empty volume and then place a sphere in it
        PolyVox::SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
        createSphereInVolume(volData, 30);
 
        //Extract the surface
        SurfaceMesh<PositionMaterialNormal> mesh;
        CubicSurfaceExtractorWithNormals<SimpleVolume, PolyVox::MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
        /*IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);*/
        surfaceExtractor.execute();
 
        scene::SMesh *my_mesh = new scene::SMesh;
        scene::IMeshBuffer * my_buffer = ConvertMesh(mesh);
        my_mesh->addMeshBuffer(my_buffer);
        my_mesh->recalculateBoundingBox();
        scene::ISceneNode* my_node = smgr->addMeshSceneNode(my_mesh, 0, 0, core::vector3df(2000*2, 550*2, 2000*2),core::vector3df(0, 100, 0),core::vector3df(20.0F, 20.0F, 20.0F)); 
 
        while(device->run()){
                if(device->isWindowActive()){
                        driver->beginScene();
                        
                        smgr->drawAll();
 
                        driver->endScene();
                }
        }
        device->drop();
        return 1;
} 
 
I can't test it so far, because I have a problem with installing PolyVox, but i would like to hear some comments about my code. ;)
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

Do I need the boost-library for PolyVox ? (I looked into the source (typdef.h) and i think that is my problem)
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: How to pick blocks in minecraft?

Post by serengeor »

804 wrote:Do I need the boost-library for PolyVox ? (I looked into the source (typdef.h) and i think that is my problem)
http://thermite3d.org/joomla/polyvox-technology/about wrote:Architecture:
Written in standard c++.
Cross platform (Windows and Linux).
No dependencies beyond standard library.
Bindings available to other languages.
Graphics API independent.
Is it really that hard to find the manual/doc read it yourself?
http://thermite3d.org/resources/documen ... index.html
Took me like 20s at most to find those.
Working on game: Marrbles (Currently stopped).
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: How to pick blocks in minecraft?

Post by Virror »

No, you dont need boost for PolyVox. On a first and quick glance the code looks good to me. PolyVox should be easy to "install", just include all the c files under PolyVox/PolyVoxCore/source and PolyVox/PolyVoxCore/source/PolyVoxImpl, just dont include SurfaceEdge.cpp since it seems to be missing h-files.
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

And what about Cmake?
There is a Long part about it in the Installation guite but i don't Know why
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: How to pick blocks in minecraft?

Post by serengeor »

804 wrote:And what about Cmake?
There is a Long part about it in the Installation guite but i don't Know why
Re-read everything again then..
Working on game: Marrbles (Currently stopped).
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

Virror wrote:No, you dont need boost for PolyVox. On a first and quick glance the code looks good to me. PolyVox should be easy to "install", just include all the c files under PolyVox/PolyVoxCore/source and PolyVox/PolyVoxCore/source/PolyVoxImpl, just dont include SurfaceEdge.cpp since it seems to be missing h-files.
But when you include just the .cpp files i still need the headers, doesn't you ?
And by the way, what about the .dll (in some threads i read about a dll).

PS: I tried to include polyvox in my projects for about 3 days, read the instalation guite about 10000 times, played a bit with Cmake, ...
-> no result :x :cry: :( :evil: :oops:
So please make me happy by loading up an example project which uses irrlicht and polyvox (including all files, dlls or whatever)
PLEASE! PLEASE! PLEASE!
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: How to pick blocks in minecraft?

Post by Radikalizm »

804 wrote:
Virror wrote:No, you dont need boost for PolyVox. On a first and quick glance the code looks good to me. PolyVox should be easy to "install", just include all the c files under PolyVox/PolyVoxCore/source and PolyVox/PolyVoxCore/source/PolyVoxImpl, just dont include SurfaceEdge.cpp since it seems to be missing h-files.
But when you include just the .cpp files i still need the headers, doesn't you ?
And by the way, what about the .dll (in some threads i read about a dll).

PS: I tried to include polyvox in my projects for about 3 days, read the instalation guite about 10000 times, played a bit with Cmake, ...
-> no result :x :cry: :( :evil: :oops:
So please make me happy by loading up an example project which uses irrlicht and polyvox (including all files, dlls or whatever)
PLEASE! PLEASE! PLEASE!

How much actual programming experience do you even have? Learn the mechanics of your language and your programming environment

I'm sorry, but this is getting pretty ridiculous...
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

I Know and i am no beginner in c++ but i am so frustrated ...
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: How to pick blocks in minecraft?

Post by Virror »

Well, it also helps a lot if you tell us what environment you are using.
You will also need to include the paths to all the header files in your project, or the compiler wont find them.
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: How to pick blocks in minecraft?

Post by 804 »

OK, there had been a few simple mistakes...
-i forgot to include the irrlicht-lib
-i mixed up a few versions of polyvox
:oops:
Here is my code:

Code: Select all

#include <PolyVoxCore/MaterialDensityPair.h>
//#include <PolyVoxCore/CubicSurfaceExtractorWithNormals.h>
#include <irrsurfaceextractor.h>
#include <PolyVoxCore/SurfaceMesh.h>
#include <PolyVoxCore/SimpleVolume.h>
#include <irrlicht.h>
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
using namespace PolyVox;
using namespace irr;
 
void createSphereInVolume(PolyVox::SimpleVolume<MaterialDensityPair44>& 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.getWidth(); z++)
        {
                for (int y = 0; y < volData.getHeight(); y++)
                {
                        for (int x = 0; x < volData.getDepth(); 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.
                                if(fDistToCenter <= fRadius)
                                {
                                        //Our new density value
                                        uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
 
                                        //Get the old voxel
                                        MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
 
                                        //Modify the density
                                        voxel.setDensity(uDensity);
 
                                        //Wrte the voxel value into the volume  
                                        volData.setVoxelAt(x, y, z, voxel);
                                }
                        }
                }
        }
}
 
int main()
{
        IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 768), 16);
    if (device == 0)
        return 1; // could not create selected driver.
    gui::IGUIEnvironment* gui = device->getGUIEnvironment();
    video::IVideoDriver* driver = device->getVideoDriver();
        irr::scene::ISceneManager* smgr = device->getSceneManager();
 
        //Create an empty volume and then place a sphere in it
        PolyVox::SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
        createSphereInVolume(volData, 30);
 
        //Extract the surface
        scene::IMeshBuffer * meshbuffer;
        IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceExtractor([b][i][u]&volData[/u][/i][/b], volData.getEnclosingRegion(), &meshbuffer);
        surfaceExtractor.execute();
 
        scene::SMesh *my_mesh = new scene::SMesh;
        my_mesh->recalculateBoundingBox();
        scene::ISceneNode* my_node = smgr->addMeshSceneNode(my_mesh, 0, 0, core::vector3df(2000*2, 550*2, 2000*2),core::vector3df(0, 100, 0),core::vector3df(20.0F, 20.0F, 20.0F)); 
 
        while(device->run()){
                if(device->isWindowActive()){
                        driver->beginScene();
                        
                        smgr->drawAll();
 
                        driver->endScene();
                }
        }
        device->drop();
        return 1;
}
and now there is a compiler error (i think something with the constructor)...

Code: Select all

IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceExtractor([b][i][u]&volData[/u][/i][/b], volData.getEnclosingRegion(), &meshbuffer);
i found an interresting article in this forum and implemented it to my code (irrsurfaceextractor.h)
http://irrlicht.sourceforge.net/forum/v ... 5&p=259648
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
Post Reply