📄 renderer.h
字号:
// Renderer.h
#ifndef RENDERER_H
#define RENDERER_H
#include "params.h"
#include "color.h"
#include "linkedlist.cpp"
#include "line.h"
#include "sphere.h"
#include "cylinder.h"
#include "plate.h"
#include "BitMapImage.h"
#include "vr.h"
#include "wrl.h"
class Mesh;
/** \nosubgrouping */
/** Handles the rendering functions and modes, such as backface culling,
perspective/orthographic view, colors, highlights, transformations etc.
*/
class Renderer {
friend Mesh;
public:
#ifndef SKIP_THIS
Renderer();
~Renderer();
#endif
/************************************************/
/** \name Rendering modes */
//@{
/** Set the rendering mode
\param mode The new render mode
\retval OK Operation succeeded
*/
RESULT setRenderMode(RENDER_MODE mode = WIREFRAME);
/** Get current rendering mode
\param mode \out Current rendering mode
\retval OK Operation succeeded
*/
RESULT getRenderMode(RENDER_MODE &mode);
/** Set to perspective/orthographics mode
\param perspective The new perspective/orthographics mode (true for perspective, else false)
\retval OK Operation succeeded
*/
RESULT setPerspective(bool perspective = true);
/** Get current perspective/orthographics mode
\param perspective \out If true, current mode is perspective. Otherwise, mode is orthographics
\retval OK Operation succeeded
*/
RESULT getPerspective(bool &perspective);
/** Enable/disable backface culling
\param enable If true, backface culling is enabled
\retval OK Operation succeeded
*/
RESULT setBackfaceCulling(bool enable = true);
/** Get current backface culling mode (enabled/disabled)
\param enable \out If true, backface culling is enabled. Otherwise, it's disabled.
\retval OK Operation succeeded
*/
RESULT getBackfaceCulling(bool &enable);
/** Toggles rendering of lines
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
*/
RESULT setLineDrawing(bool enable = true);
/** Gets the current line drawing policy
\param enable \out If true, line drawing is enabled. Otherwise, it's disabled.
\retval OK Operation succeeded
*/
RESULT getLineDrawing(bool &enable);
/** Toggles rendering of spheres
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
*/
RESULT setSphereDrawing(bool enable = true);
/** Gets the current sphere drawing policy
\param enable \out If true, sphere drawing is enabled. Otherwise, it's disabled.
\retval OK Operation succeeded
*/
RESULT getSphereDrawing(bool &enable);
/** Toggles rendering of cylinders
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
*/
RESULT setCylinderDrawing(bool enable = true);
/** Gets the current cylinder drawing policy
\param enable \out If true, cylinder drawing is enabled. Otherwise, it's disabled.
\retval OK Operation succeeded
*/
RESULT getCylinderDrawing(bool &enable);
/** Toggles rendering of plates
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
*/
RESULT setPlateDrawing(bool enable = true);
/** Gets the current plate drawing policy
\param enable \out If true, plate drawing is enabled. Otherwise, it's disabled.
\retval OK Operation succeeded
*/
RESULT getPlateDrawing(bool &enable);
/** Displays text at given screen coordinates
\param text The text to be displayed
\param coord The coordinate in which the text will be displayed on the screen, where (0,0) is the top left corner
\retval OK Operation succeeded
\retval OversizedString Text is longer than MAX_STRING_SIZE
\note
- If text is NULL, the text is cleared (equivalent to displayText("", coord)).
- The text's maximal allowed size is MAX_STRING_SIZE.
- If coord is NULL, the text is displayed at (0,0).
- With each call to this function, the previous text is cleared (no matter where it was displayed on the screen).
*/
RESULT displayText(const char* text = NULL, const Coord2D *coord = NULL);
/** Toggles auto rendering after each model change.
If set to false, rendering of the window will occur only when the user calls \e refreshScreen().
Otherwise, the window will be re-rendered after each mouse move and model change.
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
\sa refreshScreen()
*/
RESULT setAutoRefresh(bool enable = true);
/** Refreshes the model viewed in the window (in case the user made a change which has not yet been shown).
\retval OK Operation succeeded
\sa setAutoRefresh()
*/
RESULT refreshScreen();
/** Toggles auto scaling after each model change.
If set to true, rescaling of the model will occur automatically after every model change.
\param enable Toggles on (true) or off (false)
\retval OK Operation succeeded
\note This function is usually used with the Mesh::startNewModel() function, in order to rescale the model after each change, to fit nicely in the render window.
\sa Mesh::startNewModel()
*/
RESULT setAutoScale(bool enable = true);
/** Toggles interacting with the model (using the mouse events).
\param enable If true, all mouse events are enabled (the model can transformed, scaled and rotated); else, they're disabled
\retval OK Operation succeeded
*/
RESULT setMouseInteraction(bool enable = true);
#ifndef SKIP_THIS
bool interactionEnabled; // mouse interaction
#endif
//@}
/************************************************/
/** \name Transformations */
//@{
// transformations - rotate, translate and scale
// functions used directly by the user
/** Rotate the mesh around a given axis at a given angle
\param axis The axis to rotate around
\param angle The angel to rotate by (in degrees)
\retval OK Operation succeeded
*/
RESULT rotate(AXIS axis, int angle);
/** Translate the mesh
\param dx How much to translate in the X axis
\param dy How much to translate in the Y axis
\param dz How much to translate in the Z axis
\retval OK Operation succeeded
*/
RESULT translate(int dx, int dy, int dz=0);
/** Scale the mesh (uniformly on each axis).
\param dy How much to scale the model. If dy>0, the model will be enlarged, otherwise it will be shrinked.
\retval OK Operation succeeded
*/
RESULT scale(int dy);
#ifndef SKIP_THIS
// functions used when the mouse moves on the screen
RESULT screen_rotate(float angle, int axisx, int axisy, int axisz);
RESULT screen_translate(int dx, int dy, int dz=0);
RESULT screen_scale(int dy);
#endif
//@}
/************************************************/
/** \name Colors */
//@{
/** Set background color
\param color The new color for the background
\retval OK Operation succeeded
*/
RESULT setBgColor(Color color);
/** Set background color
\param color \out The current background color
\retval OK Operation succeeded
*/
RESULT getBgColor(Color& color);
/** Set the default vertices color
\param color The new default vertices color
\retval OK Operation succeeded
*/
RESULT setVerticesDefaultColor(Color color);
/** Get the default vertices color
\param color \out The default vertices color
\retval OK Operation succeeded
*/
RESULT getVerticesDefaultColor(Color& color);
/** Set the default edges color
\param color The new default edges color
\retval OK Operation succeeded
*/
RESULT setEdgesDefaultColor(Color color);
/** Get the default edges color
\param color \out The default edges color
\retval OK Operation succeeded
*/
RESULT getEdgesDefaultColor(Color& color);
/** Set the default faces color
\param color The new default faces color
\retval OK Operation succeeded
*/
RESULT setFacesDefaultColor(const Color color);
/** Get the default faces color
\param color \out The default faces color
\retval OK Operation succeeded
*/
RESULT getFacesDefaultColor(Color& color);
/** Set the default lines color
\param color The new default lines color
\retval OK Operation succeeded
*/
RESULT setLinesDefaultColor(const Color color);
/** Get the default lines color
\param color \out The default lines color
\retval OK Operation succeeded
*/
RESULT getLinesDefaultColor(Color& color);
/** Set the default spheres color
\param color The new default spheres color
\retval OK Operation succeeded
*/
RESULT setSpheresDefaultColor(const Color color);
/** Get the default spheres color
\param color \out The default spheres color
\retval OK Operation succeeded
*/
RESULT getSpheresDefaultColor(Color& color);
/** Set the default cylinders color
\param color The new default cylinders color
\retval OK Operation succeeded
*/
RESULT setCylindersDefaultColor(const Color color);
/** Get the default cylinders color
\param color \out The default cylinders color
\retval OK Operation succeeded
*/
RESULT getCylindersDefaultColor(Color& color);
/** Set the default plates color
\param color The new default plates color
\retval OK Operation succeeded
*/
RESULT setPlatesDefaultColor(const Color color);
/** Get the default plates color
\param color \out The default plates color
\retval OK Operation succeeded
*/
RESULT getPlatesDefaultColor(Color& color);
/** Set the color of the given vertex
\param vID The ID of the vertex
\param color A pointer to the new color. If NULL, the default vertices color is used
\retval OK Operation succeeded
\retval VertexNotFound No vertex was found with the given ID
*/
RESULT setVertexColor(VertexID vID, const Color* color = NULL);
/** Get the color of the given vertex
\param vID The ID of the vertex
\param color \out The color of the given vertex
\retval OK Operation succeeded
\retval VertexNotFound No vertex was found with the given ID
*/
RESULT getVertexColor(VertexID vID, Color& color);
/** Set the color of the given edge
\param eID The ID of the edge
\param color A pointer to the new color. If NULL, the default edges color is used
\retval OK Operation succeeded
\retval EdgeNotFound No edge was found with the given ID
*/
RESULT setEdgeColor(EdgeID eID, const Color* color = NULL);
/** Get the color of the given edge
\param eID The ID of the edge
\param color \out The color of the given edge
\retval OK Operation succeeded
\retval EdgeNotFound No edge was found with the given ID
*/
RESULT getEdgeColor(EdgeID eID, Color& color);
/** Set the color of the given face
\param fID The ID of the face
\param color A pointer to the new color. If NULL, the default faces color is used
\retval OK Operation succeeded
\retval FaceNotFound No face was found with the given ID
*/
RESULT setFaceColor(FaceID fID, const Color* color = NULL);
/** Get the color of the given face
\param fID The ID of the face
\param color \out The color of the given face
\retval OK Operation succeeded
\retval FaceNotFound No face was found with the given ID
*/
RESULT getFaceColor(FaceID fID, Color& color);
/** Set the color of the given line
\param lID The ID of the line
\param color A pointer to the new color. If NULL, the default lines color is used
\retval OK Operation succeeded
\retval LineNotFound No line was found with the given ID
*/
RESULT setLineColor(LineID lID, const Color* color = NULL);
/** Get the color of the given line
\param lID The ID of the line
\param color \out The color of the given line
\retval OK Operation succeeded
\retval LineNotFound No line was found with the given ID
*/
RESULT getLineColor(LineID lID, Color& color);
/** Set the color of the given sphere
\param sID The ID of the sphere
\param color A pointer to the new color. If NULL, the default spheres color is used
\retval OK Operation succeeded
\retval SphereNotFound No sphere was found with the given ID
*/
RESULT setSphereColor(SphereID sID, const Color* color = NULL);
/** Get the color of the given sphere
\param sID The ID of the sphere
\param color \out The color of the given sphere
\retval OK Operation succeeded
\retval SphereNotFound No sphere was found with the given ID
*/
RESULT getSphereColor(SphereID sID, Color& color);
/** Set the color of the given cylinder
\param cID The ID of the cylinder
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -