Skip to main content
GameDev.net gamedev.net
🔒 Locked

vector class returning valid glVertex3f params

Started by FlyingDemon Apr 19, 2004 at 11:40 PM 3 replies 300+ views
Original Post
FlyingDemon
FlyingDemon
how would i get my vector class to return a valid variable(s) to use in OpenGL. eg. class Vector{ public: float x, y, z; blah... }; how can i make a function that makes it possible to use my vector class like this: Vector vec; glVertex3f(vec); or glVertex3f(vec.ReturnGL3F) to be used instead of glVertex3f(vec.x, vec.y, vec.z); i''ve tried so many different ways but i just cant get it to work.
SiCrane
SiCrane
Did you try something like:

void glVertex(const Vector & vec) {
glVertex3f(vec.x, vec.y, vec.z);
}
FlyingDemon
FlyingDemon
yes, but things get confusing whem im using values from a vector and values from somewere else like 2dvectors (float var[2]) and other raw data that wasn't arranged in vectors. I forgot to put the 3f on the openGl functions and also forgot to remove the 3f on that function, thats how it got confussing.




[edited by - FlyingDemon on April 19, 2004 12:55:56 AM]
Sneftel
Sneftel
How 'bout:

class Vector
{
public:
union
{
struct
{
float x, y, z;
};
float xyz[3];
};
};

Vector vec;
glVertex3fv(vec.xyz);


Unnamed structs aren't technically part of the standard (tho for all I know they were added in c++0x), but both GCC and MSVC++ support them.

"Sneftel is correct, if rather vulgar." --Flarelocke

[edited by - sneftel on April 20, 2004 1:08:47 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.