/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : tools.h Component : 3D visualisation Fonctionality : contains specifications for objects used in 3D visualisation ******************************************************************/ #ifndef __tools_H #define __tools_H #include #define epsilon 1e-9 class Matrix; class Vector; class Matrix2; class Vector2; class Facette; enum t_boolean { FALSE, TRUE }; struct position { double x; double y; double z; }; struct position_plan { int x; int y; }; struct position_plan_double { double x; double y; }; struct direction { double dx; double dy; double dz; }; struct plan { double a; double b; double c; double d; }; /* a^2+b^2+c^2 = 1 and a>0 */ class Facette { public: Facette (); Facette (position anOrg, position p0, position p1, position p2, position p3); Facette (position anOrg, position p0, position p1, position p2, position p3, position p4, position p5); ~Facette (); position point[6]; int nbPoints; void set (position anOrg, position p0, position p1, position p2, position p3); void set (position anOrg, position p0, position p1, position p2, position p3, position p4, position p5); direction getNormalDirection (); Vector getNormalVector (); protected: position org; plan facettePlan; }; class Vector { public: Vector (); Vector (double x, double y, double z); ~Vector (); void set (double x, double y, double z); void display (); double x(); double y(); double z(); void scal (double k); friend Vector operator+ (Vector& v1, Vector& v2); friend Vector operator- (Vector& v1, Vector& v2); friend Vector operator* (double k, Vector& v); friend Vector operator* (Matrix& m, Vector& v); protected: double v[3]; }; class Matrix { public: Matrix (); Matrix (double xx, double xy, double xz, double yx, double yy, double yz, double zx, double zy, double zz); ~Matrix (); void display (); double xx(); double xy(); double xz(); double yx(); double yy(); double yz(); double zx(); double zy(); double zz(); void scal (double k); void tr (); int inverse (); // return 0 if non inversable else 1 void set_rotation (double teta, double phi); // void set_matrix (Matrix& m); friend Matrix operator+ (Matrix& m1, Matrix& m2); friend Matrix operator- (Matrix& m1, Matrix& m2); friend Matrix operator* (Matrix& m1, Matrix& m2); friend Matrix operator* (double k, Matrix& m); friend Matrix tr (Matrix& m); friend double det (Matrix& m); friend Vector operator* (Matrix& m, Vector& v); friend Matrix inverse (Matrix& m); friend double mult_lin_col (Matrix& m1, int lin1, Matrix& m2, int col2); protected: double m[3][3]; }; class Matrix2; class Vector2 { public: Vector2 (); Vector2 (double x, double y); ~Vector2 (); void display (); double x(); double y(); void scal (double k); friend Vector2 operator+ (Vector2& v1, Vector2& v2); friend Vector2 operator- (Vector2& v1, Vector2& v2); friend Vector2 operator* (double k, Vector2& v); friend Vector2 operator* (Matrix2& m, Vector2& v); protected: double v[2]; }; class Matrix2 { public: Matrix2 (); Matrix2 (double xx, double xy, double yx, double yy ); ~Matrix2 (); void display (); double xx(); double xy(); double yx(); double yy(); void scal (double k); void tr (); int inverse (); // return 0 if non inversable else 1 friend Matrix2 operator+ (Matrix2& m1, Matrix2& m2); friend Matrix2 operator- (Matrix2& m1, Matrix2& m2); friend Matrix2 operator* (Matrix2& m1, Matrix2& m2); friend Matrix2 operator* (double k, Matrix2& m); friend Matrix2 tr (Matrix2& m); friend double det (Matrix2& m); friend Vector2 operator* (Matrix2& m, Vector2& v); friend Matrix2 inverse (Matrix2& m); friend double mult_lin_col_2x2 (Matrix2& m1, int lin1, Matrix2& m2, int col2); protected: double m[2][2]; }; void swap_double (double& a, double& b); double det2x2 (double a, double c, double b, double d); direction get_direction_from_2_positions (position p1, position p2); plan get_plan_from_direction_and_position (direction d, position p); void get_teta_phi_from_direction (direction viewed_direction, double* teta, double* phi); double get_dist_positions (position p1, position p2); position projection_on_plan (position pos, plan proj_plan); double maxim (double a, double b); double minim (double a, double b); double get_norm (double a, double b, double c); t_boolean equal (double x, double y); float cosDeg(int angle); float sinDeg(int angle); position init_position (); position_plan double_to_int (position_plan_double input); plan get_plan_from_3_positions (position p1, position p2, position p3); t_boolean belong_to_plan (position pos, plan p); position setPosition (double ix, double iy, double iz); #endif