# Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = 0.0f,0.0f,5.0f ?

OpenTK 0.9.8-1 linux Ubuntu 9.04 Mono

```Grid.points.Add(new Vector3(0.0f,0.0f,0.0f);
Vector3 Center=new Vector3(50.0f,50.0f,0.0f); //Shift to Center
foreach (Vector3 pG in Grid.points) {
pG.Sub(ref Center);//.Sub(Center);
System.Console.WriteLine(pG.ToString());
}
return Grid;```

Orig Grid
(-50, -50, 0)
Call outside Grid generating static function(return Grid).

```System.Console.WriteLine("Grid +5 Z");
foreach (Vector3 v3Grid in Grid.points) {
System.Console.WriteLine(v3Grid.ToString());
}```

Grid +5 Z
(0, 0, 5)

```        #region public void Add()

/// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
{
this.X += right.X;
this.Y += right.Y;
this.Z += right.Z;
}```

Why X is overwrited instead of adding? Also there is not possible to input data directly in .X .Y .Z vars in foreach reference statement. Maybe it's possible to add some kind of "static" to .X .Y .Z?

## Comment viewing options

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

this.X += right.X;

.. is equivalent to ..

this.X = this.X + right.X;

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

i mean action not op i know what += mean but sometimes this have overload meaning.. and i can't find what's wrong ....
Add/Sub after "Orig Grid" seems to operate on data before "centered"("Orig Grid")..
well not exactly overwrited....
Raw Data (generated in static function)
(0, 0, 0)
(100, 0, 0)
(100, 100, 0)
Orig Grid (Add ref Center inside static function)
(-50, -50, 0)
(50, -50, 0)
(50, 50, 0)
v3f.Sub(0,0,-5f on returned data from static function in non-static function)
Grid +5 Z
(0, 0, 5)
(100, 0, 5)
(100, 100, 5)
(0, 100, 5)
v3f.Add(0,0,5f on returned data from static function in non-static function);
Grid +5 Z
(0, 0, 5)
(100, 0, 5)
(100, 100, 5)

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

Try removing all "static" everywhere. Why are you using static data/methods..?

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

to not call new every time it's part of helper toolkit that is not so dynamic to create every time(C++ background :)). it will be complex to keep code readable without static calls and very mesy to create 3-4 new's to call single function.

and even not using static result is same :(

```				MeshLib MeshLibrary=new MeshLib();
MeshLibrary.hh=new LightsBuilderTechDemo.MeshLib.Helpers();
Mesh Grid= MeshLibrary.hh.CreateGrid(100.0f,100.0f,1.0f);
System.Console.WriteLine("Grid +5 Z");```

Grid +5 Z
(0, 0, 5)

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

Vector3 is a value type, not a reference type. Your foreach loops operate on copies: they do not modify the original data in Grid.points.

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

thnx i forgetting basics. (i really starting to literally hate C# concepts).
i will try workaround with (for/with)..

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

```for (int i=0;i<Grid.points.Count;i++) {
Vector3.Sub(Grid.points[i],Center);
}```

same... uhh i feel like newbie . i understand this is not C# tutorials site but can anyone provide a tip in correct way to implement collections of Vector3 variables to be properly accessed via foreach or such? or i need implement IEnumerable?

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

```for (int i=0; i < Grid.points.Count; i++) {
Grid.points[i] = Vector3.Sub(Grid.points[i],Center);
}```

### Re: Why -50.0f,-50.0f,0.0f Vector3.Add 0.0f,0.0f,5.0f = ...

thanks fiddler it works. quite surprised that Grid.points[i].Sub(Grid.points[i],Center) / Vector3.Sub(ref Grid.points[i],ref Center, out Grid.points[i] ) won't... need in future rethink engine struct.