SOFA plugin: SofaSimpleGUI  master
Open source framework for multi-physics simuation
sofa::simplegui::SofaGL Class Reference

#include <SofaGL.h>

Detailed Description

OpenGL interface to a SofaScene. This is not a viewer, this is an object used by a viewer to display a Sofa scene and to pick objects in it. It contains a pointer to the Sofa scene. Several viewers can be connected to a single scene through such interfaces.

Picking returns a PickedPoint which describes a particle. It is up to the application to create the appropriate Interactor, which can then be inserted in the Sofa scene. This class provides the functions to attach/detach an interactor and move it.

Author
Francois Faure, 2014

Protected Attributes

SofaScene_sofaScene
 
GLint _viewport [4]
 
GLdouble _mvmatrix [16]
 
GLdouble _projmatrix [16]
 
sofa::gl::DrawToolGL _drawToolGL
 
sofa::core::visual::VisualParams_vparams
 
Picked_to_Interactor _picked_to_interactor
 
Interactor_drag
 The currently active interactor. More...
 
bool _isPicking
 if we are doing OpenGL picking More...
 
GLint pickX
 
GLint pickY
 
GLuint selectBuf [BUFSIZE]
 
GLint hits
 

Public Member Functions

 SofaGL (SofaScene *s)
 
void draw ()
 Draw the scene and stores the transformation matrices, for picking. This requires an OpenGL context. It is supposed to be used by the drawing method of a viewer, after setting the modelview matrix. More...
 
void viewAll (SReal *xcam, SReal *ycam, SReal *zcam, SReal *xcen, SReal *ycen, SReal *zcen, SReal a, SReal *nearPlane, SReal *farPlane)
 Compute the parameters to pass to gluPerspective to make the whole scene visible. The new camera center is set on the line from the current camera center to the scene center, at the appropriate distance. More...
 
void getSceneBBox (float *xmin, float *ymin, float *zmin, float *xmax, float *ymax, float *zmax)
 Compute the bounding box of the scene. More...
 
void glPick (int x, int y)
 Try to pick a displayed thing along a ray, using OpenGL picking. The ray starts at the camera center and passes through point with coordinates x,y in image coordinates (origin on top left). In this experimental implementation, this function just prints something on the standard output. More...
 
void getPickDirection (GLdouble *dx, GLdouble *dy, GLdouble *dz, int x, int y)
 getPickDirection Compute the direction of a button click, returned as a unit vector More...
 
Interaction
PickedPoint pick (GLdouble ox, GLdouble oy, GLdouble oz, int x, int y)
 Try to pick a particle along a ray. The ray starts at the camera center and passes through point with coordinates x,y ox, oy, oz are the camera center in world coordinates. x,y in image coordinates (origin on top left). If a point is picked, the application may create an Interactor based on it. More...
 
void attach (Interactor *)
 Insert an interactor in the scene Does not check if it is already there, so be careful not to insert the same twice. More...
 
InteractorgetInteractor (const PickedPoint &picked)
 getInteractor More...
 
InteractorpickInteractor (GLdouble ox, GLdouble oy, GLdouble oz, int x, int y)
 Try to pick an Interactor along a ray. The ray starts at the camera center and passes through point with coordinates x,y ox, oy, oz are the camera center in world coordinates. x,y in image coordinates (origin on top left). More...
 
void move (Interactor *, int x, int y)
 move the interactor according to the mouse pointer. x,y in image coordinates (origin on top left). More...
 
void detach (Interactor *)
 Remove the interactor from the scene, without deleting it. More...
 

Protected Member Functions

void draw (sofa::core::visual::VisualParams *)
 

Attribute details

◆ _drag

Interactor* sofa::simplegui::SofaGL::_drag
protected

The currently active interactor.

◆ _drawToolGL

sofa::gl::DrawToolGL sofa::simplegui::SofaGL::_drawToolGL
protected

◆ _isPicking

bool sofa::simplegui::SofaGL::_isPicking
protected

if we are doing OpenGL picking

◆ _mvmatrix

GLdouble sofa::simplegui::SofaGL::_mvmatrix[16]
protected

◆ _picked_to_interactor

Picked_to_Interactor sofa::simplegui::SofaGL::_picked_to_interactor
protected

Currently available interactors, associated with picked points. The interactors are not necessarily being manipulated. Only one is typically manipulated at a given time.

◆ _projmatrix

GLdouble sofa::simplegui::SofaGL::_projmatrix[16]
protected

◆ _sofaScene

SofaScene* sofa::simplegui::SofaGL::_sofaScene
protected

◆ _viewport

GLint sofa::simplegui::SofaGL::_viewport[4]
protected

