4
* Created on: Nov 28, 2008
8
#include <srSensor/sampleSensor.h>
12
SampleSensor::SampleSensor(dtCore::RefPtr<BodyBase> attachedBody,
13
osg::Vec3f translation, osg::Vec3f orientation,
17
SensorBase(attachedBody, translation, orientation, name, "SampleSensor", NO_CAMERA, active),
21
this->sensorReturnValueType = typeid(float*).name();
25
SampleSensor::~SampleSensor() {
26
// TODO Auto-generated destructor stub
29
void SampleSensor::getParameter(const std::string &name, ParameterReturnValue parameter) {
31
ObjectBase::getParameter(name, parameter);
35
void SampleSensor::setParameter(const std::string &name, ParameterReturnValue parameter) {
37
ObjectBase::setParameter(name, parameter);
40
void SampleSensor::evaluate(ParameterReturnValue srv) {
42
if (srv.type!=this->sensorReturnValueType) {
43
std::ostringstream msg; msg.clear(); msg.str("");
44
msg << "Parameter type needs to be " << sensorReturnValueType;
45
msg << " while given type is " << srv.type;
49
float* data = reinterpret_cast<float*> (srv.pValue);
50
*data = this->sensorValue;
54
void SampleSensor::requestData() {
58
pos = osg::Vec3f(5,5,5); rot = osg::Vec3f(5,5,5);
59
getParameter("AbsPosition", MAKE_PARAMETER_VALUE(&pos));
60
//getParameter("AbsOrientation", MAKE_PARAMETER_VALUE(&rot));
62
sensorValue = myFancySimulatedEnvironmentFunction(pos, rot);
66
void SampleSensor::getNewSensorValue() {
72
void SampleSensor::getSensorValue(std::ostream& theStream) const {
74
theStream << sensorValue;
78
float SampleSensor::myFancySimulatedEnvironmentFunction(osg::Vec3f pos, osg::Vec3f rot) {
80
return (pos - osg::Vec3f(20,15,0)).length();
84
void SampleSensor::update(float deltaSimTme) {
86
if (active && isActiveSensor) requestData();