## Plane Plane — Adds capabilities to draw and handle planes. |

## Synopsis

                        Plane;
    enum                Plane_hidingMode;
    #define             PLANE_SIDE_PLUS
    #define             PLANE_SIDE_MINUS
    #define             PLANE_SIDE_NONE

    Plane*              planeNew                            (float vertices[8][3],
                                                             float vect[3],
                                                             float dist,
                                                             Color *color);
    Plane*              planeNew_undefined                  ();
    void                planeDraw                           (Plane *plane);
    int                 planeShowHide                       (Plane *plane,
                                                             VisuData *visuData,
                                                             gboolean hide,
                                                             float side);
    int                 planeShowHide_all                   (VisuData *visuData,
                                                             Plane **listOfPlanes);
    void                planeGet_nVectUser                  (Plane *plane,
                                                             float *vect);
    void                planeGet_color                      (Plane *plane,
                                                             Color **color);
    void                planeGet_distanceFromOrigin         (Plane *plane,
                                                             float *dist);
    GList*              planeGet_intersection               (Plane *plane);
    int                 planeGet_hiddenState                (Plane *plane);
    gboolean            planeGet_rendered                   (Plane *plane);
    gboolean            planeSet_color                      (Plane *plane,
                                                             Color *color);
    gboolean            planeSet_normalVector               (Plane *plane,
                                                             float vect[3]);
    gboolean            planeSet_distanceFromOrigin         (Plane *plane,
                                                             float dist);
    int                 planeSet_hiddenState                (Plane *plane,
                                                             int side);
    int                 planeSet_hidingMode                 (Plane_hidingMode mode);
    int                 planeSet_rendered                   (Plane *plane,
                                                             gboolean rendered);

    void                planesDraw_list                     (Plane **list,
                                                             int openGLId);
    gboolean            planesExport_XMLFile                (gchar *filename,
                                                             Plane **list,
                                                             GError **error);
    gboolean            planesParse_XMLFile                 (gchar *filename,
                                                             Plane ***list,
                                                             GError **error);
    gboolean            planesGet_visibility                (Plane **listOfPlanes,
                                                             float point[3]);
    gboolean            planesGet_intersection              (Plane **listOfPlanes,
                                                             float pointA[3],
                                                             float pointB[3],
                                                             float inter[3]);

## Description

A Plane is a GObject. It is defined by its normal vector and the distance of the plane with the origin (see `planeSet_normalVector()` and `planeSet_distanceFromOrigin()`). When these informations are given and an OpenGLView is used to render the plane, V_Sim computes the intersections of the plane with the bounding box (see `planeGet_intersection()`).

Planes can be used to hide nodes defining their `planeSet_hiddenState()` and `planeSet_hidingMode()`. A list of planes can also be exported or imported from an XML file using `planesExport_XMLFile()` and `planesParse_XMLFile()`.

Planes can have transparency but the support of it is limited to one plane. If several planes are drawn with transparency, they may hide each other because of the implementation of transparency in OpenGL (planes are treated as single polygons).

## Details

### Plane

    typedef struct _Plane Plane;

All fields are private, use the access routines.

### enum Plane_hidingMode

    typedef enum
      {
        plane_hideUnion,
        plane_hideInter,
        plane_nbHidingMode
      } Plane_hidingMode;

Enum used to address different hiding modes. See `planeSet_hidingMode()` for further details.

`plane_hideUnion` | element are masked if one plane at least mask it ;
`plane_hideInter` | element are masked if all planes mask it ;
`plane_nbHidingMode` | number of masking possibilities.

### PLANE_SIDE_PLUS

    #define PLANE_SIDE_PLUS +1

This is a key that defines which side is hidden by the plane. For this value, the side is the one pointed by the normal vector.

### PLANE_SIDE_MINUS

    #define PLANE_SIDE_MINUS -1

This is a key that defines which side is hidden by the plane. For this value, the side is the one at the opposite of the one pointed by the normal vector.

### PLANE_SIDE_NONE

    #define PLANE_SIDE_NONE 0

This is a key that defines which side is hidden by the plane. For this value, no node is hidden.

### planeNew ()

    Plane*              planeNew                            (float vertices[8][3],
                                                             float vect[3],
                                                             float dist,
                                                             Color *color);

Create a plane with the specified attributes.

`view` : | a OpenGLView object that describes the rendering box ;
`vect` : | three values defining the normal vector (unitary or not) ;
`dist` : | the distance between origin and intersection of the plane and the line made by origin and normal vector ;
`color` : | a Color.
Returns : | a newly allocated Plane structure.

### planeNew_undefined ()

    Plane*              planeNew_undefined                  ();

Create a new plane with default values. This plane can't be rendered directly and one needs to computes its intersection with the bounding box before using `planeComputeInter()`.

Returns : | a newly allocated Plane structure.

### planeDraw ()

    void                planeDraw                           (Plane *plane);

Call OpenGL primitives to draw the plane.

`plane` : | a Plane.

### planeShowHide ()

    int                 planeShowHide                       (Plane *plane,
                                                             VisuData *visuData,
                                                             gboolean hide,
                                                             float side);

A call to this method change the visibility flag of all nodes of the given VisuData. Notice that this method makes a call to visuData_createAllNodes if necessary.

`plane` : | a Plane ;
`visuData` : | a VisuData which show or hide nodes to;
`hide` : | a boolean, TRUE to hide elements, FALSE to return them to visibility ;
`side` : | give a positive number to hide elements in the same side that the normal vector, a negative number will hide the other nodes.
Returns : | 1 if the calling method should ask for redraw, 0 otherwise.

### planeShowHide_all ()

    int                 planeShowHide_all                   (VisuData *visuData,
                                                             Plane **listOfPlanes);

This method test for each node if it is hidden or not by the combination of all the given planes.

`visuData` : | a VisuData which show or hide nodes to;
`listOfPlanes` : | an array of Plane, NULL terminated.
Returns : | 1 if `visuData_createAllNodes()` should be called.

### planeGet_nVectUser ()

    void                planeGet_nVectUser                  (Plane *plane,
                                                             float *vect);

Stores the coordinates of the normal vector in `vec` of the plane. It returns the values given by the user, not the normalized vaues.

`plane` : | a Plane.
`vect` : | an already alloacted (size 3) float array.

### planeGet_color ()

    void                planeGet_color                      (Plane *plane,
                                                             Color **color);

Stores the color of the plane.

`plane` : | a Plane ;
`color` : | a Color pointer location to store the value.

### planeGet_distanceFromOrigin ()

    void                planeGet_distanceFromOrigin         (Plane *plane,
                                                             float *dist);

Stores the distance of the plane to the origin.

`plane` : | a Plane ;
`dist` : | a float location to store the value.

### planeGet_intersection ()

    GList*              planeGet_intersection               (Plane *plane);

The list of intersection between the plane and the box is made of float[3]. The `planeComputeInter()` should have been called before.

`plane` : | a Plane.
Returns : | a list of float[3] elements. This list is owned by V_Sim.

### planeGet_hiddenState ()

    int                 planeGet_hiddenState                (Plane *plane);

The plane can hide the nodes on one of its side. this method get the status for the given `plane`.

`plane` : | a Plane.
Returns : | the state, defined by PLANE_SIDE_PLUS or PLANE_SIDE_MINUS or PLANE_SIDE_NONE.

### planeGet_rendered ()

    gboolean            planeGet_rendered                   (Plane *plane);

Get the visibility of a plane.

`plane` : | a Plane.
Returns : | TRUE if the plane is visible.

### planeSet_color ()

    gboolean            planeSet_color                      (Plane *plane,
                                                             Color *color);

Change the color of the plane.

`plane` : | a Plane object ;
`color` : | a Color.
Returns : | 0 if everything went right.

### planeSet_normalVector ()

    gboolean            planeSet_normalVector               (Plane *plane,
                                                             float vect[3]);

Change the normal vector defining the orientation of the plane.

`plane` : | a Plane object ;
`vect` : | three values defining the normal vector (unitary or not).
Returns : | 1 if the intersections should be recalculated by a call to `planeComputeInter()`, 0 if not. Or -1 if there is an error.

