Esempio n. 1
0
	float getAngle(const Vector2f& v1,const Vector2f& v2)  {
		Vector2f diff = v2 - v1;
		return calculateRotation(diff);
		/*
		Vector2f vn1 = normalize(v1);
		Vector2f vn2 = normalize(v2);
		if ( vn1 != vn2 ) {			
			float dt = dot(vn1,vn2);		
			if ( dt < -1.0f ) {
				dt = -1.0f;
			}
			if ( dt > 1.0f ) {
				dt = 1.0f;
			}
			float tmp = acos(dt);
			float cross = (vn1.x * vn2.y) - (vn2.x * vn1.y);
			if ( cross < 0.0f ) {
				tmp = 2.0f * PI - tmp;
			}
			return tmp;		
		}
		else {
			return 0.0f;
		}
		*/
	}
bool ThirdPersonCameraManipulator::handleMouseMove( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	float dx = ea.getX() - _windowCenterX;
	float dy = ea.getY() - _windowCenterY;

	// If the difference is less than one pixel, ignore it. This tolerance is essential in case we're unable to warp the cursor to the exact center(for example, if the center is a non-integer).
	if(dx < 1 && dx > -1)
		dx = 0;
	if(dy < 1 && dy > -1)
		dy = 0;

	if( dx == 0.f && dy == 0.f ) return false;	// if there's no movement, return now.

	centerMousePointer( ea, aa );

	_azimuth -= dx * .001;
	_zenith -= dy * .001;
	if ( _zenith < _zenithMin) _zenith = _zenithMin;
	else if ( _zenith > _zenithMax) _zenith = _zenithMax;
	if ( _azimuth >= 2 * pi ) _azimuth -= 2 * pi;
	else if ( _azimuth < 0 ) _azimuth += 2 * pi;

	calculateRotation();

	return true;
}
Esempio n. 3
0
GameActorView* Sun::getView() const {
    GameActorView *view = new GameActorView("qrc:/qml/sun");
    view->setProperty("identifier", identifier);
    view->setProperty("x", position[0]);
    view->setProperty("y", position[1]);
    view->setProperty("angle", calculateRotation());
    return view;
}
Esempio n. 4
0
void
SoBillboard::doAction(SoAction *action)
//
////////////////////////////////////////////////////////////////////////
{
    SbRotation rot = calculateRotation(action->getState());
    //if (! rotation.isIgnored() && ! rotation.isDefault())
    SoModelMatrixElement::rotateBy(action->getState(), this, rot);
    //rotation.getValue());
}
Esempio n. 5
0
void DrawPointTool::updateStatusText()
{
	if (isDragging() && rotating)
	{
		static const double pi_x_2 = M_PI * 2.0;
		static const double to_deg = 180.0 / M_PI;
		double angle = fmod(calculateRotation(constrained_pos, constrained_pos_map) + pi_x_2, pi_x_2) * to_deg;
		setStatusBarText( trUtf8("<b>Angle:</b> %1° ").arg(QLocale().toString(angle, 'f', 1)) + "| " +
		                  tr("<b>%1</b>: Fixed angles. ").arg(ModifierKey::control()) );
	}
	else
	{
		setStatusBarText( tr("<b>Click</b>: Create a point object. <b>Drag</b>: Create an object and set its orientation (if rotatable). "));
	}
}
ThirdPersonCameraManipulator::ThirdPersonCameraManipulator()
{
	_distance = 10;
	_minDistance = 1;
	_maxDistance = 500;
	_azimuth = 0.0f;
	_zenith = pi/4;
	_zenithMin = 0.001;
	_zenithMax = 3*pi/4;
	calculateRotation();

	osg::ref_ptr<osgGA::GUIEventAdapter> ea = new osgGA::GUIEventAdapter();
	osgViewer::Viewer* aa = getViewer();
	centerMousePointer(*ea, *aa);

}
Esempio n. 7
0
void
SoBillboard::getMatrix(SoGetMatrixAction *action)
//
////////////////////////////////////////////////////////////////////////
{
    //if (! rotation.isIgnored() && ! rotation.isDefault()) {
    SbRotation rot = calculateRotation(action->getState());
    SbMatrix &ctm = action->getMatrix();
    SbMatrix &inv = action->getInverse();
    SbMatrix m;

    rot.getValue(m);
    ctm.multLeft(m);
    rot.invert();
    rot.getValue(m);
    inv.multRight(m);
    //}
}
Esempio n. 8
0
void DrawPointTool::dragMove()
{
	updateStatusText();
	
	bool new_rotating = preview_object && preview_object->getSymbol()->asPoint()->isRotatable();
	if (new_rotating && !rotating && active_modifiers & Qt::ControlModifier)
		angle_helper->setActive(true, preview_object->getCoordF());
	rotating = new_rotating;
	
	if (rotating)
	{
		renderables->removeRenderablesOfObject(preview_object, false);
		preview_object->setRotation(calculateRotation(constrained_pos, constrained_pos_map));
		preview_object->update();
		renderables->insertRenderablesOfObject(preview_object);
	}
	
	updateDirtyRect();
}
void DrawPointTool::dragMove()
{
	if (preview_object->getSymbol()->asPoint()->isRotatable())
	{
		bool enable_angle_helper = active_modifiers & Qt::ControlModifier;
		if (angle_helper->isActive() != enable_angle_helper)
		{
			angle_helper->setActive(enable_angle_helper, preview_object->getCoordF());
			updateConstrainedPositions();
		}
		
		renderables->removeRenderablesOfObject(preview_object.get(), false);
		preview_object->setRotation(calculateRotation(constrained_pos, constrained_pos_map));
		preview_object->update();
		renderables->insertRenderablesOfObject(preview_object.get());
		updateDirtyRect();
		
		updateStatusText();
	}
}
Esempio n. 10
0
bool * Blocks::format(bool block[]) {
	return block = rotate(block, calculateRotation(block));
}
Esempio n. 11
0
bool DrawPathTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (!isDrawingButton(event->button()))
		return false;

	left_mouse_down = false;
	
	if (picking_angle)
	{
		picking_angle = false;
		picked_angle = pickAngle(map_coord, widget);
		return true;
	}
	else if (!editingInProgress())
	{
		return false;
	}
	
	if (following)
	{
		finishFollowing();
		if ((event->button() == Qt::RightButton) && drawOnRightClickEnabled())
			finishDrawing();
		return true;
	}
	
	if (!create_segment)
		return true;
	
	if (previous_point_is_curve_point && !dragging && !create_spline_corner)
	{
		// The new point has not been added yet
		MapCoord coord;
		if (shift_pressed)
		{
			coord = snap_helper->snapToObject(map_coord, widget);
		}
		else if (angle_helper->isActive())
		{
			QPointF constrained_pos;
			angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget);
			coord = MapCoord(constrained_pos_map);
		}
		else
		{
			coord = MapCoord(map_coord);
		}
		
		if (draw_dash_points)
			coord.setDashPoint(true);
		preview_path->addCoordinate(coord);
		updatePreviewPath();
		updateDirtyRect();
	}
	
	previous_point_is_curve_point = dragging;
	if (previous_point_is_curve_point)
	{
		QPointF constrained_pos;
		angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget);
		
		previous_pos_map = click_pos_map;
		previous_drag_map = constrained_pos_map;
		previous_point_direction = calculateRotation(constrained_pos.toPoint(), constrained_pos_map);
	}
	
	updateAngleHelper();
	
	create_spline_corner = false;
	path_has_preview_point = false;
	dragging = false;
	
	if ((event->button() == Qt::RightButton) && drawOnRightClickEnabled())
		finishDrawing();
	return true;
}
Esempio n. 12
0
bool DrawPathTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	cur_pos = event->pos();
	cur_pos_map = map_coord;
	
	if (!containsDrawingButtons(event->buttons()))
	{
		updateHover();
	}
	else if (!editingInProgress())
	{
		left_mouse_down = true;
		if (picking_angle)
			pickAngle(map_coord, widget);
		else
			return false;
	}
	else if (following)
	{
		updateFollowing();
	}
	else
	{
		bool drag_distance_reached = (event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx();
		if (dragging && !drag_distance_reached)
		{
			if (create_spline_corner)
			{
				create_spline_corner = false;
			}
			else if (path_has_preview_point)
			{
				undoLastPoint();
			}
		}
		else if (drag_distance_reached)
		{
			// Giving a direction by dragging
			dragging = true;
			create_spline_corner = false;
			create_segment = true;
			
			if (previous_point_is_curve_point)
				angle_helper->setCenter(click_pos_map);
			
			QPointF constrained_pos;
			angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget);
			
			if (previous_point_is_curve_point)
			{
				hidePreviewPoints();
				float drag_direction = calculateRotation(constrained_pos.toPoint(), constrained_pos_map);
				
				// Add a new node or convert the last node into a corner?
				if ((widget->mapToViewport(previous_pos_map) - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx())
					createPreviewCurve(MapCoord(click_pos_map), drag_direction);
				else
				{
					create_spline_corner = true;
					// This hides the old direction indicator
					previous_drag_map = previous_pos_map;
				}
			}
			
			updateDirtyRect();
		}
	}
	
	return true;
}
Esempio n. 13
0
void NiAnimation::updateSkeletonAnimation(xn::UserGenerator &user_generator)
{
    XnUInt16 num_users = MAX_USERS;
    user_generator.GetUsers(all_users, num_users);

    // tracking only default (first) person
    if (!user_generator.GetSkeletonCap().IsTracking(DEFAULT_USER)) return;

    // POSITION

    // animik: x,y,z € <-196, 196>

    XnSkeletonJointPosition torso;
    user_generator.GetSkeletonCap().GetSkeletonJointPosition(all_users[0], XN_SKEL_TORSO, torso);
    if (torso.fConfidence == 1) setPosition(torso.position.X*MM0, torso.position.Y*MM0+40, 150-torso.position.Z*MM0);


    // ROTATION

    double x, y, z, tx, ty, tz;

    // hip -> abdomen -> chest -> ...
    if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, tx, ty, tz, MM1) &&
        calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x,  y,  z, MM1))
        setRotation(getNodeByName("hip"), (x+tx)/2, (y+ty)/2, (z+tz)/2);

    if (calculateRotation(user_generator, XN_SKEL_TORSO, x, y, z, MM1))
        setRotation(getNodeByName("abdomen"), x, y, z);

    if (calculateRotation(user_generator, XN_SKEL_NECK, tx, ty, tz, MM1)) // !!! + torso ^
        setRotation(getNodeByName("chest"), (x+tx)/2, (y+ty)/2, (z+tz)/2);

    // ... -> neck -> head
    if (calculateRotation(user_generator, XN_SKEL_NECK, x, y, z, MM1))
        setRotation(getNodeByName("neck"), x, y, z);

    if (calculateRotation(user_generator, XN_SKEL_HEAD, x, y, z, MM1))
        setRotation(getNodeByName("head"), x, y, z);

    if (!global_mirror)
    {
        // ... -> lCollar -> lShldr -> lForeArm -> lHand
        if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("rCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("rForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("rHand"), x, y, z/MM2);

        // ... -> rCollar -> rShldr -> rForeArm -> rHand
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("lCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("lForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("lHand"), x, y, z/MM2);

        // hip -> lThigh -> lShin -> lFoot
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) )
            setRotation(getNodeByName("lThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("lShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("lFoot"), x/MM3, y, z);

        // hip -> rThigh -> rShin -> rFoot
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3))
            setRotation(getNodeByName("rThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("rShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("rFoot"), x/MM3, y, z);
    }
    else
    {
        // ... -> lCollar -> lShldr -> lForeArm -> lHand
        if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("lCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("lForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("lHand"), x, y, z/MM2);

        // ... -> rCollar -> rShldr -> rForeArm -> rHand
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("rCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("rForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("rHand"), x, y, z/MM2);

        // hip -> lThigh -> lShin -> lFoot
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) )
            setRotation(getNodeByName("rThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("rShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("rFoot"), x/MM3, y, z);

        // hip -> rThigh -> rShin -> rFoot
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3))
            setRotation(getNodeByName("lThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("lShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("lFoot"), x/MM3, y, z);
    }

    // add frame to animation
    if (is_recording)
    {
        setFrame(current_frame++);
        if (current_frame % 10 == 0) addKeyFrameAllJoints();
        else deleteKeyFrameAllJoints();
    }
}