View Full Version : [something fun] vector class, what do I need??

02-17-2014, 02:25 PM
so this is a little thing I'm doing for a rebuild of a project in the Python27 language.
I'm worried more about quality than performance.

so what I'm trying to do is design a vector class for 1D to 4D vectors and quaternions,
and have the class be able to easily convert between their representative values.
NOTE: this is a single class, not multiple classes for each vector type

the class supports 4D:
vertices - [X,Y,Z,W] (or quaternions)
normals - [I,J,K,H]
texCoords - [S,T,R,Q] (where Q is used for the 3D texCoord angle (sent to GL as [S,T,Q]))
colors - [R,G,B,A]

what and all do I to perform the proper conversions??

I've tried looking a few times, with no luck other than what I know above, excluding how [S,T,R] can also be [U,V,W].
(but [U,V,W] can also be curve-surface representation)

what exactly do vector letters stand for and what do they mean??
I'm tired of finding bits and pieces of their meanings... google sucks >.<
(we need a wiki on this or something)

02-17-2014, 05:44 PM
I do not know what you are asking. If you are asking how to create this class in Python you best ask on a Python forum

02-17-2014, 10:21 PM
oh I was only trying to hint at the code needing to be in python...

I know nothing about proper vector methods, and I want to build a single vector class that can hold any type of 1D to 4D data and convert the properly.
(such as converting a 4D quaternion to a 2D vertex)

also note:
I use the term "Vertex" standing for an XYZW position.
where "FacePoint" is the combined weights,vert,normal,colors,UV's,NBTs,etc...

anyways... what I'm asking is...
what do I need to put into a class like this??
and how would I go about building the methods??

I'm currently trying to follow about 6 high-end to mid-end game-engine src's from engines such as CryEngine3 to Unity...
I'm asking here because there's an quite overwhelming amount of src to look at,
and it could take quite alot longer to figure out than from asking experienced developers.

02-18-2014, 05:06 AM
First you have to ask yourself do I really need to do this when there are a lot of vector libraries out there like glm and the functions they have tend to cover what your need in practice.

But if you think you want to write one then start small. Have a base class with some basic function then add more as you have needs.

Libraries are best developed with a purpose in mind, ie, you have a need so you write it rather that writing it and trying to find where to use it.

02-18-2014, 07:06 AM
ok... the need is for an interface for converting data...
and yes I do need to write it because it converts data types.

for example, you store a vector as a bs24 (3-byte signed int) and want to convert it to a bf(5) (5-byte float)
my data interface is already fully capable of this.

I'm not mentioning the needs... I'm supporting future development...
but now I need to know all of the things applied between vectors and quaternions to convert them appropriately.
(this is for the scripting interface which handles the model data you're converting)
^ say... *.MDL0 >>> *.BLEND --- *.BLEND >>> *.DAT
(Wii >>> Blender24 --- Blender26 >>> GCN)

I basically need to convert between all vector types here, and need an interface that can do it.

I WILL however take a look into a python translation of your GLM recommendation.
thanks. :)

02-18-2014, 09:38 PM
^ say... *.MDL0 >>> *.BLEND --- *.BLEND >>> *.DAT
This is data conversion. It is not really relevant to this forum.

know all of the things applied between vectors and quaternions
vectors and quaternions aren't directly related; one is a direction and length, the other is a method of storing a rotation around an axis. (among other uses)

I basically need to convert between all vector types
How long is a piece of string.

02-18-2014, 11:34 PM
I'm not sure why you posted this in "OpenGL Advanced". It's nothing to do with OpenGL, and is certainly not advanced.

02-19-2014, 08:04 AM
I'm not sure why you posted this in "OpenGL Advanced". It's nothing to do with OpenGL, and is certainly not advanced.
well, ok, could this be moved to a more appropriate thread plox.
I'm only a noob, so IDK this forum yet :P

the reason I ask here is cause I assume you guys know more about vectors and quaternions than what I can find on google.

it's only "advanced" because I associated this category with Modern GL... heh
and I figured the coding was kindof advanced for it's level.

This is data conversion. It is not really relevant to this forum.
exactly... the only relevence is me, trying to get this to work with GL...
I need to know what I need so I can have a check-list... basically

[/COLOR]vectors and quaternions aren't directly related; one is a direction and length, the other is a method of storing a rotation around an axis. (among other uses)
IK... but there's conversion methods between them... or maybe that's just BrawlBox... :P

How long is a piece of string.
lol please :3

