Problem with vertex arrays
Hi all,
I am currently looking into moving my rendering engine from using literally hundreds of thousands of glvertex/normal/texcoord function calls to vertex arrays etc. I have been looking at some example programs and can see how they are using the arrays, but this is where my problem begins. I have an object class that has arrays of vertex and triangle classes:
object
/ \
/ \
/ \
/ \
Vertex List Triangle List
the vertex class hold an x,y,z float value for the coordinate. The triangle currently holds a pointer and an index to the vertex in the vertex list, also x,y for each vertex for texture mapping.
I cannot think how to use vertex arrays with this kind of structure, so does anyone know if this is possible - or how to use them with the smallest changes possible.
Hope this all makes sense.
Thanks.
Ok I -think- it''s possible to use your existing classes with little or no modification using some fancy class design.
I''m not sure what to do about the triangle class, but certainly you can modify your vertex class to expose the vertex data contained within by overloading the * operator for your class.
In your class definition you would have something like the following:
operator float * (void);
And in your class implementation you would have something like this:
Vector3d::operator float * (void)
{
return &m_fX;
}
However for this to work you would need to create a union in your class definition such as:
union
{
float m_fVector[3];
struct
{
float m_fX, m_fY, m_fZ;
};
};
That way returning a reference to m_fX would essentially be the same as returning the first element in m_fVector, which would allow you to use your class in a function call.
For working code check out the GEKx maths library featured in the code of the day section some months back on www.flipcode.com.
Maybe you could use something similar to allow you to use your triangle classes with OpenGL?
-------- E y e .Scream Software --------
----------------------------------------
/-\
http://www.eyescream.cjb.net | * |
\-/
----------------------------------------
I''m not sure what to do about the triangle class, but certainly you can modify your vertex class to expose the vertex data contained within by overloading the * operator for your class.
In your class definition you would have something like the following:
operator float * (void);
And in your class implementation you would have something like this:
Vector3d::operator float * (void)
{
return &m_fX;
}
However for this to work you would need to create a union in your class definition such as:
union
{
float m_fVector[3];
struct
{
float m_fX, m_fY, m_fZ;
};
};
That way returning a reference to m_fX would essentially be the same as returning the first element in m_fVector, which would allow you to use your class in a function call.
For working code check out the GEKx maths library featured in the code of the day section some months back on www.flipcode.com.
Maybe you could use something similar to allow you to use your triangle classes with OpenGL?
-------- E y e .Scream Software --------
----------------------------------------
/-\
http://www.eyescream.cjb.net | * |
\-/
----------------------------------------
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement