SilverScreen Solid Modeler

near_primitive1

near_primitive1

Previous topic Next topic  

near_primitive1

Previous topic Next topic JavaScript is required for the print function  

 

SilverScreenAPI

 

int near_primitive1(int p_type, int x, int y);

 

int p_type;   // An integer primitive flag

int x;        // An integer x-coordinate

int y;        // An integer y-coordinate

 

 




Synopsis

#include "silver.h"

#include "ssnodes.h"

 

The near_primitive1 function builds a p-group of visible primitives 'near' the 2D screen coordinate defined by the values of x and y. p_type controls the type type of primitives considered. If no primitive satisfies the type requirements, or the screen coordinate is invalid, then the current p-group will become empty.

 

 

Parameters

p_type is a primitive-level bits flag value whose meaning is as follows:

 

Value

Meaning

BITS_LINE

Only line primitives are tested for nearness to x,y

BITS_POLYGON

Only polygon primitives are tested for nearness to x,y

BITS_CIRCLE

Only circle primitives are tested for nearness to x,y

BITS_SPLINE

Only spline primitives are tested for nearness to x,y

BITS_BEZIER

Only bezier primitives are tested for nearness to x,y

BITS_POLYLINE

Only polyline primitives are tested for nearness to x,y

BITS_POINT

Only point primitives are tested for nearness to x,y

BITS_ARC

Only arc primitives are tested for nearness to x,y

 

x is the x-coordinate of the 2D point used to select entities

y is the y-coordinate of the 2D point used to select entities

 

 

Return Value

near_primitive1 returns the number of items in the p-group that satisfied the selection conditions. If the screen position does not resolve to one candidate then all candidates are added to the p-group.

 

 

Remarks

You may not treat p_type as a bit-flag in this function (values may not be Or'd). The reason is that all primitives in an primitive group (the p-group) must have the same type.

 

 

See Also

near_entity1, near_entity2, get_pgroup_item, pick_primitive

 

 

Example

The following code waits for a mouse-left press, then uses the 2D position of the cursor to place of the polygons near it into the p-group. Finally, it changes the edge and surface color of the p-group to light-red:

 

C / C++ Code

 

 #include "silver.h"

 #include "ssnodes.h"

 #include "sskeys.h"

 

 void main(void)

    {

    int xpos, ypos, key;

 

    do

       {

       key = inchar();

       }

    while ( key != M_LUP );

 

    pointer_position(&xpos, &ypos);

 

    if ( near_primitive1(BITS_POLYGON, xpos, ypos) > 0 )

       {

       ss_command("redraw p-group color light-red");

       ss_command("surface p-group fill-color light-red");

       }

    }