/* * PVVMUD a 3D MUD * Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org) * * 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 * */ #include "pvvmud.H" #include "plane.H" CPlane::CPlane(){ m_a = m_b = m_c = m_d = 0.0; } CPlane::CPlane(const CVector & point,const CVector & normal){ m_a = normal.getX(); m_b = normal.getY(); m_c = normal.getZ(); m_d = -(m_a*point.getX()+m_b*point.getY()+m_c*point.getZ()); // Normalize plane double k = 1/sqrt(m_a*m_a+m_b*m_b+m_c*m_c); m_a *= k; m_b *= k; m_c *= k; m_d *= k; } CPlane::CPlane(const CVertex & point,const CVector & normal){ CVector vector(point); *this = CPlane(vector,normal); } CPlane::CPlane(const CVertex & v1,const CVertex & v2,const CVertex & v3){ CVector edge = v2-v1; *this = CPlane(v1,edge.cross(v3-v2)); } double CPlane::distance(const CVector & position){ return (m_a*position.getX()+m_b*position.getY()+m_c*position.getZ()+m_d); } double CPlane::getA() const { return m_a; } double CPlane::getB() const { return m_b; } double CPlane::getC() const { return m_c; } double CPlane::getD() const { return m_d; } ostream& operator<<(ostream&s,const CPlane& p){ return s << "(" << p.getA() << "," << p.getB() << "," << p.getC() << "," << p.getD() << ")"; }