user225626
user225626

Reputation: 1099

Question about variable constructors:

If...

vec3 myVec3 = vec3(1.0, 0.0, 0.5); // myVec3 = {1.0, 0.0, 0.5}
vec3 temp = vec3(myVec3); // temp = myVec3
vec2 myVec2 = vec2(myVec3); // myVec2 = {myVec3.x, myVec3.y}

myVec4 = vec4(myVec2, temp, 0.0); // myVec4 = {myVec2.x, myVec2.y, temp.x, 0.0}

Then what does the following represent?

myVec4 = vec4(temp, myVec2, 0.0); // myVec4 =

Thanks .

Upvotes: 0

Views: 144

Answers (2)

Tom Andersen
Tom Andersen

Reputation: 7200

The way I would figure stuff like that out, assuming it compiles and runs, it to use the debugger or printf to see what you get.

On my xode 3.2.x - It does not compile. In fact vec2 myVec2 = vec2(myVec3); also does not compile.

Also: last line has an error which makes sense when you read it.

code.mm:73:0 code.mm:73: error: no matching function for call to 'Vector4<float>::Vector4(vec3&, vec2&, double)'

I have always found the constructor rules for C++ to be pretty complex. Let the compiler tell it like it is.

Upvotes: 1

Pivot
Pivot

Reputation: 3446

If temp is indeed a vec3 as you’ve defined, both of the constructors for myVec4 are illegal, as both contain enough components in the first two arguments to initialize the entire vec4.

Upvotes: 1

Related Questions