### planeSet_distanceFromOrigin ()

    gboolean            planeSet_distanceFromOrigin         (Plane *plane,
                                                             float dist);

Change the position of the plane.

`plane` : | a Plane object ;
`dist` : | the distance between origin and intersection of the plane and the line made by origin and normal vector.
Returns : | 1 if the intersections should be recalculated by a call to `planeComputeInter()`, 0 if not. Or -1 if there is an error.

### planeSet_hiddenState ()

    int                 planeSet_hiddenState                (Plane *plane,
                                                             int side);

The plane can hide the nodes on one of its side. The `side` argument can be PLANE_SIDE_PLUS or PLANE_SIDE_MINUS or PLANE_SIDE_NONE. It codes the side of the plane which hides the nodes. If PLANE_SIDE_NONE is selected all nodes are rendered.

`plane` : | a Plane ;
`side` : | a key, PLANE_SIDE_NONE, PLANE_SIDE_PLUS or PLANE_SIDE_MINUS.
Returns : | 1 if `planeShowHide_all()` should be called.

### planeSet_hidingMode ()

    int                 planeSet_hidingMode                 (Plane_hidingMode mode);

This method is used to set the hiding mode flag. In union mode, elements are not drwn if they are hidden by one plane at least. In intersection mode, elements are only hidden if masked by all planes. This flag has no relevence if `planeShowHide()` is used, but only if `planeShowHide_all()` is called.

`mode` : | a value related to the hiding mode (look at the enum Plane_hidingMode).
Returns : | 1 if `planeShowHide_all()` should be called.

### planeSet_rendered ()

    int                 planeSet_rendered                   (Plane *plane,
                                                             gboolean rendered);

Change the visibility of the plane.

`plane` : | a Plane ;
`rendered` : | TRUE to make the plane drawable.
Returns : | 1 if `planeShowHide_all()` should be called.

### planesDraw_list ()

    void                planesDraw_list                     (Plane **list,
                                                             int openGLId);

Call OpenGL primitives to draw each plane of the given list. It's a convenient wrapper around `planeDraw()` for a list.

`list` : | an array of Plane (NULL terminated).

### planesExport_XMLFile ()

    gboolean            planesExport_XMLFile                (gchar *filename,
                                                             Plane **list,
                                                             GError **error);

Export in XML format the given list of planes to the given file.

`filename` : | the file to export to ;
`list` : | an array (NULL terminated) to export ;
`error` : | a pointer to store the error (can be NULL).
Returns : | TRUE if everything goes right, if not and `error` (if not NULL) is set and contains the message of the error.

### planesParse_XMLFile ()

    gboolean            planesParse_XMLFile                 (gchar *filename,
                                                             Plane ***list,
                                                             GError **error);

Read the given file (syntax in XML) and create a list of planes. This list is an allocated array that should be deallocated with `g_free()`. This array has always one argument, since it is NULL terminated.

`filename` : | the file to parse ;
`list` : | a pointer to store the parsed list (will be allocated and NULL terminated) ;
`error` : | a pointer to store the error (can be NULL).
Returns : | TRUE if everything goes right, if not and `error` (if not NULL) is set and contains the message of the error.

### planesGet_visibility ()

    gboolean            planesGet_visibility                (Plane **listOfPlanes,
                                                             float point[3]);

Compute the visibility of the given `point`, following the masking scheme of the given plane list.

`listOfPlanes` : | an array of Plane, NULL terminated ;
`point` : | three cartesian coordinates.
Returns : | TRUE if the point is not masked.

### planesGet_intersection ()

    gboolean            planesGet_intersection              (Plane **listOfPlanes,
                                                             float pointA[3],
                                                             float pointB[3],
                                                             float inter[3]);

Compute the location of the intersection point of segment AB with list of planes `listOfPlanes`. If there are several intersections, the closest to point A is returned.

`listOfPlanes` : | an array of Plane, NULL terminated ;
`pointA` : | three cartesian coordinates.
`pointB` : | three cartesian coordinates.
`inter` : | a location to store the intersection point.
Returns : | TRUE if there is an intersection.