Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavoir for single value constructor in Vec3f and Mesh.vertex(). Unify? #32

Open
mantaraya36 opened this issue Feb 4, 2020 · 20 comments

Comments

@mantaraya36
Copy link
Contributor

From karl:

Compare to the behavior of the vertex() call on Mesh. vertex(1.0) adds the vertex {1.0, 0.0, .0.0}. vertex(1.0, 2.0) adds the vertex {1.0, 2.0, 0.0}. but Vec3f(1.0) makes {1.0, 1.0, 1.0}?

@younkhg
Copy link
Contributor

younkhg commented Feb 6, 2020

Mesh::vertex(x, y) is useful for 2D drawing, and z=0 is desired in that case
In that sense Mesh::vertex(x) being (x, 0, 0) makes sense for 1D drawing, but do we do 1D drawing? I think Mesh::vertex(x) can be removed

Vec3f(x) being (x, x, x) can be convenient and intuitive for graphics people since it matches behavior of GLSL vec3 v = vec3(x) = (x, x, x), but in GLSL vec3 does not allow vec3(x, y). One param case is the only special case and other times you have to give all three numbers.

If Vec3f(x) results (x, 0, 0) that can also be reasonable option. I think for this one we can choose one. I'd vote for leaving as it is for compatibility.

Vec3f(x, y) results (x, y, x) and this is the most weird and confusing part in this topic. The Vec::set methods are where this behavior comes from:

Vec& set(const T& v1, const T& v2) { return set(v1, v2, v1, v1, v1, v1); }
/// Set first 3 elements
Vec& set(const T& v1, const T& v2, const T& v3) {
return set(v1, v2, v3, v1, v1, v1);
}
/// Set first 4 elements
Vec& set(const T& v1, const T& v2, const T& v3, const T& v4) {
return set(v1, v2, v3, v4, v1, v1);
}
/// Set first 5 elements
Vec& set(const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) {
return set(v1, v2, v3, v4, v5, v1);
}
/// Set first 6 elements
Vec& set(const T& v1, const T& v2, const T& v3, const T& v4, const T& v5,
const T& v6) {
switch (N) {
default:
(*this)[5] = v6;
case 5:
(*this)[4] = v5;
case 4:
(*this)[3] = v4;
case 3:
(*this)[2] = v3;
case 2:
(*this)[1] = v2;
case 1:
(*this)[0] = v1;
}
return *this;
}

These set calls I think need further discussion.

@LancePutnam
Copy link
Member

LancePutnam commented Feb 6, 2020

I see no signature Mesh::vertex(float x), so maybe Mesh::vertex(const Vertex& v) is called implicity? If I do mesh.vertex(1), it adds {1,1,1}.

I strongly agree to leave Vec(x) as {x,x,x} for backwards/GLSL compatibility.

You should also pull changes from AlloSystem every so often. The Vec::set functions where fixed several months ago: https://github.com/AlloSphere-Research-Group/AlloSystem/blob/646bac1232d230f61dbdaaef38327de1a244b43f/allocore/allocore/math/al_Vec.hpp#L193

There are probably more fixes that could be pulled in.

I would not make Mesh dependent on OpenGL, especially if just for the primitive types. You are not always needing rendering when working with meshes.

@konhyong
Copy link
Contributor

konhyong commented Feb 6, 2020 via email

@kybr
Copy link
Member

kybr commented Feb 7, 2020 via email

@younkhg
Copy link
Contributor

younkhg commented Feb 7, 2020

We can put explicit in front of the constructor and make it compile error. That will also make mesh.vertex(1.0) a compile error.

@konhyong
Copy link
Contributor

konhyong commented Feb 7, 2020 via email

@kybr
Copy link
Member

kybr commented Feb 7, 2020 via email

@grrrwaaa
Copy link
Member

grrrwaaa commented Feb 8, 2020 via email

@kybr
Copy link
Member

kybr commented Feb 8, 2020 via email

@grrrwaaa
Copy link
Member

grrrwaaa commented Feb 8, 2020 via email

@younkhg
Copy link
Contributor

younkhg commented Feb 8, 2020

v += 1 could look weird but sometimes v *= 0.5 is quite useful

@kybr
Copy link
Member

kybr commented Feb 8, 2020 via email

@younkhg
Copy link
Contributor

younkhg commented Feb 8, 2020 via email

@kybr
Copy link
Member

kybr commented Feb 9, 2020 via email

@younkhg
Copy link
Contributor

younkhg commented Feb 9, 2020

I did not have confusion about what the current += does. I was saying if we want some other possibly more meaningful thing there's one option ("can be") of making it work on the magnitude. (which I don't think is better than current functionality)

@kybr
Copy link
Member

kybr commented Feb 9, 2020 via email

@kybr
Copy link
Member

kybr commented Feb 9, 2020 via email

@younkhg
Copy link
Contributor

younkhg commented Feb 9, 2020

I think it is interesting. We learn that a vector has magnitude and direction, and the magnitude approach will operate on the one of the component directly.

Then we can document the code like "operations with scalar work as if the scalar is operated on the magnitude"

@matthewjameswright
Copy link
Member

matthewjameswright commented Feb 9, 2020 via email

@LancePutnam
Copy link
Member

v + x was implemented as v + Vec3(x, x, x) to be compatible with GLSL. This often comes in handy, for instance applying a smooth step to a vector vv(3.-2.*v). Graham is right that Vec ops are more array-oriented. I have never seen anywhere, in code or math, where v + x means v (|v|+x)/|v|.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants