1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
2 | * |
---|
3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
5 | * (at your option) any later version. The full license is in LICENSE file |
---|
6 | * included with this distribution, and on the openscenegraph.org website. |
---|
7 | * |
---|
8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
9 | * You have to aquire licenses for all used proprietary modules. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * OpenSceneGraph Public License for more details. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <visual_draw3D.h> |
---|
18 | |
---|
19 | using namespace osgVisual; |
---|
20 | |
---|
21 | visual_draw3D::visual_draw3D(void) |
---|
22 | { |
---|
23 | #include <leakDetection.h> |
---|
24 | } |
---|
25 | |
---|
26 | visual_draw3D::~visual_draw3D(void) |
---|
27 | { |
---|
28 | } |
---|
29 | |
---|
30 | void visual_draw3D::init( osg::CoordinateSystemNode* rootNode_, osgViewer::Viewer *viewer_ ) |
---|
31 | { |
---|
32 | osg::Matrix testmatrix = viewer_->getCamera()->getViewMatrix(); |
---|
33 | |
---|
34 | testmatrix.makeTranslate( 2.0, 2.0, 2.0 ); |
---|
35 | //testmatrix. |
---|
36 | osg::ref_ptr<osg::Geode> hudGeode = new osg::Geode(); |
---|
37 | rootNode_->addChild( hudGeode ); |
---|
38 | |
---|
39 | |
---|
40 | // create background |
---|
41 | |
---|
42 | // configuring background shape |
---|
43 | float depth = -0.1; // Paint background behind text. |
---|
44 | osg::Vec4f bgColor_rgba = osg::Vec4(1.0f,1.0,0.8f,0.2f); |
---|
45 | osg::Vec3 hudCenter = osg::Vec3(0.0, 0.0, 0.0); |
---|
46 | float baseSize = 200; |
---|
47 | float addSize = 70; |
---|
48 | |
---|
49 | |
---|
50 | osg::Geometry* hudBackground = new osg::Geometry; |
---|
51 | |
---|
52 | osg::Vec3Array* vertices = new osg::Vec3Array; |
---|
53 | vertices->push_back(hudCenter+osg::Vec3(baseSize+addSize, baseSize, depth)); |
---|
54 | vertices->push_back(hudCenter+osg::Vec3(baseSize, baseSize+addSize, depth)); |
---|
55 | vertices->push_back(hudCenter+osg::Vec3(-baseSize , baseSize+addSize, depth)); |
---|
56 | vertices->push_back(hudCenter+osg::Vec3(-baseSize-addSize, baseSize,depth)); |
---|
57 | vertices->push_back(hudCenter+osg::Vec3(-baseSize-addSize, -baseSize,depth)); |
---|
58 | vertices->push_back(hudCenter+osg::Vec3(-baseSize , -baseSize-addSize, depth)); |
---|
59 | vertices->push_back(hudCenter+osg::Vec3(baseSize, -baseSize-addSize, depth)); |
---|
60 | vertices->push_back(hudCenter+osg::Vec3(baseSize+addSize, -baseSize, depth)); |
---|
61 | hudBackground->setVertexArray(vertices); |
---|
62 | |
---|
63 | osg::Vec3Array* normals = new osg::Vec3Array; |
---|
64 | normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); |
---|
65 | hudBackground->setNormalArray(normals); |
---|
66 | hudBackground->setNormalBinding(osg::Geometry::BIND_OVERALL); |
---|
67 | |
---|
68 | osg::Vec4Array* colors = new osg::Vec4Array; |
---|
69 | colors->push_back( bgColor_rgba ); |
---|
70 | hudBackground->setColorArray(colors); |
---|
71 | hudBackground->setColorBinding(osg::Geometry::BIND_OVERALL); |
---|
72 | |
---|
73 | hudBackground->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON,0,8)); |
---|
74 | |
---|
75 | osg::StateSet* stateset = hudBackground->getOrCreateStateSet(); |
---|
76 | stateset->setMode(GL_BLEND,osg::StateAttribute::ON); |
---|
77 | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
---|
78 | |
---|
79 | } |
---|