Skip to main content
GameDev.net gamedev.net
🔒 Locked

struct pointer

Started by giugio Jul 2, 2008 at 2:55 PM 5 replies 1k views
Original Post
giugio
giugio
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.
i_luv_cplusplus
i_luv_cplusplus
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

std::vector<3dpoint> points;

for (int i=0;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]
OpenGL fanboy.
dmatter
dmatter
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
dmatter
dmatter
Quote:
Original post by agi_shi
That, and 3dpoint is an invalid identifier [wink]

*sighs* - 'Course it is [rolleyes]
thedustbustr
thedustbustr
if you cant use a vector,

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

for (size_t i=0; ipoints.x = 1;
points.y = 0;
points.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;
giugio
giugio
thanks , this is ok

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.