【发布时间】:2012-03-20 12:49:13
【问题描述】:
我正在尝试为三角形类的三个对象设置第二个和第三个角的值。如果显式完成,则如下所示:
triangle_mesh[0].set_vector_point2(vector_anchors[1]);
triangle_mesh[1].set_vector_point3(vector_anchors[1]);
triangle_mesh[1].set_vector_point2(vector_anchors[2]);
triangle_mesh[2].set_vector_point3(vector_anchors[2]);
triangle_mesh[2].set_vector_point2(vector_anchors[3]);
triangle_mesh[0].set_vector_point3(vector_anchors[3]);
这工作!打印这些三角形,我得到(n.b. 第一个角已经设置 - 这不是问题):
triangle0 is ( 0, 0, -1) (1, 0, 0) (-0.5, -0.866025, 0)
triangle1 is ( 0, 0, -1) (-0.5, 0.866025, 0) (1, 0, 0)
triangle2 is ( 0, 0, -1) (-0.5, -0.866025, 0) (-0.5, 0.866025, 0)
不过,首先,这很难看,其次,它必须推广到我要设置三个以上三角形的情况。我的代码是:
for (int longitude = 0; longitude < num_longitudes; longitude++){
SurfaceVector current_anchor = vector_anchors[1 + longitude];
triangle_mesh[longitude].set_vector_point2(current_anchor);
triangle_mesh[(longitude + 1) % num_longitudes].set_vector_point3(current_anchor);
}
*n.b. num_longitudes 是 3*
我已经检查了 一切我能想到的,但是现在当我打印出我的三角形时,我得到了:
triangle0 is ( 0, 0, -1) (-0.5, -0.866025, 0) (-0.5, -0.866025, 0)
triangle1 is ( 0, 0, -1) (-0.5, -0.866025, 0) (-0.5, -0.866025, 0)
triangle2 is ( 0, 0, -1) (-0.5, -0.866025, 0) (-0.5, -0.866025, 0)
有人知道可能出了什么问题吗?!
编辑
三角形上的vector_point变量是指针,设置如下:
void set_vector_point1(SurfaceVector vector_point) { vector_point1 = &vector_point; }
【问题讨论】: