Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tgSystem.h>
- #include "CPhysicsManager.h"
- #include "CTileManager.h"
- #include "CTile.h"
- #include "CCamera.h"
- #include "CClock.h"
- #include "CSettings.h"
- #include "AppRoot.h"
- #include <tgCCore.h>
- #include "Managers/CModelManager.h"
- #include "Managers/CWorldManager.h"
- #include "Managers/CLightManager.h"
- #include "GameStateMachine/CGameStates.h"
- #include "CAudioHandler.h"
- #include <tgMemoryDisable.h>
- // Math and base includes
- #include <Common/Base/hkBase.h>
- #include <Physics/Physics/Dynamics/World/hknpWorld.h>
- #include <Physics/Physics/hknpTypes.h>
- #include <Physics/Physics/Collide/Shape/Convex/hknpConvexShape.h>
- #include <Physics/Physics/Dynamics/Material/hknpMaterial.h>
- #include <Physics/Physics/Dynamics/Material/hknpMaterialLibrary.h>
- #include <tgMemoryEnable.h>
- CTile::CTile( tgCV3D Pos, tgFloat SizeXZ, tgFloat SizeY, tgUInt32 Type, tgUInt32 Theme, tgUInt32 TextureIndex)
- {
- m_pWorld = CPhysicsManager::GetInstance().GetWorld();
- m_Type = Type;
- m_Position = Pos;
- m_OriginalPosition = Pos;
- m_Rotation = 0;
- m_SizeXZ = SizeXZ;
- m_SizeY = SizeY;
- if(Type != CTile::TILETYPE_EMPTY){
- if(CGameStates::GetInstance().GetStateMenu()->GetIsEditingLevel()){
- tgCString AssetName = CTileManager::GetInstance().GetTileModel(Type, Theme)->GetAssetName();
- m_pModel = CModelManager::GetInstance().LoadModel(AssetName, tgCString("tile_model%d", CTileManager::GetInstance().GetAllTiles().size()), true);
- tgCTexture* Texture;
- Texture = CTileManager::GetInstance().GetTileTexture(Type, Theme);
- m_pModel->GetMesh(0)->GetSubMesh(0)->Material.SetColormap(*Texture);
- }
- else{
- // Get correct model from tile manager
- if(Type >= CTile::TILETYPE_NORESPAWNING)
- m_pModel = CTileManager::GetInstance().GetTileModelWithTextureIndex(Type, Type);
- else
- m_pModel = CTileManager::GetInstance().GetTileModel(Type, Theme);
- }
- m_pModelMatrix = new tgCMatrix(tgCMatrix::Identity);
- m_RespawnTime = 10.0f;
- hknpMaterial Material;
- Material.m_restitution = 0.0f;
- Material.m_restitutionCombinePolicy = hknpMaterial::CombinePolicy::COMBINE_GEOMETRIC_MEAN;
- hknpMaterialId MaterialID = m_pWorld->accessMaterialLibrary()->addEntry(Material);
- hknpConvexShape *pShape = hknpConvexShape::createFromHalfExtents(hkVector4(SizeXZ + 0.01f, 0.2f, SizeXZ + 0.01f));
- hknpBodyCinfo Info;
- Info.m_shape = pShape;
- Info.m_materialId = MaterialID;
- Info.m_position.set(Pos.x, Pos.y, Pos.z);
- Info.m_motionType = hknpMotionType::STATIC;
- Info.m_mass = 7.5f;
- m_pModel->GetTransform().GetMatrixLocal().Translate(Pos, tgCMatrix::COMBINE_REPLACE);
- m_BodyID = m_pWorld->createBody(Info);
- pShape->removeReference();
- if(Type == TILETYPE_DESTRUCTIBLE || Type == TILETYPE_DESTRUCTIBLE2 || Type == TILETYPE_DESTRUCTIBLE3 || Type >= TILETYPE_NORESPAWNING)
- m_pWorld->setBodyProperty<int>(m_BodyID, 10008, 1);
- else
- m_pWorld->setBodyProperty<int>(m_BodyID, 10008, 0);
- m_HasPlayedBreakSound = false;
- m_TileBreakSoundDelay = 0.0f;
- m_pWorld->setBodyQuality(m_BodyID, hknpBodyQualityId::PRESET_DEBRIS);
- }
- }
- CTile::~CTile( void )
- {
- if(m_Type != CTile::TILETYPE_EMPTY){
- delete m_pModelMatrix;
- m_pWorld->destroyBodies(&m_BodyID, 1);
- }
- }
- void CTile::Update( tgFloat DeltaTime )
- {
- if(m_Type != CTile::TILETYPE_EMPTY){
- m_pWorld->getBodyTransform(m_BodyID).get4x4ColumnMajor(reinterpret_cast<tgFloat*>(m_pModelMatrix));
- if((m_Type == TILETYPE_INDESTRUCTIBLE || m_Type == TILETYPE_RESPAWNPOINT) && m_pWorld->getBody(m_BodyID).getMotionType() != hknpMotionType::STATIC)
- m_pWorld->setBodyMotionType(m_BodyID, hknpMotionType::STATIC);
- if(m_Type < TILETYPE_NORESPAWNING){
- if(m_pWorld->getBodyTransform(m_BodyID).getTranslation()(1) <= -5.0f){
- m_RespawnTimer += DeltaTime;
- m_RespawnTimer = tgMathClamp(0.0f, m_RespawnTimer, m_RespawnTime);
- if(m_RespawnTimer >= m_RespawnTime){
- hknpBodyCinfo Info;
- m_pWorld->getBodyCinfo(m_BodyID, Info);
- Info.m_position.set(m_OriginalPosition.x, m_OriginalPosition.y, m_OriginalPosition.z);
- Info.m_orientation.setAxisAngle(hkVector4(0.0f, 1.0f, 0.0f), 0.0f);
- Info.m_orientation.normalize();
- hkTransform Transform = m_pWorld->getBody(m_BodyID).getTransform();
- Transform.setRotation(Info.m_orientation);
- Transform.setTranslation(Info.m_position);
- m_pWorld->setBodyTransform(m_BodyID, Transform);
- m_pWorld->setBodyMotionType(m_BodyID, hknpMotionType::STATIC);
- m_RespawnTimer = 0.0f;
- m_TileBreakSoundDelay = 0.0f;
- }
- }
- }
- }
- }
- void CTile::Render( void )
- {
- if(m_Type != CTile::TILETYPE_EMPTY){
- m_pModel->GetTransform().GetMatrixLocal() = *m_pModelMatrix;
- m_pModel->Update();
- if(m_pModel->GetTransform().GetMatrixLocal().Pos.y > -10.0f){
- if(!CGameStates::GetInstance().GetStateEditor()->GetIfInEditor() || CGameStates::GetInstance().GetStateMenu()->GetIsEditingLevel()){
- m_pModel->Render();
- }
- }
- else{
- if(m_pWorld->getBody(m_BodyID).getMotionType() == hknpMotionType::DYNAMIC)
- m_pWorld->setBodyMotionType(m_BodyID, hknpMotionType::STATIC);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement