]> git.mxchange.org Git - flightgear.git/commitdiff
Initial revision.
authorcurt <curt>
Wed, 27 Aug 1997 21:31:17 +0000 (21:31 +0000)
committercurt <curt>
Wed, 27 Aug 1997 21:31:17 +0000 (21:31 +0000)
Main/views.c [new file with mode: 0644]
Main/views.h [new file with mode: 0644]

diff --git a/Main/views.c b/Main/views.c
new file mode 100644 (file)
index 0000000..154051e
--- /dev/null
@@ -0,0 +1,135 @@
+/**************************************************************************
+ * views.c -- data structures and routines for managing and view parameters.
+ *
+ * Written by Curtis Olson, started August 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include "views.h"
+
+#include "../constants.h"
+
+#include "../Flight/flight.h"
+#include "../Math/mat3.h"
+#include "../Math/polar.h"
+#include "../Scenery/scenery.h"
+
+
+/* Initialize a view structure */
+void fgViewInit(struct VIEW *v) {
+    v->view_offset = 0.0;
+    v->goal_view_offset = 0.0;
+}
+
+
+/* Update the view parameters */
+void fgViewUpdate(struct FLIGHT *f, struct VIEW *v) {
+    MAT3vec vec, forward;
+    MAT3mat R, TMP, UP, LOCAL, VIEW;
+
+    /* calculate view position in current FG view coordinate system */
+    v->view_pos = fgPolarToCart(FG_Longitude, FG_Lat_geocentric, 
+                            FG_Radius_to_vehicle * FEET_TO_METER + 1.0);
+    v->view_pos.x -= scenery.center.x;
+    v->view_pos.y -= scenery.center.y;
+    v->view_pos.z -= scenery.center.z;
+
+    printf("View pos = %.4f, %.4f, %.4f\n", 
+          v->view_pos.x, v->view_pos.y, v->view_pos.z);
+
+    /* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */
+    MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
+    MAT3rotate(R, vec, FG_Phi);
+    /* printf("Roll matrix\n"); */
+    /* MAT3print(R, stdout); */
+
+    MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
+    /* MAT3mult_vec(vec, vec, R); */
+    MAT3rotate(TMP, vec, FG_Theta);
+    /* printf("Pitch matrix\n"); */
+    /* MAT3print(TMP, stdout); */
+    MAT3mult(R, R, TMP);
+
+    MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
+    /* MAT3mult_vec(vec, vec, R); */
+    /* MAT3rotate(TMP, vec, FG_Psi - FG_PI_2); */
+    MAT3rotate(TMP, vec, -FG_Psi);
+    /* printf("Yaw matrix\n");
+    MAT3print(TMP, stdout); */
+    MAT3mult(LOCAL, R, TMP);
+    /* printf("LOCAL matrix\n"); */
+    /* MAT3print(LOCAL, stdout); */
+
+    /* Derive the local UP transformation matrix based on *geodetic*
+     * coordinates */
+    MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
+    MAT3rotate(R, vec, FG_Longitude);     /* R = rotate about Z axis */
+    /* printf("Longitude matrix\n"); */
+    /* MAT3print(R, stdout); */
+
+    MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
+    MAT3mult_vec(vec, vec, R);
+    MAT3rotate(TMP, vec, -FG_Latitude);  /* TMP = rotate about X axis */
+    /* printf("Latitude matrix\n"); */
+    /* MAT3print(TMP, stdout); */
+
+    MAT3mult(UP, R, TMP);
+    /* printf("Local up matrix\n"); */
+    /* MAT3print(UP, stdout); */
+
+    MAT3_SET_VEC(v->local_up, 1.0, 0.0, 0.0);
+    MAT3mult_vec(v->local_up, v->local_up, UP);
+
+    printf("    Local Up = (%.4f, %.4f, %.4f)\n", 
+          v->local_up[0], v->local_up[1], v->local_up[2]);
+    
+    /* Alternative method to Derive local up vector based on
+     * *geodetic* coordinates */
+    /* alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0); */
+    /* printf("    Alt Up = (%.4f, %.4f, %.4f)\n", 
+       alt_up.x, alt_up.y, alt_up.z); */
+
+    /* Derive the VIEW matrix */
+    MAT3mult(VIEW, LOCAL, UP);
+    /* printf("VIEW matrix\n"); */
+    /* MAT3print(VIEW, stdout); */
+
+    /* generate the current up, forward, and fwrd-view vectors */
+    MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
+    MAT3mult_vec(v->view_up, vec, VIEW);
+
+    MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
+    MAT3mult_vec(forward, vec, VIEW);
+    printf("Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
+          forward[2]);
+
+    MAT3rotate(TMP, v->view_up, v->view_offset);
+    MAT3mult_vec(v->view_forward, forward, TMP);
+
+}
+
+
+/* $Log$
+/* Revision 1.1  1997/08/27 21:31:17  curt
+/* Initial revision.
+/*
+ */
diff --git a/Main/views.h b/Main/views.h
new file mode 100644 (file)
index 0000000..7c7ed83
--- /dev/null
@@ -0,0 +1,61 @@
+/**************************************************************************
+ * views.h -- data structures and routines for managing and view parameters.
+ *
+ * Written by Curtis Olson, started August 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef VIEWS_H
+#define VIEWS_H
+
+
+#include "../types.h"
+#include "../Flight/flight.h"
+#include "../Math/mat3.h"
+
+
+/* Define a structure containing view information */
+struct VIEW {
+    struct fgCartesianPoint view_pos;
+    MAT3vec local_up, view_up, view_forward;
+    double view_offset, goal_view_offset;
+};
+
+
+extern struct VIEW current_view;
+
+
+/* Initialize a view structure */
+void fgViewInit(struct VIEW *v);
+
+/* Update the view parameters */
+void fgViewUpdate(struct FLIGHT *f, struct VIEW *v);
+
+
+#endif /* VIEWS_H */
+
+
+/* $Log$
+/* Revision 1.1  1997/08/27 21:31:18  curt
+/* Initial revision.
+/*
+ */