le3d - LightEngine 3D
A straightforward C++ 3D software engine for real-time graphics
renderer.h
Go to the documentation of this file.
1 
33 /*****************************************************************************
34  The renderer assumes a right handed coordinate system:
35  - X goes right
36  - Y goes top
37  - Z goes backward
38 ******************************************************************************/
39 
40 #ifndef LE_RENDERER_H
41 #define LE_RENDERER_H
42 
43 #include "global.h"
44 #include "config.h"
45 
46 #include "color.h"
47 #include "geometry.h"
48 #include "mesh.h"
49 #include "bset.h"
50 #include "rasterizer.h"
51 #include "trilist.h"
52 #include "verlist.h"
53 
54 /*****************************************************************************/
59 typedef enum {
66 
67 /*****************************************************************************/
73 {
74 public:
75  LeRenderer(int width = LE_RESOX_DEFAULT, int height = LE_RESOY_DEFAULT);
76  ~LeRenderer();
77 
78  void render(const LeMesh * mesh);
79  void render(const LeBSet * bset);
80  void flush();
81 
82  int getViewportCoordinates(const LeVertex & pos, LeVertex & viewCoords);
83 
84  void setViewPosition(const LeVertex & pos);
85  void setViewAngle(const LeVertex & angleYZX);
86  void updateViewMatrix();
87 
88  void setViewMatrix(const LeMatrix & view);
89 
90  void setViewport(int left, int top, int right, int bottom);
91  void setViewClipping(float near, float far);
92  void setViewProjection(float fov);
93  void setViewOffset(float offset);
94 
96 
97  void setFog(bool enable);
98  void setFogProperties(LeColor color, float near, float far);
99 
100  void setMipmapping(bool enable);
101 
102  void setTriangleList(LeTriList * trilist);
104 
105 private:
106  bool checkMemory(int noVertexes, int noTriangles);
107 
108  int build(const LeMesh * mesh, LeVertex vertexes[], LeTriangle tris[], int indices[]);
109  int build(const LeBSet * bset, LeVertex vertexes[], LeTriangle tris[], int indices[]);
110 
111  void updateFrustrum();
112 
113  void transform(const LeMatrix &matrix, const LeVertex srcVertexes[], LeVertex dstVertexes[], int nb);
114  int project(LeTriangle tris[], const int srcIndices[], int dstIndices[], int nb);
115  int clip3D(LeTriangle tris[], const int srcIndices[], int dstIndices[], int nb, LePlane &plane);
116  int clip2D(LeTriangle tris[], const int srcIndices[], int dstIndices[], int nb, LeAxis &axis);
117  int backculling(LeTriangle tris[], const int srcIndices[], int dstIndices[], int nb);
118 
119  LeVerList intVerlist;
120  LeTriList intTrilist;
121  LeVerList * usedVerlist;
122  LeTriList * usedTrilist;
124  int extra;
125  int extraMax;
127  LeColor * colors;
129  LeVertex viewPosition;
130  LeVertex viewAngle;
131  LeMatrix viewMatrix;
133  LePlane viewFrontPlan;
134  LePlane viewBackPlan;
136  LePlane viewLeftPlan;
137  LePlane viewRightPlan;
138  LePlane viewTopPlan;
139  LePlane viewBotPlan;
141  LeAxis viewLeftAxis;
142  LeAxis viewRightAxis;
143  LeAxis viewTopAxis;
144  LeAxis viewBottomAxis;
145  float viewFov;
147  float ztx;
148  float zty;
150  float vOffset;
152  LE_BACKCULLING_MODES backMode;
153  bool mipmappingEnable;
154  bool fogEnable;
155 };
156 
157 #endif // LE_RENDERER_H
void setViewOffset(float offset)
Set the renderer view offset (for triangle sorting)
Definition: renderer.cpp:361
void setViewAngle(const LeVertex &angleYZX)
Set the rendering view angle (in degrees)
Definition: renderer.cpp:279
Definition: renderer.h:64
Render meshes and billboard sets to 2D triangle lista.
Definition: renderer.h:72
LightEngine 3D: Billboard set container and manipulator.
void setFog(bool enable)
Enable or disable quadratic ambient fog.
Definition: renderer.cpp:392
LightEngine 3D: Mesh container and manipulator.
Represent a rasterizable triangle.
Definition: trilist.h:75
LightEngine 3D: General engine configuration file.
void setBackcullingMode(LE_BACKCULLING_MODES mode)
Set the backculling mode.
Definition: renderer.cpp:372
LightEngine 3D: Triangle lists.
LE_BACKCULLING_MODES
Backculling modes.
Definition: renderer.h:59
LightEngine 3D: Global helpers and definitions.
int getViewportCoordinates(const LeVertex &pos, LeVertex &viewCoords)
Return the viewport coordinates of a 3D vertex.
Definition: renderer.cpp:188
void flush()
Flush the currently selected triangle list.
Definition: renderer.cpp:235
void setViewClipping(float near, float far)
Set the rendering near & far clipping distances.
Definition: renderer.cpp:333
void setViewPosition(const LeVertex &pos)
Set the rendering view position.
Definition: renderer.cpp:269
Contain and manage triangle lists.
Definition: trilist.h:93
~LeRenderer()
Definition: renderer.cpp:73
Definition: renderer.h:62
void render(const LeMesh *mesh)
Render a 3D mesh.
Definition: renderer.cpp:83
Definition: renderer.h:60
LeRenderer(int width=LE_RESOX_DEFAULT, int height=LE_RESOY_DEFAULT)
Definition: renderer.cpp:49
LightEngine 3D: Vertex lists.
#define LE_RESOX_DEFAULT
Definition: config.h:37
Represent an RGBA color.
Definition: color.h:42
void setViewProjection(float fov)
Set the rendering field of view angle (in degrees)
Definition: renderer.cpp:346
#define LE_RESOY_DEFAULT
Definition: config.h:38
LightEngine 3D: Triangle rasterizer (textured and textured with alpha channel)
void setFogProperties(LeColor color, float near, float far)
Configure quadratic ambient fog characteristics.
Definition: renderer.cpp:404
Represent a vertex in 3D space.
Definition: geometry_scalar.h:46
Represent a 4x4 matrix to handle 3D transforms.
Definition: geometry_scalar.h:346
void setViewport(int left, int top, int right, int bottom)
Set the rendering viewport.
Definition: renderer.cpp:313
Definition: renderer.h:61
LightEngine 3D: Color implementation.
LeTriList * getTriangleList()
Retrieve the associated triangle list.
Definition: renderer.cpp:258
void setTriangleList(LeTriList *trilist)
Associate an external triangle list (for storage)
Definition: renderer.cpp:247
Represent an axis in 3D space.
Definition: geometry_scalar.h:265
Definition: renderer.h:63
LightEngine 3D: Vertex / axis / plane / matrix objects.
const LeVertex left
Definition: geometry_scalar.h:665
void setViewMatrix(const LeMatrix &view)
Set the rendering view matrix.
Definition: renderer.cpp:299
void updateViewMatrix()
Update the rendering view matrix with position, scaling and angle vectors.
Definition: renderer.cpp:288
const LeVertex right
Definition: geometry_scalar.h:666
Contain and manage vertex lists.
Definition: verlist.h:46
Represent a plane in 3D space.
Definition: geometry_scalar.h:302
Contain and manage a 3D mesh.
Definition: mesh.h:47
Contain and manage a billboard set.
Definition: bset.h:52
void setMipmapping(bool enable)
Enable or disable texture mipmapping.
Definition: renderer.cpp:382