tags:

views:

29

answers:

2

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 .

+1  A: 

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.

Pivot
Thank you for this Pivot.
+1  A: 

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::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.

Tom Andersen
Thank you for this Tom. I'm also wondering whether these are more OpenGL ES 2.0-specific 'constructor' rules now that you mention it. (I don't think pg. 80 of the gold book goes anywhere near what is adequate for what the shorthand rules are for the args.)
It seems like you should go straight to the source—the GLSL ES specification (http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf). Vector and matrix constructors are covered in section 5.4.2, which is page 48 in the version of the spec that I linked to.
Pivot
Thanks Pivot, I'll take a look at that.
Pivot, I had no idea that spec existed. Thank you very much for that. I may end up carrying a printout of that around instead of the book.