123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- #include "Block.h"
- #include "Inventory.h"
- #include "Globals.h"
- Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
- : Inventory( pos, hasInventory ),
- Model3D(),
- zType( zType )
- {
- transparent = false;
- passable = false;
- hp = 1;
- maxHP = 1;
- hardness = 1;
- this->zTool = zTool;
- speedModifier = 1;
- memset( sideVisible, 1, 6 );
- Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
- }
- Block::~Block()
- {}
- bool Block::isTransparent() const
- {
- return transparent;
- }
- bool Block::isPassable() const
- {
- return passable;
- }
- void Block::setSideVisible( Direction dir, bool visible )
- {
- sideVisible[ getDirectionIndex( dir ) ] = visible;
- }
- const BlockType* Block::zBlockType() const
- {
- return zType;
- }
- BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
- : Item( zType, name )
- {
- placeable = 1;
- transparent = 0;
- passable = 0;
- hp = 0;
- maxHP = 0;
- hardness = 0;
- toolId = 0;
- speedModifier = 0;
- }
- BasicBlockItemType::BasicBlockItemType( int id )
- : ItemType( id )
- {}
- void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
- {
- ItemType::loadSuperItem( zItem, zReader );
- BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
- if( !item )
- throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
- zReader->lese( (char*)&item->transparent, 1 );
- zReader->lese( (char*)&item->passable, 1 );
- zReader->lese( (char*)&item->hp, 4 );
- zReader->lese( (char*)&item->maxHP, 4 );
- zReader->lese( (char*)&item->hardness, 4 );
- zReader->lese( (char*)&item->toolId, 4 );
- zReader->lese( (char*)&item->speedModifier, 4 );
- }
- Framework::Model3DData* BasicBlockItemType::getItemModel() const
- {
- if( window->zBildschirm()->zGraphicsApi()->hasModel( "itemCube" ) )
- return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
- else
- {
- Framework::Model3DData* data = window->zBildschirm()->zGraphicsApi()->createModel( "itemCube" );
- data->setAmbientFactor( 0.8f );
- data->setDiffusFactor( 0.1f );
- data->setSpecularFactor( 0.1f );
- float size = 0.2f;
- float left, right, top, bottom;
-
- left = (float)((size / 2.0) * -1);
-
- right = left + (float)size;
-
- top = (float)(size / 2.0);
-
- bottom = top - (float)size;
- float front = -size / 2;
- float back = front + size;
- Vertex3D* vertecies = new Vertex3D[ 24 ];
- for( int i = 0; i < 24; i++ )
- vertecies[ i ].knochenId = 0;
- vertecies[ 0 ].pos = Vec3<float >( left, top, front );
- vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
- vertecies[ 1 ].pos = Vec3<float >( right, top, front );
- vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
- vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
- vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
- vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
- vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
- vertecies[ 4 ].pos = Vec3<float >( left, top, back );
- vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
- vertecies[ 5 ].pos = Vec3<float >( right, top, back );
- vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
- vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
- vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
- vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
- vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
- vertecies[ 8 ].pos = Vec3<float >( left, top, front );
- vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
- vertecies[ 9 ].pos = Vec3<float >( right, top, front );
- vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
- vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
- vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
- vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
- vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
- vertecies[ 12 ].pos = Vec3<float >( left, top, back );
- vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
- vertecies[ 13 ].pos = Vec3<float >( right, top, back );
- vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
- vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
- vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
- vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
- vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
- vertecies[ 16 ].pos = Vec3<float >( left, top, front );
- vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
- vertecies[ 17 ].pos = Vec3<float >( right, top, front );
- vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
- vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
- vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
- vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
- vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
- vertecies[ 20 ].pos = Vec3<float >( left, top, back );
- vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
- vertecies[ 21 ].pos = Vec3<float >( right, top, back );
- vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
- vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
- vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
- vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
- vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
- data->setVertecies( vertecies, 24 );
-
-
- Polygon3D* p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 6 + 16;
- p->indexList[ 1 ] = 2 + 16;
- p->indexList[ 2 ] = 3 + 16;
- p->indexList[ 3 ] = 6 + 16;
- p->indexList[ 4 ] = 3 + 16;
- p->indexList[ 5 ] = 7 + 16;
- data->addPolygon( p );
-
- p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 1 + 8;
- p->indexList[ 1 ] = 7 + 8;
- p->indexList[ 2 ] = 3 + 8;
- p->indexList[ 3 ] = 1 + 8;
- p->indexList[ 4 ] = 5 + 8;
- p->indexList[ 5 ] = 7 + 8;
- data->addPolygon( p );
-
- p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 4 + 16;
- p->indexList[ 1 ] = 1 + 16;
- p->indexList[ 2 ] = 0 + 16;
- p->indexList[ 3 ] = 4 + 16;
- p->indexList[ 4 ] = 5 + 16;
- p->indexList[ 5 ] = 1 + 16;
- data->addPolygon( p );
-
- p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 0 + 8;
- p->indexList[ 1 ] = 2 + 8;
- p->indexList[ 2 ] = 6 + 8;
- p->indexList[ 3 ] = 0 + 8;
- p->indexList[ 4 ] = 6 + 8;
- p->indexList[ 5 ] = 4 + 8;
- data->addPolygon( p );
-
- p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 4;
- p->indexList[ 1 ] = 6;
- p->indexList[ 2 ] = 7;
- p->indexList[ 3 ] = 4;
- p->indexList[ 4 ] = 7;
- p->indexList[ 5 ] = 5;
- data->addPolygon( p );
-
- p = new Polygon3D();
- p->indexAnz = 6;
- p->indexList = new int[ p->indexAnz ];
- p->indexList[ 0 ] = 0;
- p->indexList[ 1 ] = 3;
- p->indexList[ 2 ] = 2;
- p->indexList[ 3 ] = 0;
- p->indexList[ 4 ] = 1;
- p->indexList[ 5 ] = 3;
- data->addPolygon( p );
- data->calculateNormals();
- return data;
- }
- }
- Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
- {
- return 0;
- }
|