00001 #include <assert.h>
00002 #include <math\Matrix4x4.h>
00003 #include <stdio.h>
00004 #include "Universe\Entity.h"
00005
00006 Entity::Entity (FrameManager* frameManager)
00007 :
00008 baseFrame( 0 ) ,
00009 name(NULL),
00010 frameManager( frameManager )
00011 {
00012 this->SetName( "" ) ;
00013 }
00014
00015 Entity::Entity (const Entity& right)
00016 :
00017 baseFrame( right.baseFrame ),
00018 name(NULL),
00019 frameManager( right.frameManager )
00020
00021 {
00022
00023 this->SetName( right.GetName() ) ;
00024
00025 }
00026
00027
00028 Entity::~Entity()
00029 {
00030
00031 baseFrame = 0 ;
00032 frameManager = NULL ;
00033 delete[] name ;
00034 name = NULL ;
00035
00036 }
00037
00038
00039
00040
00041 void Entity::SetBaseFrame (const unsigned int baseFrame)
00042 {
00043
00044 this->baseFrame = baseFrame ;
00045
00046 }
00047
00048 void Entity::SetFrameManager (FrameManager* frameManager)
00049 {
00050
00051 this->frameManager = frameManager ;
00052
00053 }
00054
00055 Matrix4x4 Entity::GetTransform () const
00056 {
00057
00058 assert( frameManager != NULL ) ;
00059 return frameManager->GetTransformRelative( baseFrame, 0 ) ;
00060
00061 }
00062
00063 unsigned int Entity::BaseFrame () const
00064 {
00065
00066 static char copyright[] = "copyright 1999 ian gipson SFU engineering" ;
00067 return baseFrame ;
00068
00069 }
00070
00071 void Entity::SetName (const char* name)
00072 {
00073
00074 delete[] this->name ;
00075 this->name = new char[ strlen( name ) + 1 ] ;
00076 strcpy( this->name, name ) ;
00077
00078 }
00079
00080 const char* Entity::GetName () const
00081 {
00082
00083 return this->name ;
00084
00085 }
00086
00087
00088
00089 bool Entity::DeserializeEntity( IfstreamWithComments& is )
00090 {
00091
00092 char line[ 256 ] = "" ;
00093 is.GetSolidLine( line, 256 ) ;
00094 if( stricmp( line, "#entity" ) != 0 )
00095 {
00096 return false;
00097 }
00098
00099 is.GetSolidLine( line, 256 ) ;
00100 while( stricmp( line, "#end_entity" ) != 0 )
00101 {
00102 char keyWord[ 256 ] = "" ;
00103 ::sscanf( line, "%s", &keyWord[ 0 ] ) ;
00104
00105 if( stricmp( keyWord, "#name") == 0 )
00106 {
00107 char name[ 256 ] = "" ;
00108 ::sscanf( line, "%s%s", &keyWord[ 0 ], &name[ 0 ] ) ;
00109 this->SetName( name ) ;
00110 }
00111 else
00112 {
00113 }
00114 is.GetSolidLine( line, 256 );
00115 assert( stricmp( line, "#end_entity" ) == 0 );
00116 }
00117 return true;
00118 }
00119
00120
00121