コード例 #1
0
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;
}
コード例 #2
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();
	}

	// 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;
}
コード例 #3
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;

}