00001
00002 #include "main.h"
00003 #include "table.h"
00004
00005
00006
00007 Table::Table()
00008 : nxActor(NULL), node(NULL)
00009 {
00010 logger->log( "Table ctor()" );
00011 }
00012
00013
00014
00015 Table::~Table()
00016 {
00017 if ( NULL != this->nxActor )
00018 {
00019
00020 nxScene->releaseActor( *this->nxActor );
00021 this->nxActor = NULL;
00022 }
00023 if ( NULL != this->node )
00024 {
00025 this->node->remove();
00026 this->node = NULL;
00027 }
00028 logger->log( "Table dtor()" );
00029 }
00030
00031
00032
00033 ERR_TYPE Table::update( u32 timeMS )
00034 {
00035
00036 return ERR_OK;
00037 }
00038
00039
00040
00041
00042 ERR_TYPE Table::load( stringc meshFileName, stringc diffuseMapFileName, vector3df scale )
00043 {
00044 IAnimatedMesh* tableMesh = smgr->getMesh( meshFileName.c_str() );
00045 if ( NULL == tableMesh )
00046 {
00047 return ERR_TABLE_LOAD_FAILED;
00048 }
00049
00050
00051 ITexture* diffuseMap = driver->getTexture( diffuseMapFileName.c_str() );
00052 if ( NULL == diffuseMap )
00053 {
00054 return ERR_TABLE_LOAD_FAILED;
00055 }
00056
00057
00058 this->node = smgr->addAnimatedMeshSceneNode( tableMesh );
00059 if ( NULL == this->node )
00060 {
00061 return ERR_TABLE_LOAD_FAILED;
00062 }
00063
00064
00065 this->node->setScale( scale );
00066
00067
00068 this->node->setMaterialFlag( EMF_LIGHTING, false );
00069
00070
00071 this->node->setMaterialTexture( 0, diffuseMap );
00072
00073
00074
00075
00076 S3DVertex* vertices = (S3DVertex*) this->node->getMesh()->getMesh(0)->getMeshBuffer(0)->getVertices();
00077 u32 vertexCount = this->node->getMesh()->getMesh(0)->getMeshBuffer(0)->getVertexCount();
00078 for ( u32 i=0; i<vertexCount; i++ )
00079 {
00080
00081 if ( false == vertices[i].Normal.equals( vector3df(0.0f, 1.0f, 0.0f ) ) )
00082 {
00083
00084 vertices[i].TCoords.X = 0.0f;
00085 vertices[i].TCoords.Y = 0.0f;
00086 }
00087 }
00088
00089
00090 this->node->getMaterial(0).SpecularColor.set( 255, 255, 255, 255 );
00091 this->node->getMaterial(0).Shininess = 20.0f;
00092
00093 return ERR_OK;
00094 }
00095
00096
00097
00098 ERR_TYPE Table::createNxActor( vector3df size )
00099 {
00100
00101 NxReal irrToPhysxScaler = 0.4f;
00102 NxVec3 boxDim( size.X * irrToPhysxScaler, 1.0f, size.Z * irrToPhysxScaler );
00103
00104
00105 NxActorDesc actorDesc;
00106 NxBodyDesc bodyDesc;
00107
00108
00109 NxBoxShapeDesc boxDesc;
00110 boxDesc.dimensions.set( boxDim );
00111
00112 actorDesc.shapes.pushBack( &boxDesc );
00113
00114 actorDesc.body = &bodyDesc;
00115 actorDesc.density = 10000.0f;
00116
00117 this->nxActor = nxScene->createActor( actorDesc );
00118 if ( NULL == this->nxActor )
00119 {
00120 return ERR_TABLE_CREATEACTOR_FAILED;
00121 }
00122
00123 this->nxActor->setName( "Table" );
00124
00125 this->nxActor->setGlobalPosition( NxVec3(50, 50, 0) );
00126 this->nxActor->raiseBodyFlag( NX_BF_FROZEN );
00127
00128 return ERR_OK;
00129 }