Jump to content
  • Advertisement
Sign in to follow this  
giugio

struct pointer

This topic is 3737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Quote:
Original post by agi_shi
That, and 3dpoint is an invalid identifier [wink]

*sighs* - 'Course it is [rolleyes]

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.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;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!