Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

planecollider.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2003 Koblenz University
00006    $Id: planecollider.cpp,v 1.8 2004/04/15 18:34:06 rollmark Exp $
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; version 2 of the License.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 #include "planecollider.h"
00023 
00024 using namespace oxygen;
00025 using namespace salt;
00026 
00027 PlaneCollider::PlaneCollider() : Collider()
00028 {
00029 }
00030 
00031 void PlaneCollider::SetParams(float a, float b, float c, float d)
00032 {
00033     // The plane's normal vector is (a,b,c), and it must have length 1
00034     float l = Vector3f(a,b,c).Length();
00035     if (l != 0)
00036         {
00037             a /= l;
00038             b /= l;
00039             c /= l;
00040             d /= l;
00041         }
00042 
00043     dGeomPlaneSetParams(mODEGeom, a, b, c, d);
00044 }
00045 
00046 bool PlaneCollider::ConstructInternal()
00047 {
00048     if (! Collider::ConstructInternal())
00049         {
00050             return false;
00051         }
00052 
00053     // a plane with normal pointing up, going through the origin
00054     mODEGeom = dCreatePlane(0, 0, 1, 0, 0);
00055 
00056     return (mODEGeom != 0);
00057 }
00058 
00059 void
00060 PlaneCollider::SetParams(const salt::Vector3f& pos, salt::Vector3f normal)
00061 {
00062     normal.Normalize();
00063     float d = pos.Dot(normal);
00064     dGeomPlaneSetParams(mODEGeom, normal.x(), normal.y(), normal.z(), d);
00065 }
00066 
00067 void
00068 PlaneCollider::SetPosition(const salt::Vector3f& /*pos*/)
00069 {
00070     // planes are non placeable geoms
00071 }
00072 
00073 void
00074 PlaneCollider::SetRotation(const Matrix& /*rot*/)
00075 {
00076     // planes are non placeable geoms
00077 }
00078 
00079 float
00080 PlaneCollider::GetPointDepth(const Vector3f& pos)
00081 {
00082     Vector3f worldPos(GetWorldTransform() * pos);
00083     return dGeomPlanePointDepth
00084         (mODEGeom,worldPos[0],worldPos[1],worldPos[2]);
00085 }
00086 
00087 
00088 

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4