Original Post
I am trying to write basic operation of 3d vectors represented by arrays.
float pointa[3]={2.0f, 1.5f, 3.0f};
float pointb[3]={2.4f, 2.9f, -0.5f };
float pointc[3];
Given pointa and pointb, I want to make pointc to be the sum of pinta and pointb by using a function with pointers or reference (not by return value). What I want is like:
void Add(float pointp[3], float pointq[3], float* out)
{
out[0] = pointp[0] + pointq[0];
out[1] = pointp[1] + pointq[1];
out[2] = pointp[2] + pointq[2];
}
But even if I write
Add(pointa, pointb, pointc);
it seems pointc does not become the desired sum;
What's wrong with this? If I write
void AddVersion2(float pointp[3], float pointq[3], float & out0, float & out1, float & out2)
{
out0 = pointp[0] + pointq[0];
out1 = pointp[1] + pointq[1];
out2 = pointp[2] + pointq[2];
}
then
AddVersion2(pointa, pointb, pointc[0], pointc[1], pointc[2])
should work, but I want to avoid the long parameters.
But how can I write simpler function using array?
If I use a struct for definition of a 3d-vector (x, y, z components) and if I write a simple function like Add(pointa, pointb, pointc) by reference, then it works.
Should I avoid array representation of 3-d points?
James
Edited by - jamesh on 2/23/00 1:19:58 PM