02-19-2014, 05:42 PM
trying to get this to work with GL...
Have you read the OpenGL specs (http://www.opengl.org/registry/doc/glspec44.core.pdf). You will see all the formats supported for vertices and textures. It is up to you what formats
you want you are prepared to read and convert into these formats.

there's conversion methods between them
A quaternion has 4 components - anything that can contain 4 values can be thought of as a quaternion.
A vector has n components, in graphics we think of 2 for 2D and 3 for 3D.

If you are looking at a general converter, you should look at a component to component conversion not vector to vector since 2 vectors can have a different a
number of components.

02-19-2014, 06:28 PM
I have the 4.4 reference off-hand, though I do need to look at it more often <.<

anyways, yeh... not exactly what I need...
component to component can already be done in my interface.
(such as undoing a slew of floats as ints with an exponent (Nintendo-styled))

what I'm having a problem with is my srcs...
none of them defines a general class for handling everything that isn't WIP (not even working)...
almost all of my srcs define classes for vec2, vec3, vec4, and quaternion, and bloat the code by defining methods for each...

I just want 1 class for everything, with methods to adapt to the comparison or the conversion specs,
but I wouldn't know what I'd need, or where to even start off at...

I'm no math expert... I graduated at Algebra1 level, with SOME geometry knowledge I just knew (I wasn't even self-taught it).
I surprised my teacher with the "college level geometry" I knew... but unfortunately, that's as far as I go...
I havn't been in college, nor done anything much to get me much farther in math, other than looking at others srcs to try and decipher them.
(I can't even read math on Wikipedia)

so anyways...
all I'm asking for is a checklist...
what methods would I need for something like this??

02-19-2014, 11:48 PM
It sounds to me like you are looking for template classes (which are available in C++) but I don't know that Python can do that. But even with templates you eventually have to write code that will take for example
a vec2(float,float) can convert to say vec2(int,int) vec2(float,int) vec2(int,float) vec2(double,float) vec2(float,double) vec2(double,double) vec2(int,double) vec2(double,int) if you want all those options - this is not bloat.

There is no checklist other than what conversions you need. If you need only need vec2(float,float) to vec2(int,int) that's all you write. No one can tell you what you need. OpenGl has native support for float,int,doubles and bytes. But they are
not all valid in all combinations. With shaders you can pack several things into 1 byte if you want and people do.

02-20-2014, 09:01 AM
ok, the inputs for my class are already pretty much figured out:

vector( BF32(0.0), BU8(0), BU8(0) ) # these are internal data types of my system
vector( 0.0, 0.0, 0.0, 1.0 )
vector( [0.0, 1.0] ) #or tuples
vector( vector( 0, 0, 0 ) )

the methods are my problem...
what are all of the common conversion methods??

V = vector( 1.0 )
print V.asVec( 3 ) # idk, just something I pulled out of my A (IDK what to define in the vector() class)
# >>> vector( 1.0, 0.0, 0.0 )

what I'm converting can be from anywhere, and I want to support as much as possible...
that's why I'm coming to your guys, since I can minorly understand C++

you guys know more than almost any C++ src could tell me, which is why I ask.

keep in mind, I'm not the only one working on scripts that use this system...
once dev5 of my program is released, it needs to be ready for anyone who wants to add support for a format.

I'm trying to make the interface fully capable on either end.
(pre-transformed (verts ready for animation (*.mdl0, *.dat)), or raw (posed verts (*.obj, *.dae)))

the interface will automatically fill the opposite side once the initial side is filled.
this will make exporting to a format fast and easy, while keeping your imported model properly stored.
(your data will literally be readily handed to you in your script depending on which side you need)

02-20-2014, 06:19 PM
You can read the specs for C++ but basically it only supports signed and unsigned 32 bit and 64 bit float, double, int plus 8 bit byte. But conversion between these don't always make sense for example a byte cannot hold all values of a double.

Your little example of vec1 -> vec3 is straight forward, there are 4 commonly used - with 1 to 4 components with padding (ie vec1 -> vec3) done with 0.0.

The glm template I mentioned does all of these conversions. Data conversion is handled through object constructors eg

glm::dvec3 v3 // 3 component vector each of size double
glm::vec2 = glm::vec2(v3); // convert to 2 component float
glm::vec3 v = glm::vec3(v2,0.0f) // convert to 3 componet float, set extra component to 0.0 float

02-21-2014, 06:56 AM
excuse me for the late reply, I'm kinda busy with my WinXP installation...
(just removed a rootkit while removing all explorer.exe references (I have a new shell))


But conversion between these don't always make sense for example a byte cannot hold all values of a double.
that's where percentage comes in. (depending on the exact conversion needed)

but indeed, I'll take a look into GLM before saying anything else here :)
thanks for that btw. ;)

04-13-2014, 10:03 AM
hey is this the right GLM library:??

also... from your example... glm doesn't look exactly like what I need, but it does look like it contains alot of what I need...

what I mean is pre-defined types... what I need is 1 type with defined references.
since what this class is used for is conversion specifically...

the class stores the data in memory on both ends for use with exporting.

I'm sure you're questioning the "both ends" part...
what I mean there is transformed vs un-transformed.

for example, un-transformed is the data you'd store in GPU-RAM while transformed is... yea, what's displayed... heh

this is for use with the export interface, so you can get data from either side of the interface.
the class, depending on what's needed from the function params you give in your export code, which tell the vertex format you need, is what returns the data you need secifically in it's format.
(you don't do any conversion work in your import or export scripts, all you do is simply hand the data to the interface)

the vector class manages verts, normals (including NBT), colors, and UVs all in one in whatever the required format is.
this is to make co-representation easy in case there so happens to be any conversion work you need to do.

the vector class stores everything in it's original quality (for GL usage and to keep memory low), but makes things easy for the requirements for export or co-rep usage.
(co-rep as in displaying the colors of the normal values with maybe a few modifications)
^ handling normals as color vectors including RGBA