1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
|
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2016 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.15 2007/07/14 12:43:44 benedetti
Added Doxygen documentation.
Revision 1.14 2007/07/09 22:47:18 benedetti
Removed using namespace std and modified accordingly.
Revision 1.13 2007/06/25 10:21:38 fiorin
Added some std:: here and there
Revision 1.12 2007/06/13 17:15:09 benedetti
Added one-level undo system and sticky trackmodes.
Revision 1.11 2007/05/15 14:59:10 benedetti
Main restructuring. added many new modes
Revision 1.10 2007/02/26 01:30:02 cignoni
Added reflection Name
Revision 1.9 2006/02/13 13:10:27 cignoni
Added Zmode for moving objects along the perpendicular to the viewplane
Revision 1.8 2004/07/18 06:54:08 cignoni
Added Scaling
Revision 1.7 2004/07/11 22:06:56 cignoni
Added scaling by wheel
Revision 1.6 2004/06/09 14:01:13 cignoni
Heavily restructured. To be completed only rotation works...
Revision 1.5 2004/05/14 03:15:09 ponchio
Redesigned partial version.
Revision 1.4 2004/05/07 12:46:08 cignoni
Restructured and adapted in a better way to opengl
Revision 1.3 2004/04/07 10:54:11 cignoni
Commented out unused parameter names and other minor warning related issues
Revision 1.2 2004/03/25 14:55:25 ponchio
Adding copyright.
****************************************************************************/
#ifndef TRACKMODE_H
#define TRACKMODE_H
#include <vcg/space/line3.h>
#include <vcg/space/plane3.h>
#include <vcg/space/segment3.h>
#include <vcg/space/ray3.h>
#include <wrap/gui/view.h>
namespace vcg {
class Trackball;
/*!
@brief Base class for all the manipulators.
Functions in this class implements the default
behaviour of a manipulator: <em>doing nothing</em>.
Every manipulator must be subclass of this class.
*/
class TrackMode {
public:
/*!
@brief The default virtual destructor
*/
virtual ~TrackMode () {
}
/*!
@brief The default manipulator application for mouse drags.
This default application does nothing.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
virtual void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief The default manipulator application for mouse scrolls.
This default application does nothing.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
virtual void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief The default manipulator's begin action function.
This default implementation does nothing.
*/
virtual void SetAction ();
/*!
@brief The default manipulator's reset function.
If a manipulator has a state, it can be reset to the inital state calling this function.
*/
virtual void Reset ();
/*!
@brief The default manipulator's name.
@return the constant string "TrackMode"
*/
virtual const char *Name (){
return "TrackMode";
};
/*!
@brief The default manipulator's render function.
@param trackball the manipulator manager.
*/
virtual void Draw (Trackball * trackball);
/*!
@brief The default avaibility to manipulator changes inside an action.
Every manipulator class can choose if the manipulator manager can switch
between it and another manipulator in the middle of an user action,
e.g. switching Trackball's current_mode without releasing the mouse button.
The default behaviour is to allow the switch.
Blocking switches is useful for stateful manipulators, regarding state
consistency respect to Trackball's %Undo() calls.
@return false if manipulator permits the switch.
*/
virtual bool isSticky();
/*!
@brief The default manipulator's undo function.
If a manipulator has a state, it must be undoable with a call of this function.
The undo must recreate the state present before the last Apply() call.
This default implementation does nothing.
*/
virtual void Undo();
virtual bool IsAnimating(const Trackball *tb);
virtual void Animate(unsigned int msec, Trackball *tb);
};
/*!
@brief An inactive manipulator.
This manipulator is useful only for drawing the inactive trackball
and for feeding occasional Trackball's modes with inactive manipulators.
*/
class InactiveMode:public TrackMode {
public:
/*!
@brief Return this manipulator's name.
@return the constant string "InactiveMode"
*/
const char *Name () {
return "InactiveMode";
};
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
};
/* View space modes */
// old interfaces
/*
class SphereMode: public TrackMode {
}
class CylinderMode: public TrackMode {
}
class PlaneMode: public TrackMode {
}
class ZMode: public TrackMode {
}
class LineMode: public TrackMode {
}
class LineMode: public TrackMode {
}
class ScaleMode: public TrackMode {
*/
// Sphere mode.
/*!
@brief The classic \e arcball manipulator.
This class implements the classic free rotation manipulator,
called \e arcball or \e trackball.
This is a stateless manipulator, result of the Apply function is
determined only by the mouse coordinates.
*/
class SphereMode:public TrackMode {
public:
/*!
@brief Apply a rotation, function of the user mouse drag action.
Map a mouse drag action on a rotation, and apply the rotation to the manipulated objects.
If the user does not hit the sphere that surrounds the manipulated object(s),
a rotational hyperboloid is used to compute the rotation.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Return this manipulator's name.
@return the constant string "SphereMode"
*/
const char *Name () {
return "SphereMode";
};
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
};
// Panning mode.
/*!
@brief The panning manipulator.
This manipulator implements a bidimensional translation
on the view plane.
This is a stateless manipulator, result of the Apply function is
determined only by the mouse coordinates.
*/
class PanMode:public TrackMode {
public:
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is dragged in the plane parallel to the screen.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Return this manipulator's name.
@return the constant string "PanMode"
*/
const char *Name () {
return "PanMode";
};
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
};
// Z mode.
/*!
@brief The Z-directional manipulator.
This manipulator implements a monodimensional translation
on the axis normal to the view plane.
Dragging the mouse up and down or scrolling the
mouse wheel will move the object along the Z of the camera.
This is a stateless manipulator, result of the Apply functions is
determined only either by the mouse coordinates or by the mouse wheel notch.
*/
class ZMode:public TrackMode {
public:
/*!
@brief Return this manipulator's name.
@return the constant string "ZMode"
*/
const char *Name () {
return "ZMode";
};
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is moved along the Z of the camera:
- Dragging the mouse down will move the object nearer to the camera.
- Dragging the mouse up will move the object farther from the camera.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Apply a translation, function of the user mouse wheel action.
The manipulated object is moved along the Z of the camera:
- Scrolling the mouse wheel down will move the object nearer to the camera.
- Scrolling the mouse wheel up will move the object farther from the camera.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
};
// Scale Mode.
/*!
@brief The scale manipulator.
This manipulator implements a scaling transformation.
Dragging the mouse up and down or scrolling the
mouse wheel will scale the object.
This is a stateless manipulator, result of the Apply functions is
determined only either by the mouse coordinates or by the mouse wheel notch.
*/
class ScaleMode:public TrackMode {
public:
/*!
@brief Return this manipulator's name.
@return the constant string "ScaleMode"
*/
const char *Name () {
return "ScaleMode";
};
/*!
@brief Apply a scaling, function of the user mouse drag action.
The manipulated object is scaled in this way:
- Dragging the mouse up will scale the object to a smaller dimension.
- Dragging the mouse down will scale the object to a greater dimension.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Apply a scaling, function of the user mouse wheel action.
The manipulated object is scaled in this way:
- Scrolling the mouse wheel up will scale the object to a smaller dimension.
- Scrolling the mouse wheel down will scale the object to a greater dimension.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
};
// Axis mode.
/*!
@brief The one-directional manipulator.
This manipulator implements a monodimensional translation
on a constrained direction.
Dragging the mouse up and down or scrolling the
mouse wheel will move the object along the direction.
This is a stateless manipulator, result of the Apply functions is
determined only either by the mouse coordinates or by the mouse wheel notch.
*/
class AxisMode:public TrackMode {
public:
/*!
@brief The line constructor.
This manipulator needs to be initialized with a direction.
This constructor can initialize it with a Line3f.
The line will be normalized.
@param ln the line that represent the direction.
*/
AxisMode (const Line3f & ln)
: axis (ln) {
}
/*!
@brief The origin-direction constructor.
This manipulator needs to be initialized with a direction.
This constructor can initialize it with two Point3f,
representing a point and a vector.
@param origin a point on the line.
@param direction the line direction.
*/
AxisMode (const Point3f & origin, const Point3f & direction)
: axis(Line3fN (origin, direction)) {
}
/*!
@brief Return this manipulator's name.
@return the constant string "AxisMode"
*/
const char *Name () {
return "AxisMode";
};
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is moved along the direction.
If the pointer ray is divergent from the direction the
object is not moved.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Apply a translation, function of the user mouse wheel action.
The manipulated object is moved along the direction.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
private:
/// The direction, stored as a normalized line.
Line3fN axis;
};
// Plane mode.
/*!
@brief The planar manipulator.
This manipulator implements a bidimensional translation
on a constrained plane.
This is a stateless manipulator, result of the Apply function is
determined only by the mouse coordinates.
*/
class PlaneMode:public TrackMode {
public:
/*!
@brief The plane costants constructor.
This manipulator needs to be initialized with a plane.
This constructor can initialize it with the four coefficients
of the plane equation \f$ ax + by + cz + d = 0 \f$.
@param a the first coefficient of the plane equation.
@param b the second coefficient of the plane equation.
@param c the third coefficient of the plane equation.
@param d the fourth coefficient of the plane equation.
*/
PlaneMode (float a, float b, float c, float d)
: plane(Plane3f(d,Point3f(a,b,c))){
}
/*!
@brief The plane constructor.
This manipulator needs to be initialized with a plane.
This constructor can initialize it with a Plane3f.
@param pl the plane.
*/
PlaneMode (Plane3f & pl)
: plane(pl) {
}
/*!
@brief Return this manipulator's name.
@return the constant string "PlaneMode"
*/
const char *Name () {
return "PlaneMode";
};
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is dragged in the plane.
If the pointer ray is divergent from the plane the
object is not moved.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
private:
/// The plane.
Plane3f plane;
};
// Cylinder mode.
/*!
@brief The constrained rotation manipulator.
This manipulator implements a rotation manipulator, that
make the rotation constrained around a given axis.
The user can either drag the mouse or scroll the wheel,
in either cases the rotation's angle is influenced by
the radius of the trackball.
This is a stateless manipulator, result of the Apply functions is
determined only either by the mouse coordinates or by the mouse wheel notch.
*/
class CylinderMode:public TrackMode {
public:
/*!
@brief The line constructor.
This manipulator needs to be initialized with an axis.
This constructor can initialize it with a Line3f.
The line will be normalized.
@param ln the line that represent the axis.
@param s a rotational snap angle non negative
*/
CylinderMode (Line3fN & ln,float s=0.0f)
: axis (ln), snap(s){
assert(snap>=0.0);
}
/*!
@brief The origin-direction constructor.
This manipulator needs to be initialized with a axis.
This constructor can initialize it with two Point3f,
representing a point and a vector.
@param origin a point on the axis.
@param direction the axis direction.
@param s a rotational snap angle (non negative)
*/
CylinderMode (const Point3f & origin, const Point3f & direction,float s=0.0f)
: axis (Line3fN(origin,direction)), snap(s){
assert(snap>=0.0);
}
/*!
@brief Return this manipulator's name.
@return the constant string "CylinderMode"
*/
const char *Name () {
return "CylinderMode";
};
/*!
@brief Apply a rotation, function of the user mouse drag action.
The manipulated object is rotated around the axis.
if the axis is too perpendicular to view plane, the angle is specified
only by the vertical component of the mouse drag and the radius.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Apply a rotation, function of the user mouse wheel action.
The manipulated object is rotated around the axis.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
private:
/// The axis, stored as a normalized line.
Line3fN axis;
/// The rotational snap value
float snap;
};
// Path mode.
/*!
@brief The path constrained manipulator.
This manipulator moves the object along an eventually closed path.
The user can either drag the mouse or scroll the wheel,
when the user drags the mouse, the object tries to slide toward it.
The object is assumed to initially be on the same position
of the first point on the path.
This is a \b stateful manipulator, result of the Apply functions is
determined by the objects's position along the path and
by either the mouse coordinates or the mouse wheel notch.
*/
class PathMode:public TrackMode {
public:
/*!
@brief The vector-boolean constructor.
The vector passed to build the path is copied locally.
The boolean value specifies if the path is to be closed.
If the boolean value is not specified, the path is not closed.
@warning the path is \b not assumed to have 0-length segments, so, if you want to close the path, please <b>do not</b> add a copy of the first point on the end of the vector.
@param pts the path nodes.
@param w a boolean value that closes the path.
*/
PathMode ( const std::vector < Point3f > &pts, bool w = false)
: points(), wrap(w), current_state(0), initial_state(0), old_hitpoint()
{
Init(pts);
assert(min_seg_length > 0.0f);
}
/*!
@brief The segment constructor.
If the path is a simple segment, it can be specified just with the endpoints.
@param start the starting point.
@param end the ending point.
*/
PathMode ( const Point3f &start, const Point3f &end )
: points(), wrap(false), current_state(0), initial_state(0), old_hitpoint()
{
points.push_back(start);
points.push_back(end);
path_length=Distance(start,end);
min_seg_length=path_length;
assert(min_seg_length > 0.0f);
}
/*!
@brief Return this manipulator's name.
@return the constant string "PathMode"
*/
const char *Name () {
return "PathMode";
};
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is moved along the path.
This function implements an algorithm that makes
the object try to slide on the path towards the
mouse pointer.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Apply a translation, function of the user mouse wheel action.
The manipulated object is moved along the path.
A step of the mouse wheel makes the object slide
by a distance equal to the half of the shortest
segment on the path.
@param trackball the manipulator manager.
@param WheelNotch the mouse wheel notch.
*/
void Apply (Trackball * trackball, float WheelNotch);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
/*!
@brief The begin action function.
This function is to be called at the begin of an user action.
*/
void SetAction ();
/*!
@brief The reset function.
This function reset the object position to the initial point.
*/
void Reset ();
/*!
@brief Try to set the inital point.
This function try to set the starting point in the point
passed as parameter, if the point passed does not reside
on the path, the start is put on the closest point on it.
@param p the point wished for the start.
@return the starting point on the path.
*/
Point3f SetStartNear(Point3f p);
/*!
@brief The (non) avaibility to manipulator changes inside an action.
This manipulator has an internal state and does not allow a
switch in the middle of a function.
@return the costant boolean true.
*/
bool isSticky();
/*!
@brief The undo function.
This function recreates the state present before the last Apply() call.
*/
void Undo();
private:
/*!
@brief The data initializer.
Initialize the internal state and checks params validity.
@param points the path nodes.
*/
void Init(const std::vector < Point3f > &points);
/*!
@brief The state interpreter.
Given the state, return the current point, the previous node and
the next node on the path.
The algoritm is linear in the node paths.
@param state the given state.
@param point is set to the current point.
@param prev_point is set to the point of current point's previous node.
@param next_point is set to the point of current point's next node.
*/
void GetPoints(float state, Point3f & point, Point3f & prev_point, Point3f & next_point);
/*!
@brief The state normalizer.
Normalize a given state in the right interval:
- \f$ [0 \ldots 1] \f$ if the path is open.
- \f$ [0 \ldots 1) \f$ if the path is closed (because it wraps).
@param state the given state.
*/
float Normalize(float state);
/*!
@brief Compute the new point and the \f$\Delta\f$-state.
Given a state and the mouse coords ray, computes the new
state point and return the \f$\Delta\f$-state.
The algoritm is linear in the node paths.
@param state the given state.
@param ray the ray relative to mouse coords.
@param hit_point is set to the new state point.
@return the \f$\Delta\f$-state.
*/
float HitPoint(float state, Ray3fN ray, Point3f &hit_point);
/*!
@brief Compute the verse to follow for slide nearer to a given point.
Given the current state point, the point of previus and
next node and a reference point, compute the verse to
follow for the object to come closer to the reference point.
@param reference_point
@param current_point
@param prev_point
@param next_point
@return -1, 0 or 1 if the verse is respectively towars the startpoint, null or towards the endpoint.
*/
int Verse(Point3f reference_point,Point3f current_point,Point3f prev_point,Point3f next_point);
/// The node vector.
std::vector < Point3f > points;
/// True if the path is closed, false otherwise.
bool wrap;
/// The current state.
float current_state;
/// The initial state.
float initial_state;
/// The path length.
float path_length;
/// The length of the shostest path segment
float min_seg_length;
/// The point relative to the old state.
Point3f old_hitpoint;
/// current_state after an Undo() call.
float undo_current_state;
/// old_hitpoint after an Undo() call.
Point3f undo_old_hitpoint;
};
// Area mode.
/*!
@brief The area constrained manipulator.
This manipulator moves the object inside a poligonal area.
The user can drag the object inside a planar area, defined by a polygon.
The polygon can be non convex, and is specified with a vector of vertexes.
If the object's trajectory intersects some poligon side, it tries to slide
around it, in a <em>"rubber band flavoured"</em> way.
The object is assumed to initially be on the same position of the
first vertex.
This is a \b stateful manipulator, result of the Apply function is
determined by the objects's position inside the area and
by the mouse coordinates.
*/
class AreaMode:public TrackMode {
public:
/*!
@brief The constructor.
From the given vector, is calculated the plane of the polygon, then
every point in the vector is projected on this plane.
The vector passed to build the polygon is copied locally.
@warning The vector is assumed to be formed of \b non collinear points.
@warning The polygon is \b not assumed to have 0-length sides, so please <b>do not</b> add a copy of the first point on the end of the vector.
@param pts the vertexes vector.
*/
AreaMode (const std::vector < Point3f > &pts)
{
Init(pts);
assert(min_side_length > 0.0f);
}
/*!
@brief Return this manipulator's name.
@return the constant string "AreaMode"
*/
const char *Name () {
return "AreaMode";
};
/*!
@brief Apply a translation, function of the user mouse drag action.
The manipulated object is moved inside the poligon.
This function implements an algorithm that makes
the object try to slide around the polygon borders.
@param trackball the manipulator manager.
@param new_point the new mouse pointer coordinate.
*/
void Apply (Trackball * trackball, Point3f new_point);
/*!
@brief Render this manipulator.
@param trackball the manipulator manager.
*/
void Draw (Trackball * trackball);
/*!
@brief The begin action function.
This function is to be called at the begin of an user action.
*/
void SetAction ();
/*!
@brief The reset function.
This function reset the object position to the initial point.
*/
void Reset ();
/*!
@brief Try to set the inital point.
This function try to set the starting point in the point
passed as parameter, if the point passed does not reside
in the area, the start is put in the closest point on it.
@param p the point wished for the start.
@return the starting point in the area.
*/
Point3f SetStartNear(Point3f p);
/*!
@brief The (non) avaibility to manipulator changes inside an action.
This manipulator has an internal state and does not allow a
switch in the middle of a function.
@return The costant boolean true.
*/
bool isSticky();
/*!
@brief The undo function.
This function recreates the state present before the last Apply() call.
*/
void Undo();
private:
/*!
@brief The data initializer.
Initialize the internal state and checks params validity.
@param pts The polygon vertexes.
*/
void Init(const std::vector < Point3f > &pts);
/*!
@brief Point in Polygon test.
Checks if a given point relies inside the poligon area,
using the ray tracing algorithm, linear in the number
of vertexes.
@param point The point to test.
@return true if the point is inside the polygon, false otherwise.
*/
bool Inside(Point3f point);
/*!
@brief Try to move the object inside the polygon
Given a point inside the area and a destination in the
poligon plane, try to move the point toward the destination,
sliding on any evenual border of the polygon.
The object can be imagined tied with a rubber attached to
destination, so it won't go back from it to slide around a border.
The algorithm is quadratic in the number of vertexes
(worst case, really really unlikely).
@param start the starting point <b>assumed inside</b>.
@param end the destination <b>assumed in the plane</b>.
@return the final move vector.
*/
Point3f Move(Point3f start,Point3f end);
/// The vertexes vector.
std::vector < Point3f > points;
/// True in time inteval between a call to SetAction () and a call to Apply()
bool begin_action;
/// One of the two dimensions used during the point in polygon test.
int first_coord_kept;
/// One of the two dimensions used during the point in polygon test.
int second_coord_kept;
/// The length of the shortest border
float min_side_length;
/// The current status.
Point3f status;
/// The screen space differenve between the object and the cursor during an action.
Point3f delta_mouse;
/// The old status.
Point3f old_status;
/// The initial status.
Point3f initial_status;
/// The polygon plane
Plane3f plane;
/// The rubberband handle (current destination in Move())
Point3f rubberband_handle ;
/// Current action's object trace
std::vector < Point3f > path;
/// begin_action after an Undo() call.
bool undo_begin_action;
/// status after an Undo() call.
Point3f undo_status;
/// delta_mouse after an Undo() call.
Point3f undo_delta_mouse;
/// old_status after an Undo() call.
Point3f undo_old_status;
/// rubberband_handle after an Undo() call.
Point3f undo_rubberband_handle;
/// path endpoint after an Undo() call.
size_t undo_path_index;
};
// Polar mode.
/* WARNING this mode is not compatible with the other rotation modes */
class PolarMode:public TrackMode {
public:
PolarMode(): alpha(0), beta(0), enda(0), endb(0) {}
void Apply (Trackball * trackball, Point3f new_point);
const char *Name () {
return "PolarMode";
};
void SetAction();
void Reset();
void Draw (Trackball * trackball);
private:
float alpha, beta; //rotation in y and x axis
float enda, endb; //store intermediate values of alpha and beta
};
class NavigatorWasdMode:public TrackMode {
public:
NavigatorWasdMode();
void Apply (Trackball * trackball, Point3f new_point);
const char *Name () {
return "NavigatorWasdMode";
};
//void SetAction();
void Reset();
//void Draw (Trackball * trackball);
bool isSticky();
bool IsAnimating(const Trackball *tb);
void Animate(unsigned int msec, Trackball *tb);
void SetAction ();
/// specific option setup methods for this mode
void FlipH(), FlipV(); // flips mouse controls
void SetTopSpeedsAndAcc(float speed_h, float speed_v, float acc=0.0); // (top) speed is in units on sec
// Acc is in units on sec^2, if 0 then no-inertia
void SetStepOnWalk(float width, float height); // optionally, set step-on-walk effects
void Apply (Trackball * trackball, float WheelNotch);
private:
float alpha, beta; //rotation in y and x axis
Point3f current_speed;
float step_current, step_last, step_x;
int _flipH, _flipV;
float accX, accY, accZ, dumping, topSpeedH, topSpeedV;
float step_height, step_length; // height of steps
};
}//namespace
#endif
|