QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_viewport.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
17//
18// defines ON_Viewport
19//
21
22#if !defined(OPENNURBS_VIEWPORT_INC_)
23#define OPENNURBS_VIEWPORT_INC_
24
26// Class ON_Viewport
27//
28// This object represents a viewing frustum
31{
33public:
34
35 // Default z=up perspective camera direction
37
38 // Construction
42
43 bool IsValidCamera() const;
44 bool IsValidFrustum() const;
45
46 // ON_Object overrides //////////////////////////////////////////////////////
47 //
48
49 /*
50 Description:
51 Test for a valid camera, frustum, and screen port.
52 Parameters:
53 text_log - [in] if the object is not valid and text_log
54 is not NULL, then a brief englis description of the
55 reason the object is not valid is appened to the log.
56 The information appended to text_log is suitable for
57 low-level debugging purposes by programmers and is
58 not intended to be useful as a high level user
59 interface tool.
60 Returns:
61 @untitled table
62 true camera, frustum, and screen port are valid.
63 false camera, frustum, or screen port is invalid.
64 Remarks:
65 Overrides virtual ON_Object::IsValid
66 See Also:
67 IsValidCamera, IsValidFrustum
68 */
69 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
70
71 // Description:
72 // Dumps debugging text description to a text log.
73 //
74 // Parameters:
75 // dump_target - [in] text log
76 //
77 // Remarks:
78 // This overrides the virtual ON_Object::Dump() function.
79 void Dump(
80 ON_TextLog& // dump_target
81 ) const;
82
83 // Description:
84 // Writes ON_Viewport defintion from a binary archive.
85 //
86 // Parameters:
87 // binary_archive - [in] open binary archive
88 //
89 // Returns:
90 // true if successful.
91 //
92 // Remarks:
93 // This overrides the virtual ON_Object::Write() function.
95 ON_BinaryArchive& // binary_archive
96 ) const;
97
98
99 // Description:
100 // Reads ON_Viewport defintion from a binary archive.
101 //
102 // Parameters:
103 // binary_archive - [in] open binary archive
104 //
105 // Returns:
106 // true if successful.
107 //
108 // Remarks:
109 // This overrides the virtual ON_Object::Read() function.
111 ON_BinaryArchive& // binary_archive
112 );
113
114
115 // ON_Geometry overrides //////////////////////////////////////////////////////
116 //
117
118 // Description:
119 // The dimension of a camera view frustum is 3.
120 //
121 // Returns:
122 // 3
123 //
124 // Remarks:
125 // This is virtual ON_Geometry function.
126 int Dimension() const;
127
128 // Description:
129 // Gets bounding box of viewing frustum.
130 //
131 // Parameters:
132 // boxmin - [in/out] array of Dimension() doubles
133 // boxmax - [in/out] array of Dimension() doubles
134 // bGrowBox - [in] (default=false)
135 // If true, then the union of the input bbox and the
136 // object's bounding box is returned in bbox.
137 // If false, the object's bounding box is returned in bbox.
138 //
139 // Returns:
140 // @untitled table
141 // true Valid frustum and bounding box returned.
142 // false Invalid camera or frustum. No bounding box returned.
143 //
144 // Remarks:
145 // This overrides the virtual ON_Geometry::GetBBox() function.
146 ON_BOOL32 GetBBox( // returns true if successful
147 double*, // boxmin
148 double*, // boxmax
149 ON_BOOL32 = false // bGrowBox
150 ) const;
151
152 // Description:
153 // Transforms the view camera location, direction, and up.
154 //
155 // Parameters:
156 // xform - [in] transformation to apply to camera.
157 //
158 // Returns:
159 // @untitled table
160 // true Valid camera was transformed.
161 // false Invalid camera, frustum, or transformation.
162 //
163 // Remarks:
164 // This overrides the virtual ON_Geometry::Transform() function.
166 const ON_Xform& // xform
167 );
168
169 // Interface /////////////////////////////////////////////////////////////////
170 //
171 void Initialize();
172
173 ON::view_projection Projection() const;
174
175 /*
176 Description:
177 Unconditionally set the projection.
178 Parameters:
179 projection - [in]
180 See Also:
181 ON_Viewport::SetParallelProjection
182 ON_Viewport::SetPerpectiveProjection
183 ON_Viewport::SetTwoPointPerspectiveProjection
184 */
185 bool SetProjection( ON::view_projection projection );
186
187 /*
188 Description:
189 Use this function to change projections of valid viewports
190 from persective to parallel. It will make common additional
191 adjustments to the frustum so the resulting views are similar.
192 The camera location and direction will not be changed.
193 Parameters:
194 bSymmetricFrustum - [in]
195 True if you want the resulting frustum to be symmetric.
196 Remarks:
197 If the current projection is parallel and bSymmetricFrustum,
198 FrustumIsLeftRightSymmetric() and FrustumIsTopBottomSymmetric()
199 are all equal, then no changes are made and true is returned.
200 */
201 bool ChangeToParallelProjection( bool bSymmetricFrustum );
202
203 /*
204 Description:
205 Use this function to change projections of valid viewports
206 from parallel to perspective. It will make common additional
207 adjustments to the frustum and camera location so the resulting
208 views are similar. The camera direction and target point are
209 not be changed.
210 Parameters:
211 target_distance - [in]
212 If ON_UNSET_VALUE this parameter is ignored. Otherwise
213 it must be > 0 and indicates which plane in the current
214 view frustum should be perserved.
215 bSymmetricFrustum - [in]
216 True if you want the resulting frustum to be symmetric.
217 lens_length - [in] (pass 50.0 when in doubt)
218 35 mm lens length to use when changing from parallel
219 to perspective projections. If the current projection
220 is perspective or lens_length is <= 0.0,
221 then this parameter is ignored.
222 Remarks:
223 If the current projection is perspective and bSymmetricFrustum,
224 FrustumIsLeftRightSymmetric() and FrustumIsTopBottomSymmetric()
225 are all equal, then no changes are made and true is returned.
226 */
227 bool ChangeToPerspectiveProjection(
228 double target_distance,
229 bool bSymmetricFrustum,
230 double lens_length
231 );
232
233 /*
234 Description:
235 Use this function to change projections of valid viewports
236 to a two point perspective. It will make common additional
237 adjustments to the frustum and camera location and direction
238 so the resulting views are similar.
239 Parameters:
240 target_distance - [in]
241 If ON_UNSET_VALUE this parameter is ignored. Otherwise
242 it must be > 0 and indicates which plane in the current
243 view frustum should be perserved.
244 up - [in]
245 This direction will be the locked up direction. Pass
246 ON_3dVector::ZeroVector if you want to use the world axis
247 direction that is closest to the current up direction.
248 Pass CameraY() if you want to preserve the current up direction.
249 lens_length - [in] (pass 50.0 when in doubt)
250 35 mm lens length to use when changing from parallel
251 to perspective projections. If the current projection
252 is perspective or lens_length is <= 0.0,
253 then this parameter is ignored.
254 Remarks:
255 If the current projection is perspective and
256 FrustumIsLeftRightSymmetric() is true and
257 FrustumIsTopBottomSymmetric() is false, then no changes are
258 made and true is returned.
259 */
260 bool ChangeToTwoPointPerspectiveProjection(
261 double target_distance,
262 ON_3dVector up,
263 double lens_length
264 );
265
266 /*
267 Returns:
268 True if the projection is ON::perspective_view.
269 */
270 bool IsPerspectiveProjection() const;
271
272 /*
273 Returns
274 IsPerspectiveProjection()
275 && CameraUpIsLocked()
276 && FrustumIsLeftRightSymmetric
277 && !FrustumIsTopBottomSymmetric
278 */
279 bool IsTwoPointPerspectiveProjection() const;
280
281 /*
282 Returns:
283 True if the projection is ON::parallel_view.
284 */
285 bool IsParallelProjection() const;
286
287 // These return true if the current direction and up are not zero and not
288 // parallel so the camera position is well defined.
289 bool SetCameraLocation( const ON_3dPoint& );
290 bool SetCameraDirection( const ON_3dVector& );
291 bool SetCameraUp( const ON_3dVector& );
292
293 ON_3dPoint CameraLocation() const;
294 ON_3dVector CameraDirection() const;
295 ON_3dVector CameraUp() const;
296
297 bool CameraLocationIsLocked() const;
298 bool CameraDirectionIsLocked() const;
299 bool CameraUpIsLocked() const;
300 bool FrustumIsLeftRightSymmetric() const;
301 bool FrustumIsTopBottomSymmetric() const;
302
303 void SetCameraLocationLock( bool bLockCameraLocation );
304 void SetCameraDirectionLock( bool bLockCameraDirection ) ;
305 void SetCameraUpLock( bool bLockCameraUp );
306 void SetFrustumLeftRightSymmetry( bool bForceLeftRightSymmetry );
307 void SetFrustumTopBottomSymmetry( bool bForceTopBottomSymmetry );
308 void UnlockCamera(); // sets all camera locks to false
309 void UnlockFrustumSymmetry(); // sets all frustum symmetry locks to false
310
311 // returns true if current camera orientation is valid
312 bool GetCameraFrame(
313 double*, // CameraLocation[3]
314 double*, // CameraX[3]
315 double*, // CameraY[3]
316 double* // CameraZ[3]
317 ) const;
318
319 // these do not check for a valid camera orientation
320 ON_3dVector CameraX() const; // unit to right vector
321 ON_3dVector CameraY() const; // unit up vector
322 ON_3dVector CameraZ() const; // unit vector in -CameraDirection
323
324
325 bool IsCameraFrameWorldPlan(
326 // Returns true if the camera direction = some world axis.
327 // The indices report which axes are used. For a "twisted"
328 // plan view it is possible to have zero x and y indices.
329 // This function returns true if and only if the "z" index
330 // is non-zero.
331 //
332 // Indices are +/-1 = world +/-x, +/-2 = world +/-y, +/-3 = world +/-z,
333 int*, // if true and plan is axis aligned, view x index, else 0
334 int*, // if true and plan is axis aligned, view y index, else 0
335 int* // if true, view z index, else 0
336 );
337
338 bool GetCameraExtents(
339 // returns bounding box in camera coordinates - this is useful information
340 // for setting view frustrums to include the point list
341 int, // count = number of 3d points
342 int, // stride = number of doubles to skip between points (>=3)
343 const double*, // 3d points in world coordinates
344 ON_BoundingBox& cambbox, // bounding box in camera coordinates
345 int bGrowBox = false // set to true if you want to enlarge an existing camera coordinate box
346 ) const;
347
348 bool GetCameraExtents(
349 // returns bounding box in camera coordinates - this is useful information
350 // for setting view frustrums to include the point list
351 const ON_BoundingBox&, // world coordinate bounding box
352 ON_BoundingBox& cambbox, // bounding box in camera coordinates
353 int bGrowBox = false // set to true if you want to enlarge an existing camera coordinate box
354 ) const;
355
356 bool GetCameraExtents(
357 // returns bounding box in camera coordinates - this is useful information
358 // for setting view frustrums to include the point list
359 ON_3dPoint&, // world coordinate bounding sphere center
360 double, // world coordinate bounding sphere radius
361 ON_BoundingBox& cambox, // bounding box in camera coordinates
362 int bGrowBox = false // set to true if you want to enlarge an existing camera coordinate box
363 ) const;
364
365 /*
366 Description:
367 Set the view frustum. If FrustumSymmetryIsLocked() is true
368 and left != -right or bottom != -top, then they will be
369 adjusted so the resulting frustum is symmetric.
370 */
371 bool SetFrustum(
372 double left, //
373 double right, // ( left < right )
374 double bottom, //
375 double top, // ( bottom < top )
376 double near_dist, //
377 double far_dist // ( 0 < near_dist < far_dist ) // ignored by Rhino version 1.0
378 );
379 bool GetFrustum(
380 double* left, //
381 double* right, // (left < right)
382 double* bottom, //
383 double* top, // (bottom < top)
384 double* near_dist = NULL, //
385 double* far_dist = NULL // (0 < near_dist < far_dist)
386 ) const;
387
388 // SetFrustumAspect() changes the larger of the frustum's widht/height
389 // so that the resulting value of width/height matches the requested
390 // aspect. The camera angle is not changed. If you change the shape
391 // of the view port with a call SetScreenPort(), then you generally
392 // want to call SetFrustumAspect() with the value returned by
393 // GetScreenPortAspect().
394 bool SetFrustumAspect( double );
395
396 // Returns frustum's width/height
397 bool GetFrustumAspect( double& ) const;
398
399 // Returns world coordinates of frustum's center
400 bool GetFrustumCenter( double* ) const;
401
402 // The near clipping plane stored in the Rhino 1.0 file is frequently very
403 // small and useless for high quality z-buffer based rendering. The far
404 // clipping value is not stored in the file. Use these functions to set
405 // the frustum's near and far clipping planes to appropriate values.
406 double FrustumLeft() const;
407 double FrustumRight() const;
408 double FrustumBottom() const;
409 double FrustumTop() const;
410 double FrustumNear() const;
411 double FrustumFar() const;
412
413 /*
414 Returns:
415 frustum right - frustum left
416 */
417 double FrustumWidth() const; // right - left
418
419 /*
420 Returns:
421 frustum right - frustum left
422 */
423 double FrustumHeight() const; // top - bottom
424
425 /*
426 Returns:
427 Minimum of fabs(FrustumWidth()) and fabs(FrustumHeight())
428 */
429 double FrustumMinimumDiameter() const;
430
431 /*
432 Returns:
433 Maximum of fabs(FrustumWidth()) and fabs(FrustumHeight())
434 */
435 double FrustumMaximumDiameter() const;
436
437
438 bool SetFrustumNearFar(
439 const double* bboxmin, // 3d bounding box min
440 const double* bboxmax // 3d bounding box max
441 );
442 bool SetFrustumNearFar(
443 const double* center, // 3d bounding sphere center
444 double radius // 3d bounding sphere radius
445 );
446 bool SetFrustumNearFar(
447 double near_dist, // ( > 0 )
448 double far_dist //
449 );
450
451 /*
452 Description:
453 If needed, adjust the current frustum so it has the
454 specified symmetries and adjust the camera location
455 so the target plane remains visible.
456 Parameters:
457 bLeftRightSymmetric - [in]
458 If true, the frustum will be adjusted so left = -right.
459 bTopBottomSymmetric - [in]
460 If true, the frustum will be adjusted so top = -bottom.
461 target_distance - [in]
462 If projection is not perspective or target_distance
463 is ON_UNSET_VALUE, this this parameter is ignored.
464 If the projection is perspective and target_distance
465 is not ON_UNSET_VALUE, then it must be > 0.0 and
466 it is used to determine which plane in the old
467 frustum will appear unchanged in the new frustum.
468 bool
469 Returns true if the returned viewport has a frustum
470 with the specified symmetries.
471 */
472 bool ChangeToSymmetricFrustum(
473 bool bLeftRightSymmetric,
474 bool bTopBottomSymmetric,
475 double target_distance
476 );
477
478 /*
479 Get near and far clipping distances of a point
480 Parameters:
481 point - [in]
482 near_dist - [out]
483 near distance of the point (can be < 0)
484 far_dist - [out]
485 far distance of the point (can be equal to near_dist)
486 bGrowNearFar - [in]
487 If true and input values of near_dist and far_dist
488 are not ON_UNSET_VALUE, the near_dist and far_dist
489 are enlarged to include bbox.
490 Returns:
491 True if the point is ing the view frustum and
492 near_dist/far_dist were set.
493 False if the bounding box does not intesect the
494 view frustum.
495 */
496 bool GetPointDepth(
497 ON_3dPoint point,
498 double* near_dist,
499 double* far_dist,
500 bool bGrowNearFar=false
501 ) const;
502
503 /*
504 Description:
505 Get near and far clipping distances of a bounding box
506 Parameters:
507 bbox - [in]
508 bounding box
509 near_dist - [out]
510 near distance of the box (can be < 0)
511 far_dist - [out]
512 far distance of the box (can be equal to near_dist)
513 bGrowNearFar - [in]
514 If true and input values of near_dist and far_dist
515 are not ON_UNSET_VALUE, the near_dist and far_dist
516 are enlarged to include bbox.
517 Returns:
518 True if the bounding box intersects the view frustum and
519 near_dist/far_dist were set.
520 False if the bounding box does not intesect the view frustum.
521 */
522 bool GetBoundingBoxDepth(
523 ON_BoundingBox bbox,
524 double* near_dist,
525 double* far_dist,
526 bool bGrowNearFar=false
527 ) const;
528
529 /*
530 Description:
531 Get near and far clipping distances of a bounding sphere.
532 Parameters:
533 sphere - [in]
534 bounding sphere
535 near_dist - [out]
536 near distance of the sphere (can be < 0)
537 far_dist - [out]
538 far distance of the sphere (can be equal to near_dist)
539 bGrowNearFar - [in]
540 If true and input values of near_dist and far_dist
541 are not ON_UNSET_VALUE, the near_dist and far_dist
542 are enlarged to include bbox.
543 Returns:
544 True if the sphere intersects the view frustum and
545 near_dist/far_dist were set.
546 False if the sphere does not intesect the view frustum.
547 */
548 bool GetSphereDepth(
549 ON_Sphere sphere,
550 double* near_dist,
551 double* far_dist,
552 bool bGrowNearFar=false
553 ) const;
554
555 /*
556 Description:
557 Set near and far clipping distance subject to constraints.
558 Parameters:
559 near_dist - [in] (>0) desired near clipping distance
560 far_dist - [in] (>near_dist) desired near clipping distance
561 min_near_dist - [in]
562 If min_near_dist <= 0.0, it is ignored.
563 If min_near_dist > 0 and near_dist < min_near_dist,
564 then the frustum's near_dist will be increased to
565 min_near_dist.
566 min_near_over_far - [in]
567 If min_near_over_far <= 0.0, it is ignored.
568 If near_dist < far_dist*min_near_over_far, then
569 near_dist is increased and/or far_dist is decreased
570 so that near_dist = far_dist*min_near_over_far.
571 If near_dist < target_dist < far_dist, then near_dist
572 near_dist is increased and far_dist is decreased so that
573 projection precision will be good at target_dist.
574 Otherwise, near_dist is simply set to
575 far_dist*min_near_over_far.
576 target_dist - [in]
577 If target_dist <= 0.0, it is ignored.
578 If target_dist > 0, it is used as described in the
579 description of the min_near_over_far parameter.
580 */
581 bool SetFrustumNearFar(
582 double near_dist,
583 double far_dist,
584 double min_near_dist,
585 double min_near_over_far,
586 double target_dist
587 );
588
589 // Description:
590 // Get near clipping plane.
591 //
592 // near_plane - [out] near clipping plane if camera and frustum
593 // are valid. The plane's frame is the same as the camera's
594 // frame. The origin is located at the intersection of the
595 // camera direction ray and the near clipping plane.
596 //
597 // Returns:
598 // true if camera and frustum are valid.
599 bool GetNearPlane(
600 ON_Plane& near_plane
601 ) const;
602
603 // Description:
604 // Get far clipping plane.
605 //
606 // far_plane - [out] far clipping plane if camera and frustum
607 // are valid. The plane's frame is the same as the camera's
608 // frame. The origin is located at the intersection of the
609 // camera direction ray and the far clipping plane.
610 //
611 // Returns:
612 // true if camera and frustum are valid.
613 bool GetFarPlane(
614 ON_Plane& far_plane
615 ) const;
616
617 /*
618 Description:
619 Get left world frustum clipping plane.
620 Parameters:
621 left_plane - [out]
622 frustum left side clipping plane. The normal points
623 into the visible region of the frustum. If the projection
624 is perspective, the origin is at the camera location,
625 otherwise the origin isthe point on the plane that is
626 closest to the camera location.
627 Returns:
628 True if camera and frustum are valid and plane was set.
629 */
630 bool GetFrustumLeftPlane(
631 ON_Plane& left_plane
632 ) const;
633
634 /*
635 Description:
636 Get right world frustum clipping plane.
637 Parameters:
638 right_plane - [out]
639 frustum right side clipping plane. The normal points
640 out of the visible region of the frustum. If the projection
641 is perspective, the origin is at the camera location,
642 otherwise the origin isthe point on the plane that is
643 closest to the camera location.
644 Returns:
645 True if camera and frustum are valid and plane was set.
646 */
647 bool GetFrustumRightPlane(
648 ON_Plane& right_plane
649 ) const;
650
651 /*
652 Description:
653 Get right world frustum clipping plane.
654 Parameters:
655 right_plane - [out]
656 frustum bottom side clipping plane. The normal points
657 into the visible region of the frustum. If the projection
658 is perspective, the origin is at the camera location,
659 otherwise the origin isthe point on the plane that is
660 closest to the camera location.
661 Returns:
662 True if camera and frustum are valid and plane was set.
663 */
664 bool GetFrustumBottomPlane(
665 ON_Plane& bottom_plane
666 ) const;
667
668 /*
669 Description:
670 Get right world frustum clipping plane.
671 Parameters:
672 top_plane - [out]
673 frustum top side clipping plane. The normal points
674 into the visible region of the frustum. If the projection
675 is perspective, the origin is at the camera location,
676 otherwise the origin isthe point on the plane that is
677 closest to the camera location.
678 Returns:
679 True if camera and frustum are valid and plane was set.
680 */
681 bool GetFrustumTopPlane(
682 ON_Plane& top_plane
683 ) const;
684
685 // Description:
686 // Get corners of near clipping plane rectangle.
687 //
688 // Parameters:
689 // left_bottom - [out]
690 // right_bottom - [out]
691 // left_top - [out]
692 // right_top - [out]
693 //
694 // Returns:
695 // true if camera and frustum are valid.
696 bool GetNearRect(
697 ON_3dPoint& left_bottom,
698 ON_3dPoint& right_bottom,
699 ON_3dPoint& left_top,
700 ON_3dPoint& right_top
701 ) const;
702
703 // Description:
704 // Get corners of far clipping plane rectangle.
705 //
706 // Parameters:
707 // left_bottom - [out]
708 // right_bottom - [out]
709 // left_top - [out]
710 // right_top - [out]
711 //
712 // Returns:
713 // true if camera and frustum are valid.
714 bool GetFarRect(
715 ON_3dPoint& left_bottom,
716 ON_3dPoint& right_bottom,
717 ON_3dPoint& left_top,
718 ON_3dPoint& right_top
719 ) const;
720
721
722 /*
723 Description:
724 Location of viewport in pixels.
725 These are provided so you can set the port you are using
726 and get the appropriate transformations to and from
727 screen space.
728 Parameters:
729 port_left - [in]
730 port_right - [in] (port_left != port_right)
731 port_bottom - [in]
732 port_top - [in] (port_top != port_bottom)
733 port_near - [in]
734 port_far - [in]
735 Example:
736
737 // For a Windows window
738 int width = width of window client area in pixels;
739 int height = height of window client area in pixels;
740 port_left = 0;
741 port_right = width;
742 port_top = 0;
743 port_bottom = height;
744 port_near = 0;
745 port_far = 1;
746 SetScreenPort( port_left, port_right,
747 port_bottom, port_top,
748 port_near, port_far );
749
750 Returns:
751 true if input is valid.
752 See Also:
753 ON_Viewport::GetScreenPort
754 */
755 bool SetScreenPort(
756 int port_left,
757 int port_right,
758 int port_bottom,
759 int port_top,
760 int port_near = 0,
761 int port_far = 0
762 );
763
764 bool GetScreenPort(
765 int* left,
766 int* right, //( port_left != port_right )
767 int* port_bottom,
768 int* port_top, //( port_bottom != port_top)
769 int* port_near=NULL,
770 int* port_far=NULL
771 ) const;
772
773 bool GetScreenPortAspect( double& ) const; // port's |width/height|
774
775 bool GetCameraAngle(
776 double* half_diagonal_angle, // 1/2 of diagonal subtended angle
777 double* half_vertical_angle, // 1/2 of vertical subtended angle
778 double* half_horizontal_angle // 1/2 of horizontal subtended angle
779 ) const;
780 bool GetCameraAngle(
781 double* half_smallest_angle // 1/2 of smallest subtended view angle
782 ) const;
783 bool SetCameraAngle(
784 double half_smallest_angle // 1/2 of smallest subtended view angle
785 // 0 < angle < pi/2
786 );
787
788 // These functions assume the camera is horizontal and crop the
789 // film rather than the image when the aspect of the frustum
790 // is not 36/24. (35mm film is 36mm wide and 24mm high.)
791 //
792 // The SetCamera35mmLensLength() preserves camera location,
793 // changes the frustum, but maintains the frsutrum's aspect.
794 bool GetCamera35mmLensLength(
795 double* lens_length
796 ) const;
797 bool SetCamera35mmLensLength(
798 double lens_length
799 );
800
801 // Same as GetCamera35mmLensLength() with "lens" misspelled.
802 bool GetCamera35mmLenseLength(
803 double* lens_length
804 ) const;
805
806 // Same as SetCamera35mmLensLength() with "lens" misspelled.
807 bool SetCamera35mmLenseLength(
808 double lens_length
809 );
810
811 bool GetXform(
812 ON::coordinate_system srcCS,
813 ON::coordinate_system destCS,
814 ON_Xform& matrix // 4x4 transformation matrix (acts on the left)
815 ) const;
816
817 /*
818 Description:
819 Get the world coordinate line in the view frustum
820 that projects to a point on the screen.
821 Parameters:
822 screenx - [in]
823 screeny - [in] (screenx,screeny) = screen location
824 world_line - [out] 3d world coordinate line segment
825 starting on the near clipping plane and ending
826 on the far clipping plane.
827 Returns:
828 true if successful.
829 false if view projection or frustum is invalid.
830 */
831 bool GetFrustumLine(
832 double screenx,
833 double screeny,
834 ON_Line& world_line
835 ) const;
836
837 // display tools
838 bool GetWorldToScreenScale(
839 const ON_3dPoint& point_in_frustum, // [in] point in viewing frustum.
840 double* pixels_per_unit // [out] scale = number of pixels per world unit at the 3d point
841 ) const;
842
843 bool GetCoordinateSprite(
844 int, // size in pixels of coordinate sprite axes
845 int, int, // screen (x,y) for sprite origin
846 int[3], // returns depth order for axes
847 double [3][2] // screen coords for axes ends
848 ) const;
849
850 // Use Extents() as a quick way to set a viewport to so that bounding
851 // volume is inside of a viewports frusmtrum.
852 // The view angle is used to determine the position of the camera.
853 bool Extents(
854 double half_view_angle, // 1/2 smallest subtended view angle
855 // (0 < angle < pi/2)
856 const ON_BoundingBox& world_bbox// 3d world coordinate bounding box
857 );
858 bool Extents(
859 double half_view_angle, // 1/2 smallest subtended view angle
860 // (0 < angle < pi/2)
861 const ON_3dPoint& center, // 3d world coordinate bounding sphere center
862 double radius // 3d sphere radius
863 );
864
866 // View changing from screen input points. Handy for
867 // using a mouse to manipulate a view.
868 //
869
871 // ZoomToScreenRect() may change camera and frustum settings
872 bool ZoomToScreenRect(
873 int screen_x0,
874 int screen_y0, // (x,y) screen coords of a rectangle corner
875 int screen_x1,
876 int screen_y1 // (x,y) screen coords of opposite rectangle corner
877 );
878
880 // DollyCamera() does not update the frustum's clipping planes.
881 // To update the frustum's clipping planes call DollyFrustum(d)
882 // with d = dollyVector o cameraFrameZ. To convert screen locations
883 // into a dolly vector, use GetDollyCameraVector().
884 bool DollyCamera( // Does not update frustum. To update frustum use
885 // DollyFrustum(d) with d = dollyVector o cameraFrameZ
886 const ON_3dVector& dolly_vector // dolly vector in world coordinates
887 );
888
890 // Gets a world coordinate dolly vector that can be passed to
891 // DollyCamera().
892 bool GetDollyCameraVector(
893 int screen_x0,
894 int screen_y0, // (x,y) screen coords of start point
895 int screen_x1,
896 int screen_y1, // (x,y) screen coords of end point
897 double proj_plane_dist, // distance of projection plane from camera.
898 // When in doubt, use 0.5*(frus_near+frus_far).
899 ON_3dVector& dolly_vector // world coordinate dolly vector returned here
900 ) const;
901
903 // Moves frustum's clipping planes
904 bool DollyFrustum(
905 double dolly_distance // distance to move in camera direction
906 );
907
908 /*
909 Description:
910 Apply scaling factors to parallel projection clipping coordinates
911 by setting the m_clip_mod transformation.
912 Parameters:
913 x - [in] x > 0
914 y - [in] y > 0
915 Example:
916 If you want to compress the view projection across the viewing
917 plane, then set x = 0.5, y = 1.0, and z = 1.0.
918 Returns:
919 True if successful.
920 False if input is invalid or the view is a perspective view.
921 */
922 bool SetViewScale( double x, double y );
923 void GetViewScale( double* x, double* y ) const;
924
925 // OBSOLETE - use SetViewScale
926 //__declspec(deprecated) bool ScaleView( double x, double y, double z );
927
928 /*
929 Description:
930 Gets the m_clip_mod transformation;
931 Returns:
932 value of the m_clip_mod transformation.
933 */
934 ON_Xform ClipModXform() const;
935
936 /*
937 Description:
938 Gets the m_clip_mod_inverse transformation;
939 Returns:
940 value of the m_clip_mod_inverse transformation.
941 */
942 ON_Xform ClipModInverseXform() const;
943
944 /*
945 Returns:
946 True if clip mod xform is identity.
947 */
948 bool ClipModXformIsIdentity() const;
949
950 /*
951 Description:
952 Return a point on the central axis of the view frustum.
953 This point is a good choice for a general purpose target point.
954 Parameters:
955 target_distance - [in]
956 If target_distance > 0.0, then the distance from the returned
957 point to the camera plane will be target_distance. Note that
958 if the frustum is not symmetric, the distance from the
959 returned point to the camera location will be larger than
960 target_distanct.
961 If target_distance == ON_UNSET_VALUE and the frustum
962 is valid with near > 0.0, then 0.5*(near + far) will be used
963 as the target_distance.
964 Returns:
965 A point on the frustum's central axis. If the viewport or input
966 is not valid, then ON_3dPoint::UnsetPoint is returned.
967 */
968 ON_3dPoint FrustumCenterPoint( double target_distance ) const;
969
970 /*
971 Returns:
972 The current value of the target point. This point does not play
973 a role in the view projection calculations. It can be used as a
974 fixed point when changing the camera so the visible regions of the
975 before and after frustums both contain the region of interest.
976 Remarks:
977 The default constructor sets this point on ON_3dPoint::UnsetPoint.
978 You must explicitly call one SetTargetPoint() functions to set
979 the target point.
980 */
981 ON_3dPoint TargetPoint() const;
982
983 /*
984 Description:
985 Set the target point.
986 Parameters:
987 target_point - [in]
988 When in doubt, the point returned by FrustumCenterPoint(ON_UNSET_VALUE)
989 is a good choice.
990 Remarks:
991 The default constructor sets this point on ON_3dPoint::UnsetPoint.
992 You must explicitly call one SetTargetPoint() functions to set
993 the target point.
994 */
995 bool SetTargetPoint( ON_3dPoint target_point );
996
997 /*
998 Description:
999 Get the distance from the target point to the camera plane.
1000 Note that if the frustum is not symmetric, then this distance
1001 is shorter than the distance from the target to the camera location.
1002 Parameters:
1003 bUseFrustumCenterFallback - [in]
1004 If bUseFrustumCenterFallback is false and the target point is
1005 not valid, then ON_UNSET_VALUE is returned.
1006 If bUseFrustumCenterFallback is true and the frustum is valid
1007 and current target point is not valid or is behind the camera,
1008 then 0.5*(near + far) is returned.
1009 Returns:
1010 Shortest signed distance from camera plane to target point.
1011 If the target point is on the visible side of the camera,
1012 a positive value is returned. ON_UNSET_VALUE is returned
1013 when the input of view is not valid.
1014 */
1015 double TargetDistance( bool bUseFrustumCenterFallback ) const;
1016
1017 void SetMinNearOverFar(double);
1018 double MinNearOverFar() const;
1019
1020 /*
1021 Description:
1022 Expert user function to control the minimum
1023 ratio of near/far when perspective projections
1024 are begin used.
1025 Parameters:
1026 min_near_over_far - [in]
1027 Remarks:
1028 This is a runtime setting and is not saved in 3dm files.
1029 */
1030 void SetPerspectiveMinNearOverFar(double min_near_over_far);
1031
1032 /*
1033 Description:
1034 Expert user function to get the minimum runtime
1035 value of near/far when perspective projections
1036 are begin used.
1037 Returns:
1038 The minimum permitted value of near/far when perspective
1039 projections are begin used.
1040 Remarks:
1041 This is a runtime setting and is not saved in 3dm files.
1042 */
1043 double PerspectiveMinNearOverFar() const;
1044
1045 /*
1046 Description:
1047 Expert user function to control the minimum
1048 value of near when perspective projections
1049 are begin used.
1050 Parameters:
1051 min_near_dist - [in]
1052 Remarks:
1053 This is a runtime setting and is not saved in 3dm files.
1054 */
1055 void SetPerspectiveMinNearDist(double min_near_dist);
1056
1057 /*
1058 Description:
1059 Expert user function to get the minimum
1060 value of near when perspective projections
1061 are begin used.
1062 Returns:
1063 The minimum permitted value of near when perspective
1064 projections are begin used.
1065 Remarks:
1066 This is a runtime setting and is not saved in 3dm files.
1067 */
1068 double PerspectiveMinNearDist() const;
1069
1070 /*
1071 Description:
1072 Sets the viewport's id to the value used to
1073 uniquely identify this viewport.
1074 Parameters:
1075 viewport_id - [in]
1076 Returns:
1077 True if the viewport's id was successfully set
1078 and false otherwise (ie. the viewport uuid has
1079 already been set).
1080 Remarks:
1081 There is no approved way to change the viewport
1082 id once it is set in order to maintain consistency
1083 across multiple viewports and those routines that
1084 manage them.
1085 */
1086 bool SetViewportId(const ON_UUID& viewport_id );
1087
1088 ON_UUID ViewportId(void) const;
1089
1090 /*
1091 Description:
1092 EXPERT USER function to change the viewport's id.
1093 If you change the id, you risk damaging display
1094 and visibility relationships in the model.
1095 Parameters:
1096 viewport_id - [in]
1097 */
1098 void ChangeViewportId(const ON_UUID& viewport_id);
1099
1100protected:
1101
1102 // These boolean status flags are set to true when
1103 // the associated fields contain valid values.
1107 unsigned char m_reserved1;
1108
1109 // Camera Settings: ///////////////////////////////////////////////
1110
1111 // perspective or parallel projection
1112 ON::view_projection m_projection;
1113
1114 // Camera location, direction and orientation (in world coordinates).
1115 // These values are used to set the camera frame vectors CamX, CamY,
1116 // CamZ. If bValidCamera is true, then the CamX, CamY and CamZ
1117 // vectors are properly initialized and should be used
1118 // instead of CamDir[] and CamUp[]. The frame vectors CamX, CamY, CamZ
1119 // are always a right handed orthonormal frame. The CamDir
1120 // and CamUp vectors contain the values passed to SetViewCamera().
1121
1122 // If true and the camera is valid, then the corresponding camera
1123 // parameter will not be changed by view editing functions. This
1124 // permits user interface to easily preserve important camera
1125 // features without having to perform excessive calculations.
1129 unsigned char m_frustum_symmetry_flags; // 0 != (flags & 1) top/bottom symmetry enforced
1130 // 0 != (flags & 2) left/right symmetry enforced.
1131 ON_3dPoint m_CamLoc; // camera location
1132 ON_3dVector m_CamDir; // from camera towards view (nonzero and not parallel to m_CamUp)
1133 ON_3dVector m_CamUp; // (nonzero and not parallel to m_CamDir)
1134
1135 // The camera frame vectors are properly initialized by SetCamera()
1139
1140 // View Frustum Settings: ///////////////////////////////////////
1141 // left, right are camera X coords on near clipping plane
1142 // bottom, top are camera Y coords on near clipping plane
1143 // near = distance from camera to near clipping plane
1144 // far = distance from camera to far clipping plane
1145 double m_frus_left, m_frus_right; // frus_left < frus_right
1146 double m_frus_bottom, m_frus_top; // frus_bottom < frus_top
1147 double m_frus_near, m_frus_far; // frus_near < frus_far
1148 // in perspective, 0 < frus_near
1149
1150
1151 // Device View Port Box Settings: ( in display device coordinates ) ////
1152 // The point (left,bottom,-near), in camera coordinates, of the view
1153 // frustum is mapped to pixel coordinate (port_left,port_bottom,port_near).
1154 // The point (right,top,-far), in camera coordinates, of the view frustum
1155 // is mapped to pixel coordinate (port_right,port_top,port_far).
1156 int m_port_left, m_port_right; // port_left != port_right
1157 int m_port_bottom, m_port_top; // port_bottom != port_top
1158 // In many situations including Windows,
1159 // port_left = 0,
1160 // port_right = viewport width-1,
1161 // port_top = 0,
1162 // port_bottom = viewport height-1.
1163 int m_port_near, m_port_far; // (If you want an 8 bit z-buffer with
1164 // z=255 being "in front of" z=0, then
1165 // set port_near = 255 and port_far = 0.)
1166
1167
1168 // The location of this point has no impact on the
1169 // view projection. It is simply a suggestion for a
1170 // fixed point when views are rotated or the isometric
1171 // depth when perpsective views are dollied. The default
1172 // is ON_UNSET_POINT.
1174
1175private:
1176 // When this id matches the viewport id saved in an ON_DisplayMaterialRef
1177 // list in ON_3dmObjectAttributes, then the the display material is used
1178 // for that object in this view.
1180
1181 bool SetCameraFrame(); // used to set m_CamX, m_CamY, m_CamZ
1182
1183 // This transform is used to tweak the clipping
1184 // coordinates. The default is the identity.
1185 // Modify this transformation when you need to do
1186 // things like z-buffer bias, non-uniform viewplane
1187 // scaling, and so on.
1188
1189 /*
1190 Description:
1191 Sets the m_clip_mod transformation;
1192 Parameters:
1193 clip_mod_xform - [in] invertable transformation
1194 */
1195 bool SetClipModXform( ON_Xform clip_mod_xform );
1198
1199 // Runtime values that depend on the graphics hardware being used.
1200 // These values are not saved in 3dm files.
1203};
1204
1205ON_DECL
1206bool
1208 const ON_3dVector&, // X, // X,Y,Z must be a right handed orthonormal basis
1209 const ON_3dVector&, // Y,
1210 const ON_3dVector&, // Z,
1211 double*, // angle1, // returns rotation about world Z
1212 double*, // angle2, // returns rotation about world X ( 0 <= a2 <= pi )
1213 double* // angle3 // returns rotation about world Z
1214 );
1215
1216ON_DECL
1217bool
1218ON_ViewportFromRhinoView( // create ON_Viewport from legacy Rhino projection info
1219 ON::view_projection, // projection,
1220 const ON_3dPoint&, // rhvp_target, // 3d point
1221 double, // rhvp_angle1 in radians
1222 double, // rhvp_angle2 in radians
1223 double, // rhvp_angle3 in radians
1224 double, // rhvp_viewsize, // > 0
1225 double, // rhvp_cameradist, // > 0
1226 int, // screen_width,
1227 int, // screen_height,
1229 );
1230
1231/*
1232Description:
1233 Calculate the corners of the polygon that is the
1234 intersection of a view frustum with and infinte plane.
1235Parameters:
1236 vp - [in] defines view frustum
1237 plane_equation - [in] defined infinte plane
1238 points - [out] corners of the polygon.
1239 If true is returned and points.Count() is zero, then
1240 the plane missed the frustum. Note that the start/end
1241 point is not duplicated in the list.
1242Returns:
1243 True if input was valid, false otherwise. Note that
1244 even when true is returned, the returned points.Count()
1245 may be zero if the plane and frustum do not intersect.
1246*/
1247ON_DECL
1248bool
1250 const ON_Viewport& vp,
1251 const ON_PlaneEquation& plane_equation,
1253 );
1254
1255#endif
1256
@ Transform
Definition RSMetaType.h:67
Definition opennurbs_point.h:403
Definition opennurbs_point.h:931
Definition opennurbs_archive.h:152
Definition opennurbs_bounding_box.h:25
Definition opennurbs_geometry.h:36
virtual ON_BOOL32 GetBBox(double *boxmin, double *boxmax, int bGrowBox=false) const =0
ON_Geometry & operator=(const ON_Geometry &)
Definition opennurbs_geometry.cpp:26
virtual int Dimension() const =0
Definition opennurbs_line.h:20
virtual void Dump(ON_TextLog &) const
Definition opennurbs_object.cpp:1695
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
Definition opennurbs_object.cpp:1734
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
Definition opennurbs_object.cpp:1714
Definition opennurbs_point.h:1169
Definition opennurbs_plane.h:20
Definition opennurbs_array.h:46
Definition opennurbs_sphere.h:22
Definition opennurbs_textlog.h:20
Definition opennurbs_uuid.h:31
Definition opennurbs_viewport.h:31
ON_3dPoint m_target_point
Definition opennurbs_viewport.h:1173
double m__MIN_NEAR_OVER_FAR
Definition opennurbs_viewport.h:1202
bool m_bLockCamDir
Definition opennurbs_viewport.h:1127
ON_3dVector m_CamDir
Definition opennurbs_viewport.h:1132
bool m_bLockCamLoc
Definition opennurbs_viewport.h:1128
ON::view_projection m_projection
Definition opennurbs_viewport.h:1112
ON_3dVector m_CamX
Definition opennurbs_viewport.h:1136
double m_frus_far
Definition opennurbs_viewport.h:1147
ON_3dPoint m_CamLoc
Definition opennurbs_viewport.h:1131
unsigned char m_reserved1
Definition opennurbs_viewport.h:1107
int m_port_bottom
Definition opennurbs_viewport.h:1157
ON_3dVector m_CamY
Definition opennurbs_viewport.h:1137
ON_3dVector m_CamZ
Definition opennurbs_viewport.h:1138
void SetMinNearOverFar(double)
bool m_bLockCamUp
Definition opennurbs_viewport.h:1126
double m_frus_left
Definition opennurbs_viewport.h:1145
ON_UUID m_viewport_id
Definition opennurbs_viewport.h:1179
ON_Xform m_clip_mods
Definition opennurbs_viewport.h:1196
double m_frus_bottom
Definition opennurbs_viewport.h:1146
double MinNearOverFar() const
int m_port_far
Definition opennurbs_viewport.h:1163
unsigned char m_frustum_symmetry_flags
Definition opennurbs_viewport.h:1129
bool m_bValidCamera
Definition opennurbs_viewport.h:1104
ON_Xform m_clip_mods_inverse
Definition opennurbs_viewport.h:1197
ON_3dVector m_CamUp
Definition opennurbs_viewport.h:1133
int m_port_left
Definition opennurbs_viewport.h:1156
bool m_bValidPort
Definition opennurbs_viewport.h:1106
double m__MIN_NEAR_DIST
Definition opennurbs_viewport.h:1201
static const ON_3dVector Default3dCameraDirection
Definition opennurbs_viewport.h:36
ON_OBJECT_DECLARE(ON_Viewport)
bool m_bValidFrustum
Definition opennurbs_viewport.h:1105
Definition opennurbs_xform.h:28
Base class for all projection tools.
Definition Projection.js:18
#define ON_DECL
Definition opennurbs_defines.h:92
#define ON_CLASS
Definition opennurbs_defines.h:91
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362
ON_DECL bool ON_GetViewportRotationAngles(const ON_3dVector &, const ON_3dVector &, const ON_3dVector &, double *, double *, double *)
Definition opennurbs_viewport.cpp:92
ON_DECL bool ON_IntersectViewFrustumPlane(const ON_Viewport &vp, const ON_PlaneEquation &plane_equation, ON_SimpleArray< ON_3dPoint > &points)
Definition opennurbs_viewport.cpp:3611
ON_DECL bool ON_ViewportFromRhinoView(ON::view_projection, const ON_3dPoint &, double, double, double, double, double, int, int, ON_Viewport &)
Definition opennurbs_viewport.cpp:1837