示例#1
0
HOBJECT WorldModel::AttachObject( HOBJECT hObj )
{
	if( !hObj ) return LTNULL;

	// Make sure the object is detached first.
	DetachObject( hObj );

	LTVector	vPos, vParentPos;
	LTRotation	rRot, rParentRot;

	// Get our position and rotation

	g_pLTServer->GetObjectPos( m_hObject, &vParentPos );
	g_pLTServer->GetObjectRotation( m_hObject, &rParentRot );
	
	LTMatrix mRot;
	rParentRot.ConvertToMatrix( mRot );

	// Get the attachment object pos / rot

	g_pLTServer->GetObjectPos( hObj, &vPos );
	g_pLTServer->GetObjectRotation( hObj, &rRot );

	// Calculate the offsets...

	LTVector	vPosOffset( ~mRot * (vPos - vParentPos) );
	LTRotation	rRotOffset = rRot * ~rParentRot;

	// Attach it...

	HATTACHMENT	hAttachment;
	LTRESULT	LTRes = g_pLTServer->CreateAttachment( m_hObject, hObj, LTNULL, 
													   &vPosOffset, &rRotOffset, &hAttachment );
	if( LTRes != LT_OK )
		return NULL;

	LTObjRefNotifier ref( *this );
	ref = hObj;
	m_AttachmentList.push_back( ref );

	// If the object is a WorldModel set it's activate parent...

	if( IsWorldModel( hObj ))
	{
		WorldModel *pWorldModel = dynamic_cast<WorldModel*>(g_pLTServer->HandleToObject( hObj ));
		if( pWorldModel )
		{
			// Send any activate messages the WorldModel recevies to us...

			pWorldModel->SetActivateParent( m_hObject );

			// Add the WorldModel to our list of objects to inherit our ActivateType...

			m_ActivateTypeHandler.InheritObject( hObj );
		}
	}

	return hObj;
}
示例#2
0
void WorldModel::DetachObject( HOBJECT hObj )
{
	if( !hObj ) return;

	// Remove the object from our list of attachments.  Should only be in here once.
	for( ObjRefNotifierList::iterator iter = m_AttachmentList.begin( ); iter != m_AttachmentList.end( ); iter++ )
	{
		if( hObj == *iter )
		{
			// Remove it from our list.
			m_AttachmentList.erase( iter );
			break;
		}
	}
	

	HATTACHMENT	hAttachment = NULL;
	if( g_pLTServer->FindAttachment( m_hObject, hObj, &hAttachment ) != LT_OK )
		return;

	g_pLTServer->RemoveAttachment( hAttachment );

	// If the object is a WorldModel set it's activate parent...

	if( IsWorldModel( hObj ))
	{
		WorldModel *pWorldModel = dynamic_cast<WorldModel*>(g_pLTServer->HandleToObject( hObj ));
		if( pWorldModel )
		{
			// No longer send any activate messages the WorldModel recevies to us...

			pWorldModel->SetActivateParent( LTNULL );

			// Remove the WorldModel from our list of object to inherit our ActivateType...

			m_ActivateTypeHandler.DisownObject( hObj );
		}
	}

	// Don't just let the object float 

	uint32	dwFlags;
	g_pCommonLT->GetObjectFlags( hObj, OFT_Flags, dwFlags );

	if( (IsKindOf(hObj, "Prop" )) && (dwFlags & FLAG_GRAVITY) )
	{
		LTVector	vVel;

		g_pPhysicsLT->GetVelocity( hObj, &vVel );

		if( vVel.y > -0.1f )
		{
			vVel.y -= 10.0f;
			g_pPhysicsLT->SetVelocity( hObj, &vVel );
		}
	}
}
示例#3
0
static void CreateServerMark(CLIENTWEAPONFX & theStruct)
{
	// If this isn't a GameBase object, return...

	if (!IsWorldModel(theStruct.hObj)) return;

	// See if we should create a mark, or simply move one of the GameBase's
	// marks.

	// If the GameBase has the max number of marks or this mark is very close
	// to a pre-existing mark, just move that mark to the new position.

    WorldModel* pObj = (WorldModel*) g_pLTServer->HandleToObject(theStruct.hObj);
	if (!pObj) return;

	pObj->CreateServerMark( theStruct );
}