Maya 1.0
Public Slots | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
MayaWidget Class Reference

A core widget for displaying objects. More...

#include <maya.h>

Inherits QOpenGLWidget.

Public Slots

void paintGL ()
 Renders the scene. More...
 
virtual void mousePressEvent (QMouseEvent *)
 Process mouse click events. More...
 
virtual void mouseReleaseEvent (QMouseEvent *)
 Process the mouse release events. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 Process the mouse double click events. More...
 
virtual void mouseMoveEvent (QMouseEvent *)
 Overloaded function to capture the mouse events. More...
 
virtual void wheelEvent (QWheelEvent *)
 Overloaded function to capture the wheel events. More...
 
virtual void keyPressEvent (QKeyEvent *)
 Key events. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This function has been overloaded mainly to enable and disable the display of the tool on the screen. More...
 

Public Member Functions

 MayaWidget (QWidget *=nullptr)
 Create a widget for real time rendering. More...
 
 ~MayaWidget ()
 Release allocated resources.
 
void SetCamera (const Camera &)
 Set the viewing camera. More...
 
QVector< CameraGetCameras () const
 Return the set of cameras.
 
Camera GetCamera () const
 Get the camera. More...
 
void AddCamera ()
 Add the current camera to the set of reference cameras.
 
void DeleteCamera ()
 Remove the current camera from the set.
 
void ChangeCamera ()
 Charge une nouvelle position de la camera.
 
void SetPlanes (const double &, const double &)
 Set the near and far planes. More...
 
void SetPlane (const Box2 &, const double &, const double &)
 Change the parameter of the plane. More...
 
void SetLight (const Vector &)
 Change the light position. More...
 
void SetAnchor (const Vector &)
 Modify the anchor position. More...
 
Ray ConvertPixelToRay (const QPoint &) const
 Convert a pixel on the screen of the viewport into a ray. More...
 
Ray ConvertPixelToRay (const QPoint &, int, int, int) const
 Convert a pixel on the screen of the viewport into a ray, with anti-aliasing. More...
 
void SetWorld (const MayaGeometryAll &)
 Set the geometry instances to be rendered. More...
 
void AppendWorld (const MayaGeometryAll &)
 Append objects or instances to be rendered. More...
 
void ReplaceInWorld (const MayaGeometryAll &)
 Replace instances to be rendered. More...
 
void ReplaceMaterialInWorld (MayaGeometryAll &)
 Replace material of all instances. More...
 
void ClearWorld ()
 Clear all objects in the scene.
 
void SaveScreen (int=1280, int=720)
 Capture the rendering viewport and save it to disk.
 
void SaveScreen (int, int, const QString &)
 Capture the rendering viewport and save it to disk. More...
 

Static Public Member Functions

