Exemplo n.º 1
0
void CBubbleRob::putBubbleRobTagToSceneObject(int objectHandle,float maxVelocity)
{	// This creates/updates a BUBBLEROB_DATA_MAXVELOCITY tag
	// 1. Get all the developer data attached to the associated scene object (this is custom data added by the developer):
	int buffSize=simGetObjectCustomDataLength(objectHandle,DEVELOPER_DATA_HEADER);
	char* datBuff=new char[buffSize];
	simGetObjectCustomData(objectHandle,DEVELOPER_DATA_HEADER,datBuff);
	std::vector<unsigned char> developerCustomData(datBuff,datBuff+buffSize);
	delete[] datBuff;
	// 2. From that retrieved data, extract sub-data with the BUBBLEROB_DATA_MAXVELOCITY tag, update it, and add it back to the retrieved data:
	std::vector<unsigned char> bubbleRobVelocityData;
	CAccess::extractSerializationData(developerCustomData,BUBBLEROB_DATA_MAXVELOCITY,bubbleRobVelocityData);
	bubbleRobVelocityData.clear(); // we discard the old value (if present)
	CAccess::push_float(bubbleRobVelocityData,maxVelocity); // we replace it with the new value
	CAccess::insertSerializationData(developerCustomData,BUBBLEROB_DATA_MAXVELOCITY,bubbleRobVelocityData);
	// 3. We add/update the scene object with the updated custom data:
	simAddObjectCustomData(objectHandle,DEVELOPER_DATA_HEADER,(simChar*)&developerCustomData[0],int(developerCustomData.size()));
}
Exemplo n.º 2
0
void CK3::putK3TagToSceneObject(int objectHandle,int modelVersion,float maxVelocity,float maxAccel,float maxArmAccel)
{	// This creates/updates a K3_BASE tag
	// 1. Get all the developer data attached to the associated scene object (this is custom data added by the developer):
	int buffSize=simGetObjectCustomDataLength(objectHandle,DEVELOPER_DATA_HEADER);
	char* datBuff=new char[buffSize];
	simGetObjectCustomData(objectHandle,DEVELOPER_DATA_HEADER,datBuff);
	std::vector<unsigned char> developerCustomData(datBuff,datBuff+buffSize);
	delete[] datBuff;
	// 2. From that retrieved data, extract sub-data with the K3_BASE,K3_MAXVELOCITY, etc tags, update them, and add them back to the retrieved data:
	std::vector<unsigned char> k3Data;

	CAccess::extractSerializationData(developerCustomData,K3_BASE,k3Data);
	k3Data.clear(); // we discard the old value (if present)
	CAccess::push_float(k3Data,0); // we replace it with the new value
	CAccess::insertSerializationData(developerCustomData,K3_BASE,k3Data);

	CAccess::extractSerializationData(developerCustomData,K3_MAXVELOCITY,k3Data);
	k3Data.clear();
	CAccess::push_float(k3Data,maxVelocity);
	CAccess::insertSerializationData(developerCustomData,K3_MAXVELOCITY,k3Data);

	CAccess::extractSerializationData(developerCustomData,K3_MODELVERSION,k3Data);
	k3Data.clear();
	CAccess::push_int(k3Data,modelVersion);
	CAccess::insertSerializationData(developerCustomData,K3_MODELVERSION,k3Data);

	CAccess::extractSerializationData(developerCustomData,K3_MAXACCELERATION,k3Data);
	k3Data.clear();
	CAccess::push_float(k3Data,maxAccel);
	CAccess::insertSerializationData(developerCustomData,K3_MAXACCELERATION,k3Data);

	CAccess::extractSerializationData(developerCustomData,K3_GRIPPER_ARMMAXACCELERATION,k3Data);
	k3Data.clear();
	CAccess::push_float(k3Data,maxArmAccel);
	CAccess::insertSerializationData(developerCustomData,K3_GRIPPER_ARMMAXACCELERATION,k3Data);

	// 3. We add/update the scene object with the updated custom data:
	simAddObjectCustomData(objectHandle,DEVELOPER_DATA_HEADER,(simChar*)&developerCustomData[0],int(developerCustomData.size()));
}