internal void AddCollider(cl_entity_t *pEntity) { var node = _old.Find(pEntity->index); if (node != null) { _old.Remove(node); _added.AddFirst(node); // if model changed if (_rigidbodyCache[node.Value].ModelInUse != pEntity->curstate.modelindex) { var shape = GetCollisionShape(pEntity); if (shape == null) { return; } _rigidbodyCache[node.Value].RigidBody.CollisionShape = shape; } } else { var shape = GetCollisionShape(pEntity); if (shape == null) { return; } RigidBody kinematic = BulletHelper.CreateBodyForEntity(0, pEntity, shape, BWorld.Instance); _rigidbodyCache[pEntity->index] = new RigidbodyCache { RigidBody = kinematic, ModelInUse = pEntity->curstate.modelindex }; BWorld.Instance.AddRigidBody(kinematic); _added.AddFirst(pEntity->index); } }
private CollisionShape GetCollisionShape(cl_entity_t *pEntity) { // directly read from cache. CollisionShape shape = _shapesCache[pEntity->curstate.modelindex]; // cache missing if (shape == null) { if (pEntity->model->type == modtype.mod_brush) { int brushIndex = 0; unsafe { // The name looks like "*XX", we ignore '*' and parse to integer. var p = pEntity->model->name + 1; while (*p != 0) { brushIndex = brushIndex * 10 + (*p - 48); p++; } } shape = new GImpactMeshShape(_bspModels[brushIndex]); _shapesCache[pEntity->curstate.modelindex] = shape; } else if (pEntity->model->type == modtype.mod_studio) { Vector3 aabbSize = (pEntity->curstate.maxs - pEntity->curstate.mins) * GBConstant.G2BScale; shape = new BoxShape(aabbSize / 2f); } else { return(null); } } return(shape); }
/// <summary> /// Add collider for entity in current frame. /// The collider will flush out after this frame. /// </summary> /// <param name="pEntity"></param> public static void AddCollider(cl_entity_t *pEntity) { _kinematicsManager.AddCollider(pEntity); }