shape.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Matthew Williams   *
00003  *   matt@milliams.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef SHAPE_H
00022 #define SHAPE_H
00023 
00024 //#include <string>
00025 
00026 #include "sceneobject.h"
00027 #include "edge.h"
00028 #include "group.h"
00029 #include "libs/maths.h"
00030 
00038 namespace sparkle
00039 {
00040     class Node; //forward declaration to child node
00041     class Edge; //
00042     class Group;    //to set owner group
00043     
00045 
00050     class Shape : public SceneObject
00051     {
00052         public:
00054 
00055 
00058             Shape();
00062             ~Shape();
00064             
00066 
00067 
00073             virtual int addNode(double x, double y);
00079             virtual int removeNode(Node *nodeToRemove);
00080             
00087             virtual int addEdge(int nodeIndex1, int nodeIndex2);
00088             
00093             void setName(std::string newName) {shapeName = newName;}
00098             void setGroup(Group* newGroup);
00099             
00107             void resetVolatileVars();
00114             void addForce(double xNodeForce, double yNodeForce, Node* childNode);
00120             void applyUniformForce(double xForce, double yForce);   //apply equal force to all nodes. eg. gravity
00126             void updateStaticVars(double deltaTime);
00128             
00137             Node* nodeAt(int index) {return &nodes[index];} //inline
00141             virtual int numOfNodes() const {return nodes.size();}   //inline
00145             virtual int numOfEdges() const {return edges.size();}   //inline
00146             
00150             double getMass() const {return mass;}   //inline
00151             
00155             double getComX() const {return com.x;}  //inline
00159             double getComY() const {return com.y;}  //inline
00163             VecXY getCom() const {return com;}  //inline
00167             Vector<double> getComVector() const {return Vector<double>(com);}   //inline
00168             
00173             double getMomentOfInertia();
00174             
00178             std::string name() const {return shapeName;}    //inline
00183             Group* group() const {return ownerGroup;}   //inline
00185             
00186         protected:
00190             std::vector<Node> nodes;
00194             std::vector<Edge> edges;
00195             
00199             Group* ownerGroup;
00200             
00201             //meta
00205             std::string shapeName;
00206             
00207             //attributes which seldom change
00211             double mass;
00215             double momentOfInertia;
00216             
00217             //variables which accumulate between ticks (static variable)
00221             sparkle::VecXY linearVelocity;
00225             sparkle::VecXY com;
00229             double angularVelocity;
00233             double angle;
00234             
00235             //variables which change and are reset every tick (volatile variable)
00239             sparkle::VecXY force;
00243             double torque;
00244             
00248             void calculateCOM();
00252             void updateAttributes();    //must be called everytime mass or the number of nodes is changed
00253     };
00254 };
00255 
00256 #endif // SHAPE_H

Hosted by SourceForge.net Logo Generated on Sat Sep 16 01:51:07 2006 for Sparkle by Doxygen 1.4.6.