Sign in to follow this  
giugio

struct pointer

Recommended Posts

Hy. I read about dont use array or collection for store the 3d point in a model. Then how to indexes a havy structure of point: struct 3dpoint { float x; float y; float z } 3dpoint point= new 3dpoint(); point->x = 1; point->y = 0; point->z = 1; ..ecc for 1000000 next how to access at the 20000 point with pointers? or scroll all the 100000 points? thanks.

Share this post


Link to post
Share on other sites
struct 3dpoint
{
float x;
float y;
float z
}

You didn't specify the language you are using, but I guess from syntax it's C++.

I suggest using std::vector so:

#include <vector>

std::vector<3dpoint> points;

for (int i=0;i<number_of_points;i++)
{
3dpoint point;
point.x = 1;
point.y = 0;
point.z = 1;
points.push_back(point);
}

then you can refer to your points as points[number]

Share this post


Link to post
Share on other sites
Quote:
Original post by giugio
I read about dont use array or collection for store the 3d point in a model.

It seems you've been misinformed - the most natural way to have a collection of points is by storing those points in a container.

Ex (C++):

std::vector<3dpoint> vertices; // your empty collection of points

Share this post


Link to post
Share on other sites
if you cant use a vector,

size_t num = 1000000;
point3d points = new point3d[num];

for (size_t i=0; i<num; ++i) {
points[i].x = 1;
points[i].y = 0;
points[i].z = 0;
}

size_t which = 46463;
int x = points[which].x;
int y = *(points+which).y;
//int z = *(points+which*sizeof(point3d)); //wrong

delete[] point3d;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this