Remap.h
Go to the documentation of this file.00001 #ifndef REMAP_H_
00002 #define REMAP_H_
00003
00004 template<typename Triple>
00005 class TripleRemapXYZ
00006 {
00007 public:
00008 static float& x (Triple& triple)
00009 {
00010 return triple.x();
00011 }
00012 static float& y (Triple& triple)
00013 {
00014 return triple.y();
00015 }
00016 static float& z (Triple& triple)
00017 {
00018 return triple.z();
00019 }
00020 };
00021
00022 template<typename Triple>
00023 class TripleRemapYZX
00024 {
00025 public:
00026 static float& x (Triple& triple)
00027 {
00028 return triple.y();
00029 }
00030 static float& y (Triple& triple)
00031 {
00032 return triple.z();
00033 }
00034 static float& z (Triple& triple)
00035 {
00036 return triple.x();
00037 }
00038 };
00039
00040 template<typename Triple>
00041 class TripleRemapZXY
00042 {
00043 public:
00044 static float& x (Triple& triple)
00045 {
00046 return triple.z();
00047 }
00048 static float& y (Triple& triple)
00049 {
00050 return triple.x();
00051 }
00052 static float& z (Triple& triple)
00053 {
00054 return triple.y();
00055 }
00056 };
00057
00058 const float arrowhead_length = 16;
00059 const float arrowhead_radius = 4;
00060
00061 inline void draw_arrowline (const float length, PointVertex* line, const std::size_t axis)
00062 {
00063 (*line++).vertex = vertex3f_identity;
00064 (*line).vertex = vertex3f_identity;
00065 vertex3f_to_array((*line).vertex)[axis] = length - arrowhead_length;
00066 }
00067
00068 template<typename VertexRemap, typename NormalRemap>
00069 inline void draw_arrowhead (const std::size_t segments, const float length, FlatShadedVertex* vertices, VertexRemap,
00070 NormalRemap)
00071 {
00072 std::size_t head_tris = (segments << 3);
00073 const double head_segment = c_2pi / head_tris;
00074 for (std::size_t i = 0; i < head_tris; ++i) {
00075 {
00076 FlatShadedVertex& point = vertices[i * 6 + 0];
00077 VertexRemap::x(point.vertex) = length - arrowhead_length;
00078 VertexRemap::y(point.vertex) = arrowhead_radius * static_cast<float> (cos(i * head_segment));
00079 VertexRemap::z(point.vertex) = arrowhead_radius * static_cast<float> (sin(i * head_segment));
00080 NormalRemap::x(point.normal) = arrowhead_radius / arrowhead_length;
00081 NormalRemap::y(point.normal) = static_cast<float> (cos(i * head_segment));
00082 NormalRemap::z(point.normal) = static_cast<float> (sin(i * head_segment));
00083 }
00084 {
00085 FlatShadedVertex& point = vertices[i * 6 + 1];
00086 VertexRemap::x(point.vertex) = length;
00087 VertexRemap::y(point.vertex) = 0;
00088 VertexRemap::z(point.vertex) = 0;
00089 NormalRemap::x(point.normal) = arrowhead_radius / arrowhead_length;
00090 NormalRemap::y(point.normal) = static_cast<float> (cos((i + 0.5) * head_segment));
00091 NormalRemap::z(point.normal) = static_cast<float> (sin((i + 0.5) * head_segment));
00092 }
00093 {
00094 FlatShadedVertex& point = vertices[i * 6 + 2];
00095 VertexRemap::x(point.vertex) = length - arrowhead_length;
00096 VertexRemap::y(point.vertex) = arrowhead_radius * static_cast<float> (cos((i + 1) * head_segment));
00097 VertexRemap::z(point.vertex) = arrowhead_radius * static_cast<float> (sin((i + 1) * head_segment));
00098 NormalRemap::x(point.normal) = arrowhead_radius / arrowhead_length;
00099 NormalRemap::y(point.normal) = static_cast<float> (cos((i + 1) * head_segment));
00100 NormalRemap::z(point.normal) = static_cast<float> (sin((i + 1) * head_segment));
00101 }
00102
00103 {
00104 FlatShadedVertex& point = vertices[i * 6 + 3];
00105 VertexRemap::x(point.vertex) = length - arrowhead_length;
00106 VertexRemap::y(point.vertex) = 0;
00107 VertexRemap::z(point.vertex) = 0;
00108 NormalRemap::x(point.normal) = -1;
00109 NormalRemap::y(point.normal) = 0;
00110 NormalRemap::z(point.normal) = 0;
00111 }
00112 {
00113 FlatShadedVertex& point = vertices[i * 6 + 4];
00114 VertexRemap::x(point.vertex) = length - arrowhead_length;
00115 VertexRemap::y(point.vertex) = arrowhead_radius * static_cast<float> (cos(i * head_segment));
00116 VertexRemap::z(point.vertex) = arrowhead_radius * static_cast<float> (sin(i * head_segment));
00117 NormalRemap::x(point.normal) = -1;
00118 NormalRemap::y(point.normal) = 0;
00119 NormalRemap::z(point.normal) = 0;
00120 }
00121 {
00122 FlatShadedVertex& point = vertices[i * 6 + 5];
00123 VertexRemap::x(point.vertex) = length - arrowhead_length;
00124 VertexRemap::y(point.vertex) = arrowhead_radius * static_cast<float> (cos((i + 1) * head_segment));
00125 VertexRemap::z(point.vertex) = arrowhead_radius * static_cast<float> (sin((i + 1) * head_segment));
00126 NormalRemap::x(point.normal) = -1;
00127 NormalRemap::y(point.normal) = 0;
00128 NormalRemap::z(point.normal) = 0;
00129 }
00130 }
00131 }
00132
00133 #endif