sparkle::Shape Class Reference
[Sparkle Library]

Basic shape type. More...

#include <shape.h>

Inherits sparkle::SceneObject.

Inherited by sparkle::Square.

Collaboration diagram for sparkle::Shape:

Collaboration graph
[legend]
List of all members.

Public Member Functions

ctors/dtor
 Shape ()
 ~Shape ()
Modifiers
virtual int addNode (double x, double y)
virtual int removeNode (Node *nodeToRemove)
virtual int addEdge (int nodeIndex1, int nodeIndex2)
void setName (std::string newName)
void setGroup (Group *newGroup)
void resetVolatileVars ()
void addForce (double xNodeForce, double yNodeForce, Node *childNode)
void applyUniformForce (double xForce, double yForce)
void updateStaticVars (double deltaTime)
Getters
Not necessarily const

NodenodeAt (int index)
virtual int numOfNodes () const
virtual int numOfEdges () const
double getMass () const
double getComX () const
double getComY () const
VecXY getCom () const
Vector< double > getComVector () const
double getMomentOfInertia ()
std::string name () const
Groupgroup () const

Protected Member Functions

void calculateCOM ()
void updateAttributes ()

Protected Attributes

std::vector< Nodenodes
std::vector< Edgeedges
GroupownerGroup
std::string shapeName
double mass
double momentOfInertia
sparkle::VecXY linearVelocity
sparkle::VecXY com
double angularVelocity
double angle
sparkle::VecXY force
double torque

Detailed Description

Basic shape type.

A basic convex polygon grouping of nodes with an associated mass


Constructor & Destructor Documentation

Shape::Shape  ) 
 

Creates a shape with no nodes

Shape::~Shape  ) 
 

Deconstructor


Member Function Documentation

int Shape::addNode double  x,
double  y
[virtual]
 

Add node to shape to x,y

Parameters:
x X-coord
y Y-coord
Returns:
Number of nodes

Reimplemented in sparkle::Square.

int Shape::removeNode Node nodeToRemove  )  [virtual]
 

Remove node from shape

Parameters:
nodeToRemove Node to remove
Returns:
Number of nodes

Reimplemented in sparkle::Square.

int Shape::addEdge int  nodeIndex1,
int  nodeIndex2
[virtual]
 

Create an edge between the nodes at the two indices

Parameters:
nodeIndex1 Index of start node
nodeIndex2 Index of end node
Returns:
Number of edges

Reimplemented in sparkle::Square.

void sparkle::Shape::setName std::string  newName  )  [inline]
 

Set the name of the shape

Parameters:
newName New name

void Shape::setGroup Group newGroup  ) 
 

Set the group of the shape

Parameters:
newGroup The new group of the shape

void Shape::resetVolatileVars  ) 
 

Resets instantaneous variables which must be reset between ticks

Postcondition:
force.x = 0
force.y = 0
torque = 0
Todo:
Link post conds to attributes

void Shape::addForce double  xNodeForce,
double  yNodeForce,
Node childNode
 

When a force is applid to a node, it will call this function to calculate the effect it will have on the shape

Parameters:
xNodeForce Force in x direction
yNodeForce Force in y direction
childNode Pointer to caller

void sparkle::Shape::applyUniformForce double  xForce,
double  yForce
 

Apply a force to whole shape so only linear momentum is changed

Parameters:
xForce Force in x direction
yForce Force in y direction

void Shape::updateStaticVars double  deltaTime  ) 
 

Once the forces have been applied to all the node, this will calculate what actually happens to the shape.

Parameters:
deltaTime Time passed since last call
Todo:
Make the delta a static member variable to it doesnt need to be passed

Node* sparkle::Shape::nodeAt int  index  )  [inline]
 

Parameters:
index The index of the node within the shape
Returns:
A pointer to the node at index

virtual int sparkle::Shape::numOfNodes  )  const [inline, virtual]
 

Returns:
Number of nodes in shape

Reimplemented in sparkle::Square.

virtual int sparkle::Shape::numOfEdges  )  const [inline, virtual]
 

Returns:
Number of edges in shape

double sparkle::Shape::getMass  )  const [inline]
 

Returns:
Mass of shape

double sparkle::Shape::getComX  )  const [inline]
 

Returns:
X-coord of centre of mass

double sparkle::Shape::getComY  )  const [inline]
 

Returns:
Y-coord of centre of mass

VecXY sparkle::Shape::getCom  )  const [inline]
 

Returns:
VecXY of centre of mass

Vector<double> sparkle::Shape::getComVector  )  const [inline]
 

Returns:
Vector of centre of mass

double Shape::getMomentOfInertia  ) 
 

Will recalculate the moment of inertia before returning

Returns:
Moment of inertia

std::string sparkle::Shape::name  )  const [inline]
 

Returns:
The name of the shape

Group* sparkle::Shape::group  )  const [inline]
 

Get the group of the shape. If it is not in a group, it will return 0.

Returns:
A pointer to the group of the shape

void Shape::calculateCOM  )  [protected]
 

Calculate the CoM of the shape

void Shape::updateAttributes  )  [protected]
 

Recalculate the CoM and Moment of inertia of the shape


Member Data Documentation

std::vector<Node> sparkle::Shape::nodes [protected]
 

The nodes owned by the shape

std::vector<Edge> sparkle::Shape::edges [protected]
 

The Edges connecting the nodes

Group* sparkle::Shape::ownerGroup [protected]
 

If this shape is in a group, it will be referenced here

std::string sparkle::Shape::shapeName [protected]
 

Name of shape

double sparkle::Shape::mass [protected]
 

Mass in kilogrammes of the shape

double sparkle::Shape::momentOfInertia [protected]
 

Moment of inertia of the shape. Must be calculated through sparkle::momentOfInertia(...)

sparkle::VecXY sparkle::Shape::linearVelocity [protected]
 

Current linear velocity of shape

sparkle::VecXY sparkle::Shape::com [protected]
 

Current CoM of shape

double sparkle::Shape::angularVelocity [protected]
 

Current angular velocity of shape

double sparkle::Shape::angle [protected]
 

Current angle of shape relative to starting position

sparkle::VecXY sparkle::Shape::force [protected]
 

Tick-cumulative force

double sparkle::Shape::torque [protected]
 

Tick-cumulative torque


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