◆ _vparams

sofa::core::visual::VisualParams* sofa::simplegui::SofaGL::_vparams
protected

◆ hits

GLint sofa::simplegui::SofaGL::hits
protected

◆ pickX

GLint sofa::simplegui::SofaGL::pickX
protected

◆ pickY

GLint sofa::simplegui::SofaGL::pickY
protected

◆ selectBuf

GLuint sofa::simplegui::SofaGL::selectBuf[BUFSIZE]
protected

Constructor details

◆ SofaGL()

sofa::simplegui::SofaGL::SofaGL ( SofaScene s)
Parameters
sThe Sofa scene to interact with, the scene MUST already be opened !

Function details

◆ attach()

void sofa::simplegui::SofaGL::attach ( Interactor interactor)

Insert an interactor in the scene Does not check if it is already there, so be careful not to insert the same twice.

◆ detach()

void sofa::simplegui::SofaGL::detach ( Interactor drag)

Remove the interactor from the scene, without deleting it.

◆ draw() [1/2]

void sofa::simplegui::SofaGL::draw ( )

Draw the scene and stores the transformation matrices, for picking. This requires an OpenGL context. It is supposed to be used by the drawing method of a viewer, after setting the modelview matrix.

◆ draw() [2/2]

void sofa::simplegui::SofaGL::draw ( sofa::core::visual::VisualParams vparams)
protected

◆ getInteractor()

Interactor * sofa::simplegui::SofaGL::getInteractor ( const PickedPoint picked)

getInteractor

Parameters
picked
Returns
Interactor acting on the given picked point, or NULL if none

◆ getPickDirection()

void sofa::simplegui::SofaGL::getPickDirection ( GLdouble *  dx,
GLdouble *  dy,
GLdouble *  dz,
int  x,
int  y 
)

getPickDirection Compute the direction of a button click, returned as a unit vector

Parameters
dxnormalized direction
dynormalized direction
dznormalized direction
xx-coordinate of the click
yy-coordinate of the click (origin on top)

◆ getSceneBBox()

void sofa::simplegui::SofaGL::getSceneBBox ( float *  xmin,
float *  ymin,
float *  zmin,
float *  xmax,
float *  ymax,
float *  zmax 
)

Compute the bounding box of the scene.

◆ glPick()

void sofa::simplegui::SofaGL::glPick ( int  x,
int  y 
)

Try to pick a displayed thing along a ray, using OpenGL picking. The ray starts at the camera center and passes through point with coordinates x,y in image coordinates (origin on top left). In this experimental implementation, this function just prints something on the standard output.

◆ move()

void sofa::simplegui::SofaGL::move ( Interactor interactor,
int  x,
int  y 
)

move the interactor according to the mouse pointer. x,y in image coordinates (origin on top left).

◆ pick()

PickedPoint sofa::simplegui::SofaGL::pick ( GLdouble  ox,
GLdouble  oy,
GLdouble  oz,
int  x,
int  y 
)

Try to pick a particle along a ray. The ray starts at the camera center and passes through point with coordinates x,y ox, oy, oz are the camera center in world coordinates. x,y in image coordinates (origin on top left). If a point is picked, the application may create an Interactor based on it.

Returns
a valid PickedPoint if succeeded, an invalid PickedPoint if not.

◆ pickInteractor()

Interactor * sofa::simplegui::SofaGL::pickInteractor ( GLdouble  ox,
GLdouble  oy,
GLdouble  oz,
int  x,
int  y 
)

Try to pick an Interactor along a ray. The ray starts at the camera center and passes through point with coordinates x,y ox, oy, oz are the camera center in world coordinates. x,y in image coordinates (origin on top left).

Returns
Pointer if an Interactor is found, NULL if not.

◆ viewAll()

void sofa::simplegui::SofaGL::viewAll ( SReal *  xcam,
SReal *  ycam,
SReal *  zcam,
SReal *  xcen,
SReal *  ycen,
SReal *  zcen,
SReal  a,
SReal *  nearPlane,
SReal *  farPlane 
)

Compute the parameters to pass to gluPerspective to make the whole scene visible. The new camera center is set on the line from the current camera center to the scene center, at the appropriate distance.

Parameters
xcamCamera center (input-output)
ycamCamera center (input-output)
zcamCamera center (input-output)
xcenCenter of the scene (output)
ycenCenter of the scene (output)
zcenCenter of the scene (output)
aCamera vertical angle (input)
nearSmaller than the nearest distance from the new camera center to the scene (output)
farLarger than the nearest distance from the new camera center to the scene (output)

Enum details

◆ anonymous enum

anonymous enum
protected
Enumerator
BUFSIZE