28 #include <Eigen/Dense> 42 "out vec4 out_Color;\n" 46 " out_Color = ex_Color;\n" 47 " gl_FragDepth = depth;\n" 53 "in vec4 in_Position;\n" 54 "out vec4 ex_Color;\n" 56 "uniform mat4 modelMatrix;\n" 57 "uniform mat4 viewMatrix;\n" 58 "uniform mat4 projectionMatrix;\n" 59 "uniform vec4 in_Color;\n" 60 "uniform float nearPlane;\n" 61 "uniform float farPlane;\n" 64 " gl_Position = (viewMatrix * modelMatrix) * in_Position;\n" 65 " depth = (farPlane+nearPlane)/(farPlane-nearPlane) + ( (2*nearPlane*farPlane)/(farPlane-nearPlane) ) * (1/gl_Position[2]);\n" 66 " depth = (depth+1.0)/2.0;\n" 67 " gl_Position = projectionMatrix * gl_Position;\n" 68 " ex_Color = in_Color;\n" 95 #ifdef TUCANOSHADERDIR 106 camerarep_shader.
load(
"phongshader", shader_dir);
117 glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
119 camerarep_shader.
bind();
126 Eigen::Vector4f color (1.0, 1.0, 0.0, 1.0);
129 camerarep_shader.
setUniform(
"has_color",
true);
130 camerarep_shader.
setUniform(
"default_color", color);
134 glEnable(GL_DEPTH_TEST);
138 glDisable(GL_DEPTH_TEST);
140 camerarep_shader.
unbind();
153 vector< Eigen::Vector4f > vert;
154 vector< Eigen::Vector3f > norm;
155 vector< Eigen::Vector4f > color;
156 vector< GLuint > elementsVertices;
162 vert.push_back ( Eigen::Vector4f( 0.25, -0.25, 0.5, 1.0) );
163 vert.push_back ( Eigen::Vector4f( 0.50, -0.50, -0.5, 1.0) );
164 vert.push_back ( Eigen::Vector4f( 0.50, 0.50, -0.5, 1.0) );
165 vert.push_back ( Eigen::Vector4f( 0.25, 0.25, 0.5, 1.0) );
166 norm.push_back ( Eigen::Vector3f( 1.0, 0.0, 0.0) );
167 norm.push_back ( Eigen::Vector3f( 1.0, 0.0, 0.0) );
168 norm.push_back ( Eigen::Vector3f( 1.0, 0.0, 0.0) );
169 norm.push_back ( Eigen::Vector3f( 1.0, 0.0, 0.0) );
170 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
171 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
172 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
173 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
174 elementsVertices.push_back(0);
175 elementsVertices.push_back(1);
176 elementsVertices.push_back(2);
177 elementsVertices.push_back(2);
178 elementsVertices.push_back(3);
179 elementsVertices.push_back(0);
182 vert.push_back ( Eigen::Vector4f(-0.25, -0.25, 0.5, 1.0) );
183 vert.push_back ( Eigen::Vector4f(-0.50, -0.50, -0.5, 1.0) );
184 vert.push_back ( Eigen::Vector4f(-0.50, 0.50, -0.5, 1.0) );
185 vert.push_back ( Eigen::Vector4f(-0.25, 0.25, 0.5, 1.0) );
186 norm.push_back ( Eigen::Vector3f( -1.0, 0.0, 0.0) );
187 norm.push_back ( Eigen::Vector3f( -1.0, 0.0, 0.0) );
188 norm.push_back ( Eigen::Vector3f( -1.0, 0.0, 0.0) );
189 norm.push_back ( Eigen::Vector3f( -1.0, 0.0, 0.0) );
190 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
191 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
192 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
193 color.push_back( Eigen::Vector4f( 1.0, 0.0, 0.0, 1.0) );
194 elementsVertices.push_back(4);
195 elementsVertices.push_back(7);
196 elementsVertices.push_back(6);
197 elementsVertices.push_back(6);
198 elementsVertices.push_back(5);
199 elementsVertices.push_back(4);
202 vert.push_back ( Eigen::Vector4f( 0.25, -0.25, 0.5, 1.0) );
203 vert.push_back ( Eigen::Vector4f( 0.50, -0.50, -0.5, 1.0) );
204 vert.push_back ( Eigen::Vector4f(-0.25, -0.25, 0.5, 1.0) );
205 vert.push_back ( Eigen::Vector4f(-0.50, -0.50, -0.5, 1.0) );
206 norm.push_back ( Eigen::Vector3f( 0.0, -1.0, 0.0) );
207 norm.push_back ( Eigen::Vector3f( 0.0, -1.0, 0.0) );
208 norm.push_back ( Eigen::Vector3f( 0.0, -1.0, 0.0) );
209 norm.push_back ( Eigen::Vector3f( 0.0, -1.0, 0.0) );
210 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
211 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
212 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
213 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
214 elementsVertices.push_back(8);
215 elementsVertices.push_back(10);
216 elementsVertices.push_back(11);
217 elementsVertices.push_back(11);
218 elementsVertices.push_back(9);
219 elementsVertices.push_back(8);
222 vert.push_back ( Eigen::Vector4f( 0.25, 0.25, 0.5, 1.0) );
223 vert.push_back ( Eigen::Vector4f( 0.50, 0.50, -0.5, 1.0) );
224 vert.push_back ( Eigen::Vector4f(-0.25, 0.25, 0.5, 1.0) );
225 vert.push_back ( Eigen::Vector4f(-0.50, 0.50, -0.5, 1.0) );
226 norm.push_back ( Eigen::Vector3f( 0.0, 1.0, 0.0) );
227 norm.push_back ( Eigen::Vector3f( 0.0, 1.0, 0.0) );
228 norm.push_back ( Eigen::Vector3f( 0.0, 1.0, 0.0) );
229 norm.push_back ( Eigen::Vector3f( 0.0, 1.0, 0.0) );
230 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
231 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
232 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
233 color.push_back( Eigen::Vector4f( 0.0, 1.0, 0.0, 1.0) );
234 elementsVertices.push_back(12);
235 elementsVertices.push_back(13);
236 elementsVertices.push_back(15);
237 elementsVertices.push_back(15);
238 elementsVertices.push_back(14);
239 elementsVertices.push_back(12);
242 vert.push_back ( Eigen::Vector4f( 0.5, -0.50, -0.5, 1.0) );
243 vert.push_back ( Eigen::Vector4f( 0.5, 0.50, -0.5, 1.0) );
244 vert.push_back ( Eigen::Vector4f(-0.5, -0.50, -0.5, 1.0) );
245 vert.push_back ( Eigen::Vector4f(-0.5, 0.50, -0.5, 1.0) );
246 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, -1.0) );
247 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, -1.0) );
248 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, -1.0) );
249 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, -1.0) );
250 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
251 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
252 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
253 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
254 elementsVertices.push_back(16);
255 elementsVertices.push_back(18);
256 elementsVertices.push_back(19);
257 elementsVertices.push_back(19);
258 elementsVertices.push_back(17);
259 elementsVertices.push_back(16);
262 vert.push_back ( Eigen::Vector4f( 0.25, -0.25, 0.5, 1.0) );
263 vert.push_back ( Eigen::Vector4f( 0.25, 0.25, 0.5, 1.0) );
264 vert.push_back ( Eigen::Vector4f(-0.25, -0.25, 0.5, 1.0) );
265 vert.push_back ( Eigen::Vector4f(-0.25, 0.25, 0.5, 1.0) );
266 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, 1.0) );
267 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, 1.0) );
268 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, 1.0) );
269 norm.push_back ( Eigen::Vector3f( 0.0, 0.0, 1.0) );
270 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
271 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
272 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
273 color.push_back( Eigen::Vector4f( 0.0, 0.0, 1.0, 1.0) );
274 elementsVertices.push_back(20);
275 elementsVertices.push_back(21);
276 elementsVertices.push_back(23);
277 elementsVertices.push_back(23);
278 elementsVertices.push_back(22);
279 elementsVertices.push_back(20);
float getNearPlane(void) const
Returns near plane value.
Definition: camera.hpp:319
void loadNormals(vector< Eigen::Vector3f > &norm)
Load normals (x,y,z) as a vertex attribute.
Definition: mesh.hpp:384
void getViewMatrix(GLdouble *matrix)
Return the modelview matrix as a GLdouble array.
Definition: camera.hpp:126
void loadColors(vector< Eigen::Vector4f > &clrs)
Load colors (r,g,b,a) as a vertex attribute.
Definition: mesh.hpp:438
void initialize(string shader_dir="../effects/shaders/")
Initializes shaders.
Definition: camerarep.hpp:104
void getProjectionMatrix(GLdouble *matrix)
Return the projection matrix as a GLdouble array.
Definition: camera.hpp:142
const string camerarep_vertex_code
Default vertex shader for rendering trackball representation.
Definition: camerarep.hpp:51
Definition: bufferobject.hpp:34
float getFarPlane(void) const
Returns far plane value.
Definition: camera.hpp:328
void initialize(void)
Calls all the functions related to the shader initialization, i.e., creates, loads the shaders from t...
Definition: shader.hpp:641
void render(const Tucano::Camera &camera, const Tucano::Camera &light)
Render camera representation.
Definition: camerarep.hpp:114
A Shader object represents one GLSL program.
Definition: shader.hpp:45
Camera visual representation.
Definition: camerarep.hpp:77
void loadIndices(vector< GLuint > &ind)
Load indices into indices array.
Definition: mesh.hpp:448
const string camerarep_fragment_code
Default fragment shader for rendering camera representation.
Definition: camerarep.hpp:39
CameraRep()
Default Constructor.
Definition: camerarep.hpp:89
void setDefaultAttribLocations(void)
Sets default attribute locations. vertex coords -> location 0 normals -> location 1 colors -> locatio...
Definition: mesh.hpp:474
void resetModelMatrix(void)
Resets the model matrix.
Definition: model.hpp:159
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
Eigen::Affine3f model_matrix
Model matrix, holds information about the models location and orientation.
Definition: model.hpp:21
virtual void unbindBuffers(void)
Unbinds all buffers.
Definition: mesh.hpp:702
void loadVertices(vector< Eigen::Vector4f > &vert)
Load vertices (x,y,z,w) and creates appropriate vertex attribute. The default attribute name is "in_P...
Definition: mesh.hpp:312
Tucano::Shader camerarep_shader
Definition: camerarep.hpp:81
void createGeometry(void)
Define camera geometry.
Definition: camerarep.hpp:151
void load(string name, string shader_dir="")
Loads a shader given a directory and a name. Searches for all shader extensions in directory...
Definition: shader.hpp:436
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
virtual void renderElements(void)
Call the draw method for rendering triangles. This method requires that a index buffer has been creat...
Definition: mesh.hpp:726
virtual void bindBuffers(void)
Binds all buffers.
Definition: mesh.hpp:677
#define stringify(x)
Definition: misc.hpp:33
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
Defines an abstract camera with a projection and view matrices.
Definition: camera.hpp:37
void setAttributeLocation(Shader *shader)
Automatically sets the attribute locations for a given Shader.
Definition: mesh.hpp:541
Eigen::Vector4f getViewport(void) const
Returns the viewport coordinates.
Definition: camera.hpp:246
void setUniform(GLint location, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given a location and the vector values. ...
Definition: shader.hpp:1258