25 #include "g-map-vertex.hh"
30 using namespace GMap3d;
38 static float fpmod(
float div,
float mod)
40 float res = fmod(div,mod);
41 return (res < 0 ? res + mod : res);
49 static CVertex multMatrixVector(
const float mat[3][3],
float x,
float y,
float z)
52 mat[0][0] * x + mat[0][1] * y + mat[0][2] * z,
53 mat[1][0] * x + mat[1][1] * y + mat[1][2] * z,
54 mat[2][0] * x + mat[2][1] * y + mat[2][2] * z);
61 static void createRotationMatrix(
float mat[3][3],
float angle,
const CVertex & axe)
63 float cos_a = cosf(angle);
64 float sin_a = sinf(angle);
65 float inv_cos = 1. - cos_a;
68 mat[0][0] = cos_a + (inv_cos * axe.getX() * axe.getX());
69 mat[0][1] = (inv_cos * axe.getX() * axe.getY()) - (sin_a * axe.getZ());
70 mat[0][2] = (inv_cos * axe.getX() * axe.getZ()) + (sin_a * axe.getY());
72 mat[1][0] = (inv_cos * axe.getX() * axe.getY()) + (sin_a * axe.getZ());
73 mat[1][1] = cos_a + (inv_cos * axe.getY() * axe.getY());
74 mat[1][2] = (inv_cos * axe.getY() * axe.getZ()) - (sin_a * axe.getX());;
76 mat[2][0] = (inv_cos * axe.getX() * axe.getZ()) - (sin_a * axe.getY());
77 mat[2][1] = (inv_cos * axe.getY() * axe.getZ()) + (sin_a * axe.getX());
78 mat[2][2] = cos_a + (inv_cos * axe.getZ() * axe.getZ());
87 float alpha_rad = rad(fpmod(eye_pos -> getRotationAlpha() - 90.0, 360));
88 float beta_rad = rad(fpmod(eye_pos -> getRotationBeta() + 90.0, 360));
89 float distance = eye_pos -> getDistance();
91 eye_coord.setX(pt_view -> getLookAt(0) + distance * cosf(alpha_rad) * sinf(beta_rad));
92 eye_coord.setY(pt_view -> getLookAt(1) + distance * sinf(alpha_rad) * sinf(beta_rad));
93 eye_coord.setZ(pt_view -> getLookAt(2) + distance * cosf(beta_rad));
100 CVertex CControler::calculEyePosition(
TViewId AView)
134 if (alpha == 0) alpha = eye_pos -> getAngleRotation();
135 if (!positive) alpha = -alpha;
138 CVertex cam_y(pt_view -> getLookAt(0) -
eye_coord.getX(),
139 pt_view -> getLookAt(1) -
eye_coord.getY(),
140 pt_view -> getLookAt(2) -
eye_coord.getZ());
143 float rotation_mat[3][3];
144 createRotationMatrix(rotation_mat, rad(alpha), OZ);
145 CVertex coord_pt_view = multMatrixVector(rotation_mat, cam_y.getX(),cam_y.getY(),cam_y.getZ() );
149 pt_view -> setLookAt(0,coord_pt_view.getX());
150 pt_view -> setLookAt(1,coord_pt_view.getY());
151 pt_view -> setLookAt(2,coord_pt_view.getZ());
154 eye_pos -> setRotationAlpha(fpmod(eye_pos -> getRotationAlpha() + alpha,360));
168 if (beta == 0) beta = eye_pos -> getAngleRotation();
169 if (!positive) beta = -beta;
172 CVertex cam_y(pt_view -> getLookAt(0) -
eye_coord.getX(),
173 pt_view -> getLookAt(1) -
eye_coord.getY(),
174 pt_view -> getLookAt(2) -
eye_coord.getZ());
177 CVertex axe_de_rotation = OZ * cam_y;
178 axe_de_rotation.normalize();
180 float rotation_mat[3][3];
181 createRotationMatrix(rotation_mat, rad(-beta), axe_de_rotation);
182 CVertex coord_pt_view = multMatrixVector(rotation_mat, cam_y.getX(),cam_y.getY(),cam_y.getZ() );
186 pt_view -> setLookAt(0,coord_pt_view.getX());
187 pt_view -> setLookAt(1,coord_pt_view.getY());
188 pt_view -> setLookAt(2,coord_pt_view.getZ());
191 eye_pos -> setRotationBeta(fpmod(eye_pos -> getRotationBeta() + beta,360));
207 if (coeff == 0) coeff = eye_pos -> getPasAvancement();
208 if (!positive) coeff = -coeff;
210 CVertex direction(pt_view -> getLookAt(0) -
eye_coord.getX(),
211 pt_view -> getLookAt(1) -
eye_coord.getY(),
212 pt_view -> getLookAt(2) -
eye_coord.getZ());
214 direction.normalize();
218 pt_view -> setLookAt(0,pt_view -> getLookAt(0) + direction.getX());
219 pt_view -> setLookAt(1,pt_view -> getLookAt(1) + direction.getY());
220 pt_view -> setLookAt(2,pt_view -> getLookAt(2) + direction.getZ());
233 if (coeff == 0) coeff = eye_pos -> getPasAvancement();
234 if (!positive) coeff = -coeff;
236 CVertex avant(pt_view -> getLookAt(0) -
eye_coord.getX(),
237 pt_view -> getLookAt(1) -
eye_coord.getY(),
238 pt_view -> getLookAt(2) -
eye_coord.getZ());
240 CVertex direction=avant*OZ;
241 direction.normalize();
245 pt_view -> setLookAt(0,pt_view -> getLookAt(0) + direction.getX());
246 pt_view -> setLookAt(1,pt_view -> getLookAt(1) + direction.getY());
247 pt_view -> setLookAt(2,pt_view -> getLookAt(2) + direction.getZ());
259 if (!positive) coeff = -coeff;
260 pt_view -> setLookAt(0,pt_view -> getLookAt(0) + coeff);
268 if (!positive) coeff = -coeff;
269 pt_view -> setLookAt(1,pt_view -> getLookAt(1) + coeff);
278 if (!positive) coeff = -coeff;
279 pt_view -> setLookAt(2,pt_view -> getLookAt(2) + coeff);