Package com.openinventor.inventor
Class SbViewportRegion
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.SbViewportRegion
-
public class SbViewportRegion extends Inventor
Class for representing a viewport. This class represents the active viewport region in a display window. It contains the screen-space (pixels) size of the window as well as the origin and size of the viewport within the window. The viewport origin and size is stored both as pixel values and as normalized values (fraction of the window).Initially the viewport is the same as the full window. Methods allow the viewport to be set either in terms of screen-space pixels or as normalized coordinates, where (0,0) is the lower-left corner of the window and (1,1) is the upper-right corner.
Remember that
getWindowSize()
returns the size of the window, not the viewport. Always callgetViewportOriginPixels()
andgetViewportSizePixels()
if you need the actual viewport in pixels.Also remember:
- To normalize a point: use the viewport origin and size.
- To normalize a distance: use only the viewport size.
The
normalize()
method is convenient for normalizing a point, but note that it normalizes to the range 0..1 and some Open Inventor classes expect values normalized to the the range -1..1. Currently you must do this normalization yourself.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SbViewportRegion()
Default constructor.SbViewportRegion(short width, short height)
Calls SbViewportRegion(width, height, (float)1.0).SbViewportRegion(short width, short height, float newScale)
Constructor that takes width and a height in pixels.SbViewportRegion(SbVec2i32 winSize)
Calls SbViewportRegion(winSize, (float)1.0).SbViewportRegion(SbVec2i32 winSize, float newScale)
Constructor that takes width and a height in pixels.SbViewportRegion(SbVec2s winSize)
Calls SbViewportRegion(winSize, (float)1.0).SbViewportRegion(SbVec2s winSize, float newScale)
Constructor that takes width and a height in pixels.SbViewportRegion(SbViewportRegion vpReg)
Constructor that takes a viewport region.SbViewportRegion(java.awt.Dimension dim)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
float
getPixelsPerInch()
Returns the pixel-per-inch ratio for the display device the viewport is part of.float
getPixelsPerPoint()
Convenience function that returns number of pixels per printer's point.float
getViewportAspectRatio()
Returns aspect ratio (width/height) of viewport.SbVec2f
getViewportOrigin()
Returns viewport origin in 0..1 normalized coordinates relative to the current window size.SbVec2s
getViewportOriginPixels()
Returns viewport origin in pixels.SbVec2i32
getViewportOriginPixelsi32()
Returns viewport origin in pixels.SbVec2f
getViewportSize()
Returns viewport size in 0..1 normalized coordinates relative to the current window size.SbVec2s
getViewportSizePixels()
Returns viewport size in pixels.SbVec2i32
getViewportSizePixelsi32()
Returns viewport size in pixels.SbVec2s
getWindowSize()
Returns window size in pixels.SbVec2i32
getWindowSizei32()
Returns window size in pixels.SbVec2f
normalize(SbVec2s position)
Compute the 0..1 normalized coordinates of the specified pixel position, relative to the current viewport (not window).void
scaleHeight(float ratio)
Scales viewport within window to be the given ratio of its current height, leaving the resulting viewport centered about the same point as the current one.void
scaleWidth(float ratio)
Scales viewport within window to be the given ratio of its current width, leaving the resulting viewport centered about the same point as the current one.void
setPixelsPerInch(float ppi)
Sets the pixel-per-inch ratio for the display device the viewport is part of.void
setValue(SbViewportRegion copyFrom)
void
setViewport(float left, float bottom, float width, float height)
Sets viewport to given region, specified as normalized coordinates relative to the current window size, where (0,0) is the lower-left corner and (1,1) is the upper-right.void
setViewport(SbVec2f origin, SbVec2f size)
Sets viewport to given region, specified as normalized coordinates relative to the current window size, where (0,0) is the lower-left corner and (1,1) is the upper-right.void
setViewportPixels(short left, short bottom, short width, short height)
Sets viewport to given region, specified as pixel coordinates in window: (0,0) is the lower-left corner.void
setViewportPixels(SbVec2i32 origin, SbVec2i32 size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates.void
setViewportPixels(SbVec2s origin, SbVec2s size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates.void
setWindowSize(short width, short height)
Changes window size to given width and height in pixels.void
setWindowSize(SbVec2i32 winSize)
Changes window size to given width and height in pixels, given asSbVec2i32
.void
setWindowSize(SbVec2s winSize)
Changes window size to given width and height in pixels, given asSbVec2s
.static SbViewportRegion[]
toArray(long nativeArray, long length)
-
Methods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
-
-
-
Constructor Detail
-
SbViewportRegion
public SbViewportRegion(java.awt.Dimension dim)
-
SbViewportRegion
public SbViewportRegion(SbVec2i32 winSize)
Calls SbViewportRegion(winSize, (float)1.0).
-
SbViewportRegion
public SbViewportRegion(SbVec2s winSize)
Calls SbViewportRegion(winSize, (float)1.0).
-
SbViewportRegion
public SbViewportRegion(short width, short height)
Calls SbViewportRegion(width, height, (float)1.0).
-
SbViewportRegion
public SbViewportRegion(SbVec2s winSize, float newScale)
Constructor that takes width and a height in pixels. Sets the window and the viewport.
-
SbViewportRegion
public SbViewportRegion()
Default constructor. Sets window size and viewport to default 100 x 100 pixels.
-
SbViewportRegion
public SbViewportRegion(short width, short height, float newScale)
Constructor that takes width and a height in pixels. Sets the window and the viewport.
-
SbViewportRegion
public SbViewportRegion(SbViewportRegion vpReg)
Constructor that takes a viewport region.
-
SbViewportRegion
public SbViewportRegion(SbVec2i32 winSize, float newScale)
Constructor that takes width and a height in pixels. Sets the window and the viewport.
-
-
Method Detail
-
normalize
public SbVec2f normalize(SbVec2s position)
Compute the 0..1 normalized coordinates of the specified pixel position, relative to the current viewport (not window).- Parameters:
position
- in pixel coordinates- Returns:
- position in normalized coordinates (0 <= x,y <= 1)
-
toArray
public static SbViewportRegion[] toArray(long nativeArray, long length)
-
getPixelsPerPoint
public float getPixelsPerPoint()
Convenience function that returns number of pixels per printer's point.
-
setValue
public void setValue(SbViewportRegion copyFrom)
-
setViewportPixels
public void setViewportPixels(short left, short bottom, short width, short height)
Sets viewport to given region, specified as pixel coordinates in window: (0,0) is the lower-left corner. The normalized viewport origin and size are recomputed. The specified values are not clamped to the window size.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getViewportOriginPixels
public SbVec2s getViewportOriginPixels()
Returns viewport origin in pixels.
-
getViewportOrigin
public SbVec2f getViewportOrigin()
Returns viewport origin in 0..1 normalized coordinates relative to the current window size.
-
setWindowSize
public void setWindowSize(SbVec2i32 winSize)
Changes window size to given width and height in pixels, given asSbVec2i32
. If viewport has not been explicitly set by the application, the viewport is also changed to the specified width and height. If the viewport has been explicitly set, then the stored normalized values are applied to the new window to compute a new viewport origin and size in pixels.
-
getViewportSize
public SbVec2f getViewportSize()
Returns viewport size in 0..1 normalized coordinates relative to the current window size.
-
getViewportOriginPixelsi32
public SbVec2i32 getViewportOriginPixelsi32()
Returns viewport origin in pixels.
-
setViewport
public void setViewport(float left, float bottom, float width, float height)
Sets viewport to given region, specified as normalized coordinates relative to the current window size, where (0,0) is the lower-left corner and (1,1) is the upper-right. The normalized values are applied to the current window size to compute a new viewport origin and size in pixels.
-
setViewportPixels
public void setViewportPixels(SbVec2i32 origin, SbVec2i32 size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates. The normalized viewport origin and size are recomputed. The specified values are not clamped to the window size.
-
setViewportPixels
public void setViewportPixels(SbVec2s origin, SbVec2s size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates. The normalized viewport origin and size are recomputed. The specified values are not clamped to the window size.
-
setViewport
public void setViewport(SbVec2f origin, SbVec2f size)
Sets viewport to given region, specified as normalized coordinates relative to the current window size, where (0,0) is the lower-left corner and (1,1) is the upper-right. The viewport origin and size in pixels are recomputed.
-
getWindowSizei32
public SbVec2i32 getWindowSizei32()
Returns window size in pixels. NOTE: By default this is also the viewport size in pixels, but in general this is not the viewport size. UsegetViewportSizePixels()
.
-
getWindowSize
public SbVec2s getWindowSize()
Returns window size in pixels. NOTE: By default this is also the viewport size in pixels, but in general this is not the viewport size. UsegetViewportSizePixels()
.
-
scaleHeight
public void scaleHeight(float ratio)
Scales viewport within window to be the given ratio of its current height, leaving the resulting viewport centered about the same point as the current one.
-
setPixelsPerInch
public void setPixelsPerInch(float ppi)
Sets the pixel-per-inch ratio for the display device the viewport is part of. The default value is 72 (1 pixel per printer's point).
-
getPixelsPerInch
public float getPixelsPerInch()
Returns the pixel-per-inch ratio for the display device the viewport is part of.
-
scaleWidth
public void scaleWidth(float ratio)
Scales viewport within window to be the given ratio of its current width, leaving the resulting viewport centered about the same point as the current one.
-
getViewportSizePixels
public SbVec2s getViewportSizePixels()
Returns viewport size in pixels.
-
setWindowSize
public void setWindowSize(SbVec2s winSize)
Changes window size to given width and height in pixels, given asSbVec2s
. If viewport has not been explicitly set by the application, the viewport is also changed to the specified width and height. If the viewport has been explicitly set, then the stored normalized values are applied to the new window to compute a new viewport origin and size in pixels.
-
getViewportSizePixelsi32
public SbVec2i32 getViewportSizePixelsi32()
Returns viewport size in pixels.
-
getViewportAspectRatio
public float getViewportAspectRatio()
Returns aspect ratio (width/height) of viewport.
-
setWindowSize
public void setWindowSize(short width, short height)
Changes window size to given width and height in pixels. If viewport has not been explicitly set by the application, the viewport is also changed to the specified width and height. If the viewport has been explicitly set, then the stored normalized values are applied to the new window to compute a new viewport origin and size in pixels.
-
-