diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-11 11:13:15 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-11 11:13:15 -0500 |
| commit | cce568a7f56861d6249d7445f51d0ed27c560a5c (patch) | |
| tree | dc16d597f2b5ba37935993add262bff28dc2ca44 /src/entities.cpp | |
| parent | f07294ca65143fac8b1b426d1854212403721226 (diff) | |
checkpoint - mostly working condition after changes
Diffstat (limited to 'src/entities.cpp')
| -rw-r--r-- | src/entities.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index bd24830..1383ebe 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -38,7 +38,7 @@ EntityType *EntityType_Create() { return &entityType; } -Entity_Base *EntityType_CreateGenericInstance(EntityType *et, CompInstance *srcInstance) { +Entity_Base *EntityType_CreateGenericInstance(EntityType *et, CompInstance *srcInstance, InstPos *instPos) { assert(et != nullptr); Entity_Base *genericEntity = ECS_CreateGenericEntity(); auto *level = PkeLevel_Get(pkeSettings.rt.activeLevel); @@ -48,6 +48,10 @@ Entity_Base *EntityType_CreateGenericInstance(EntityType *et, CompInstance *srcI auto &etd = et->details[i]; auto *compInst = ECS_CreateInstance(genericEntity, etd.grBinds); + btVector3 scaling{1.f,1.f,1.f}; + btTransform posRot{}; + btScalar mass = 1.f; + if (srcInstance != nullptr) { if (srcInstance->collisionCallback.name[0] != '\0') { strncpy(compInst->collisionCallback.name, srcInstance->collisionCallback.name, CallbackSignatureLength); @@ -55,25 +59,34 @@ Entity_Base *EntityType_CreateGenericInstance(EntityType *et, CompInstance *srcI } compInst->physicsLayer = srcInstance->physicsLayer; compInst->physicsMask = srcInstance->physicsMask; + posRot = instPos->posRot; } else { compInst->physicsLayer = etd.bt.startingCollisionLayer; compInst->physicsMask = etd.bt.startingCollisionMask; + posRot.setIdentity(); } + if (instPos != nullptr) { + mass = instPos->mass; + scaling = instPos->scale; + } else { + mass = etd.bt.startingMass; + } + btVector3 localInertia(0, 0, 0); - etd.bt.shape->calculateLocalInertia(etd.bt.startingMass, localInertia); - btTransform posRot{}; - posRot.setIdentity(); + etd.bt.shape->calculateLocalInertia(mass, localInertia); compInst->bt.motionState = Pke_New<btDefaultMotionState>(MemBkt_Bullet); new (compInst->bt.motionState) btDefaultMotionState(posRot); + compInst->bt.rigidBody = Pke_New<btRigidBody>(MemBkt_Bullet); - new (compInst->bt.rigidBody) btRigidBody(etd.bt.startingMass, compInst->bt.motionState, etd.bt.shape, localInertia); + new (compInst->bt.rigidBody) btRigidBody(mass, compInst->bt.motionState, etd.bt.shape, localInertia); + compInst->bt.rigidBody->setLinearVelocity(btVector3(0,0,0)); compInst->bt.rigidBody->setAngularVelocity(btVector3(0,0,0)); - compInst->bt.rigidBody->getCollisionShape()->setLocalScaling(btVector3(1, 1, 1)); + compInst->bt.rigidBody->getCollisionShape()->setLocalScaling(scaling); BtDynamicsWorld->addRigidBody(compInst->bt.rigidBody); compInst->bt.rigidBody->getBroadphaseProxy()->m_collisionFilterGroup = static_cast<PhysicsCollision_T>(compInst->physicsLayer); compInst->bt.rigidBody->getBroadphaseProxy()->m_collisionFilterMask = static_cast<PhysicsCollision_T>(compInst->physicsMask); - compInst->bt.rigidBody->setUserPointer(reinterpret_cast<void *>(compInst->entHandle.hash)); + compInst->bt.rigidBody->setUserPointer(reinterpret_cast<void *>(compInst)); } return genericEntity; } @@ -1034,6 +1047,9 @@ void EntityType_Load(EntityType &et) { assert(gltfData->buffer_views[i].type != cgltf_buffer_view_type_invalid); } + et.detailsCount = gltfData->nodes_count; + assert(et.detailsCount <= EntityTypeDetails_MAX && "Maximum supported number of meshes in gltf is hard-coded, update _MAX if not unreasonable"); + std::filesystem::path gltfPath{asset->basePath}; gltfPath.replace_filename(gltfData->buffers[0].uri); AssetHandle modelBinHandle = AM_Register(gltfPath.c_str(), PKE_ASSET_TYPE_UNSET); |
