Exemplo n.º 1
0
void CEntityFactory::DetachProperty(CEntity& Entity, const nString& TypeName) const
{
	CPropertyInfo PropInfo;

	nString FullType = StrPropPrefix + TypeName;
	if (!PropertyMeta.Get(FullType.Get(), PropInfo))
		if (!PropertyMeta.Get(TypeName.Get(), PropInfo))
			n_error("No such property \"%s\"", TypeName.Get()); //???error?

	n_assert(PropInfo.pStorage);

#ifdef _DEBUG
	if (!PropInfo.pStorage->Contains(Entity.GetUniqueID()))
		n_error("CEntity::RemoveProperty: CProperty '%s' does not exist on entity!", TypeName.Get());
#endif

	(*PropInfo.pStorage)[Entity.GetUniqueID()]->ClearEntity(); //???need or there is always destructor?
	PropInfo.pStorage->Erase(Entity.GetUniqueID());
}
Exemplo n.º 2
0
// The ODENearCallback for CShape::Collide.
//
// 31-May-05   floh    invert contact normal if necessary, the contact normal
//                     in ODE always points into pShape1, however, we want
//                     the contact normal always to point away from the
//                     "other" object
void CShape::ODENearCallback(void* data, dGeomID o1, dGeomID o2)
{
	CShape* pThis = (CShape*)data;

	// collide geom with sub-space
	if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
	{
		dSpaceCollide2(o1, o2, data, &ODENearCallback);
		return;
	}

	CShape* pShape1 = CShape::GetShapeFromGeom(o1);
	CShape* pShape2 = CShape::GetShapeFromGeom(o2);
	CShape* pOtherShape;
	if (pShape1 == pThis) pOtherShape = pShape2;
	else if (pShape2 == pThis) pOtherShape = pShape1;
	else n_error("No self in collision");

	if (CShape::CollideFilterSet->CheckShape(pOtherShape)) return;

	// do collision detection, only check for one contact
	dContactGeom ODEContact;
	int CurrCollCount;
	if (pShape1 == pThis) CurrCollCount = dCollide(o1, o2, 1, &ODEContact, sizeof(dContactGeom));
	else CurrCollCount = dCollide(o2, o1, 1, &ODEContact, sizeof(dContactGeom));

	CContactPoint ContactPt;
	if (CurrCollCount > 0)
	{
		ContactPt.Position.set(ODEContact.pos[0], ODEContact.pos[1], ODEContact.pos[2]);
		ContactPt.UpVector.set(ODEContact.normal[0], ODEContact.normal[1], ODEContact.normal[2]);
		ContactPt.Material = pOtherShape->GetMaterialType();
		ContactPt.Depth = ODEContact.depth;
		CEntity* pEntity = pOtherShape->GetEntity();
		if (pEntity) ContactPt.EntityID = pEntity->GetUniqueID();
		CRigidBody* pRigidBody = pOtherShape->GetRigidBody();
		if (pRigidBody) ContactPt.RigidBodyID = pRigidBody->GetUniqueID();
		CShape::CollideContacts->Append(ContactPt);
	}
}
Exemplo n.º 3
0
void CEntityFactory::DetachAllProperties(CEntity& Entity) const
{
	for (int i = 0; i < PropStorage.Size(); i++)
		PropStorage[i]->Erase(Entity.GetUniqueID());
}