How to create polyhedron mesh using reactphysics3d - c++

I am using reactphysics3d library https://github.com/DanielChappuis/reactphysics3d
I am trying to create a square pyramid as a polyhedron mesh - 4 outer triangular faces and two base triangular faces.
I am able to successfully create the polygon vertex array, but I am having problems with the polyhedron creation stage.
I am following the progression of shape creation as outlined in the user manual.
I would appreciate help with this!
Thanks
This is my code - I tried using a triangular pyramid (triangle base with triangle faces) to create a triangular mesh and was able to do so. I was then able to create a concave shape.
However, I want to create a convex shape using a polyhedron mesh for a triangle pyramid with a square base.
Any advice would be appreciated!
//array of 5 points, 3 coordinates
float vertices[15];
for(int k=0; k<5; k++){
std::string vert = "v" + std::to_string(k);
vertices[3*k] = j3["data"]["vertices"][vert]["x"];
vertices[3*k+1] = j3["data"]["vertices"][vert]["y"];
vertices[3*k+2] = j3["data"]["vertices"][vert]["z"];
std::cout << std::setprecision(8);
std::cout << "added " << vertices[3*k] << "to index" << 3*k << std::endl;
std::cout << "added " << vertices[3*k+1] << "to index" << 3*k+1 << std::endl;
std::cout << "added " << vertices[3*k+2] << "to index" << 3*k+2 << std::endl;
}
//6 triangle faces
int indices[18];
//each face is defined through vertices (ccw)
//face1
indices[0] = 0; indices[1] = 2; indices[2] = 1;
//face2
indices[3] = 0; indices[4] = 2; indices[5] = 3;
//face3
indices[6] = 0; indices[7] = 4; indices[8] = 3;
//face4
indices[9] = 0; indices[10] = 1; indices[11] = 4;
//face5
indices[12] = 1; indices[13] = 2; indices[14] = 4;
//face6
indices[15] = 4; indices[16] = 2; indices[17] = 3;
rp3d::PolygonVertexArray::PolygonFace* polygonFaces = new rp3d::PolygonVertexArray::PolygonFace[6];
rp3d::PolygonVertexArray::PolygonFace* face = polygonFaces;
//each face has 3 indices
//6 triangles
for (int f=0; f<6; f++){
face->indexBase = f*3;
face->nbVertices = 3;
}
std::cout << "created polygon faces" << std::endl;
//create the polygon vertex array
rp3d::PolygonVertexArray* pva = new rp3d::PolygonVertexArray(5, vertices, sizeof(float), indices, sizeof(int), 6, polygonFaces, rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
std::cout << "polygon vertex array created" << std::endl;
//create the polyhedron mesh
rp3d::PolyhedronMesh* pMesh = new rp3d::PolyhedronMesh(pva);
std::cout << "polyhedron mesh created" << std::endl;
//create the convex mesh collision shape
rp3d::ConvexMeshShape* convexMesh = new rp3d::ConvexMeshShape(pMesh);
std::cout << "convex mesh shape created" << std::endl;

i think you forget a face++ in the faces loop

Related

C++//STL to OBJ Converter: How can i make my program run faster

I am creating an "STL to OBJ" format converter. The program contains a header file that reads the data from an STL file. and the main program takes that data and writes it to a new OBJ file.
everything works great but with large files the program takes so long. I know exactly which part makes the program slow and I can't find any alternative of it. It is in the part "// Create Array for the Faces" exactly in the For-Loop.
First I want to explain a bit about STL and OBJ files. In general, any 3D image in the STL format is created from a large number of triangles and each triangle has 3 vertices (each vertex has 3 points: x, y and z). But there are many repeated vertices because the triangles are connected to each other. But in the OBJ format, 2 parts are responsible for it: one is "List of Vertices" and here vertices are sorted one after another without repetition. the second part is "List of Faces" and it is the Numbers of Index of the vertices.
this is my main code:
#include "Header.h"
using namespace std;
string inputFile = "Fidgit.stl"; //Import einen STL-Datei (1.6MB)
string outputFile = "Fidgit1.obj"; //Export einen OBJ-Datei (1.1MB)
int main(int argc, char** argv)
{
auto t0 = std::chrono::system_clock::now();
std::cout << "Lesen der STL-Datei" << std::endl;
std::vector<float> coords, normals;
std::vector<unsigned int> tris, solids;
stl_reader::ReadStlFile(inputFile.c_str(), coords, normals, tris, solids);
const size_t numTris = tris.size() / 3;
std::cout << " Numbers of Triangels: " << numTris << std::endl;
auto t1 = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0);
std::cout << " duration: " << elapsed.count() << " ms" << std::endl;
std::cout << "writing OBJ-File" << std::endl;
std::ofstream fileOBJ(outputFile.c_str(), std::ios::out);
std::cout << " Erstelle Liste der Punkte" << std::endl;
fileOBJ << "# Object name:" << std::endl;
fileOBJ << outputFile << std::endl;
fileOBJ << std::endl;
fileOBJ << "# Begin list of vertices" << std::endl;
vector<string> AllVertex;
std::ifstream inFile(outputFile.c_str(), std::ios::in);
////////////////////////////////////////////////////////////////////////////
// Find Vertiecs coordinates and write into OBJ file
for (size_t itri = 0; itri < numTris; ++itri) {
for (size_t icorner = 0; icorner < 3; ++icorner) {
float* c = &coords[3 * tris[3 * itri + icorner]];
std::string VerStr = "v " + to_string(c[2]) + " " + to_string(c[1]) + " " + to_string(c[0]) ;
AllVertex.push_back(VerStr);
}
}
// here is a vertices containing the vertices coordinates read from the STL file.
// But there are many repeated vectors that we don't need in obj format,
// so they have to be removed by next step
vector <string> OldSTLVertex = AllVertex;
//Copy of STL vectors before removing the repeated vertices
// to be able to find the faces indexes
sort(AllteVertex.begin(), AllVertex.end());
auto last = unique(AllVertex.begin(), AllVertex.end());
AllVertex.erase(last, AllVertex.end());
vector <string> OBJVertex = AllVertex;
// here are the vectors without repetitions
// ready to be able to save the vector coordinates in the created obj file:
for (auto ind : OBJVertex)
{
fileOBJ << ind << endl;
}
fileOBJ << "# End list of vertices" << std::endl;
fileOBJ << std::endl;
auto t2 = std::chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
std::cout << " duration: " << elapsed.count() << " ms" << std::endl;
//////////////////////////////////////////////////////////////////////////////
// Create Arry for the Faces
std::cout << " Create list of faces (triangles)" << std::endl;
vector <int> OBJFaces(numTris * 3);
fileOBJ << "# Begin list of faces" << std::endl;
int iCounter = 0;
int iPercent = 0;
int vcounter = 0;
// the point here is: which index in OBJVertiecs[] hat jeder vertiec in OldSTLVertex[]
for (int i = 0; i < OldSTLVertex.size(); i++) // in my example OldSTLVertex.size() have 99030 elements
{
bool bFound = false;
int vertexIndex = 0;
while (!bFound) // for (size_t vertexIndex = 0; vertexIndex < OBJVertex.size(); ++vertexIndex)
{
if (OldSTLVertex[i] == OBJVertex[vertexIndex]) // OBJVertex have 16523 elements
{
bFound = true;
OBJFaces[vcounter] = vertexIndex;
vcounter++;
}
vertexIndex++;
}
iCounter++;
if (iCounter % (OldSTLVertex.size() / 100) == 0) // every time 10% are done
{
iPercent = iPercent + 1;
auto t3 = std::chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t2);
std::cout << " " << iPercent << "% done in " << elapsed.count() << " ms" << std::endl;
}
}
/////////////////////////////////////////////////////////////////////////////
// Write faces into OBJ file
unsigned count = 0;
for (auto ind : OBJFaces)
{
if (count++ % 3 == 0) fileOBJ << "f ";
fileOBJ << ind + 1 << " ";
if (count % 3 == 0) fileOBJ << std::endl;
}
fileOBJ << "# End list of faces" << std::endl;
fileOBJ << std::endl;
auto t4 = std::chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(t4 - t0);
std::cout << "OBJ file written in " << elapsed.count() << " ms." << std::endl;
return 0;
}
Your current code first maps all vertices in the STL to the OBJ string format of the vertex index they reference, then uses std::unique to reduce this list, then uses an O(n) lookup on each vertex to find the original index. This is O(n*m) and is very expensive if both n and m are large.
Instead, you can do the following:
Walk the elements of tris, and for each referenced vertex idx use a std::map<std::tuple<float, float, float>, unsigned int> to deduplicate them.
If it is not present, you push the coord triple to a vector obj_coords and overwrite tris[idx] with its new index.
If it was present you simply overwrite tris[idx] with the existing index.
When rendering the vectors you can almost dump obj_coords as-is.
When rendering the faces, you simply follow the indirection in coords
So, in summary:
using Coord = std::tuple<float, float, float>;
std::map<Coord, int> coordToIndex;
std::vector<Coord> obj_coords;
for (auto &idx : tris) {
const Coord c = { coords[3*idx+0], coords[3*idx+1], coords[3*idx+2] };
if (auto it = coordToIndex.find(c); it != coordToIndex.end()) {
// We saw this vertex before
idx = it->second;
} else {
// New vertex.
obj_coords.push_back(c);
idx = obj_coords.size()-1;
coordToIndex[c] = idx; // Also create an entry in coordToIndex
}
}
Then, generating vertexes is simple: (not sure why you swapped z and x though)
for (const auto& coord : obj_coords) {
fileOBJ << "v " << std::get<2>(coord) << " " << std::get<1>(coord) << " " << std::get<0>(coord) << "\n";
}
And finally, the faces:
for (int tri = 0; tri < tris.size(); tri += 3) {
fileOBJ << "f " << tris[tri+0] << " " << tris[tri+1] << " " << tris[tri+2] << "\n"
}
You may have noticed I use "\n" instead of std::endl. This is because std::endl implies std::flush, which tries to ensure that data is written to disk. Calling this is as often as you will is wasteful.
Instead, you can just flush once manually, or trust that the destructor will do it for you:
fileOBJ << std::flush;

