我建议改变一下你如何查看变换。
使transform
一个类,使它不需要其他类派生它。所有需要转换点的数据都可以保存在这个类中。
添加构造缩放变换,平移变换和旋转变换的函数。
添加函数来乘法变换,并乘以一个变换和一个点。这些可以是用于转换其他形状的构件。
根据需要添加用于转换其他形状的函数。
在骨骼形态,
class transform { ... };
class position { ... };
// tag structs
struct rotation_about_x {};
struct rotation_about_y {};
struct rotation_about_z {};
// Functions to construct transforms
transform construct_scale_transform(double scale_factor) { ... };
transform construct_translation_transform(position pos) { ... };
transform construct_rotation_transform(double angle, rotation_about_x tag) { ... };
transform construct_rotation_transform(double angle, rotation_about_y tag) { ... };
transform construct_rotation_transform(double angle, rotation_about_z tag) { ... };
// Function to transform a point.
position operator*(transform const& t, position const& p) { ... }
// Function to multiply transforms.
transform operator*(transform const& t1, transform const& t2) { ... }
// Functions to apply transforms to other objects.
triangle operator*(transform const& tr, triangle const& t) { ... }
...
用法:
transform t1 = construct_rotation_transform(10, rotation_about_x{});
transform t2 = construct_translation_transform({20, 10, 0});
position p1{100, 200, 30};
position p2 = t1*t2*p1;
triangle tr1{ ... }
triangle tr2 = t1*t2*tr1;
如果你要使用相同的组合变换多次,计算加起来变换第一和将其用于所有转换。
transform t1 = construct_rotation_transform(10, rotation_about_x{});
transform t2 = construct_rotation_transform(5, rotation_about_y{});
transform t3 = construct_translation_transform({20, 10, 0});
tranform tc = t1 * t2 * t3;
position p1{100, 200, 30};
position p2 = tc*p1;
triangle tr1{ ... }
triangle tr2 = tc*tr1;
那么,你要么具有外部世界可见的功能(其中包括派生类),要么将其隐藏给每个人。 – DeiDei
可以apply_transforms三角形类上的公共静态? –
我建议你不要再为此烦恼了。你困扰我的字符串类,它与几何无关,也可以访问这个函数吗? –