WorldViz User Forum  

Go Back   WorldViz User Forum > Plug-in development

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 02-12-2008, 01:29 PM
RedSpikeyThing RedSpikeyThing is offline
Member
 
Join Date: Feb 2008
Posts: 9
Multiple Copies of same sensor plugin

I'm trying to write a sensor for Vizard that simply regurgitates a text file of (x, y, z) positions whenever the update function is called. Internally, it uses a vector to keep track of which sensor is associated with which file. This works as expected with one sensor.
When a second sensor is added, however, no data is returned and Vizard simply gets (0, 0, 0). I've tried outputting the memory address of the sensor that is passed as a parameter to the DLS and it is always the same. This suggests that either Vizard is never calling the update function with the second sensor, or that it is calling it with a pointer to the same sensor. I should note that each sensor does call the initialize function properly and that two separate memory addresses are received when they are initialized.

Any help would be greatly appreciated. Thanks!
Reply With Quote
  #2  
Old 02-12-2008, 03:06 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
The UpdateSensor function is called once per frame, regardless of how many instances of your sensors have been created. You should store each sensor pointer in a global vector during initialization, then iterate through them in the UpdateSensor function. Here is some pseudo code that should explain the general idea:
Code:
typedef struct {
	VRUTSensorObj*		instance;
	SOME_OBJECT_HANDLE	handle;
} MySensor;

std::vector< MySensor > m_sensors;

void InitializeSensor(void *sensor)
{
	//Create internal sensor object
	MySensor ms;
	ms.instance = (VRUTSensorObj *)sensor);
	ms.handle = CREATE_OBJECT_HANDLE;

	//Save sensor number in user field
	ms.instance->user[0] = m_sensors.size();

	//Set data size
	ms.instance->dataSize = 7;

	//Notify successfull initialization
	ms.instance->status = TRUE;

	//Save object in global array
	m_sensors.push_back(ms);
}


void UpdateSensor(void *sensor)
{
	//Update 'data' field of all sensors
	for(unsigned int i = 0; i < m_sensors.size(); ++i) {
		GET_OBJECT_DATA(m_sensors[i].handle,m_sensors[i].instance->data);
	}
}
Let me know if anything is unclear.
Reply With Quote
  #3  
Old 02-12-2008, 03:10 PM
RedSpikeyThing RedSpikeyThing is offline
Member
 
Join Date: Feb 2008
Posts: 9
beautiful, thank you for the quick reply. The lack of documentation for this is very frustrating...
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple shadows using projector theuberk Vizard 13 02-24-2009 03:56 AM
Multiple Mesh Avatar Texturing v-jbinney Vizard 6 11-13-2007 12:00 PM
Multiple labs Plymouth Vizard 1 03-05-2007 10:43 AM
Multiple Stages in one Program Amit Vizard 7 11-11-2005 11:20 AM
Multiple Environments bstankie Vizard 1 11-17-2003 11:49 AM


All times are GMT -7. The time now is 10:27 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC