OpenCOVER
coBillboard.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef CO_BILLBOARD_H
9#define CO_BILLBOARD_H
10
24/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
25 *
26 * This library is open source and may be redistributed and/or modified under
27 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
28 * (at your option) any later version. The full license is in LICENSE file
29 * included with this distribution, and on the openscenegraph.org website.
30 *
31 * This library is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * OpenSceneGraph Public License for more details.
35*/
36
37/*
38 Billboards can either rotate about an axis or a point.
39
40 Axial billboards rotate about the axis specified by coBillboard::setAxis.
41 The rotation is about the origin (0,0,0). In all cases,
42 if the geometry is modeled in the XY plane, with -Z forward, then
43 the billboard is rotated so that the normal(Z by default) axis points
44 back to the eye point.
45 The +Y axis is the default axis of rotation. An axial rotate
46 billboard is specified by setting the rotation mode of the billboard to
47 the value coBillboard::AXIAL_ROT using coBillboard::setMode. The axis of
48rotation (x, y, z) is specified using coBillboard::setAxis.
49coBillboard::getAxis returns the axis of the coBillboard.
50
51If the rotation mode of the billboard is set to coBillboard::POINT_ROT_EYE,
52the billboard is rotated so that the +Z axis of the osg::Geometry aligns
53as closely as possible with the axis specified with
54pfBillboard::setAxis, in eye space. In particular, if the axis is
55+Y (as it is by default) and you display a text, then, the text always
56stays readable.
57
58If the rotation mode of the billboard is set to
59coBillboard::POINT_ROT_WORLD, the billboard is rotated so that the angle
60between the +Y axis of the osg::Geometry and axis specified with
61pfBillboard::setAxis (in world space) is minimized.
62
63Both coBillboard::AXIAL_ROT and coBillboard::POINT_ROT_WORLD billboards
64may "spin" about the rotation or alignment axis when viewed along that
65axis.
66*/
67
68#include <osg/Transform>
69#include <osg/Quat>
70#include <util/coExport.h>
71
72namespace opencover
73{
77class COVEREXPORT coBillboard : public osg::Transform
78{
79public:
81
82 coBillboard(const coBillboard &pat, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
83
84 virtual osg::Object *cloneType() const
85 {
86 return new coBillboard();
87 }
88 virtual osg::Object *clone(const osg::CopyOp &copyop) const
89 {
90 return new coBillboard(*this, copyop);
91 }
92 virtual bool isSameKindAs(const osg::Object *obj) const
93 {
94 return dynamic_cast<const coBillboard *>(obj) != NULL;
95 }
96 virtual const char *className() const
97 {
98 return "coBillboard";
99 }
100 virtual const char *libraryname() const
101 {
102 return "OpenCOVER";
103 }
104
105 virtual void accept(osg::NodeVisitor &nv);
106
108 {
109 STOP_ROT = 0,
112 POINT_ROT_WORLD
113 };
114
115 // rotation mode
118
119 // rotation axis for AXIAL_ROT billboard,
120 // "up" vector for POINT_ROT billboards
121 // default ist +Z (0 0 1)
122 void setAxis(const osg::Vec3 &axis);
123 const osg::Vec3 &getAxis() const;
124
125 // the normal of the geometry
126 // default is -Y (0 -1 0)
127 void setNormal(const osg::Vec3 &normal);
128 const osg::Vec3 &getNormal() const;
129
130 virtual bool computeLocalToWorldMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const;
131
132 virtual bool computeWorldToLocalMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const;
133
134protected:
135 virtual ~coBillboard()
136 {
137 }
138
139 osg::Vec3 _axis;
140 osg::Vec3 _normal;
141
143
144 mutable osg::Quat _rotation;
145
146 mutable osg::Matrix _cachedMatrix;
147 mutable osg::Matrix _cachedInvMatrix;
148
149private:
150 void checkAndAdjustNormal();
151};
152}
153#endif
Definition: ARToolKit.h:33
Definition: coBillboard.h:78
RotationMode
Definition: coBillboard.h:108
@ AXIAL_ROT
Definition: coBillboard.h:110
@ POINT_ROT_EYE
Definition: coBillboard.h:111
virtual bool computeLocalToWorldMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const
const osg::Vec3 & getAxis() const
virtual ~coBillboard()
Definition: coBillboard.h:135
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Definition: coBillboard.h:88
osg::Matrix _cachedInvMatrix
Definition: coBillboard.h:147
void setAxis(const osg::Vec3 &axis)
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: coBillboard.h:92
RotationMode getMode() const
osg::Quat _rotation
Definition: coBillboard.h:144
coBillboard(const coBillboard &pat, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osg::Matrix _cachedMatrix
Definition: coBillboard.h:146
osg::Vec3 _axis
Definition: coBillboard.h:139
virtual const char * libraryname() const
Definition: coBillboard.h:100
void setMode(RotationMode mode)
osg::Vec3 _normal
Definition: coBillboard.h:140
virtual const char * className() const
Definition: coBillboard.h:96
virtual void accept(osg::NodeVisitor &nv)
virtual osg::Object * cloneType() const
Definition: coBillboard.h:84
const osg::Vec3 & getNormal() const
RotationMode _mode
Definition: coBillboard.h:142
virtual bool computeWorldToLocalMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const
void setNormal(const osg::Vec3 &normal)