// -*- c++ -*- #ifndef INCLUDED_MATH3D_M4D_H #define INCLUDED_MATH3D_M4D_H /* * Math3d - The 3D Computer Graphics Math Library * Copyright (C) 1996-2000 by J.E. Hoffmann * All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: m4d.h,v 1.1 2002/11/18 08:23:01 rst Exp $ */ #ifndef INCLUDED_MATH3D_MATH3DDEF_H #include #endif namespace Math3d { class M3d; class M4x4; /*! * 4-dimensional vector. */ class _CCMATH3D M4d { protected: double d_v[4]; public: M4d() {d_v[0]=d_v[1]=d_v[2]=d_v[3]=0.0;}; M4d(double x, double y, double z, double w) {d_v[0]=x; d_v[1]=y; d_v[2]=z; d_v[3]=w;} M4d(const M3d& A); M4d(const M4d& A); const M4d& operator=(const M4d& A); void zero(); void set(double x, double y, double z, double w) {d_v[0]=x; d_v[1]=y; d_v[2]=z; d_v[3]=w;} void copy(const M4d& A); inline double& operator[](int i); operator double*() {return(d_v);} double& x() {return(d_v[0]);} double& y() {return(d_v[1]);} double& z() {return(d_v[2]);} double& w() {return(d_v[3]);} double& get(int i); M4d operator+(const M4d& A); M4d operator+(); const M4d& operator+=(const M4d& A); M4d operator-(const M4d& A); M4d operator-(); const M4d& operator-=(const M4d& A); M4d operator*(double k); const M4d& operator*=(double k); void neg(); void abs(); void add(const M4d& A, const M4d& B); void sub(const M4d& A, const M4d& B); void scalar(double k); void normalize(); void cartesianize(); M3d cartesianized(); void rationalize(); void homogenize(); void lerp(const M4d& A, const M4d& B, double t); void min(const M4d& m); void max(const M4d& m); void cubic(const M4d& A, const M4d& TA, const M4d& TB, const M4d& B, double t); inline double operator[](int i) const; operator const double*() const {return(d_v);} double x() const {return(d_v[0]);} double y() const {return(d_v[1]);} double z() const {return(d_v[2]);} double w() const {return(d_v[3]);} double get(int i) const; double operator*(const M4d& A) const; bool operator==(const M4d& A) const; bool operator!=(const M4d& A) const; double dot(const M4d& A) const; bool cmp(const M4d& A, double epsilon=EPSILON) const; double squared() const; double length() const; friend class M3d; friend class M4x4; }; inline double& M4d::operator[](int i) { ASSERT(i>=0 && i<4); return(d_v[i]); } inline double M4d::operator[](int i) const { ASSERT(i>=0 && i<4); return(d_v[i]); } extern _CCMATH3D ostream& operator << (ostream& co, const M4d& v); } #endif // INCLUDED_MATH3D_M4D_H