Trouble with assigning the result of a function to a property
Hi, my issue is that I can't seem to be able to assign a function's return value to an instance of a Class of same type:
vb.net Code:
Dim MTranslate_Z As Matrix3D = Matrix3D.Create_Scale(2, 2, 2)
For Each Vertex As PVector In PTriangle.Vertices
Dim unused As PVector = MTranslate_Z.MultiplyVector(Vertex)
Vertex = unused
Next
More info on the above:
-PTriangle.Vertices is a property that returns an array of PVector objects.
-The "MultiplyVector" Function of the matrix returns a PVector object.
I want to assign the object returned by the function to each object looped trough in the array but it tells me "Unnecessary assignment of a value to Vertex"
I thought of making it a sub and directly change the PVector but I rather keep it as a function, how should I proceed ?
Is it in the PVector Class that I need to add something to allow this ?
Thanks in advance for the help !
Re: Trouble with assigning the result of a function to a property
Vertex is a reference to an object in PTriangle.Vertices.
If you change Vertex to point to your local instance "unused", that will have no effect on the object in PTriangle.Vertices.
You want to change the object that Vertex is referencing, which means you want to change the object in PTriangle.Vertices.
You probably don't want a For Each here, but need to iterate the Vertices collection so you can assign the "unused" reference to the indexed Vertices reference.
I'm not the expert though, so would have to research the best syntax for this.
Re: Trouble with assigning the result of a function to a property
Yeahh, you don't want a for each here.... you want a good ol' fashioned For loop... reference the items in the array through their index and assign the result frmo the function to the indexed element directly:
Code:
For x as integer = 0 to PTriangles.Vertices.Length-1
Dim Vertex As PVector = PTriangles.Vertices(x)
PTriangles.Vertices(x) = MTranslate_Z.MultiplyVector(Vertex)
Next
-tg