SolidData.cpp

Go to the documentation of this file.
00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Physics Abstraction Layer                                        *
00004  * Copyright (C) 2004-2005                                               *
00005  * Alan Fischer  alan.fischer@gmail.com                                  *
00006  * Andres Reinot  andres@reinot.com                                      *
00007  * Tyler Streeter  tylerstreeter@gmail.com                               *
00008  * All rights reserved.                                                  *
00009  * Web: opal.sourceforge.net                                             *
00010  *                                                                       *
00011  * This library is free software; you can redistribute it and/or         *
00012  * modify it under the terms of EITHER:                                  *
00013  *   (1) The GNU Lesser General Public License as published by the Free  *
00014  *       Software Foundation; either version 2.1 of the License, or (at  *
00015  *       your option) any later version. The text of the GNU Lesser      *
00016  *       General Public License is included with this library in the     *
00017  *       file license-LGPL.txt.                                          *
00018  *   (2) The BSD-style license that is included with this library in     *
00019  *       the file license-BSD.txt.                                       *
00020  *                                                                       *
00021  * This library is distributed in the hope that it will be useful,       *
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024  * license-LGPL.txt and license-BSD.txt for more details.                *
00025  *                                                                       *
00026  *************************************************************************/
00027 
00028 #include "SolidData.h"
00029 #include "BoxShapeData.h"
00030 #include "SphereShapeData.h"
00031 #include "CapsuleShapeData.h"
00032 #include "PlaneShapeData.h"
00033 #include "MeshShapeData.h"
00034 
00035 namespace opal
00036 {
00037         SolidData::SolidData()
00038         {
00039                 enabled = defaults::solid::enabled;
00040                 name = "";
00041                 sleeping = defaults::solid::sleeping;
00042                 sleepiness = defaults::solid::sleepiness;
00043                 isStatic = defaults::solid::isStatic;
00044                 // Leave the transform as an identity matrix.
00045                 // "globalLinearVel" is already initialized in its constructor.
00046                 // "globalAngularVel" is already initialized in its constructor.
00047                 linearDamping = defaults::solid::linearDamping;
00048                 angularDamping = defaults::solid::angularDamping;
00049                 // The Shape list doesn't need to be initialized.
00050         }
00051 
00052         SolidData::SolidData(const SolidData& data)
00053         {
00054                 (*this) = data;
00055         }
00056 
00057         SolidData::~SolidData()
00058         {
00059                 destroyShapes();
00060         }
00061 
00062         void SolidData::addShape(const ShapeData& data)
00063         {
00064                 ShapeData* newShape = NULL;
00065 
00066                 switch(data.getType())
00067                 {
00068                         case BOX_SHAPE:
00069                         {
00070                                 newShape = new BoxShapeData((BoxShapeData&)data);
00071                                 break;
00072                         }
00073                         case SPHERE_SHAPE:
00074                         {
00075                                 newShape = new SphereShapeData((SphereShapeData&)data);
00076                                 break;
00077                         }
00078                         case CAPSULE_SHAPE:
00079                         {
00080                                 newShape = new CapsuleShapeData((CapsuleShapeData&)data);
00081                                 break;
00082                         }
00083                         case PLANE_SHAPE:
00084                         {
00085                                 newShape = new PlaneShapeData((PlaneShapeData&)data);
00086                                 break;
00087                         }
00088                         //case RAY_SHAPE:
00089                         //{
00090                         //      newShape = new RayShapeData((RayShapeData&)data);
00091                         //      break;
00092                         //}
00093                         case MESH_SHAPE:
00094                         {
00095                                 newShape = new MeshShapeData((MeshShapeData&)data);
00096                                 break;
00097                         }
00098                         default:
00099                                 assert(false);
00100                 }
00101 
00102                 mShapes.push_back(newShape);
00103         }
00104 
00105         unsigned int SolidData::getNumShapes()const
00106         {
00107                 return (unsigned int)(mShapes.size());
00108         }
00109 
00110         ShapeData* SolidData::getShapeData(unsigned int i)const
00111         {
00112                 return mShapes.at(i);
00113         }
00114 
00115         void SolidData::destroyShapes()
00116         {
00117                 while (!mShapes.empty())
00118                 {
00119                         delete mShapes.back();
00120                         mShapes.pop_back();
00121                 }
00122         }
00123 
00124         void SolidData::operator=(const SolidData& data)
00125         {
00126                 enabled = data.enabled;
00127                 name = data.name;
00128                 sleeping = data.sleeping;
00129                 sleepiness = data.sleepiness;
00130                 isStatic = data.isStatic;
00131                 transform = data.transform;
00132                 globalLinearVel = data.globalLinearVel;
00133                 globalAngularVel = data.globalAngularVel;
00134                 linearDamping = data.linearDamping;
00135                 angularDamping = data.angularDamping;
00136 
00137                 // First remove the old Shapes.
00138                 destroyShapes();
00139 
00140                 // Allocate copies of the new Shapes.
00141                 for (unsigned int i=0; i<data.mShapes.size(); ++i)
00142                 {
00143                         addShape(*(data.mShapes[i]));
00144                 }
00145         }
00146 }
00147 

Generated on Tue May 16 17:49:52 2006 for OPAL by  doxygen 1.4.6-NO