static void GLAPIENTRY OpenGLDebugMessageCallback (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
 Custom callback for OpenGL message. More...
 

Static Public Attributes

static bool Verbose = false
 Static flag for verbose output in the console (useful for OpenGL debugging) More...
 
static GLenum GLVerboseLevel = GL_DEBUG_SEVERITY_MEDIUM
 OpenGL verbosity level. Everything below is ignored.
 

Protected Member Functions

void initializeGL ()
 Set up the rendering state.
 
void resizeGL (int, int)
 Set up the OpenGL view port and matrix mode according to the size of the window. More...
 
virtual void UpdateAnchor (QMouseEvent *)
 Update the position of the Anchor on the intersection between the ray (mouse direction and the plane). More...
 
virtual void RenderAnchor ()
 Render the focus point.
 
virtual void RenderLight ()
 Render the Light position.
 
void RenderBackGround ()
 Render the Background.
 
void RenderForeGround (QElapsedTimer)
 Render the foreground. More...
 
virtual void InitGPU ()
 Initialize GPU information (camera, textures, shaders).
 
void InitProgram ()
 Initialize the program shader.
 
void InitCamera ()
 Initialize camera transforms.
 
virtual void InitAnchorShape ()
 Initialize anchor shape.
 
virtual void InitLightShape ()
 Initialize light shape.
 
virtual void InitSphereShape ()
 Initialize transparent sphere.
 
void InitTerrainTextures ()
 Initialize the terrain texture. More...
 
void InitEnvTextures ()
 Initialize skybox (envmap) textures.
 
void InitLight ()
 Set up the OpenGL Light rendering state.
 
void updateGPU ()
 Update the GPU parameters information (light, camera).
 

Protected Attributes

MayaGpuAll gpuall
 Instances for storing the objects on the GPU.
 
MayaGpuSet anchor
 Internal instance for drawing the anchor point.
 
MayaGpuSet lightshape
 Light shape.
 
MayaGpuSet sphereshape
 Transparent sphere.
 
Camera camera
 Current camera.
 
int y0
 Reference mouse coordinates.
 
bool useCamera
 Boolean flags.
 
MayaPlane plane
 Horizontal plane.
 
Vector ancre
 Focus point.
 
Vector light
 Light point.
 
GpuParameter gpuparam
 Set of parameters defining the way objects are rendered.
 
MayaShadergpubackground
 Program used to draw background;.
 
GLuint backgroundVAO
 VAO used when drawing the background.
 
MayaCameraSet cameras
 Set of cameras.
 

Detailed Description

A core widget for displaying objects.

This class implements a widget for displaying geometric objects.

Constructor & Destructor Documentation

◆ MayaWidget()

MayaWidget::MayaWidget ( QWidget *  parent = nullptr)

Create a widget for real time rendering.

Parameters
parentParent widget.

References camera, gpuall, gpubackground, light, Vector::Null, and useCamera.

Member Function Documentation

◆ AppendWorld()

void MayaWidget::AppendWorld ( const MayaGeometryAll mga)

Append objects or instances to be rendered.

Parameters
mgaSet of objects.

References MayaGpuAll::Append(), and gpuall.

◆ ConvertPixelToRay() [1/2]

Ray MayaWidget::ConvertPixelToRay ( const QPoint &  pixel) const

Convert a pixel on the screen of the viewport into a ray.

This function relies on the camera model to compute the ray.

Parameters
pixelThe pixel coordinates.

References camera, and Camera::PixelToRay().

Referenced by UpdateAnchor().

◆ ConvertPixelToRay() [2/2]

Ray MayaWidget::ConvertPixelToRay ( const QPoint &  pixel,
int  a,
int  x,
int  y 
) const

Convert a pixel on the screen of the viewport into a ray, with anti-aliasing.

Parameters
pixelThe pixel coordinates
aAnti-aliasing.
x,yInteger coordinates of the sub-pixel.

References camera, and Camera::PixelToRay().

◆ GetCamera()

Camera MayaWidget::GetCamera ( ) const

Get the camera.

Returns
Camera.

References camera.

◆ InitTerrainTextures()

void MayaWidget::InitTerrainTextures ( )
protected

Initialize the terrain texture.

Basically load four texture images corresponding to bedrock, sand, snow, and grass, plus some additional textures with normal maps.

References gpuparam.

Referenced by InitGPU().

◆ keyPressEvent

void MayaWidget::keyPressEvent ( QKeyEvent *  e)
virtualslot

Key events.

Left and right keys: move sideway.

Up and down keys: move back and forth.

L : show light A : show anchor P : show plane

Parameters
eKey events.

References AddCamera(), Camera::BackForth(), camera, ChangeCamera(), DeleteCamera(), SaveScreen(), Camera::SideWay(), and useCamera.

◆ keyReleaseEvent

void MayaWidget::keyReleaseEvent ( QKeyEvent *  e)
virtualslot

This function has been overloaded mainly to enable and disable the display of the tool on the screen.

Parameters
eKey events.

◆ mouseDoubleClickEvent

void MayaWidget::mouseDoubleClickEvent ( QMouseEvent *  e)
virtualslot

Process the mouse double click events.

Parameters
eEvents.

References ancre, camera, and Camera::SetAt().

◆ mouseMoveEvent

void MayaWidget::mouseMoveEvent ( QMouseEvent *  e)
virtualslot

Overloaded function to capture the mouse events.

This function implements controls.

Parameters
eMouse move events.

References Camera::BackForth(), camera, Camera::LeftRightHorizontal(), Camera::LeftRightRound(), UpdateAnchor(), Camera::UpDownRound(), Camera::UpDownVertical(), Camera::View(), and y0.

◆ mousePressEvent

void MayaWidget::mousePressEvent ( QMouseEvent *  e)
virtualslot

Process mouse click events.

Parameters
eEvents.

References ancre, and y0.

◆ mouseReleaseEvent

void MayaWidget::mouseReleaseEvent ( QMouseEvent *  e)
virtualslot

Process the mouse release events.

Parameters
eEvents.

References Vector::Angle(), Camera::At(), camera, Camera::Eye(), and Math::Pi.

◆ OpenGLDebugMessageCallback()

void GLAPIENTRY MayaWidget::OpenGLDebugMessageCallback ( GLenum  source,
GLenum  type,
GLuint  id,
GLenum  severity,
GLsizei  length,
const GLchar *  message,
const void *  userParam 
)
static

Custom callback for OpenGL message.

Parameters
source
type
id
severity
length
message
userParam

References GLVerboseLevel.

Referenced by initializeGL().

◆ paintGL

void MayaWidget::paintGL ( )
slot

◆ RenderForeGround()

void MayaWidget::RenderForeGround ( QElapsedTimer  t)
protected

◆ ReplaceInWorld()

void MayaWidget::ReplaceInWorld ( const MayaGeometryAll mga)

Replace instances to be rendered.

Parameters
mgaSet of geometry instances.

References gpuall, and MayaGpuAll::Replace().

◆ ReplaceMaterialInWorld()

void MayaWidget::ReplaceMaterialInWorld ( MayaGeometryAll mga)

Replace material of all instances.

Parameters
mgaSet of geometry instances.

References gpuall, and MayaGpuAll::UpdateMaterial().

◆ resizeGL()

void MayaWidget::resizeGL ( int  w,
int  h 
)
protected

Set up the OpenGL view port and matrix mode according to the size of the window.

Parameters
w,hWidth and height of the window.

References camera, Camera::GetAngleOfViewV(), Camera::GetFar(), Camera::GetNear(), and Math::RadianToDegree().

◆ SaveScreen()

void MayaWidget::SaveScreen ( int  w,
int  h,
const QString &  url 
)

Capture the rendering viewport and save it to disk.

Parameters
wwidth of the image
hheight of the image
urlurl and name of the exported file

◆ SetAnchor()

void MayaWidget::SetAnchor ( const Vector v)

Modify the anchor position.

Tha anchor is not rendered if is out of the plane.

Parameters
vPosition of the anchor

References ancre.

Referenced by UpdateAnchor().

◆ SetCamera()

void MayaWidget::SetCamera ( const Camera c)

Set the viewing camera.

Parameters
cCamera.

References camera, Camera::GetAngleOfViewV(), Camera::GetFar(), Camera::GetNear(), and Math::RadianToDegree().

◆ SetLight()

void MayaWidget::SetLight ( const Vector p)

Change the light position.

Parameters
pPosition.

References light.

◆ SetPlane()

void MayaWidget::SetPlane ( const Box2 box,
const double &  h,
const double &  l 
)

Change the parameter of the plane.

It updates the MayaWidget view.

Parameters
boxRectangle.
hHeight of the plane.
lSpace between lines.

References plane.

◆ SetPlanes()

void MayaWidget::SetPlanes ( const double &  n,
const double &  f 
)

Set the near and far planes.

This function modifies the current camera. It updates the MayaWidget view.

Parameters
n,fNear and far planes distance.

References camera, and Camera::SetPlanes().

◆ SetWorld()

void MayaWidget::SetWorld ( const MayaGeometryAll mga)

Set the geometry instances to be rendered.

Parameters
mgaSet of geometry instances.

References MayaGpuAll::Append(), MayaGpuAll::ClearFrames(), and gpuall.

◆ UpdateAnchor()

void MayaWidget::UpdateAnchor ( QMouseEvent *  e)
protectedvirtual

Update the position of the Anchor on the intersection between the ray (mouse direction and the plane).

Parameters
eMouse event.

References ConvertPixelToRay(), MayaPlane::Intersect(), plane, and SetAnchor().

Referenced by mouseMoveEvent().

◆ wheelEvent

void MayaWidget::wheelEvent ( QWheelEvent *  e)
virtualslot

Overloaded function to capture the wheel events.

Parameters
eWheel events.

References ancre, Camera::BackForth(), camera, and Camera::View().

Member Data Documentation

◆ Verbose

bool MayaWidget::Verbose = false
static

Static flag for verbose output in the console (useful for OpenGL debugging)

< Static flag for verbose output in the console (useful for OpenGL debugging)

OpenGL verbosity level. Everything below is ignored.

Referenced by initializeGL().