[gameprogrammer] Re: dynamic array allocation in a class?
- From: "Justin Coleman" <JMCOLE@xxxxxxxxx>
- To: <gameprogrammer@xxxxxxxxxxxxx>
- Date: Thu, 10 Jun 2004 09:26:06 -0400
>>> daveslutzkin@xxxxxxxxxxx 6/10/2004 1:28:51 AM >>>
>Well, this code looks a lot like C code that's been shoehorned into a
>class, so there may be a better way to go.
It is C code... or was. I think I've got it fixed now, it's much
cleaner (to look at anyway) and does what I want it to. What's the
giveaway though, I'm curious?
I started programming in C several years ago, and never really did much
with it, but I got a fire lit under me recently and I'm trying to apply
what I already know in C to how I learn C++. Unfortunately, there's no
easy way for me to take a class on programming, so I'm having to
self-teach with books and mailing lists :)
>All right, the best way to do this is probably to use a STL vector,
as
>that's dynamically resizable and can give you some array bounds
overflow
>protection. It should also definitely be fast enough for your
purposes.
>The downside is that it won't be directly 2-dimensional, but this is
>barely a problem.
Not a problem at all, in fact I actually used the previous suggestion
of dynamically allocated 1-d arrays. The data isn't going to change once
it's loaded or generated, so I only need to allocate it once. Resize
would probably be overkill for this.
Here's what it looks like now: (btw, if anyone wants the actual code
I'd be happy to share)
typedef struct _vertex_structure {
GLfloat x, y, z;
} vertex;
typedef struct _texcoord_structure {
GLfloat u, v;
} texcoord;
typedef struct _triangle_structure {
GLuint a, b, c;
} tri;
class cSphere {
public:
vertex *verts;
texcoord *coords;
vertex *face_normals;
tri *faces;
int num_verts, num_faces, col, row;
cSphere::cSphere();
int cSphere::Generate(int rows, int columns);
int cSphere::Save(char *filename);
int cSphere::Load(char *filename);
void cSphere::Render(void);
cSphere::~cSphere();
};
>If you're using the C++ STL for the first time, it's a good idea to
read
>about it. Stroustrup's book, 'The C++ Programming Language' is good,
as
>is Josuttis' 'The Standard Template Library' (I think that's the
title).
Couldn't find either of those when I went looking, so I picked up 'STL
Programming from the Ground Up' by Schildt. His C++ book by a similar
name is much, much easier for me to learn from than the other C++ books
I have. Haven't had a chance to get into STL much, but hopefully I will
soon.
Thanks,
-Justin
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: dynamic array allocation in a class?
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- [gameprogrammer] Re: dynamic array allocation in a class?
- From: Dave Slutzkin