VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
12.5 - 2D Objects

Table of Contents

The Remote Draw API supports 2D objects such as lines, rectangles, ellipses, and triangles.

It also supports text. As seen in the example in the previous section, positions and sizes are specified as fractions of the current window size in X and Y (or width and height) using the DtVdcVector2D class. You can specify a counter-clockwise rotation in radians.

vrv_remotegraphics2d.png
2D Ellipses

12.5.1 2D Lines

DtLine2DObject represents a line that can be positioned and displayed on the screen. The line can be divided into multiple segments of varying relative lengths. Each line has a start point and an end point, specified using DtVdcVector2Ds. You can specify a color, line style, arrow style, pattern, and thickness for each segment, and the line can flash.

Line styles are specified using the DtVdcLineSegment::DtVdcLineStyle enumeration, which includes:

DtVdcLineSegment::DtVdcSegmentStyleStraight
DtVdcLineSegment::DtVdcSegmentStyleLightning.

Arrow styles are specified using the DtVdcLineSegment::DtVdcSegmentArrowStyle enumeration, which includes:

DtVdcLineSegment::DtVdcSegmentArrowStyleNoArrow
DtVdcLineSegment::DtVdcSegmentArrowStyleArrowEnd
DtVdcLineSegment::DtVdcSegmentArrowStyleArrowStart
DtVdcLineSegment::DtVdcSegmentArrowStyleArrowDouble.

The following example creates and displays a green line that goes from the bottom left-hand corner of the screen to the top right hand corner of the screen. The first 20 percent of the line should be a separate segment with double arrowheads:

DtLine2DObject* line = new DtLine2DObject( exConn, nextId++,
DtVdcVector2D( 0., 0. ), DtVdcVector2D( 1., 1. ), 2 /*segments*/, DtVdcColor::DtVdcGreen );
line->setArrowStyle(
DtVdcLineSegment::DtVdcSegmentArrowStyleArrowDouble,
0 /* segment num */ );

12.5.2 Rectangles

DtRectangleObject represents a rectangular object that can be positioned and displayed on the screen. The position specified is the lower lefthand corner of the rectangle. The size parameter specifies the length of the x-axis sides and y-axis sides, respectively (as fractions of the window size). You can specify a counter-clockwise rotation, in radians, the rectangle's color, an optional fill pattern, and whether or not it flashes.

The following example creates and displays a white rectangle at the center of the screen. It is 1/10 the size of the screen along the x-axis and 1/5 of the screen along the y-axis:

DtRectangleObject* rect = new DtRectangleObject(exConn, nextId++, DtVdcVector2D( 0.5, 0.5 ), DtVdcVector2D( 0.1, 0.2) );

12.5.3 Ellipses

DtEllipseObject represents an elliptical object that can be positioned and displayed on the screen. The position specified is the center of the ellipse The size parameter specifies the length of the ellipsis' axes parallel to the screen's x-axis and y-axis. You can specify a counter-clockwise rotation, in radians, a color, and optionally, a fill pattern. The object can flash.

The following example creates and displays a flashing yellow circle in the lower right corner. The diameter is ½ the screen.

DtEllipseObject* circle = new DtEllipseObject(exConn, nextId++,
DtVdcVector2D( 0.75, 0.25 ), DtVdcVector2D( 0.5, 0.5 ), 0., DtVdcColor::DtVdcYellow);
circle->setFlashing( true );

To hide the ellipse, do this:

circle->setVisible(false);

12.5.4 2D Triangles

DtTriangle2DObject represents a triangle that can be drawn on the Remote Draw overlay. Each vertex is specified in fractional screen coordinates. Triangles can be rotated, scaled along the X and Y axes independently, and offset from their specified position. They can be colored, filled with an optional pattern, and can flash.

Note
Because scaling is in screen coordinates, the effect of scaling will vary depending on the aspect ratio of the screen on which the graphic is viewed.

The following example creates and displays an orange-striped pattern-filled triangle that covers the upper right-hand side of the screen.

DtTriangle2DObject* triangle = new DtTriangle2DObject( exConn, nextId++, DtVdcVector2D( 0., 1. ), DtVdcVector2D( 1., 1. ),
DtVdcVector2D( 1., 0. ) );
triangle->setFill( true );
triangle->setPattern( 0x0f0f0f0f );
triangle->setColor( DtVdcColor::DtVdcOrange );

The vertices of 2D triangles are specified as three points (v_1, v_2, v_3) and one offset. The position of each vertex before rotation and scaling is v_n + offset, and the rotation and scale operations are centered around the offset.

The figure below illustrates a triangle with its vertices specified as v_1 = (0, 0), v_2 = (0.5, 0), v_3 = (0, 0.5) and an offset of (0.5, 0.5). Applying the offset to the specified vertices, it is displayed with vertices at (0.5, 0.5), (1, 0.5), and (0.5, 1). (Remember vertices are specified as screen coordinates, with 0,0 being the lower left corner of the screen and 1,1 the upper right.)

If the triangle is rotated pi/2 (90o), it rotates around the origin, as shown in the second view. If it is rotated and scaled 50%, it is displayed with vertices at (0.5, 0.5), (0.75, 0.5), (0.5, 0.75), as shown in the third view.

The smaller triangle demonstrates rotation around the origin when the origin is not a vertex.

vrv_2dtriangles.png
2D Triangles

12.5.5 2D Text

DtText2DObject is used to place text on the Remote Draw overlay. The bottom-left corner of the text is positioned using fractional screen coordinates with the DtVdcVector2D class. The text can have a color and can flash.

The following example creates and displays yellow text in the upper left-hand side of the 2D overlay that flashes "Hello World".

DtText2DObject* text = new DtText2DObject( exConn, nextId++, "Hello World", DtVdcVector2D( 0.05, 0.8 ), DtVdcColor::DtVdcYellow, true );

You must provide a font filename and size, in points. The default is ../data/fonts/arial.ttf at 14 points.

[<< Objects] [Home] [Top of Page] [3D Objects >>]


Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)