Exemplo n.º 1
0
bool CoreComponentRenderModel::initRenderModel() {

	bool meshLoading = this->mesh_->loadMesh("../models/CoreComponent.stl");

	if (!meshLoading) {
		std::cerr << "[CoreComponentRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
		return true;
	}

	// display with plate down, as this is how will be in reality
	// (we want the arduino to be on top so wires can come out)
	this->mesh_->getMesh()->setAttitude(
			osg::Quat(osg::inDegrees(180.0), osg::Vec3(1, 0, 0)));


	this->getRootNode()->addChild(this->mesh_->getMesh());
	this->getRootNode()->setUpdateCallback(
			new BodyCallback(this->getModel(),
					CoreComponentModel::B_CORE_COMPONENT_ID));

	return true;

}
bool CoreComponentRenderModel::initRenderModel() {

	bool meshLoading = this->mesh_->loadMesh(RobogenUtils::getMeshFile(
			this->getModel(),CoreComponentModel::B_CORE_COMPONENT_ID));

	if (!meshLoading) {
		std::cerr << "[CoreComponentRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
	}

	osg::ref_ptr<osg::PositionAttitudeTransform> brick = this->mesh_->getMesh();


	this->mesh_->getMesh()->setAttitude(
			RobogenUtils::getRelativeAttitude(this->getModel(),
					CoreComponentModel::B_CORE_COMPONENT_ID));

	osg::ref_ptr<osg::PositionAttitudeTransform> brickFrame(
			new osg::PositionAttitudeTransform());
	brickFrame->addChild(brick);

	this->getMeshes()->addChild(brickFrame.get());
	brickFrame->setUpdateCallback(
			new BodyCallback(this->getModel(),
					CoreComponentModel::B_CORE_COMPONENT_ID));

	if (boost::dynamic_pointer_cast<CoreComponentModel>(this->getModel())->
					isCore() ) {
		this->setColor(osg::Vec4(1,0,0,0.7));
	} else {
		this->setColor(osg::Vec4(1,1,1,0.7));
	}


	if (isDebugActive()) {
		this->activateTransparency(brick->getOrCreateStateSet());
	}
	return true;

}
bool TouchSensorRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh(
			   RobogenUtils::getMeshFile(this->getModel(),
				  TouchSensorModel::B_SENSOR_BASE_ID));

	if (!meshLoadingA) {
		std::cerr << "[TouchSensorRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
	}

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> partA =
			this->partA_->getMesh();
	partA->setAttitude(RobogenUtils::getRelativeAttitude(this->getModel(),
			  TouchSensorModel::B_SENSOR_BASE_ID));
	partA->setPosition(RobogenUtils::getRelativePosition(this->getModel(),
			  TouchSensorModel::B_SENSOR_BASE_ID));

	partA_->setColor(osg::Vec4(1, 0, 0, 0.5));

	osg::ref_ptr<osg::PositionAttitudeTransform> patPartA(
			new osg::PositionAttitudeTransform());
	patPartA->addChild(partA);

	this->getMeshes()->addChild(patPartA.get());
	patPartA->setUpdateCallback(
			new BodyCallback(this->getModel(),
					TouchSensorModel::B_SENSOR_BASE_ID));

	if(isDebugActive()) {
		this->activateTransparency(patPartA->getOrCreateStateSet());
	}

	return true;

}
Exemplo n.º 4
0
bool TouchSensorRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh("../models/TouchSensor.stl");

	if (!meshLoadingA) {
		std::cerr << "[TouchSensorRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
		return true;
	}

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> partA =
			this->partA_->getMesh();
	partA->setAttitude(osg::Quat(osg::inDegrees(-90.0), osg::Vec3(0, 0, 1)));
	partA->setPosition(
			fromOde(
					osg::Vec3(
							TouchSensorModel::SENSOR_BASE_THICKNESS / 2
									+ TouchSensorModel::SENSOR_THICKNESS / 2
									- 0.002, 0, 0)));

	partA_->setColor(osg::Vec4(1, 0, 0, 1));

	osg::ref_ptr<osg::PositionAttitudeTransform> patPartA(
			new osg::PositionAttitudeTransform());
	patPartA->addChild(partA);

	this->getRootNode()->addChild(patPartA.get());
	patPartA->setUpdateCallback(
			new BodyCallback(this->getModel(),
					TouchSensorModel::B_SENSOR_BASE_ID));

	return true;

}
bool ActiveHingeRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh("../models/ActiveHinge_Frame.stl");

	if (!meshLoadingA) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	bool meshLoadingB = this->partB_->loadMesh(
			"../models/ActiveCardanHinge_Servo_Holder.stl");

	if (!meshLoadingB) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
	}

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> frame =
			this->partA_->getMesh();

	partA_->setColor(osg::Vec4(1, 0, 0, 0.5));
	partB_->setColor(osg::Vec4(0, 1, 0, 0.5));


	// x = 0 is midpoint of slot, so  -SLOT_THICKNESS/2 is edge of frame
	// and frame is (FRAME_LENGTH + SLOT_THICKNESS) long
	// so (FRAME_LENGTH + SLOT_THICKNESS)/2 -SLOT_THICKNESS/2 =
	// FRAME_LENGTH/2
	frame->setPosition(
			fromOde(
					osg::Vec3(
							ActiveHingeModel::FRAME_LENGTH / 2,
							ActiveHingeModel::SERVO_POSITION_OFFSET,
							0)));
	frame->setAttitude(osg::Quat(osg::inDegrees(180.0), osg::Vec3(1, 0, 0)));

	osg::ref_ptr<osg::PositionAttitudeTransform> patFrame(
			new osg::PositionAttitudeTransform());
	patFrame->addChild(frame);

	this->getMeshes()->addChild(patFrame.get());
	patFrame->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_A_ID));

	// PART B
	//float servoMeshCorrection = inMm(3.2);


	// x = 0 is midpoint of slot so SLOT_THICKNESS/2 is edge of servo
	// and servo is  SERVO_LENGTH + SLOT_THICKNESS  long
	// so -(SERVO_LENGTH + SLOT_THICKNESS)/2 + SLOT_THICKNESS/2
	// = -(SERVO_LENGTH)/2
	osg::ref_ptr<osg::PositionAttitudeTransform> servo =
			this->partB_->getMesh();
	servo->setPosition(
			fromOde(
					osg::Vec3(-(ActiveHingeModel::SERVO_LENGTH) / 2, 0,
							0)));

	servo->setAttitude(osg::Quat(osg::inDegrees(270.0), osg::Vec3(1, 0, 0)));

	osg::ref_ptr<osg::PositionAttitudeTransform> patServo(
			new osg::PositionAttitudeTransform());
	patServo->addChild(servo.get());

	this->getMeshes()->addChild(patServo.get());
	patServo->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_B_ID));


	if(isDebugActive()) {
		this->activateTransparency(patFrame->getOrCreateStateSet());
		this->activateTransparency(patServo->getOrCreateStateSet());
	}

	return true;
}
bool ActiveHingeRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh(
			RobogenUtils::getMeshFile(this->getModel(),
			  ActiveHingeModel::B_SLOT_A_ID));

	if (!meshLoadingA) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	bool meshLoadingB = this->partB_->loadMesh(
			RobogenUtils::getMeshFile(this->getModel(),
			  ActiveHingeModel::B_SLOT_B_ID));

	if (!meshLoadingB) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
	}

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> frame =
			this->partA_->getMesh();

	partA_->setColor(osg::Vec4(1, 0, 0, 0.5));
	partB_->setColor(osg::Vec4(0, 1, 0, 0.5));


	frame->setPosition(RobogenUtils::getRelativePosition(this->getModel(),
			  ActiveHingeModel::B_SLOT_A_ID));

	frame->setAttitude(RobogenUtils::getRelativeAttitude(this->getModel(),
			  ActiveHingeModel::B_SLOT_A_ID));

	osg::ref_ptr<osg::PositionAttitudeTransform> patFrame(
			new osg::PositionAttitudeTransform());
	patFrame->addChild(frame);

	this->getMeshes()->addChild(patFrame.get());
	patFrame->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_A_ID));

	// PART B

	osg::ref_ptr<osg::PositionAttitudeTransform> servo =
			this->partB_->getMesh();
	servo->setPosition(RobogenUtils::getRelativePosition(this->getModel(),
			  ActiveHingeModel::B_SLOT_B_ID));

	servo->setAttitude(RobogenUtils::getRelativeAttitude(this->getModel(),
			  ActiveHingeModel::B_SLOT_B_ID));

	osg::ref_ptr<osg::PositionAttitudeTransform> patServo(
			new osg::PositionAttitudeTransform());
	patServo->addChild(servo.get());

	this->getMeshes()->addChild(patServo.get());
	patServo->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_B_ID));


	if(isDebugActive()) {
		this->activateTransparency(patFrame->getOrCreateStateSet());
		this->activateTransparency(patServo->getOrCreateStateSet());
	}

	return true;
}
bool ActiveCardanRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh(
			"../models/ActiveCardanHinge_Servo_Holder.stl");

	if (!meshLoadingA) {
		std::cerr << "[ActiveCardanRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	bool meshLoadingB = this->partB_->loadMesh(
			"../models/ActiveCardanHinge_Servo_Holder.stl");

	if (!meshLoadingB) {
		std::cerr << "[ActiveCardanRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	bool meshLoadingC = this->patCross_->loadMesh(
			"../models/ActiveCardan_CrossShaft.stl");

	if (!meshLoadingC) {
		std::cerr << "[ActiveCardanRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
	}

	float meshCorrection = inMm(0.5);

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> partA =
			this->partA_->getMesh();

	partA_->setColor(osg::Vec4(1, 0, 0, 1));
	partB_->setColor(osg::Vec4(0, 1, 0, 1));

	partA->setPosition(
			osg::Vec3(
					fromOde(meshCorrection +
							ActiveCardanModel::SLOT_THICKNESS
									+ ActiveCardanModel::CONNNECTION_PART_LENGTH
											/ 2), 0, 0));

	partA->setAttitude(osg::Quat(osg::inDegrees(90.0), osg::Vec3(0, 0, 1)) *
			osg::Quat(osg::inDegrees(90.0), osg::Vec3(1, 0, 0)));

	osg::ref_ptr<osg::PositionAttitudeTransform> patPartA(
			new osg::PositionAttitudeTransform());
	patPartA->addChild(partA);

	this->getRootNode()->addChild(patPartA.get());
	patPartA->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveCardanModel::B_SLOT_A_ID));

	//attachAxis(patPartA);

	// Cross
	osg::ref_ptr<osg::PositionAttitudeTransform> cross =
			this->patCross_->getMesh();

	osg::ref_ptr<osg::PositionAttitudeTransform> patCross(
			new osg::PositionAttitudeTransform());
	patCross->addChild(cross.get());

	this->getRootNode()->addChild(patCross.get());
	patCross->setUpdateCallback(
			new BodyCallback(this->getModel(),
					ActiveCardanModel::B_CROSS_PART_A_ID));
	//attachAxis(patCross);

	// PART B
	osg::ref_ptr<osg::PositionAttitudeTransform> partB =
			this->partB_->getMesh();
	partB->setPosition(
			fromOde(
					osg::Vec3(
							-(meshCorrection + ActiveCardanModel::SLOT_THICKNESS
									+ ActiveCardanModel::CONNNECTION_PART_LENGTH
											/ 2), 0, 0)));

	osg::Quat rotateY(osg::inDegrees(90.0), osg::Vec3(0, 1, 0));
	osg::Quat rotateServoX(osg::inDegrees(90.0), osg::Vec3(1, 0, 0));
	partB->setAttitude(rotateServoX * rotateY *
			osg::Quat(osg::inDegrees(90.0), osg::Vec3(1, 0, 0)));

	osg::ref_ptr<osg::PositionAttitudeTransform> patPartB(
			new osg::PositionAttitudeTransform());
	patPartB->addChild(partB.get());

	this->getRootNode()->addChild(patPartB.get());
	patPartB->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveCardanModel::B_SLOT_B_ID));

	//attachAxis(patPartB);

	return true;

}
Exemplo n.º 8
0
bool ActiveHingeRenderModel::initRenderModel() {

	bool meshLoadingA = this->partA_->loadMesh("../models/ActiveHinge_Frame.stl");

	if (!meshLoadingA) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	bool meshLoadingB = this->partB_->loadMesh(
			"../models/ActiveCardanHinge_Servo_Holder.stl");

	if (!meshLoadingB) {
		std::cerr << "[ActiveHingeRenderModel] Error loading model"
				<< std::endl;
		return false;
	}

	if (isDebugActive()) {
		this->showDebugView();
		return true;
	}

	// PART A
	osg::ref_ptr<osg::PositionAttitudeTransform> frame =
			this->partA_->getMesh();

	partA_->setColor(osg::Vec4(1, 0, 0, 1));
	partB_->setColor(osg::Vec4(0, 1, 0, 1));

	frame->setPosition(
			fromOde(
					osg::Vec3(
							ActiveHingeModel::FRAME_LENGTH / 2 -
							ActiveHingeModel::SLOT_THICKNESS, 0,
							0)));
	frame->setAttitude(osg::Quat(osg::inDegrees(90.0), osg::Vec3(1, 0, 0)));
	osg::ref_ptr<osg::PositionAttitudeTransform> patFrame(
			new osg::PositionAttitudeTransform());
	patFrame->addChild(frame);

	this->getRootNode()->addChild(patFrame.get());
	patFrame->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_A_ID));

	// PART B
	float servoMeshCorrection = inMm(2.2);

	osg::ref_ptr<osg::PositionAttitudeTransform> servo =
			this->partB_->getMesh();
	servo->setPosition(
			fromOde(
					osg::Vec3(
							-(ActiveHingeModel::SERVO_LENGTH / 2) - servoMeshCorrection, 0,
							0)));

	servo->setAttitude(osg::Quat(osg::inDegrees(90.0), osg::Vec3(0, 0, 1)) *
			osg::Quat(osg::inDegrees(180.0), osg::Vec3(0, 1, 0)));

	osg::ref_ptr<osg::PositionAttitudeTransform> patServo(
			new osg::PositionAttitudeTransform());
	patServo->addChild(servo.get());

	this->getRootNode()->addChild(patServo.get());
	patServo->setUpdateCallback(
			new BodyCallback(this->getModel(), ActiveHingeModel::B_SLOT_B_ID));

	return true;

}