PDA

View Full Version : Is it always good to use Vec3f / Vec4f class defined by yourself?



A_Shuang
03-14-2015, 09:21 AM
I'm currently learning OpenGL with JOGL.
What makes me confused is that when you're going to reconstruct a virtural scene containing plenty of objects, is it always good to define a Vec3f class and face class representing the vertices, normals, and faces rather than to directly use float[] type. Any ideas?

Agent D
03-14-2015, 11:18 AM
If you do not intend to do any mesh processing or collision detection, etc..., keeping track of faces or other high level topology data
is completely useless overhead.

As long as you only want to render an object, it is not neccessary to keep around anything more than vertex and index buffers, and
only until you uploaded them to a buffer object.

However, you will most likely have custom vector and matrix data types in your applications with common vector and matrix operations
for other reasons, such as keeping track of positions and orientations of objects in your scene, animations, etc...

mhagain
03-14-2015, 11:50 AM
I don't know Java, but in other languages it can add an extra degree of type-safety that may not be there otherwise.

GClements
03-15-2015, 05:48 AM
is it always good to define a Vec3f class and face class representing the vertices, normals, and faces
Always? No.

Doing so may add significant overhead, particularly for reference-based languages such as Java. If you have an array of Vec3, you have to copy the date into a float[] in order to pass it to any OpenGL function. Similarly, you can't use a multi-dimensional array where a one-dimensional array is required, as each dimension adds an extra level of indirection.

The situation is better in C or C++ as you can typically just cast an array of vector structures to a float array.