OpenGL Application crashes when accessing Assimp Texture Coordinate Data

I am trying to access the Texture Coordinate of a Cube model made in blender.
for (int i = 0; i < mMesh->mNumVertices; i++) {
std::cout << mMesh->mTextureCoords[i][0].x << " " << mMesh->mTextureCoords[i][0].y << std::endl;
}
Why is this happening.
The application window launches but the red color background doesnt display.
And the first coords also get printed 0 1
How do i solve this.
Removing this code doesn't lead to a crash.
This should be:
for (int i = 0; i < mMesh->mNumVertices; i++)
{
std::cout << mMesh->mTextureCoords[0][i].x << " " << mMesh->mTextureCoords[0][i].y << std::endl;
}
Looks like you messed up the first and second array arguments. Also, it is good practice to check if the mesh has texture coordinates or not. Then the code becomes
if (mMesh->HasTextureCoords(0)) //HasTextureCoords is an assimp function
{
for (int i = 0; i < mMesh->mNumVertices; i++)
{
std::cout << mMesh->mTextureCoords[0][i].x << " " << mMesh- >mTextureCoords[0][i].y << std::endl;
}
}

Octomap (octree) coordinates in xyx space

Given an octomap::OcTree, how can I get the cartesian coordinates of the occupied cells?
double printOccupied(boost::shared_ptr<octomap::OcTree> octree) {
// Get some octomap config data
auto res = octree->getResolution();
unsigned int max_depth = octree->getTreeDepth();
// Iterate over nodes
int count = 0;
std::cout << "printOccupied: octree res = " << res << std::endl;
std::cout << "printOccupied: octree max depth = " << max_depth << std::endl;
std::cout << "printOccupied: iterating over nodes..." << std::endl;
for (octomap::OcTree::iterator it = octree->begin(); it != octree->end(); ++it) {
if (octree->isNodeOccupied(*it) && it.getDepth() < max_depth) {
count++;
// Fetching the coordinates in octomap-space
std::cout << " x = " << it.getX() << std::endl;
std::cout << " y = " << it.getY() << std::endl;
std::cout << " z = " << it.getZ() << std::endl;
std::cout << " size = " << it.getSize() << std::endl;
std::cout << " depth = " << it.getDepth() << std::endl;
// Then convert to meters???
auto cell = std::make_tuple(it.getX() * res,
it.getY() * res,
it.getZ() * res);
}
}
std::cout << "printOccupied: number of occupied cells = " << count << std::endl;
}
For when I pass in an octree that is generated from an empty PlanningScene I get 0 occupied cells, as expected. When I use a scene that is known to have a single sphere of radius 0.05 meters at xyz coordinates (0.1, 0.8, 0.1), according to the scene's reference frame (also meters), I get the following output:
printOccupied: octree res = 0.02
printOccupied: octree max depth = 16
printOccupied: iterating over nodes...
x = -327.68
y = -327.68
z = -327.68
size = 655.36
depth = 1
x = 327.68
y = -327.68
z = -327.68
size = 655.36
depth = 1
x = -491.52
y = 491.52
z = -491.52
size = 327.68
depth = 2
x = 327.68
y = 327.68
z = -327.68
size = 655.36
depth = 1
x = -92.16
y = 624.64
z = 51.2
size = 20.48
depth = 6
x = -81.92
y = 409.6
z = 245.76
size = 163.84
depth = 3
x = -419.84
y = 624.64
z = 378.88
size = 20.48
depth = 6
x = -409.6
y = 409.6
z = 573.44
size = 163.84
depth = 3
x = 327.68
y = 327.68
z = 327.68
size = 655.36
depth = 1
printOccupied: number of occupied cells = 9
Surely there must be some conversion needed, as these octomap xyz values do not correspond to a single small sphere as expected. What is this conversion?
I see that the problem is the way in which you are using iterators. An octree has the structure of a tree, and the kind of iterator you are using navigates through the tree without taking into account the depth of the cells.
The depth counts from the tree root, so the cells that you show as output are high-level cells which should not be used, in general, for collision check purposes because of their size (depth=1 is the root of the tree, which contains 4 cells of depth 2... and that goes on recursively until max_depth, which is normally 16).
I understand that you want to know which leaf cells (the smaller ones) are occupied, and you have one iterator which might help you to do so. Here is how I do it:
for(OcTree::leaf_iterator it = octree->begin_leafs(), end = octree->end_leafs(); it != end; ++it){
// Fetching the coordinates in octomap-space
std::cout << " x = " << it.getX() << std::endl;
std::cout << " y = " << it.getY() << std::endl;
std::cout << " z = " << it.getZ() << std::endl;
std::cout << " size = " << it.getSize() << std::endl;
std::cout << " depth = " << it.getDepth() << std::endl;
}
}
No conversion is needed, xyz are already in global coordinates of the map.
Note: If you need to navigate only through cells which are inside a bounding box, take a look to the methods octree->begin_leafs_bbx() and end_leafs_bbx() to create your iterator. If you need to limit the depth of the leafs I think you can do that with those methods too.
I hope this helps. Best regards,
Adrián
EDIT: changed the code in the answer because of an error in the return type of begin_leafs(). Also, noted that begin_leafs() and end_leafs() have the same behavior than begin() and end() according to the Octomap API.

saving CGAL alpha shape surface mesh

I have never used CGAL and have got almost no C/C++ experience. But following
Google I have however managed to compile the example "Alpha_shapes_3"
(\CGAL-4.1-beta1\examples\Alpha_shapes_3) on a Windows 7 64bit machine using
visual studio 2010.
Now if we check the source code for the program "ex_alpha_shapes_3" we
notice that a data file called "bunny_1000" is red where the 3d point
cluster resides.
Now my question is how can I change the source code so that after the alpha
shape is computed for the given points, surface mesh of the alpha shape is
saved/wrote in an external file. It can be simply the list of polygons and
their respective 3D vertices. I guess these polygons will be defining the
surface mesh of the alpha shape. If I can do that I can see the output of
the alpha shape generation program in an external tool I am familiar with.
I know this is very straightforward but I could not figure this out with my
limited knowledge of CGAL.
I know you gueys have the code but I am pasting it again for completion.
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Alpha_shape_3.h>
#include <fstream>
#include <list>
#include <cassert>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Gt;
typedef CGAL::Alpha_shape_vertex_base_3<Gt> Vb;
typedef CGAL::Alpha_shape_cell_base_3<Gt> Fb;
typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_3<Gt,Tds> Triangulation_3;
typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3;
typedef Gt::Point_3 Point;
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator;
int main()
{
std::list<Point> lp;
//read input
std::ifstream is("./data/bunny_1000");
int n;
is >> n;
std::cout << "Reading " << n << " points " << std::endl;
Point p;
for( ; n>0 ; n--) {
is >> p;
lp.push_back(p);
}
// compute alpha shape
Alpha_shape_3 as(lp.begin(),lp.end());
std::cout << "Alpha shape computed in REGULARIZED mode by default"
<< std::endl;
// find optimal alpha value
Alpha_iterator opt = as.find_optimal_alpha(1);
std::cout << "Optimal alpha value to get one connected component is "
<< *opt << std::endl;
as.set_alpha(*opt);
assert(as.number_of_solid_components() == 1);
return 0;
}
After searching a lot in the internet I found that probably we need to use something like
std::list<Facet> facets;
alpha_shape.get_alpha_shape_facets
(
std::back_inserter(facets),Alpha_shape::REGULAR
);
But I am still completely clueless how to use this in the above code!
As documented here, a facet is a pair (Cell_handle c,int i) defined as the facet in c opposite to the vertex of index i.
On this page, you have the description of how the vertex indices of a cell are.
In the following code sample, I added a small output that prints an OFF file on cout by duplicating the vertices. To do something clean, you can either use a std::map<Alpha_shape_3::Vertex_handle,int> to associate a unique index per vertex or add an info to the vertices like in those examples.
/// collect all regular facets
std::vector<Alpha_shape_3::Facet> facets;
as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);
std::stringstream pts;
std::stringstream ind;
std::size_t nbf=facets.size();
for (std::size_t i=0;i<nbf;++i)
{
//To have a consistent orientation of the facet, always consider an exterior cell
if ( as.classify( facets[i].first )!=Alpha_shape_3::EXTERIOR )
facets[i]=as.mirror_facet( facets[i] );
CGAL_assertion( as.classify( facets[i].first )==Alpha_shape_3::EXTERIOR );
int indices[3]={
(facets[i].second+1)%4,
(facets[i].second+2)%4,
(facets[i].second+3)%4,
};
/// according to the encoding of vertex indices, this is needed to get
/// a consistent orienation
if ( facets[i].second%2==0 ) std::swap(indices[0], indices[1]);
pts <<
facets[i].first->vertex(indices[0])->point() << "\n" <<
facets[i].first->vertex(indices[1])->point() << "\n" <<
facets[i].first->vertex(indices[2])->point() << "\n";
ind << "3 " << 3*i << " " << 3*i+1 << " " << 3*i+2 << "\n";
}
std::cout << "OFF "<< 3*nbf << " " << nbf << " 0\n";
std::cout << pts.str();
std::cout << ind.str();
Here is my code, which outputs vtk file for visualization in Paraview. Comparing with slorior's solutions, no duplicated points are saved in the file. But my code is just for the visualization, if you need to figure out the exterior or interior simplexes, you should modify the code to get these results.
void writevtk(Alpha_shape_3 &as, const std::string &asfile) {
// http://cgal-discuss.949826.n4.nabble.com/Help-with-filtration-and-filtration-with-alpha-values-td4659524.html#a4659549
std::cout << "Information of the Alpha_Complex:\n";
std::vector<Alpha_shape_3::Cell_handle> cells;
std::vector<Alpha_shape_3::Facet> facets;
std::vector<Alpha_shape_3::Edge> edges;
// tetrahedron = cell, they should be the interior, it is inside the 3D space
as.get_alpha_shape_cells(std::back_inserter(cells), Alpha_shape_3::INTERIOR);
// triangles
// for the visualiization, don't need regular because tetrahedron will show it
//as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);
as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::SINGULAR);
// edges
as.get_alpha_shape_edges(std::back_inserter(edges), Alpha_shape_3::SINGULAR);
std::cout << "The alpha-complex has : " << std::endl;
std::cout << cells.size() << " cells as tetrahedrons" << std::endl;
std::cout << facets.size() << " triangles" << std::endl;
std::cout << edges.size() << " edges" << std::endl;
size_t tetra_num, tri_num, edge_num;
tetra_num = cells.size();
tri_num = facets.size();
edge_num = edges.size();
// vertices: points <-> id
std::map<Point, size_t> points;
size_t index = 0;
// finite_.. is from DT class
for (auto v_it = as.finite_vertices_begin(); v_it != as.finite_vertices_end(); v_it++) {
points[v_it->point()] = index;
index++;
}
// write
std::ofstream of(asfile);
of << "# vtk DataFile Version 2.0\n\nASCII\nDATASET UNSTRUCTURED_GRID\n\n";
of << "POINTS " << index << " float\n";
for (auto v_it = as.finite_vertices_begin(); v_it != as.finite_vertices_end(); v_it++) {
of << v_it->point() << std::endl;
}
of << std::endl;
of << "CELLS " << tetra_num + tri_num + edge_num << " " << 5 * tetra_num + 4 * tri_num + 3 * edge_num << std::endl;
for (auto cell:cells) {
size_t v0 = points.find(cell->vertex(0)->point())->second;
size_t v1 = points.find(cell->vertex(1)->point())->second;
size_t v2 = points.find(cell->vertex(2)->point())->second;
size_t v3 = points.find(cell->vertex(3)->point())->second;
of << "4 " << v0 << " " << v1 << " " << v2 << " " << v3 << std::endl;
}
// https://doc.cgal.org/latest/TDS_3/classTriangulationDataStructure__3.html#ad6a20b45e66dfb690bfcdb8438e9fcae
for (auto tri_it = facets.begin(); tri_it != facets.end(); ++tri_it) {
of << "3 ";
auto tmp_tetra = tri_it->first;
for (int i = 0; i < 4; i++) {
if (i != tri_it->second) {
of << points.find(tmp_tetra->vertex(i)->point())->second << " ";
}
}
of << std::endl;
}
// https://doc.cgal.org/latest/TDS_3/classTriangulationDataStructure__3.html#af31db7673a6d7d28c0bb90a3115ac695
for (auto e : edges) {
of << "2 ";
auto tmp_tetra = e.get<0>();
int p1, p2;
p1 = e.get<1>();
p2 = e.get<2>();
of << points.find(tmp_tetra->vertex(p1)->point())->second << " "
<< points.find(tmp_tetra->vertex(p2)->point())->second << std::endl;
}
of << std::endl;
of << "CELL_TYPES " << tetra_num + tri_num + edge_num << std::endl;
for (int i = 0; i < tetra_num; i++) {
of << "10 ";
}
for (int i = 0; i < tri_num; i++) {
of << "5 ";
}
for (int i = 0; i < edge_num; i++) {
of << "3 ";
}
of << std::endl;
of.close();
}

How to read height map values to generate a terrain?

I am trying to make a terrain using a height map image in OpenGL. As a experiment i use 4x4 pixel image. this is a zoomed screen shot. so you can see the pixels.
This is a part of my code.
ILubyte * image = ilGetData();
int bpp = ilGetInteger(IL_IMAGE_BPP);
std::cout << "BPP = " << bpp << std::endl;
for (int z=0; z < terrainHeight; ++z)
{
for (int x=0; x < terrainWidth; ++x)
{
pVertices[z*terrainWidth+x] = NxVec3(NxF32(x),
NxF32(image[z*terrainWidth+x]*bpp), NxF32(z));
}
}
for (int i=0; i < vertexCount; ++i)
{
std::cout << "x = " << pVertices[i].x << "\t y = "
<< pVertices[i].y << "\t z = " << pVertices[i].z << std::endl;
}
Then, i'm getting the following result.
I'm expecting the zero values(for y-coordinate) for (0,0), (1,1), (2,2) and (3,3). but the result is different. why i'm not getting the expected results ?
I think it should be image[(z*terrainWidth+x)*bpp] instead of image[z*terrainWidth+x]*bpp.