Commit 32013e5c authored by tenter's avatar tenter

add renderobjects in camera node

parent 5ae56023
Pipeline #3681 failed with stage
in 38 minutes and 59 seconds
......@@ -61,6 +61,8 @@
//== INCLUDES =================================================================
#include "CameraNode.hh"
#include <ACG/GL/IRenderer.hh>
//== NAMESPACES ===============================================================
namespace ACG {
......@@ -363,6 +365,124 @@ void CameraNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
//----------------------------------------------------------------------------
void CameraNode::getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
if (!vbo_.is_valid())
{
// cube in clip space
float data[] =
{
// float4 pos float2 coeff
-1, -1, 1, 1, 1, 0, //0 frustum vertices..
-1, -1, -1, 1, 1, 0, //1
1, -1, -1, 1, 1, 0, //2
1, -1, 1, 1, 1, 0, //3
-1, 1, 1, 1, 1, 0, //4
1, 1, 1, 1, 1, 0, //5
1, 1, -1, 1, 1, 0, //6
-1, 1, -1, 1, 1, 0, //7
0, 0, 0, 0, 0, 1, //8 cam origin vertex
};
vbo_.upload(sizeof(data), data, GL_STATIC_DRAW);
vdecl_.clear();
vdecl_.addElement(GL_FLOAT, 4, VERTEX_USAGE_POSITION);
vdecl_.addElement(GL_FLOAT, 2, VERTEX_USAGE_SHADER_INPUT, size_t(0), "inCamOriginCoeff");
}
if (!ibo_.is_valid())
{
int data[] =
{
// frustum triangles
3,2,6 , 6,5,3 , // right
1,0,4 , 4,7,1 , // left
4,5,6 , 6,7,4 , // top
0,1,2 , 2,3,0 , // bottom
0,3,5 , 5,4,0 , // back
// 2,1,7 , 7,6,2 , // front
// frustum lines
3,2, 2,6, 6,5, 5,3, // right
1,0, 0,4, 4,7, 7,1, // left
4,5, 5,6, 6,7, 7,4, // top
0,1, 1,2, 2,3, 3,0, // bottom
0,3, 3,5, 5,4, 4,0, // back
2,1, 1,7, 7,6, 6,2, // front
// cam origin to near plane lines
8,1, 8,2, 8,6, 8,7
};
ibo_.upload(sizeof(data), data, GL_STATIC_DRAW);
}
GLMatrixf camWorldToClip = projection_ * modelView_;
GLMatrixf camClipToWorld(camWorldToClip);
camClipToWorld.invert();
GLMatrixf camViewToWorld = modelView_;
camViewToWorld.invert();
Vec4f camOriginWS(camViewToWorld(0, 3),
camViewToWorld(1, 3),
camViewToWorld(2, 3),
1.0f);
RenderObject obj;
obj.initFromState(&_state);
obj.depthTest = true;
obj.shaderDesc.shadeMode = SG_SHADE_UNLIT;
obj.vertexBuffer = vbo_.id();
obj.indexBuffer = ibo_.id();
obj.vertexDecl = &vdecl_;
obj.shaderDesc.vertexTemplateFile = "Camera/vertex.glsl";
obj.setUniform("clipSpaceToWorld", camClipToWorld);
obj.setUniform("camOriginWS", camOriginWS);
bool hasOrigin = projection_.isPerspective();
GLsizei lineOffset = 5 * 6;
if (showFrustum_)
{
obj.blending = true;
obj.emissive = Vec3f(0.0f, 1.0f, 0.0f);
obj.alpha = 0.01f;
obj.glDrawElements(GL_TRIANGLES, lineOffset, GL_UNSIGNED_INT, 0);
// _renderer->addRenderObject(&obj);
GLsizei lineCount = hasOrigin ? 4 * 7 : 4 * 6;
obj.emissive = Vec3f(0.0f, 0.5f, 0.0f);
obj.alpha = 1.0f;
obj.blending = false;
obj.glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_INT, (GLvoid*)(lineOffset * sizeof(int)));
_renderer->addRenderObject(&obj);
}
else
{
obj.emissive = Vec3f(0.0f, 0.5f, 0.0f);
// only front plane
GLsizei lineCount = hasOrigin ? 4 * 1 : 4 * 2;
lineOffset += 4 * 5;
obj.glDrawElements(GL_LINES, lineCount, GL_UNSIGNED_INT, (GLvoid*)(lineOffset * sizeof(int)));
_renderer->addRenderObject(&obj);
}
}
//----------------------------------------------------------------------------
void CameraNode::pick(GLState& _state, PickTarget /*_target*/) {
_state.pick_set_maximum(2);
......
......@@ -66,6 +66,7 @@
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/GLPrimitives.hh>
#include <ACG/GL/globjects.hh>
#include <string>
#include <vector>
......@@ -107,6 +108,9 @@ public:
/// drawing
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// create render objects
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// picking
void pick(GLState& _state, PickTarget _target);
......@@ -164,6 +168,9 @@ private:
GLCylinder* cylinder_;
GLCone* cone_;
GeometryBuffer vbo_;
IndexBuffer ibo_;
VertexDeclaration vdecl_;
QString encodedView_;
......
include (plugin)
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/Camera/Camera.hh)
openflipper_plugin (INSTALLDATA Icons)
openflipper_plugin (INSTALLDATA Icons Shaders)
else()
message( WARNING "Plugin TypeCamera disabled due to missing Camera ObjectType" )
endif ()
\ No newline at end of file
#version 130
in vec2 inCamOriginCoeff;
uniform mat4 clipSpaceToWorld;
uniform vec4 camOriginWS; // cam origin in world space
void main()
{
SG_VERTEX_BEGIN;
// transform clip to world space
vec4 posWS = clipSpaceToWorld * SG_INPUT_POSOS;
posWS.xyz /= posWS.w;
posWS.w = 1;
posWS = inCamOriginCoeff.x * posWS + inCamOriginCoeff.y * camOriginWS;
sg_vPosVS = g_mWV * posWS;
sg_vPosPS = g_mP * sg_vPosVS;
SG_VERTEX_END;
#ifdef SG_OUTPUT_POSOS
SG_OUTPUT_POSOS = posWS;
#endif
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment